From 11a61325f9652341137aef6c86317bbc223afc4e Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 22 Jan 2020 20:48:56 +0100 Subject: [PATCH] removed last global keyboard handlers --- .../javascripts/services/entrypoints.js | 43 ++++++++----------- .../javascripts/services/keyboard_actions.js | 5 --- src/public/javascripts/services/tree.js | 35 --------------- .../javascripts/widgets/basic_widget.js | 2 + src/public/javascripts/widgets/global_menu.js | 16 +++---- .../javascripts/widgets/history_navigation.js | 2 +- src/public/javascripts/widgets/note_tree.js | 40 ++++++++++++++++- .../widgets/standard_top_widget.js | 2 +- .../javascripts/widgets/title_bar_buttons.js | 2 +- 9 files changed, 69 insertions(+), 78 deletions(-) diff --git a/src/public/javascripts/services/entrypoints.js b/src/public/javascripts/services/entrypoints.js index 01f092c34..f02c5fe3f 100644 --- a/src/public/javascripts/services/entrypoints.js +++ b/src/public/javascripts/services/entrypoints.js @@ -1,12 +1,8 @@ import utils from "./utils.js"; -import linkService from "./link.js"; import zoomService from "./zoom.js"; -import protectedSessionService from "./protected_session.js"; -import searchNotesService from "./search_notes.js"; import treeService from "./tree.js"; import dateNoteService from "./date_notes.js"; import noteDetailService from "./note_detail.js"; -import keyboardActionService from "./keyboard_actions.js"; import hoistedNoteService from "./hoisted_note.js"; import treeCache from "./tree_cache.js"; import server from "./server.js"; @@ -42,29 +38,24 @@ export default class Entrypoints extends Component { } findInTextListener() { - if (utils.isElectron()) { - const {remote} = require('electron'); - const {FindInPage} = require('electron-find'); - - const findInPage = new FindInPage(remote.getCurrentWebContents(), { - offsetTop: 10, - offsetRight: 10, - boxBgColor: 'var(--main-background-color)', - boxShadowColor: '#000', - inputColor: 'var(--input-text-color)', - inputBgColor: 'var(--input-background-color)', - inputFocusColor: '#555', - textColor: 'var(--main-text-color)', - textHoverBgColor: '#555', - caseSelectedColor: 'var(--main-border-color)' - }); - - keyboardActionService.setGlobalActionHandler("FindInText", () => { - if (!glob.activeDialog || !glob.activeDialog.is(":visible")) { - findInPage.openFindWindow(); - } - }); + if (!utils.isElectron()) { + return; } + + const {remote} = require('electron'); + const {FindInPage} = require('electron-find'); + const findInPage = new FindInPage(remote.getCurrentWebContents(), { + offsetTop: 10, + offsetRight: 10, + boxBgColor: 'var(--main-background-color)', + boxShadowColor: '#000', + inputColor: 'var(--input-text-color)', + inputBgColor: 'var(--input-background-color)', + inputFocusColor: '#555', + textColor: 'var(--main-text-color)', + textHoverBgColor: '#555', + caseSelectedColor: 'var(--main-border-color)' + }); } zoomOutListener() { diff --git a/src/public/javascripts/services/keyboard_actions.js b/src/public/javascripts/services/keyboard_actions.js index 1188c453d..16f802523 100644 --- a/src/public/javascripts/services/keyboard_actions.js +++ b/src/public/javascripts/services/keyboard_actions.js @@ -29,10 +29,6 @@ server.get('keyboard-shortcuts-for-notes').then(shortcutForNotes => { } }); -function setGlobalActionHandler(actionName, handler) { - console.log("Useless handler for " + actionName); -} - function setElementActionHandler($el, actionName, handler) { keyboardActionsLoaded.then(() => { const action = keyboardActionRepo[actionName]; @@ -103,7 +99,6 @@ function updateDisplayedShortcuts($container) { } export default { - setGlobalActionHandler, setElementActionHandler, triggerAction, getAction, diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js index 22f430623..f8a14e880 100644 --- a/src/public/javascripts/services/tree.js +++ b/src/public/javascripts/services/tree.js @@ -374,9 +374,6 @@ async function createNote(node, parentNoteId, target, extraOptions = {}) { window.cutToNote.removeSelection(); } - // FIXME - await noteDetailService.saveNotesIfChanged(); - noteDetailService.addDetailLoadedListener(note.noteId, noteDetailService.focusAndSelectTitle); const noteEntity = await treeCache.getNote(note.noteId); @@ -510,32 +507,6 @@ ws.subscribeToOutsideSyncMessages(async syncData => { } }); -keyboardActionService.setGlobalActionHandler('CreateNoteAfter', async () => { - const node = appContext.getMainNoteTree().getActiveNode(); - const parentNoteId = node.data.parentNoteId; - const isProtected = await treeUtils.getParentProtectedStatus(node); - - if (node.data.noteId === 'root' || node.data.noteId === await hoistedNoteService.getHoistedNoteId()) { - return; - } - - await createNote(node, parentNoteId, 'after', { - isProtected: isProtected, - saveSelection: true - }); -}); - -async function createNoteInto(saveSelection = false) { - const node = appContext.getMainNoteTree().getActiveNode(); - - if (node) { - await createNote(node, node.data.noteId, 'into', { - isProtected: node.data.isProtected, - saveSelection: saveSelection - }); - } -} - async function reloadNotes(noteIds, activateNotePath = null) { if (noteIds.length === 0) { return; @@ -550,12 +521,6 @@ async function reloadNotes(noteIds, activateNotePath = null) { appContext.trigger('notesReloaded', { noteIds, activateNotePath }); } -window.glob.cutIntoNote = () => createNoteInto(true); - -keyboardActionService.setGlobalActionHandler('CutIntoNote', () => createNoteInto(true)); - -keyboardActionService.setGlobalActionHandler('CreateNoteInto', createNoteInto); - $(window).bind('hashchange', async function() { if (isNotePathInAddress()) { const [notePath, tabId] = getHashValueFromAddress(); diff --git a/src/public/javascripts/widgets/basic_widget.js b/src/public/javascripts/widgets/basic_widget.js index c60fac88b..0bf4fdc4a 100644 --- a/src/public/javascripts/widgets/basic_widget.js +++ b/src/public/javascripts/widgets/basic_widget.js @@ -10,6 +10,8 @@ class BasicWidget extends Component { $widget.find("[data-trigger-event]").on('click', e => { const eventName = $(e.target).attr('data-trigger-event'); + console.log("Triggering " + eventName); + this.appContext.trigger(eventName); }); diff --git a/src/public/javascripts/widgets/global_menu.js b/src/public/javascripts/widgets/global_menu.js index 5bbaecd18..86052a45d 100644 --- a/src/public/javascripts/widgets/global_menu.js +++ b/src/public/javascripts/widgets/global_menu.js @@ -29,7 +29,7 @@ const TPL = ` `; export default class StandardTopWidget extends BasicWidget { - render() { + doRender() { this.$widget = $(TPL); const historyNavigationWidget = new HistoryNavigationWidget(this.appContext); diff --git a/src/public/javascripts/widgets/title_bar_buttons.js b/src/public/javascripts/widgets/title_bar_buttons.js index bb03969af..a958a2002 100644 --- a/src/public/javascripts/widgets/title_bar_buttons.js +++ b/src/public/javascripts/widgets/title_bar_buttons.js @@ -18,7 +18,7 @@ const TPL = ` `; export default class TitleBarButtonsWidget extends BasicWidget { - render() { + doRender() { if (!utils.isElectron()) { return; }