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

33 lines
1000 B
JavaScript
Raw Normal View History

2022-12-02 16:46:14 +01:00
import shortcutService from "../../../services/shortcuts.js";
import OnClickButtonWidget from "../onclick_button.js";
export default class AbstractLauncher extends OnClickButtonWidget {
constructor(launcherNote) {
super();
/** @type {NoteShort} */
this.launcherNote = launcherNote;
}
launch() {
throw new Error("Abstract implementation");
}
bindNoteShortcutHandler(label) {
const namespace = label.attributeId;
if (label.isDeleted) {
shortcutService.removeGlobalShortcut(namespace);
} else {
shortcutService.bindGlobalShortcut(label.value, () => this.launch(), namespace);
}
}
entitiesReloadedEvent({loadResults}) {
for (const attr of loadResults.getAttributes()) {
if (attr.noteId === this.launcherNote.noteId && attr.type === 'label' && attr.name === 'keyboardShortcut') {
this.bindNoteShortcutHandler(attr);
}
}
}
}