From 1a456bc47b3a8c25518c66978d48838e85a0ae61 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 30 Aug 2024 11:56:35 -0400 Subject: [PATCH] Save config in custom scripts editor, stop accidental 'refreshed' popup --- include/ui/customscriptseditor.h | 3 ++- src/ui/customscriptseditor.cpp | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/ui/customscriptseditor.h b/include/ui/customscriptseditor.h index 27238c4e..0e5d3489 100644 --- a/include/ui/customscriptseditor.h +++ b/include/ui/customscriptseditor.h @@ -55,7 +55,8 @@ private slots: void dialogButtonClicked(QAbstractButton *button); void createNewScript(); void loadScript(); - void refreshScripts(); + bool refreshScripts(); + void userRefreshScripts(); void removeSelectedScripts(); void openSelectedScripts(); }; diff --git a/src/ui/customscriptseditor.cpp b/src/ui/customscriptseditor.cpp index 13650053..b7180b92 100644 --- a/src/ui/customscriptseditor.cpp +++ b/src/ui/customscriptseditor.cpp @@ -27,7 +27,7 @@ CustomScriptsEditor::CustomScriptsEditor(QWidget *parent) : connect(ui->button_CreateNewScript, &QAbstractButton::clicked, this, &CustomScriptsEditor::createNewScript); connect(ui->button_LoadScript, &QAbstractButton::clicked, this, &CustomScriptsEditor::loadScript); - connect(ui->button_RefreshScripts, &QAbstractButton::clicked, this, &CustomScriptsEditor::refreshScripts); + connect(ui->button_RefreshScripts, &QAbstractButton::clicked, this, &CustomScriptsEditor::userRefreshScripts); connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &CustomScriptsEditor::dialogButtonClicked); this->initShortcuts(); @@ -57,7 +57,7 @@ void CustomScriptsEditor::initShortcuts() { shortcut_load->setObjectName("shortcut_load"); shortcut_load->setWhatsThis("Load Script..."); - auto *shortcut_refresh = new Shortcut(QKeySequence(), this, SLOT(refreshScripts())); + auto *shortcut_refresh = new Shortcut(QKeySequence(), this, SLOT(userRefreshScripts())); shortcut_refresh->setObjectName("shortcut_refresh"); shortcut_refresh->setWhatsThis("Refresh Scripts"); @@ -238,14 +238,21 @@ void CustomScriptsEditor::openSelectedScripts() { this->openScript(item); } -void CustomScriptsEditor::refreshScripts() { +// When the user refreshes the scripts we show a little tooltip as feedback. +// We don't want this tooltip to display when we refresh programmatically, like when changes are saved. +void CustomScriptsEditor::userRefreshScripts() { + if (refreshScripts()) + QToolTip::showText(ui->button_RefreshScripts->mapToGlobal(QPoint(0, 0)), "Refreshed!"); +} + +bool CustomScriptsEditor::refreshScripts() { if (this->hasUnsavedChanges) { if (this->prompt("Scripts have been modified, save changes and reload the script engine?", QMessageBox::Yes) == QMessageBox::No) - return; + return false; this->save(); } - QToolTip::showText(ui->button_RefreshScripts->mapToGlobal(QPoint(0, 0)), "Refreshed!"); emit reloadScriptEngine(); + return true; } void CustomScriptsEditor::save() { @@ -264,6 +271,7 @@ void CustomScriptsEditor::save() { } userConfig.setCustomScripts(paths, enabledStates); + userConfig.save(); this->hasUnsavedChanges = false; this->refreshScripts(); }