diff --git a/src/public/javascripts/services/app_context.js b/src/public/javascripts/services/app_context.js index cbc5bc164..cde160265 100644 --- a/src/public/javascripts/services/app_context.js +++ b/src/public/javascripts/services/app_context.js @@ -42,14 +42,12 @@ class AppContext extends Component { this.triggerEvent(eventName); }); - this.children = [ - this.tabManager, - rootWidget, - new Entrypoints(this) - ]; + this.children = [ rootWidget ]; this.executors = [ - new DialogCommandExecutor(this) + this.tabManager, + new DialogCommandExecutor(this), + new Entrypoints(this) ]; if (utils.isElectron()) { @@ -67,9 +65,7 @@ class AppContext extends Component { async triggerCommand(name, data = {}) { for (const executor of this.executors) { - const fun = executor[name + 'Command']; - - const called = await this.callMethod(executor, fun, data); + const called = await executor.handleCommand(name, data); if (called) { return; diff --git a/src/public/javascripts/services/dialog_command_executor.js b/src/public/javascripts/services/dialog_command_executor.js index 06d718a9c..fffd0f682 100644 --- a/src/public/javascripts/services/dialog_command_executor.js +++ b/src/public/javascripts/services/dialog_command_executor.js @@ -51,4 +51,20 @@ export default class DialogCommandExecutor extends Component { const d = await import("../dialogs/move_to.js"); d.showDialog(branchIds); } + + showOptionsCommand() { + import("../dialogs/options.js").then(d => d.showDialog()) + } + + showHelpCommand() { + import("../dialogs/help.js").then(d => d.showDialog()) + } + + showSQLConsoleCommand() { + import("../dialogs/sql_console.js").then(d => d.showDialog()) + } + + showBackendLogCommand() { + import("../dialogs/backend_log.js").then(d => d.showDialog()) + } } \ No newline at end of file diff --git a/src/public/javascripts/services/entrypoints.js b/src/public/javascripts/services/entrypoints.js index c3d02c151..fceb738c8 100644 --- a/src/public/javascripts/services/entrypoints.js +++ b/src/public/javascripts/services/entrypoints.js @@ -8,8 +8,8 @@ import appContext from "./app_context.js"; import Component from "../widgets/component.js"; export default class Entrypoints extends Component { - constructor(appContext, parent) { - super(appContext, parent); + constructor(parent) { + super(parent); // hot keys are active also inside inputs and content editables jQuery.hotkeys.options.filterInputAcceptingElements = false; @@ -29,13 +29,13 @@ export default class Entrypoints extends Component { }); } - openDevToolsEvent() { + openDevToolsCommand() { if (utils.isElectron()) { require('electron').remote.getCurrentWindow().toggleDevTools(); } } - findInTextEvent() { + findInTextCommand() { if (!utils.isElectron()) { return; } @@ -56,9 +56,7 @@ export default class Entrypoints extends Component { }); } - - - async createNoteIntoDayNoteEvent() { + async createNoteIntoDayNoteCommand() { const todayNote = await dateNoteService.getTodayNote(); const {note} = await server.post(`notes/${todayNote.noteId}/children?target=into`, { @@ -74,10 +72,10 @@ export default class Entrypoints extends Component { appContext.tabManager.activateTab(tabContext.tabId); await tabContext.setNote(note.noteId); - appContext.triggerEvent('focusAndSelectTitle'); + appContext.triggerCommand('focusAndSelectTitle'); } - async toggleNoteHoistingEvent() { + async toggleNoteHoistingCommand() { const note = appContext.tabManager.getActiveTabNote(); const hoistedNoteId = hoistedNoteService.getHoistedNoteId(); @@ -93,11 +91,11 @@ export default class Entrypoints extends Component { } } - copyWithoutFormattingEvent() { + copyWithoutFormattingCommand() { utils.copySelectionToClipboard(); } - toggleFullscreenEvent() { + toggleFullscreenCommand() { if (utils.isElectron()) { const win = require('electron').remote.getCurrentWindow(); @@ -111,7 +109,7 @@ export default class Entrypoints extends Component { } } - toggleZenModeEvent() { + toggleZenModeCommand() { if (!this.zenModeActive) { $(".hide-in-zen-mode,.gutter").addClass("hidden-by-zen-mode"); $("#container").addClass("zen-mode"); @@ -125,11 +123,11 @@ export default class Entrypoints extends Component { } } - reloadFrontendAppEvent() { + reloadFrontendAppCommand() { utils.reloadApp(); } - logoutEvent() { + logoutCommand() { const $logoutForm = $('
') .append($(``)); @@ -137,27 +135,11 @@ export default class Entrypoints extends Component { $logoutForm.trigger('submit'); } - showOptionsEvent() { - import("../dialogs/options.js").then(d => d.showDialog()) - } - - showHelpEvent() { - import("../dialogs/help.js").then(d => d.showDialog()) - } - - showSQLConsoleEvent() { - import("../dialogs/sql_console.js").then(d => d.showDialog()) - } - - showBackendLogEvent() { - import("../dialogs/backend_log.js").then(d => d.showDialog()) - } - - backInNoteHistoryEvent() { + backInNoteHistoryCommand() { window.history.back(); } - forwardInNoteHistoryEvent() { + forwardInNoteHistoryCommand() { window.history.forward(); } } diff --git a/src/public/javascripts/services/keyboard_actions.js b/src/public/javascripts/services/keyboard_actions.js index 4126c3ab2..5cc3c8fed 100644 --- a/src/public/javascripts/services/keyboard_actions.js +++ b/src/public/javascripts/services/keyboard_actions.js @@ -95,8 +95,8 @@ async function getAction(actionName, silent = false) { } function updateDisplayedShortcuts($container) { - $container.find('kbd[data-kb-action]').each(async (i, el) => { - const actionName = $(el).attr('data-kb-action'); + $container.find('kbd[data-kb-command]').each(async (i, el) => { + const actionName = $(el).attr('data-kb-command'); const action = await getAction(actionName, true); if (action) { @@ -104,8 +104,8 @@ function updateDisplayedShortcuts($container) { } }); - $container.find('button[data-kb-action],a.icon-action[data-kb-action],.kb-in-title').each(async (i, el) => { - const actionName = $(el).attr('data-kb-action'); + $container.find('button[data-kb-command],a.icon-action[data-kb-command],.kb-in-title').each(async (i, el) => { + const actionName = $(el).attr('data-kb-command'); const action = await getAction(actionName, true); if (action) { diff --git a/src/public/javascripts/services/spell_check.js b/src/public/javascripts/services/spell_check.js index f0979bed8..8407d37ec 100644 --- a/src/public/javascripts/services/spell_check.js +++ b/src/public/javascripts/services/spell_check.js @@ -41,7 +41,7 @@ export async function initSpellCheck() { }); }); - new ContextMenuEvent(async (info) => { + new ContextMenuListener(async (info) => { await contextMenuBuilder.showPopupMenu(info); }); } \ No newline at end of file diff --git a/src/public/javascripts/services/tab_manager.js b/src/public/javascripts/services/tab_manager.js index b2472904f..16b921cc2 100644 --- a/src/public/javascripts/services/tab_manager.js +++ b/src/public/javascripts/services/tab_manager.js @@ -250,21 +250,21 @@ export default class TabManager extends Component { this.tabsUpdate.scheduleUpdate(); } - activateNextTabEvent() { + activateNextTabCommand() { const oldIdx = this.tabContexts.findIndex(tc => tc.tabId === this.activeTabId); const newActiveTabId = this.tabContexts[oldIdx === this.tabContexts.length - 1 ? 0 : oldIdx + 1].tabId; this.activateTab(newActiveTabId); } - activatePreviousTabEvent() { + activatePreviousTabCommand() { const oldIdx = this.tabContexts.findIndex(tc => tc.tabId === this.activeTabId); const newActiveTabId = this.tabContexts[oldIdx === 0 ? this.tabContexts.length - 1 : oldIdx - 1].tabId; this.activateTab(newActiveTabId); } - closeActiveTabEvent() { + closeActiveTabCommand() { this.removeTab(this.activeTabId); } @@ -272,17 +272,17 @@ export default class TabManager extends Component { this.tabsUpdate.updateNowIfNecessary(); } - openNewTabEvent() { + openNewTabCommand() { this.openAndActivateEmptyTab(); } - async removeAllTabsEvent() { + async removeAllTabsCommand() { for (const tabIdToRemove of this.tabContexts.map(tc => tc.tabId)) { await this.removeTab(tabIdToRemove); } } - async removeAllTabsExceptForThisEvent({tabId}) { + async removeAllTabsExceptForThisCommand({tabId}) { for (const tabIdToRemove of this.tabContexts.map(tc => tc.tabId)) { if (tabIdToRemove !== tabId) { await this.removeTab(tabIdToRemove); diff --git a/src/public/javascripts/services/tree_context_menu.js b/src/public/javascripts/services/tree_context_menu.js index 8a36793b6..136ab85e8 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 || !isNotRoot ? null : { title: 'Unhoist note ', cmd: "unhoist", uiIcon: "arrow-up" }, - { title: 'Edit branch prefix ', cmd: "editBranchPrefix", uiIcon: "empty", + 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", 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/widgets/component.js b/src/public/javascripts/widgets/component.js index 6e208e70c..35020cfa4 100644 --- a/src/public/javascripts/widgets/component.js +++ b/src/public/javascripts/widgets/component.js @@ -18,7 +18,7 @@ export default class Component { async handleEvent(name, data) { await this.initialized; - const fun = this[name + 'Listener']; + const fun = this[name + 'Event']; const start = Date.now(); @@ -48,15 +48,19 @@ export default class Component { } async triggerCommand(name, data = {}) { - const fun = this[name + 'Command']; - - const called = await this.callMethod(fun, data); + const called = await this.handleCommand(name, data); if (!called) { await this.parent.triggerCommand(name, data); } } + async handleCommand(name, data) { + const fun = this[name + 'Command']; + + return await this.callMethod(fun, data); + } + async callMethod(fun, data) { if (typeof fun !== 'function') { return false; diff --git a/src/public/javascripts/widgets/global_buttons.js b/src/public/javascripts/widgets/global_buttons.js index 8953ad83a..ff23e56de 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 7765e7adf..56b53e14c 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 98e5496e6..1dbd2d082 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/standard_top_widget.js b/src/public/javascripts/widgets/standard_top_widget.js index 4b48646d9..33c13e96b 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 = `
- -
`; -const NEW_TAB_BUTTON_TPL = `
+
`; +const NEW_TAB_BUTTON_TPL = `
+
`; const FILLER_TPL = `
`; @@ -262,7 +262,7 @@ export default class TabRowWidget extends BasicWidget { ]; }, selectContextMenuItem: (e, cmd) => { - this.triggerEvent(cmd, {tabId}); + this.triggerCommand(cmd, {tabId}); } }); }); @@ -290,7 +290,7 @@ export default class TabRowWidget extends BasicWidget { window.addEventEvent('resize', resizeListener); } - this.tabEls.forEach((tabEl) => this.setTabCloseEventEvent(tabEl)); + this.tabEls.forEach((tabEl) => this.setTabCloseEvent(tabEl)); } setVisibility() { @@ -386,14 +386,14 @@ export default class TabRowWidget extends BasicWidget { this.$newTab.before($tab); this.setVisibility(); - this.setTabCloseEventEvent($tab); + this.setTabCloseEvent($tab); this.updateTitle($tab, 'New tab'); this.cleanUpPreviouslyDraggedTabs(); this.layoutTabs(); this.setupDraggabilly(); } - setTabCloseEventEvent($tab) { + setTabCloseEvent($tab) { $tab.find('.note-tab-close') .on('click', _ => appContext.tabManager.removeTab($tab.attr('data-tab-id'))); @@ -552,7 +552,7 @@ export default class TabRowWidget extends BasicWidget { this.$tabContainer.append(this.$newTab); - this.$newTab.on('click', _ => this.triggerEvent('openNewTab')); + this.$newTab.on('click', _ => this.triggerCommand('openNewTab')); } setupFiller() { diff --git a/src/views/dialogs/help.ejs b/src/views/dialogs/help.ejs index 6d25bdeb0..4ad750d81 100644 --- a/src/views/dialogs/help.ejs +++ b/src/views/dialogs/help.ejs @@ -18,12 +18,12 @@

@@ -40,10 +40,10 @@ Only in desktop (electron build):

@@ -55,9 +55,9 @@

@@ -69,15 +69,15 @@

@@ -89,12 +89,12 @@

@@ -121,9 +121,9 @@

@@ -135,10 +135,10 @@