1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Clarifies labels of certain actions, and added shortcut for note list toggle

This commit is contained in:
Laurent Cozic 2020-09-13 17:21:11 +01:00
parent 1ba0644142
commit 998dd52adc
7 changed files with 26 additions and 6 deletions

View File

@ -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

View File

@ -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 => {

View File

@ -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 => {

View File

@ -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 => {

View File

@ -4,6 +4,7 @@ const { _ } = require('lib/locale');
export const declaration:CommandDeclaration = {
name: 'focusElementSideBar',
label: () => _('Sidebar'),
parentLabel: () => _('Focus'),
};
export const runtime = (comp:any):CommandRuntime => {

View File

@ -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));
},

View File

@ -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' },