diff --git a/ElectronClient/app.js b/ElectronClient/app.js index 3949eb9cb..66eb446d3 100644 --- a/ElectronClient/app.js +++ b/ElectronClient/app.js @@ -248,6 +248,8 @@ class Application extends BaseApplication { } async generalMiddleware(store, next, action) { + let mustUpdateMenuItemStates = false; + if (action.type == 'SETTING_UPDATE_ONE' && action.key == 'locale' || action.type == 'SETTING_UPDATE_ALL') { setLocale(Setting.value('locale')); // The bridge runs within the main process, with its own instance of locale.js @@ -268,6 +270,10 @@ class Application extends BaseApplication { webFrame.setZoomFactor(Setting.value('windowContentZoomFactor') / 100); } + if (action.type == 'SETTING_UPDATE_ONE' && ['editor.codeView'].includes(action.key) || action.type == 'SETTING_UPDATE_ALL') { + mustUpdateMenuItemStates = true; + } + if (['EVENT_NOTE_ALARM_FIELD_CHANGE', 'NOTE_DELETE'].indexOf(action.type) >= 0) { await AlarmService.updateNoteNotification(action.id, action.type === 'NOTE_DELETE'); } @@ -291,15 +297,17 @@ class Application extends BaseApplication { Setting.setValue('noteListVisibility', newState.noteListVisibility); } - if (action.type.indexOf('NOTE_SELECT') === 0 || action.type.indexOf('FOLDER_SELECT') === 0) { - this.updateMenuItemStates(newState); + if (action.type.indexOf('NOTE_SELECT') === 0 || action.type.indexOf('FOLDER_SELECT') === 0 || action.type === 'NOTE_VISIBLE_PANES_TOGGLE') { + mustUpdateMenuItemStates = true; } if (['NOTE_DEVTOOLS_TOGGLE', 'NOTE_DEVTOOLS_SET'].indexOf(action.type) >= 0) { this.toggleDevTools(newState.devToolsVisible); - this.updateMenuItemStates(newState); + mustUpdateMenuItemStates = true; } + if (mustUpdateMenuItemStates) this.updateMenuItemStates(newState); + return result; } @@ -1058,12 +1066,12 @@ class Application extends BaseApplication { type: 'separator', screens: ['Main'], }, { + id: 'note:statistics', label: _('Statistics...'), click: () => { this.dispatch({ type: 'WINDOW_COMMAND', name: 'commandContentProperties', - // text: this.state.note.body, }); }, }], @@ -1209,11 +1217,40 @@ class Application extends BaseApplication { const selectedNoteIds = state.selectedNoteIds; const note = selectedNoteIds.length === 1 ? await Note.load(selectedNoteIds[0]) : null; + const aceEditorViewerOnly = state.settings['editor.codeView'] && state.noteVisiblePanes.length === 1 && state.noteVisiblePanes[0] === 'viewer'; - for (const itemId of ['copy', 'paste', 'cut', 'selectAll', 'bold', 'italic', 'link', 'code', 'insertDateTime', 'commandStartExternalEditing', 'showLocalSearch']) { - const menuItem = Menu.getApplicationMenu().getMenuItemById(`edit:${itemId}`); + // Only enabled when there's only one active note, and that note + // is a Markdown note (markup_language = MARKDOWN), and the + // editor is in edit mode (not viewer-only mode). + const singleMarkdownNoteMenuItems = [ + 'edit:bold', + 'edit:italic', + 'edit:link', + 'edit:code', + 'edit:insertDateTime', + ]; + + // Only enabled when there's only one active note. + const singleNoteMenuItems = [ + 'edit:copy', + 'edit:paste', + 'edit:cut', + 'edit:selectAll', + 'edit:showLocalSearch', + 'edit:commandStartExternalEditing', + 'note:statistics', + ]; + + for (const itemId of singleMarkdownNoteMenuItems) { + const menuItem = Menu.getApplicationMenu().getMenuItemById(itemId); if (!menuItem) continue; - menuItem.enabled = !!note && note.markup_language === MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN; + menuItem.enabled = !aceEditorViewerOnly && !!note && note.markup_language === MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN; + } + + for (const itemId of singleNoteMenuItems) { + const menuItem = Menu.getApplicationMenu().getMenuItemById(itemId); + if (!menuItem) continue; + menuItem.enabled = selectedNoteIds.length === 1; } const menuItem = Menu.getApplicationMenu().getMenuItemById('help:toggleDevTools');