diff --git a/src/public/javascripts/dialogs/add_link.js b/src/public/javascripts/dialogs/add_link.js
index d401f75f1..a75364cf3 100644
--- a/src/public/javascripts/dialogs/add_link.js
+++ b/src/public/javascripts/dialogs/add_link.js
@@ -9,14 +9,13 @@ const $autoComplete = $("#add-link-note-autocomplete");
const $linkTitle = $("#link-title");
const $addLinkTitleFormGroup = $("#add-link-title-form-group");
-export async function showDialog() {
- appContext.trigger('executeInActiveEditor', {
- callback: textEditor => {
- const hasSelection = !textEditor.model.document.selection.isCollapsed;
+/** @var TextTypeWidget */
+let textTypeWidget;
- $addLinkTitleFormGroup.toggle(!hasSelection);
- }
- });
+export async function showDialog(widget) {
+ textTypeWidget = widget;
+
+ $addLinkTitleFormGroup.toggle(!textTypeWidget.hasSelection());
utils.openDialog($dialog);
@@ -58,10 +57,7 @@ $form.on('submit', () => {
if (notePath) {
$dialog.modal('hide');
- appContext.trigger(`addLinkToActiveEditor`, {
- linkTitle: $linkTitle.val(),
- linkHref: '#' + notePath
- });
+ textTypeWidget.addLink($linkTitle.val(), '#' + notePath);
}
else {
console.error("No path to add link.");
diff --git a/src/public/javascripts/services/dialog_command_executor.js b/src/public/javascripts/services/dialog_command_executor.js
index bc6f3b7fc..06d718a9c 100644
--- a/src/public/javascripts/services/dialog_command_executor.js
+++ b/src/public/javascripts/services/dialog_command_executor.js
@@ -42,10 +42,6 @@ export default class DialogCommandExecutor extends Component {
}
}
- addLinkToTextCommand() {
- import("../dialogs/add_link.js").then(d => d.showDialog());
- }
-
async cloneNoteIdsToCommand({noteIds}) {
const d = await import("../dialogs/clone_to.js");
d.showDialog(noteIds);
diff --git a/src/public/javascripts/services/keyboard_actions.js b/src/public/javascripts/services/keyboard_actions.js
index 95bb46072..a4ee1defc 100644
--- a/src/public/javascripts/services/keyboard_actions.js
+++ b/src/public/javascripts/services/keyboard_actions.js
@@ -5,18 +5,39 @@ import appContext from "./app_context.js";
const keyboardActionRepo = {};
const keyboardActionsLoaded = server.get('keyboard-actions').then(actions => {
+ actions = actions.filter(a => !!a.actionName); // filter out separators
+
for (const action of actions) {
+ action.effectiveShortcuts = action.effectiveShortcuts.filter(shortcut => !shortcut.startsWith("global:"));
+ action.actionName = action.actionName.charAt(0).toLowerCase() + action.actionName.slice(1);
+
keyboardActionRepo[action.actionName] = action;
+ }
- for (const shortcut of action.effectiveShortcuts || []) {
- if (shortcut && !shortcut.startsWith("global:")) { // global shortcuts should be handled in the electron code
- const eventName = action.actionName.charAt(0).toLowerCase() + action.actionName.slice(1);
+ return actions;
+});
- if (action.scope !== 'note-tree') {
- // empty object param so that destructuring with optional params work
- utils.bindGlobalShortcut(shortcut, () => appContext.trigger(eventName, {}));
- }
- }
+async function getActionsForScope(scope) {
+ const actions = await keyboardActionsLoaded;
+
+ return actions.filter(action => action.scope === scope);
+}
+
+async function setupActionsForElement(scope, $el, component) {
+ const actions = await getActionsForScope(scope);
+
+ for (const action of actions) {
+ for (const shortcut of action.effectiveShortcuts) {
+ utils.bindElShortcut($el, shortcut, () => component.triggerCommand(action.actionName));
+ }
+ }
+}
+
+getActionsForScope("window").then(actions => {
+ for (const action of actions) {
+ for (const shortcut of action.effectiveShortcuts) {
+ // empty object param so that destructuring with optional params work
+ utils.bindGlobalShortcut(shortcut, () => appContext.trigger(action.actionName, {}));
}
}
});
@@ -24,8 +45,6 @@ const keyboardActionsLoaded = server.get('keyboard-actions').then(actions => {
server.get('keyboard-shortcuts-for-notes').then(shortcutForNotes => {
for (const shortcut in shortcutForNotes) {
utils.bindGlobalShortcut(shortcut, async () => {
- const treeService = (await import("./tree.js")).default;
-
appContext.tabManager.getActiveTabContext().setNote(shortcutForNotes[shortcut]);
});
}
@@ -104,5 +123,7 @@ export default {
setElementActionHandler,
triggerAction,
getAction,
- updateDisplayedShortcuts
+ updateDisplayedShortcuts,
+ getActionsForScope,
+ setupActionsForElement
};
\ No newline at end of file
diff --git a/src/public/javascripts/services/tree_context_menu.js b/src/public/javascripts/services/tree_context_menu.js
index 83b70689c..9ba209dc0 100644
--- a/src/public/javascripts/services/tree_context_menu.js
+++ b/src/public/javascripts/services/tree_context_menu.js
@@ -51,39 +51,39 @@ class TreeContextMenu {
return [
{ title: 'Open in new tab', cmd: "openInTab", uiIcon: "empty", enabled: noSelectedNotes },
- { title: 'Insert note after ', cmd: "insertNoteAfter", uiIcon: "plus",
+ { title: 'Insert note after ', cmd: "insertNoteAfter", uiIcon: "plus",
items: insertNoteAfterEnabled ? this.getNoteTypeItems("insertNoteAfter") : null,
enabled: insertNoteAfterEnabled && noSelectedNotes },
- { title: 'Insert child note ', cmd: "insertChildNote", uiIcon: "plus",
+ { title: 'Insert child note ', cmd: "insertChildNote", uiIcon: "plus",
items: notSearch ? this.getNoteTypeItems("insertChildNote") : null,
enabled: notSearch && noSelectedNotes },
- { title: 'Delete ', cmd: "delete", uiIcon: "trash",
+ { title: 'Delete ', cmd: "delete", uiIcon: "trash",
enabled: isNotRoot && !isHoisted && parentNotSearch },
{ title: "----" },
- { title: 'Search in subtree ', cmd: "searchInSubtree", uiIcon: "search",
+ { title: 'Search in subtree ', cmd: "searchInSubtree", uiIcon: "search",
enabled: notSearch && noSelectedNotes },
- isHoisted ? null : { title: 'Hoist note ', cmd: "hoist", uiIcon: "empty", enabled: noSelectedNotes && notSearch },
+ isHoisted ? null : { title: 'Hoist note ', cmd: "hoist", uiIcon: "empty", enabled: noSelectedNotes && notSearch },
!isHoisted || !isNotRoot ? null : { title: 'Unhoist note ', cmd: "unhoist", uiIcon: "arrow-up" },
- { title: 'Edit branch prefix ', cmd: "editBranchPrefix", uiIcon: "empty",
+ { title: 'Edit branch prefix ', cmd: "editBranchPrefix", uiIcon: "empty",
enabled: isNotRoot && parentNotSearch && noSelectedNotes},
{ title: "Advanced", uiIcon: "empty", enabled: true, items: [
- { title: 'Collapse subtree ', cmd: "collapseSubtree", uiIcon: "align-justify", enabled: noSelectedNotes },
+ { title: 'Collapse subtree ', cmd: "collapseSubtree", uiIcon: "align-justify", enabled: noSelectedNotes },
{ title: "Force note sync", cmd: "forceNoteSync", uiIcon: "refresh", enabled: noSelectedNotes },
- { title: 'Sort alphabetically ', cmd: "sortAlphabetically", uiIcon: "empty", enabled: noSelectedNotes && notSearch }
+ { title: 'Sort alphabetically ', cmd: "sortAlphabetically", uiIcon: "empty", enabled: noSelectedNotes && notSearch }
] },
{ title: "----" },
{ title: "Protect subtree", cmd: "protectSubtree", uiIcon: "check-shield", enabled: noSelectedNotes },
{ title: "Unprotect subtree", cmd: "unprotectSubtree", uiIcon: "shield", enabled: noSelectedNotes },
{ title: "----" },
- { title: 'Copy / clone ', cmd: "copy", uiIcon: "copy",
+ { title: 'Copy / clone ', cmd: "copy", uiIcon: "copy",
enabled: isNotRoot && !isHoisted },
- { title: 'Clone to ... ', cmd: "cloneTo", uiIcon: "empty",
+ { title: 'Clone to ... ', cmd: "cloneTo", uiIcon: "empty",
enabled: isNotRoot && !isHoisted },
- { title: 'Cut ', cmd: "cut", uiIcon: "cut",
+ { title: 'Cut ', cmd: "cut", uiIcon: "cut",
enabled: isNotRoot && !isHoisted && parentNotSearch },
- { title: 'Move to ... ', cmd: "moveTo", uiIcon: "empty",
+ { title: 'Move to ... ', cmd: "moveTo", uiIcon: "empty",
enabled: isNotRoot && !isHoisted && parentNotSearch },
- { title: 'Paste into ', cmd: "pasteInto", uiIcon: "paste",
+ { title: 'Paste into ', cmd: "pasteInto", uiIcon: "paste",
enabled: !clipboard.isClipboardEmpty() && notSearch && noSelectedNotes },
{ title: 'Paste after', cmd: "pasteAfter", uiIcon: "paste",
enabled: !clipboard.isClipboardEmpty() && isNotRoot && !isHoisted && parentNotSearch && noSelectedNotes },
diff --git a/src/public/javascripts/services/tree_keybindings.js b/src/public/javascripts/services/tree_keybindings.js
index f9843f4f9..db89d1b10 100644
--- a/src/public/javascripts/services/tree_keybindings.js
+++ b/src/public/javascripts/services/tree_keybindings.js
@@ -52,12 +52,12 @@ function getSelectedOrActiveBranchIds(treeWidget, node) {
*/
function getTemplates(treeWidget) {
return {
- "DeleteNotes": node => {
+ "deleteNotes": node => {
const branchIds = getSelectedOrActiveBranchIds(treeWidget, node);
treeChangesService.deleteNotes(treeWidget, branchIds);
},
- "MoveNoteUp": node => {
+ "moveNoteUp": node => {
const beforeNode = node.getPrevSibling();
if (beforeNode !== null) {
@@ -66,7 +66,7 @@ function getTemplates(treeWidget) {
return false;
},
- "MoveNoteDown": node => {
+ "moveNoteDown": node => {
const afterNode = node.getNextSibling();
if (afterNode !== null) {
treeChangesService.moveAfterBranch([node.data.branchId], afterNode.data.branchId);
@@ -74,12 +74,12 @@ function getTemplates(treeWidget) {
return false;
},
- "MoveNoteUpInHierarchy": node => {
+ "moveNoteUpInHierarchy": node => {
treeChangesService.moveNodeUpInHierarchy(node);
return false;
},
- "MoveNoteDownInHierarchy": node => {
+ "moveNoteDownInHierarchy": node => {
const toNode = node.getPrevSibling();
if (toNode !== null) {
@@ -88,7 +88,7 @@ function getTemplates(treeWidget) {
return false;
},
- "AddNoteAboveToSelection": () => {
+ "addNoteAboveToSelection": () => {
const node = treeWidget.getFocusedNode();
if (!node) {
@@ -113,7 +113,7 @@ function getTemplates(treeWidget) {
return false;
},
- "AddNoteBelowToSelection": () => {
+ "addNoteBelowToSelection": () => {
const node = treeWidget.getFocusedNode();
if (!node) {
@@ -138,42 +138,42 @@ function getTemplates(treeWidget) {
return false;
},
- "CollapseSubtree": node => {
+ "collapseSubtree": node => {
treeWidget.collapseTree(node);
},
- "SortChildNotes": node => {
+ "sortChildNotes": node => {
treeService.sortAlphabetically(node.data.noteId);
return false;
},
- "SelectAllNotesInParent": node => {
+ "selectAllNotesInParent": node => {
for (const child of node.getParent().getChildren()) {
child.setSelected(true);
}
return false;
},
- "CopyNotesToClipboard": node => {
+ "copyNotesToClipboard": node => {
clipboard.copy(getSelectedOrActiveBranchIds(treeWidget, node));
return false;
},
- "CutNotesToClipboard": node => {
+ "cutNotesToClipboard": node => {
clipboard.cut(getSelectedOrActiveBranchIds(treeWidget, node));
return false;
},
- "PasteNotesFromClipboard": node => {
+ "pasteNotesFromClipboard": node => {
clipboard.pasteInto(node.data.noteId);
return false;
},
- "EditNoteTitle": node => {
+ "editNoteTitle": node => {
appContext.trigger('focusOnTitle');
return false;
},
- "ActivateParentNote": node => {
+ "activateParentNote": node => {
if (!hoistedNoteService.isRootNode(node)) {
node.getParent().setActive().then(treeWidget.clearSelectedNodes);
}
diff --git a/src/public/javascripts/widgets/global_buttons.js b/src/public/javascripts/widgets/global_buttons.js
index 9ee59d0b1..8953ad83a 100644
--- a/src/public/javascripts/widgets/global_buttons.js
+++ b/src/public/javascripts/widgets/global_buttons.js
@@ -19,17 +19,17 @@ const WIDGET_TPL = `
`;
diff --git a/src/public/javascripts/widgets/global_menu.js b/src/public/javascripts/widgets/global_menu.js
index 9b5f8d83f..7765e7adf 100644
--- a/src/public/javascripts/widgets/global_menu.js
+++ b/src/public/javascripts/widgets/global_menu.js
@@ -42,44 +42,44 @@ const TPL = `
Open Dev Tools
-
+
Open SQL Console
-
+
Show backend log
-
+
Reload frontend
-
+
Toggle Zen mode
-
+
Toggle fullscreen
-
+
Show Help
-
+
diff --git a/src/public/javascripts/widgets/note_actions.js b/src/public/javascripts/widgets/note_actions.js
index ff57fe56e..62cf491e5 100644
--- a/src/public/javascripts/widgets/note_actions.js
+++ b/src/public/javascripts/widgets/note_actions.js
@@ -8,13 +8,13 @@ const TPL = `
`;
diff --git a/src/public/javascripts/widgets/note_detail.js b/src/public/javascripts/widgets/note_detail.js
index 076d2b727..79ad4d414 100644
--- a/src/public/javascripts/widgets/note_detail.js
+++ b/src/public/javascripts/widgets/note_detail.js
@@ -98,7 +98,7 @@ export default class NoteDetailWidget extends TabAwareWidget {
if (!(this.type in this.typeWidgets)) {
const clazz = typeWidgetClasses[this.type];
- const typeWidget = this.typeWidgets[this.type] = new clazz(this.appContext);
+ const typeWidget = this.typeWidgets[this.type] = new clazz(this.appContext, this);
typeWidget.spacedUpdate = this.spacedUpdate;
this.children.push(typeWidget);
diff --git a/src/public/javascripts/widgets/standard_top_widget.js b/src/public/javascripts/widgets/standard_top_widget.js
index 1e3261c58..1c067fd79 100644
--- a/src/public/javascripts/widgets/standard_top_widget.js
+++ b/src/public/javascripts/widgets/standard_top_widget.js
@@ -32,12 +32,12 @@ const TPL = `