From a679fedb587ca0f06c449f54aa30d50a23ca2ca5 Mon Sep 17 00:00:00 2001
From: zadam
Date: Sun, 16 Feb 2020 19:54:11 +0100
Subject: [PATCH] refactored keyboard actions into commands
---
.../javascripts/services/app_context.js | 14 ++--
.../services/dialog_command_executor.js | 16 +++++
.../javascripts/services/entrypoints.js | 46 ++++---------
.../javascripts/services/keyboard_actions.js | 8 +--
.../javascripts/services/spell_check.js | 2 +-
.../javascripts/services/tab_manager.js | 12 ++--
.../javascripts/services/tree_context_menu.js | 28 ++++----
src/public/javascripts/widgets/component.js | 12 ++--
.../javascripts/widgets/global_buttons.js | 6 +-
src/public/javascripts/widgets/global_menu.js | 14 ++--
.../javascripts/widgets/note_actions.js | 10 +--
.../widgets/standard_top_widget.js | 4 +-
src/public/javascripts/widgets/tab_row.js | 14 ++--
src/views/dialogs/help.ejs | 66 +++++++++----------
14 files changed, 125 insertions(+), 127 deletions(-)
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 = $('
@@ -40,10 +40,10 @@
Only in desktop (electron build):
- - opens empty tab
- - closes active tab
- - activates next tab
- - activates previous tab
+ - opens empty tab
+ - closes active tab
+ - activates next tab
+ - activates previous tab
@@ -55,9 +55,9 @@
- - - creates new note after the active note
- - - creates new sub-note into active note
- - - edit prefix of active note clone
+ - - creates new note after the active note
+ - - creates new sub-note into active note
+ - - edit prefix of active note clone
@@ -69,15 +69,15 @@
- - , - move note up/down in the note list
- - , - move note up in the hierarchy
- - , - multi-select note above/below
- - - select all notes in the current level
+ - , - move note up/down in the note list
+ - , - move note up in the hierarchy
+ - , - multi-select note above/below
+ - - select all notes in the current level
- Shift+click - select note
- - - copies active note (or current selection) into clipboard (used for cloning)
- - - cuts current (or current selection) note into clipboard (used for moving notes)
- - - pastes note(s) as sub-note into active note (which is either move or clone depending on whether it was copied or cut into clipboard)
- - - delete note / sub-tree
+ - - copies active note (or current selection) into clipboard (used for cloning)
+ - - cuts current (or current selection) note into clipboard (used for moving notes)
+ - - pastes note(s) as sub-note into active note (which is either move or clone depending on whether it was copied or cut into clipboard)
+ - - delete note / sub-tree
@@ -89,12 +89,12 @@
- - in tree pane switches from tree pane into note title. Enter from note title switches focus to text editor.
- switches back from editor to tree pane.
+ - in tree pane switches from tree pane into note title. Enter from note title switches focus to text editor.
+ switches back from editor to tree pane.
- Ctrl+K - create / edit external link
- - - create internal link
- - - inserts current date and time at caret position
- - - jump away to the tree pane and scroll to active note
+ - - create internal link
+ - - inserts current date and time at caret position
+ - - jump away to the tree pane and scroll to active note
@@ -121,9 +121,9 @@
- - - reloads Trilium frontend
- - - show developer tools
- - - show SQL console
+ - - reloads Trilium frontend
+ - - show developer tools
+ - - show SQL console
@@ -135,10 +135,10 @@
- - - Zen mode - display only note editor, everything else is hidden
- - - toggle search form in tree pane
- - - in page search
- - - show note attributes dialog
+ - - Zen mode - display only note editor, everything else is hidden
+ - - toggle search form in tree pane
+ - - in page search
+ - - show note attributes dialog