mirror of
https://github.com/zadam/trilium.git
synced 2025-11-12 08:15:52 +01:00
shortcut improvements
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import treeService from '../services/tree.js';
|
||||
import froca from "../services/froca.js";
|
||||
import contextMenu from "./context_menu.js";
|
||||
import dialogService from "../services/dialog.js";
|
||||
import server from "../services/server.js";
|
||||
|
||||
export default class ShortcutContextMenu {
|
||||
/**
|
||||
@@ -25,12 +27,13 @@ export default class ShortcutContextMenu {
|
||||
const note = await froca.getNote(this.node.data.noteId);
|
||||
const parentNoteId = this.node.getParent().data.noteId;
|
||||
|
||||
const isLbRoot = note.noteId === 'lb_root';
|
||||
const isVisibleRoot = note.noteId === 'lb_visibleshortcuts';
|
||||
const isAvailableRoot = note.noteId === 'lb_availableshortcuts';
|
||||
const isVisibleItem = parentNoteId === 'lb_visibleshortcuts';
|
||||
const isAvailableItem = parentNoteId === 'lb_availableshortcuts';
|
||||
const isItem = isVisibleItem || isAvailableItem;
|
||||
const canBeDeleted = !note.noteId.startsWith("lb_");
|
||||
const canBeReset = note.noteId.startsWith("lb_");
|
||||
|
||||
return [
|
||||
(isVisibleRoot || isAvailableRoot) ? { title: 'Add note shortcut', command: 'addNoteShortcut', uiIcon: "bx bx-plus" } : null,
|
||||
@@ -38,8 +41,8 @@ export default class ShortcutContextMenu {
|
||||
(isVisibleRoot || isAvailableRoot) ? { title: 'Add widget shortcut', command: 'addWidgetShortcut', uiIcon: "bx bx-plus" } : null,
|
||||
(isVisibleRoot || isAvailableRoot) ? { title: 'Add spacer', command: 'addSpacerShortcut', uiIcon: "bx bx-plus" } : null,
|
||||
(isVisibleRoot || isAvailableRoot) ? { title: "----" } : null,
|
||||
{ title: 'Delete <kbd data-command="deleteNotes"></kbd>', command: "deleteNotes", uiIcon: "bx bx-trash",
|
||||
enabled: !isLbRoot}, // allow everything to be deleted as a form of a reset. Root can't be deleted because it's a hoisted note
|
||||
{ title: 'Delete <kbd data-command="deleteNotes"></kbd>', command: "deleteNotes", uiIcon: "bx bx-trash", enabled: canBeDeleted },
|
||||
{ title: 'Reset', command: "resetShortcut", uiIcon: "bx bx-empty", enabled: canBeReset},
|
||||
{ title: "----" },
|
||||
isAvailableItem ? { title: 'Move to visible shortcuts', command: "moveShortcutToVisible", uiIcon: "bx bx-show", enabled: true } : null,
|
||||
isVisibleItem ? { title: 'Move to available shortcuts', command: "moveShortcutToAvailable", uiIcon: "bx bx-hide", enabled: true } : null,
|
||||
@@ -49,6 +52,18 @@ export default class ShortcutContextMenu {
|
||||
}
|
||||
|
||||
async selectMenuItemHandler({command}) {
|
||||
if (command === 'resetShortcut') {
|
||||
const confirmed = await dialogService.confirm(`Do you really want to reset "${this.node.title}"?
|
||||
All data / settings in this shortcut (and its children) will be lost
|
||||
and the shortcut will be returned to its original location.`);
|
||||
|
||||
if (confirmed) {
|
||||
await server.post(`special-notes/shortcuts/${this.node.data.noteId}/reset`);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.treeWidget.triggerCommand(command, {
|
||||
node: this.node,
|
||||
notePath: treeService.getNotePath(this.node),
|
||||
|
||||
Reference in New Issue
Block a user