From 4d205897733b8830a8d80964cc3618b84fbdc92c Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sat, 31 Oct 2020 16:29:17 +0000 Subject: [PATCH] Desktop: Remove from keymap editor commands that cannot be associated with a shortcut --- .eslintignore | 1 + .gitignore | 1 + .ignore | 1 + ElectronClient/app.ts | 12 ++++++--- ElectronClient/gui/MenuBar.tsx | 37 ++------------------------ ElectronClient/gui/menuCommandNames.ts | 37 ++++++++++++++++++++++++++ 6 files changed, 50 insertions(+), 39 deletions(-) create mode 100644 ElectronClient/gui/menuCommandNames.ts diff --git a/.eslintignore b/.eslintignore index 30873f65cf..0416f3f970 100644 --- a/.eslintignore +++ b/.eslintignore @@ -126,6 +126,7 @@ ElectronClient/gui/MainScreen/commands/toggleSideBar.js ElectronClient/gui/MainScreen/commands/toggleVisiblePanes.js ElectronClient/gui/MainScreen/MainScreen.js ElectronClient/gui/MenuBar.js +ElectronClient/gui/menuCommandNames.js ElectronClient/gui/MultiNoteActions.js ElectronClient/gui/NoteContentPropertiesDialog.js ElectronClient/gui/NoteEditor/commands/editorCommandDeclarations.js diff --git a/.gitignore b/.gitignore index 433a570480..f41f7f70a5 100644 --- a/.gitignore +++ b/.gitignore @@ -120,6 +120,7 @@ ElectronClient/gui/MainScreen/commands/toggleSideBar.js ElectronClient/gui/MainScreen/commands/toggleVisiblePanes.js ElectronClient/gui/MainScreen/MainScreen.js ElectronClient/gui/MenuBar.js +ElectronClient/gui/menuCommandNames.js ElectronClient/gui/MultiNoteActions.js ElectronClient/gui/NoteContentPropertiesDialog.js ElectronClient/gui/NoteEditor/commands/editorCommandDeclarations.js diff --git a/.ignore b/.ignore index 9170d586ea..48a1ecc655 100644 --- a/.ignore +++ b/.ignore @@ -69,6 +69,7 @@ ElectronClient/gui/MainScreen/commands/toggleSideBar.js ElectronClient/gui/MainScreen/commands/toggleVisiblePanes.js ElectronClient/gui/MainScreen/MainScreen.js ElectronClient/gui/MenuBar.js +ElectronClient/gui/menuCommandNames.js ElectronClient/gui/MultiNoteActions.js ElectronClient/gui/NoteContentPropertiesDialog.js ElectronClient/gui/NoteEditor/commands/editorCommandDeclarations.js diff --git a/ElectronClient/app.ts b/ElectronClient/app.ts index a1077806cd..562cbdc2c8 100644 --- a/ElectronClient/app.ts +++ b/ElectronClient/app.ts @@ -14,6 +14,7 @@ import Setting from 'lib/models/Setting'; import actionApi from 'lib/services/rest/actionApi.desktop'; import BaseApplication from 'lib/BaseApplication'; import { _, setLocale } from 'lib/locale'; +import menuCommandNames from './gui/menuCommandNames'; require('app-module-path').addPath(__dirname); @@ -526,7 +527,9 @@ class Application extends BaseApplication { } const keymapService = KeymapService.instance(); - keymapService.initialize(CommandService.instance().commandNames(true)); + // We only add the commands that appear in the menu because only + // those can have a shortcut associated with them. + keymapService.initialize(menuCommandNames()); try { await keymapService.loadCustomKeymap(`${dir}/keymap-desktop.json`); @@ -534,9 +537,10 @@ class Application extends BaseApplication { reg.logger().error(error); } - // Since the settings need to be loaded before the store is created, it will never - // receive the SETTING_UPDATE_ALL even, which mean state.settings will not be - // initialised. So we manually call dispatchUpdateAll() to force an update. + // Since the settings need to be loaded before the store is + // created, it will never receive the SETTING_UPDATE_ALL even, + // which mean state.settings will not be initialised. So we + // manually call dispatchUpdateAll() to force an update. Setting.dispatchUpdateAll(); await FoldersScreenUtils.refreshFolders(); diff --git a/ElectronClient/gui/MenuBar.tsx b/ElectronClient/gui/MenuBar.tsx index 01c5cc0f66..49908d0fb8 100644 --- a/ElectronClient/gui/MenuBar.tsx +++ b/ElectronClient/gui/MenuBar.tsx @@ -14,6 +14,7 @@ import InteropServiceHelper from '../InteropServiceHelper'; import { _ } from 'lib/locale'; import { MenuItem, MenuItemLocation } from 'lib/services/plugins/api/types'; import stateToWhenClauseContext from 'lib/services/commands/stateToWhenClauseContext'; +import menuCommandNames from './menuCommandNames'; const { connect } = require('react-redux'); const { reg } = require('lib/registry.js'); @@ -86,41 +87,7 @@ interface Props { pluginMenus: any[], } -const commandNames:string[] = [ - 'focusElementSideBar', - 'focusElementNoteList', - 'focusElementNoteTitle', - 'focusElementNoteBody', - 'exportPdf', - 'newNote', - 'newTodo', - 'newFolder', - 'newSubFolder', - 'print', - 'synchronize', - 'textCopy', - 'textCut', - 'textPaste', - 'textSelectAll', - 'textBold', - 'textItalic', - 'textLink', - 'textCode', - 'insertDateTime', - 'attachFile', - 'focusSearch', - 'showLocalSearch', - 'toggleSideBar', - 'toggleNoteList', - 'toggleVisiblePanes', - 'toggleExternalEditing', - 'setTags', - 'showNoteContentProperties', - 'copyDevCommand', - 'openProfileDirectory', - 'historyBackward', - 'historyForward', -]; +const commandNames:string[] = menuCommandNames(); function menuItemSetChecked(id:string, checked:boolean) { const menu = Menu.getApplicationMenu(); diff --git a/ElectronClient/gui/menuCommandNames.ts b/ElectronClient/gui/menuCommandNames.ts new file mode 100644 index 0000000000..af34d9c96b --- /dev/null +++ b/ElectronClient/gui/menuCommandNames.ts @@ -0,0 +1,37 @@ +export default function() { + return [ + 'attachFile', + 'copyDevCommand', + 'exportPdf', + 'focusElementNoteBody', + 'focusElementNoteList', + 'focusElementNoteTitle', + 'focusElementSideBar', + 'focusSearch', + 'historyBackward', + 'historyForward', + 'insertDateTime', + 'newFolder', + 'newNote', + 'newSubFolder', + 'newTodo', + 'openProfileDirectory', + 'print', + 'setTags', + 'showLocalSearch', + 'showNoteContentProperties', + 'synchronize', + 'textBold', + 'textCode', + 'textCopy', + 'textCut', + 'textItalic', + 'textLink', + 'textPaste', + 'textSelectAll', + 'toggleExternalEditing', + 'toggleNoteList', + 'toggleSideBar', + 'toggleVisiblePanes', + ]; +}