Notes/src/public/app/widgets/buttons/launcher/abstract_launcher.js

43 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-12-02 16:46:14 +01:00
import shortcutService from "../../../services/shortcuts.js";
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");
/** @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");
}
bindNoteShortcutHandler(labelOrRow) {
const namespace = labelOrRow.attributeId;
2022-12-02 16:46:14 +01:00
if (labelOrRow.isDeleted) { // only applicable if row
2022-12-02 16:46:14 +01:00
shortcutService.removeGlobalShortcut(namespace);
} else {
shortcutService.bindGlobalShortcut(labelOrRow.value, () => this.launch(), namespace);
2022-12-02 16:46:14 +01:00
}
}
entitiesReloadedEvent({loadResults}) {
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);
} 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
}