2022-12-02 16:46:14 +01:00
|
|
|
import shortcutService from "../../../services/shortcuts.js";
|
2022-12-18 22:05:06 +01:00
|
|
|
import attributesService from "../../../services/attributes.js";
|
2022-12-02 16:46:14 +01:00
|
|
|
import OnClickButtonWidget from "../onclick_button.js";
|
|
|
|
|
|
|
|
export default class AbstractLauncher extends OnClickButtonWidget {
|
|
|
|
constructor(launcherNote) {
|
|
|
|
super();
|
|
|
|
|
2022-12-11 13:20:37 +01:00
|
|
|
this.class("launcher-button");
|
|
|
|
|
2023-01-03 13:35:10 +01:00
|
|
|
/** @type {FNote} */
|
2022-12-02 16:46:14 +01:00
|
|
|
this.launcherNote = launcherNote;
|
2022-12-03 21:11:49 +01:00
|
|
|
|
|
|
|
for (const label of launcherNote.getOwnedLabels('keyboardShortcut')) {
|
|
|
|
this.bindNoteShortcutHandler(label);
|
|
|
|
}
|
2022-12-02 16:46:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
launch() {
|
|
|
|
throw new Error("Abstract implementation");
|
|
|
|
}
|
|
|
|
|
2023-06-05 16:26:05 +02:00
|
|
|
bindNoteShortcutHandler(labelOrRow) {
|
|
|
|
const namespace = labelOrRow.attributeId;
|
2022-12-02 16:46:14 +01:00
|
|
|
|
2023-06-05 16:26:05 +02:00
|
|
|
if (labelOrRow.isDeleted) { // only applicable if row
|
2022-12-02 16:46:14 +01:00
|
|
|
shortcutService.removeGlobalShortcut(namespace);
|
|
|
|
} else {
|
2023-06-05 16:26:05 +02:00
|
|
|
shortcutService.bindGlobalShortcut(labelOrRow.value, () => this.launch(), namespace);
|
2022-12-02 16:46:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
entitiesReloadedEvent({loadResults}) {
|
2023-06-05 16:12:02 +02:00
|
|
|
for (const attr of loadResults.getAttributeRows()) {
|
2022-12-02 16:46:14 +01:00
|
|
|
if (attr.noteId === this.launcherNote.noteId && attr.type === 'label' && attr.name === 'keyboardShortcut') {
|
|
|
|
this.bindNoteShortcutHandler(attr);
|
2022-12-18 22:05:06 +01:00
|
|
|
} else if (attr.type === 'label' && attr.name === 'iconClass' && attributesService.isAffecting(attr, this.launcherNote)) {
|
|
|
|
this.refreshIcon();
|
2022-12-02 16:46:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-03 21:11:49 +01:00
|
|
|
}
|