Add ability to set keyboard shortcuts for custom actions

This commit is contained in:
Marcus Huderle 2020-05-08 08:49:29 -05:00
parent 7072c001af
commit 71242e5714
3 changed files with 17 additions and 18 deletions

View file

@ -95,7 +95,7 @@ public:
Q_INVOKABLE bool getBorderVisibility(); Q_INVOKABLE bool getBorderVisibility();
Q_INVOKABLE void setSmartPathsEnabled(bool visible); Q_INVOKABLE void setSmartPathsEnabled(bool visible);
Q_INVOKABLE bool getSmartPathsEnabled(); Q_INVOKABLE bool getSmartPathsEnabled();
Q_INVOKABLE void registerAction(QString functionName, QString actionName); Q_INVOKABLE void registerAction(QString functionName, QString actionName, QString shortcut = "");
public slots: public slots:

View file

@ -2985,7 +2985,7 @@ bool MainWindow::getSmartPathsEnabled() {
return this->ui->checkBox_smartPaths->isChecked(); 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) if (!this->ui || !this->ui->menuTools)
return; return;
@ -2993,7 +2993,10 @@ void MainWindow::registerAction(QString functionName, QString actionName) {
if (Scripting::numRegisteredActions() == 1) { if (Scripting::numRegisteredActions() == 1) {
this->ui->menuTools->addSection("Custom Actions"); this->ui->menuTools->addSection("Custom Actions");
} }
this->ui->menuTools->addAction(actionName, [actionName](){ QAction *action = this->ui->menuTools->addAction(actionName, [actionName](){
Scripting::invokeAction(actionName); Scripting::invokeAction(actionName);
}); });
if (!shortcut.isEmpty()) {
action->setShortcut(QKeySequence(shortcut));
}
} }

View file

@ -11,22 +11,18 @@ function applyTint(palette, tint) {
} }
} }
let visible = true;
function applyTintToPalettes(tint) { function applyTintToPalettes(tint) {
try { try {
// const primaryPalettes = map.getPrimaryTilesetPalettes() const primaryPalettes = map.getPrimaryTilesetPalettes()
// for (let i = 0; i < primaryPalettes.length; i++) for (let i = 0; i < primaryPalettes.length; i++)
// applyTint(primaryPalettes[i], tint) applyTint(primaryPalettes[i], tint)
// const secondaryPalettes = map.getSecondaryTilesetPalettes() const secondaryPalettes = map.getSecondaryTilesetPalettes()
// for (let i = 0; i < secondaryPalettes.length; i++) for (let i = 0; i < secondaryPalettes.length; i++)
// applyTint(secondaryPalettes[i], tint) applyTint(secondaryPalettes[i], tint)
// map.setPrimaryTilesetPalettesPreview(primaryPalettes) map.setPrimaryTilesetPalettesPreview(primaryPalettes)
// map.setSecondaryTilesetPalettesPreview(secondaryPalettes) map.setSecondaryTilesetPalettesPreview(secondaryPalettes)
console.log(map.setSmartPathsEnabled(visible))
visible = !visible
} catch(err) { } catch(err) {
console.log(err) console.log(err)
} }
@ -36,9 +32,9 @@ function applyTintToPalettes(tint) {
export function on_project_opened(projectPath) { export function on_project_opened(projectPath) {
try { try {
console.log(`opened ${projectPath}`) console.log(`opened ${projectPath}`)
map.registerAction("resetTint", "View Day Tint") map.registerAction("resetTint", "View Day Tint", "K")
map.registerAction("applyMorningTint", "View Morning Tint") map.registerAction("applyMorningTint", "View Morning Tint", "N")
map.registerAction("applyNightTint", "View Night Tint") map.registerAction("applyNightTint", "View Night Tint", "Ctrl+J")
} catch(err) { } catch(err) {
console.log(err) console.log(err)
} }