diff --git a/ElectronClient/gui/KeymapConfig/utils/getLabel.ts b/ElectronClient/gui/KeymapConfig/utils/getLabel.ts index 099aeaee0..ea2f2d5c2 100644 --- a/ElectronClient/gui/KeymapConfig/utils/getLabel.ts +++ b/ElectronClient/gui/KeymapConfig/utils/getLabel.ts @@ -1,4 +1,4 @@ -import CommandService from '../../../lib/services/CommandService'; +import CommandService from 'lib/services/CommandService'; const { _ } = require('lib/locale'); const { shim } = require('lib/shim'); @@ -6,7 +6,7 @@ const { shim } = require('lib/shim'); const commandService = CommandService.instance(); const getLabel = (commandName: string) => { - if (commandService.exists(commandName)) return commandService.label(commandName); + if (commandService.exists(commandName)) return commandService.label(commandName, true); // Some commands are not registered in CommandService at the moment // Following hard-coded labels are used as a workaround diff --git a/ElectronClient/gui/NoteEditor/commands/focusElementNoteBody.ts b/ElectronClient/gui/NoteEditor/commands/focusElementNoteBody.ts index 9bec4f2a4..a79714d81 100644 --- a/ElectronClient/gui/NoteEditor/commands/focusElementNoteBody.ts +++ b/ElectronClient/gui/NoteEditor/commands/focusElementNoteBody.ts @@ -4,6 +4,7 @@ const { _ } = require('lib/locale'); export const declaration:CommandDeclaration = { name: 'focusElementNoteBody', label: () => _('Note body'), + parentLabel: () => _('Focus'), }; export const runtime = (comp:any):CommandRuntime => { diff --git a/ElectronClient/gui/NoteEditor/commands/focusElementNoteTitle.ts b/ElectronClient/gui/NoteEditor/commands/focusElementNoteTitle.ts index 3c3d3048b..5ef9db1af 100644 --- a/ElectronClient/gui/NoteEditor/commands/focusElementNoteTitle.ts +++ b/ElectronClient/gui/NoteEditor/commands/focusElementNoteTitle.ts @@ -4,6 +4,7 @@ const { _ } = require('lib/locale'); export const declaration:CommandDeclaration = { name: 'focusElementNoteTitle', label: () => _('Note title'), + parentLabel: () => _('Focus'), }; export const runtime = (comp:any):CommandRuntime => { diff --git a/ElectronClient/gui/NoteList/commands/focusElementNoteList.ts b/ElectronClient/gui/NoteList/commands/focusElementNoteList.ts index 1e8dfa1cf..d0c2b054b 100644 --- a/ElectronClient/gui/NoteList/commands/focusElementNoteList.ts +++ b/ElectronClient/gui/NoteList/commands/focusElementNoteList.ts @@ -4,6 +4,7 @@ const { _ } = require('lib/locale'); export const declaration:CommandDeclaration = { name: 'focusElementNoteList', label: () => _('Note list'), + parentLabel: () => _('Focus'), }; export const runtime = (comp:any):CommandRuntime => { diff --git a/ElectronClient/gui/SideBar/commands/focusElementSideBar.ts b/ElectronClient/gui/SideBar/commands/focusElementSideBar.ts index 90238d8d1..47f9a0a72 100644 --- a/ElectronClient/gui/SideBar/commands/focusElementSideBar.ts +++ b/ElectronClient/gui/SideBar/commands/focusElementSideBar.ts @@ -4,6 +4,7 @@ const { _ } = require('lib/locale'); export const declaration:CommandDeclaration = { name: 'focusElementSideBar', label: () => _('Sidebar'), + parentLabel: () => _('Focus'), }; export const runtime = (comp:any):CommandRuntime => { diff --git a/ReactNativeClient/lib/services/CommandService.ts b/ReactNativeClient/lib/services/CommandService.ts index 94b8c1b41..0fa985090 100644 --- a/ReactNativeClient/lib/services/CommandService.ts +++ b/ReactNativeClient/lib/services/CommandService.ts @@ -13,8 +13,19 @@ export interface CommandRuntime { export interface CommandDeclaration { name: string + // Used for the menu item label, and toolbar button tooltip label?():string, + + // This is a bit of a hack because some labels don't make much sense in isolation. For example, + // the commmand to focus the note list is called just "Note list". This makes sense within the menu + // but not so much within the keymap config screen, where the parent item is not displayed. Because + // of this we have this "parentLabel()" property to clarify the meaning of the certain items. + // For example, the focusElementNoteList will have these two properties: + // label() => _('Note list'), + // parentLabel() => _('Focus'), + // Which will be displayed as "Focus: Note list" in the keymap config screen. + parentLabel?():string, iconName?: string, // Same as `role` key in Electron MenuItem: // https://www.electronjs.org/docs/api/menu-item#new-menuitemoptions @@ -249,10 +260,13 @@ export default class CommandService extends BaseService { return command.runtime.title(command.runtime.props); } - label(commandName:string):string { + label(commandName:string, fullLabel:boolean = false):string { const command = this.commandByName(commandName); if (!command) throw new Error(`Command: ${commandName} is not declared`); - return command.declaration.label(); + const output = []; + if (fullLabel && command.declaration.parentLabel && command.declaration.parentLabel()) output.push(command.declaration.parentLabel()); + output.push(command.declaration.label()); + return output.join(': '); } exists(commandName:string):boolean { @@ -271,7 +285,7 @@ export default class CommandService extends BaseService { const command = this.commandByName(commandName, { runtimeMustBeRegistered: true }); return { - tooltip: command.declaration.label(), + tooltip: this.label(commandName), iconName: command.declaration.iconName, enabled: this.isEnabled(commandName), onClick: () => { @@ -286,7 +300,7 @@ export default class CommandService extends BaseService { const item:any = { id: command.declaration.name, - label: command.declaration.label(), + label: this.label(commandName), click: () => { this.execute(commandName, this.extractExecuteArgs(command, executeArgs)); }, diff --git a/ReactNativeClient/lib/services/KeymapService.ts b/ReactNativeClient/lib/services/KeymapService.ts index e61e42564..2594a8449 100644 --- a/ReactNativeClient/lib/services/KeymapService.ts +++ b/ReactNativeClient/lib/services/KeymapService.ts @@ -38,6 +38,7 @@ const defaultKeymapItems = { { accelerator: 'Shift+Cmd+N', command: 'focusElementNoteTitle' }, { accelerator: 'Shift+Cmd+B', command: 'focusElementNoteBody' }, { accelerator: 'Option+Cmd+S', command: 'toggleSidebar' }, + { accelerator: 'Option+Cmd+L', command: 'toggleNoteList' }, { accelerator: 'Cmd+L', command: 'toggleVisiblePanes' }, { accelerator: 'Cmd+0', command: 'zoomActualSize' }, { accelerator: 'Cmd+E', command: 'startExternalEditing' }, @@ -68,6 +69,7 @@ const defaultKeymapItems = { { accelerator: 'Ctrl+Shift+N', command: 'focusElementNoteTitle' }, { accelerator: 'Ctrl+Shift+B', command: 'focusElementNoteBody' }, { accelerator: 'F10', command: 'toggleSidebar' }, + { accelerator: 'F11', command: 'toggleNoteList' }, { accelerator: 'Ctrl+L', command: 'toggleVisiblePanes' }, { accelerator: 'Ctrl+0', command: 'zoomActualSize' }, { accelerator: 'Ctrl+E', command: 'startExternalEditing' },