Skip to content

Commit

Permalink
Save config in custom scripts editor, stop accidental 'refreshed' popup
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed Aug 30, 2024
1 parent dc79d5d commit 1a456bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion include/ui/customscriptseditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ private slots:
void dialogButtonClicked(QAbstractButton *button);
void createNewScript();
void loadScript();
void refreshScripts();
bool refreshScripts();
void userRefreshScripts();
void removeSelectedScripts();
void openSelectedScripts();
};
Expand Down
18 changes: 13 additions & 5 deletions src/ui/customscriptseditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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() {
Expand All @@ -264,6 +271,7 @@ void CustomScriptsEditor::save() {
}

userConfig.setCustomScripts(paths, enabledStates);
userConfig.save();
this->hasUnsavedChanges = false;
this->refreshScripts();
}
Expand Down

0 comments on commit 1a456bc

Please sign in to comment.