diff --git a/include/mainwindow.h b/include/mainwindow.h index bb85e62a..b2b651a8 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -95,7 +95,7 @@ public: Q_INVOKABLE bool getBorderVisibility(); Q_INVOKABLE void setSmartPathsEnabled(bool visible); Q_INVOKABLE bool getSmartPathsEnabled(); - Q_INVOKABLE void registerAction(QString functionName, QString actionName); + Q_INVOKABLE void registerAction(QString functionName, QString actionName, QString shortcut = ""); public slots: diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 310fe8b1..e562ae64 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2985,7 +2985,7 @@ bool MainWindow::getSmartPathsEnabled() { return this->ui->checkBox_smartPaths->isChecked(); } -void MainWindow::registerAction(QString functionName, QString actionName) { +void MainWindow::registerAction(QString functionName, QString actionName, QString shortcut) { if (!this->ui || !this->ui->menuTools) return; @@ -2993,7 +2993,10 @@ void MainWindow::registerAction(QString functionName, QString actionName) { if (Scripting::numRegisteredActions() == 1) { this->ui->menuTools->addSection("Custom Actions"); } - this->ui->menuTools->addAction(actionName, [actionName](){ + QAction *action = this->ui->menuTools->addAction(actionName, [actionName](){ Scripting::invokeAction(actionName); }); + if (!shortcut.isEmpty()) { + action->setShortcut(QKeySequence(shortcut)); + } } diff --git a/test_script.js b/test_script.js index 31965ce5..c10f9b39 100644 --- a/test_script.js +++ b/test_script.js @@ -11,22 +11,18 @@ function applyTint(palette, tint) { } } -let visible = true; - function applyTintToPalettes(tint) { try { - // const primaryPalettes = map.getPrimaryTilesetPalettes() - // for (let i = 0; i < primaryPalettes.length; i++) - // applyTint(primaryPalettes[i], tint) + const primaryPalettes = map.getPrimaryTilesetPalettes() + for (let i = 0; i < primaryPalettes.length; i++) + applyTint(primaryPalettes[i], tint) - // const secondaryPalettes = map.getSecondaryTilesetPalettes() - // for (let i = 0; i < secondaryPalettes.length; i++) - // applyTint(secondaryPalettes[i], tint) + const secondaryPalettes = map.getSecondaryTilesetPalettes() + for (let i = 0; i < secondaryPalettes.length; i++) + applyTint(secondaryPalettes[i], tint) - // map.setPrimaryTilesetPalettesPreview(primaryPalettes) - // map.setSecondaryTilesetPalettesPreview(secondaryPalettes) - console.log(map.setSmartPathsEnabled(visible)) - visible = !visible + map.setPrimaryTilesetPalettesPreview(primaryPalettes) + map.setSecondaryTilesetPalettesPreview(secondaryPalettes) } catch(err) { console.log(err) } @@ -36,9 +32,9 @@ function applyTintToPalettes(tint) { export function on_project_opened(projectPath) { try { console.log(`opened ${projectPath}`) - map.registerAction("resetTint", "View Day Tint") - map.registerAction("applyMorningTint", "View Morning Tint") - map.registerAction("applyNightTint", "View Night Tint") + map.registerAction("resetTint", "View Day Tint", "K") + map.registerAction("applyMorningTint", "View Morning Tint", "N") + map.registerAction("applyNightTint", "View Night Tint", "Ctrl+J") } catch(err) { console.log(err) }