1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-26 18:58:21 +02:00

Desktop: Fixes #2467: Disable or enable menu items depending on the current view

This commit is contained in:
Laurent Cozic 2020-05-06 23:31:18 +00:00
parent c273fd4d63
commit a04092c99c

View File

@ -248,6 +248,8 @@ class Application extends BaseApplication {
} }
async generalMiddleware(store, next, action) { async generalMiddleware(store, next, action) {
let mustUpdateMenuItemStates = false;
if (action.type == 'SETTING_UPDATE_ONE' && action.key == 'locale' || action.type == 'SETTING_UPDATE_ALL') { if (action.type == 'SETTING_UPDATE_ONE' && action.key == 'locale' || action.type == 'SETTING_UPDATE_ALL') {
setLocale(Setting.value('locale')); setLocale(Setting.value('locale'));
// The bridge runs within the main process, with its own instance of locale.js // 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); 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) { if (['EVENT_NOTE_ALARM_FIELD_CHANGE', 'NOTE_DELETE'].indexOf(action.type) >= 0) {
await AlarmService.updateNoteNotification(action.id, action.type === 'NOTE_DELETE'); await AlarmService.updateNoteNotification(action.id, action.type === 'NOTE_DELETE');
} }
@ -291,15 +297,17 @@ class Application extends BaseApplication {
Setting.setValue('noteListVisibility', newState.noteListVisibility); Setting.setValue('noteListVisibility', newState.noteListVisibility);
} }
if (action.type.indexOf('NOTE_SELECT') === 0 || action.type.indexOf('FOLDER_SELECT') === 0) { if (action.type.indexOf('NOTE_SELECT') === 0 || action.type.indexOf('FOLDER_SELECT') === 0 || action.type === 'NOTE_VISIBLE_PANES_TOGGLE') {
this.updateMenuItemStates(newState); mustUpdateMenuItemStates = true;
} }
if (['NOTE_DEVTOOLS_TOGGLE', 'NOTE_DEVTOOLS_SET'].indexOf(action.type) >= 0) { if (['NOTE_DEVTOOLS_TOGGLE', 'NOTE_DEVTOOLS_SET'].indexOf(action.type) >= 0) {
this.toggleDevTools(newState.devToolsVisible); this.toggleDevTools(newState.devToolsVisible);
this.updateMenuItemStates(newState); mustUpdateMenuItemStates = true;
} }
if (mustUpdateMenuItemStates) this.updateMenuItemStates(newState);
return result; return result;
} }
@ -1058,12 +1066,12 @@ class Application extends BaseApplication {
type: 'separator', type: 'separator',
screens: ['Main'], screens: ['Main'],
}, { }, {
id: 'note:statistics',
label: _('Statistics...'), label: _('Statistics...'),
click: () => { click: () => {
this.dispatch({ this.dispatch({
type: 'WINDOW_COMMAND', type: 'WINDOW_COMMAND',
name: 'commandContentProperties', name: 'commandContentProperties',
// text: this.state.note.body,
}); });
}, },
}], }],
@ -1209,11 +1217,40 @@ class Application extends BaseApplication {
const selectedNoteIds = state.selectedNoteIds; const selectedNoteIds = state.selectedNoteIds;
const note = selectedNoteIds.length === 1 ? await Note.load(selectedNoteIds[0]) : null; 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']) { // Only enabled when there's only one active note, and that note
const menuItem = Menu.getApplicationMenu().getMenuItemById(`edit:${itemId}`); // 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; 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'); const menuItem = Menu.getApplicationMenu().getMenuItemById('help:toggleDevTools');