Connect custom script editor to shortcuts editor

This commit is contained in:
GriffinR 2023-09-10 17:04:44 -04:00
parent a5a864926a
commit 1c081f2011
4 changed files with 18 additions and 12 deletions

View file

@ -387,6 +387,7 @@ private:
void initTilesetEditor();
bool initRegionMapEditor(bool silent = false);
void initShortcutsEditor();
void initCustomScriptsEditor();
void connectSubEditorsToShortcutsEditor();
bool isProjectOpen();

View file

@ -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);

View file

@ -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();

View file

@ -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<QAction *>())
if (!action->objectName().isEmpty())