diff --git a/include/mainwindow.h b/include/mainwindow.h index 41c6c7f0..36f89d48 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -387,6 +387,7 @@ private: void initTilesetEditor(); bool initRegionMapEditor(bool silent = false); void initShortcutsEditor(); + void initCustomScriptsEditor(); void connectSubEditorsToShortcutsEditor(); bool isProjectOpen(); diff --git a/include/ui/customscriptseditor.h b/include/ui/customscriptseditor.h index fd92b306..d54a7cc3 100644 --- a/include/ui/customscriptseditor.h +++ b/include/ui/customscriptseditor.h @@ -24,6 +24,9 @@ public: signals: void reloadScriptEngine(); +public slots: + void applyUserShortcuts(); + private: Ui::CustomScriptsEditor *ui; @@ -46,7 +49,6 @@ private: void restoreWindowState(); void initShortcuts(); QObjectList shortcutableObjects() const; - void applyUserShortcuts(); private slots: void dialogButtonClicked(QAbstractButton *button); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f568f505..e26dd382 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1811,6 +1811,11 @@ void MainWindow::connectSubEditorsToShortcutsEditor() { if (regionMapEditor) connect(shortcutsEditor, &ShortcutsEditor::shortcutsSaved, regionMapEditor, &RegionMapEditor::applyUserShortcuts); + + if (!customScriptsEditor) + initCustomScriptsEditor(); + connect(shortcutsEditor, &ShortcutsEditor::shortcutsSaved, + customScriptsEditor, &CustomScriptsEditor::applyUserShortcuts); } void MainWindow::on_actionPencil_triggered() @@ -2734,15 +2739,18 @@ void MainWindow::on_actionProject_Settings_triggered() { } void MainWindow::on_actionCustom_Scripts_triggered() { - if (!this->customScriptsEditor) { - this->customScriptsEditor = new CustomScriptsEditor(this); - connect(this->customScriptsEditor, &CustomScriptsEditor::reloadScriptEngine, - this, &MainWindow::reloadScriptEngine); - } + if (!this->customScriptsEditor) + initCustomScriptsEditor(); openSubWindow(this->customScriptsEditor); } +void MainWindow::initCustomScriptsEditor() { + this->customScriptsEditor = new CustomScriptsEditor(this); + connect(this->customScriptsEditor, &CustomScriptsEditor::reloadScriptEngine, + this, &MainWindow::reloadScriptEngine); +} + void MainWindow::reloadScriptEngine() { Scripting::init(this); this->ui->graphicsView_Map->clearOverlayMap(); diff --git a/src/ui/customscriptseditor.cpp b/src/ui/customscriptseditor.cpp index 7a288029..6daeb0eb 100644 --- a/src/ui/customscriptseditor.cpp +++ b/src/ui/customscriptseditor.cpp @@ -44,8 +44,7 @@ void CustomScriptsEditor::initShortcuts() { shortcut_remove->setObjectName("shortcut_remove"); shortcut_remove->setWhatsThis("Remove Selected Scripts"); - // TODO: Prevent ambiguity with MainWindow - auto *shortcut_open = new Shortcut(QKeySequence("Ctrl+O"), this, SLOT(openSelectedScripts())); + auto *shortcut_open = new Shortcut(QKeySequence(), this, SLOT(openSelectedScripts())); shortcut_open->setObjectName("shortcut_open"); shortcut_open->setWhatsThis("Open Selected Scripts"); @@ -57,9 +56,6 @@ void CustomScriptsEditor::initShortcuts() { shortcut_reload->setObjectName("shortcut_reload"); shortcut_reload->setWhatsThis("Reload Scripts"); - //connect(new QShortcut(QKeySequence("Backspace"), this), &QShortcut::activated, this, &CustomScriptsEditor::removeSelectedScripts); - //connect(new QShortcut(QKeySequence("Ctrl+O"), this), &QShortcut::activated, this, &CustomScriptsEditor::openSelectedScripts); - shortcutsConfig.load(); shortcutsConfig.setDefaultShortcuts(shortcutableObjects()); applyUserShortcuts(); @@ -78,7 +74,6 @@ QObjectList CustomScriptsEditor::shortcutableObjects() const { return shortcutable_objects; } -// TODO: Connect to shorcuts editor void CustomScriptsEditor::applyUserShortcuts() { for (auto *action : findChildren()) if (!action->objectName().isEmpty())