added note hoisting option to the note launcher

This commit is contained in:
zadam
2022-12-18 22:05:06 +01:00
parent 0de0b6fd06
commit 5fca606730
11 changed files with 61 additions and 26 deletions

View File

@@ -1,4 +1,5 @@
import shortcutService from "../../../services/shortcuts.js";
import attributesService from "../../../services/attributes.js";
import OnClickButtonWidget from "../onclick_button.js";
export default class AbstractLauncher extends OnClickButtonWidget {
@@ -33,6 +34,8 @@ export default class AbstractLauncher extends OnClickButtonWidget {
for (const attr of loadResults.getAttributes()) {
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();
}
}
}

View File

@@ -15,8 +15,8 @@ export default class NoteLauncher extends AbstractLauncher {
constructor(launcherNote) {
super(launcherNote);
this.title(this.launcherNote.title)
.icon(this.launcherNote.getIcon())
this.title(() => this.launcherNote.title)
.icon(() => this.launcherNote.getIcon())
.onClick((widget, evt) => this.launch(evt))
.onAuxClick((widget, evt) => this.launch(evt))
.onContextMenu(evt => {
@@ -25,30 +25,46 @@ export default class NoteLauncher extends AbstractLauncher {
return;
}
linkContextMenuService.openContextMenu(targetNoteId, evt);
const hoistedNoteId = this.getHoistedNoteId();
linkContextMenuService.openContextMenu(targetNoteId, hoistedNoteId, evt);
});
}
launch(evt) {
async launch(evt) {
const targetNoteId = this.getTargetNoteId();
if (!targetNoteId) {
return;
}
const hoistedNoteId = this.getHoistedNoteId();
if (!evt) {
// keyboard shortcut
appContext.tabManager.getActiveContext().setNote(targetNoteId)
return;
}
const ctrlKey = utils.isCtrlKey(evt);
if ((evt.which === 1 && ctrlKey) || evt.which === 2) {
appContext.tabManager.openTabWithNoteWithHoisting(targetNoteId);
await this.openInSameTab(targetNoteId, hoistedNoteId);
} else {
appContext.tabManager.getActiveContext().setNote(targetNoteId);
const ctrlKey = utils.isCtrlKey(evt);
if ((evt.which === 1 && ctrlKey) || evt.which === 2) {
await this.openInNewTab(targetNoteId, hoistedNoteId);
} else {
await this.openInSameTab(targetNoteId, hoistedNoteId);
}
}
}
async openInNewTab(targetNoteId, hoistedNoteId) {
const noteContext = await appContext.tabManager.openEmptyTab(null, hoistedNoteId);
await noteContext.setNote(targetNoteId);
}
async openInSameTab(targetNoteId, hoistedNoteId) {
const activeContext = appContext.tabManager.getActiveContext();
await activeContext.setHoistedNoteId(hoistedNoteId);
await activeContext.setNote(targetNoteId);
}
getTargetNoteId() {
const targetNoteId = this.launcherNote.getRelationValue('targetNote');
@@ -60,6 +76,11 @@ export default class NoteLauncher extends AbstractLauncher {
return targetNoteId;
}
getHoistedNoteId() {
return this.launcherNote.getRelationValue('hoistedNote')
|| appContext.tabManager.getActiveContext().hoistedNoteId;
}
getTitle() {
const shortcuts = this.launcherNote.getLabels("keyboardShortcut")
.map(l => l.value)
@@ -73,4 +94,4 @@ export default class NoteLauncher extends AbstractLauncher {
return title;
}
}
}

View File

@@ -4,8 +4,8 @@ export default class ScriptLauncher extends AbstractLauncher {
constructor(launcherNote) {
super(launcherNote);
this.title(this.launcherNote.title)
.icon(this.launcherNote.getIcon())
this.title(() => this.launcherNote.title)
.icon(() => this.launcherNote.getIcon())
.onClick(() => this.launch());
}