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

Desktop: Fixes #2467: Menu items were not disabled in viewer-only mode (#2576)

* preview mode fix

* preview-edit mode fixed

* remove unecessary white space

* improved logic and removed empty line

* improved code and removed comment

* improved code again

* changed note type check logic

* improved code
This commit is contained in:
Runo Saduwa 2020-03-06 23:58:52 +01:00 committed by GitHub
parent 67e5451c7c
commit 0be982c798
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -281,6 +281,8 @@ class Application extends BaseApplication {
if (['NOTE_VISIBLE_PANES_TOGGLE', 'NOTE_VISIBLE_PANES_SET'].indexOf(action.type) >= 0) { if (['NOTE_VISIBLE_PANES_TOGGLE', 'NOTE_VISIBLE_PANES_SET'].indexOf(action.type) >= 0) {
Setting.setValue('noteVisiblePanes', newState.noteVisiblePanes); Setting.setValue('noteVisiblePanes', newState.noteVisiblePanes);
const layout = newState.noteVisiblePanes[0];
this.updateMenuItemStates(layout);
} }
if (['SIDEBAR_VISIBILITY_TOGGLE', 'SIDEBAR_VISIBILITY_SET'].indexOf(action.type) >= 0) { if (['SIDEBAR_VISIBILITY_TOGGLE', 'SIDEBAR_VISIBILITY_SET'].indexOf(action.type) >= 0) {
@ -292,7 +294,8 @@ class Application extends BaseApplication {
} }
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) {
this.updateMenuItemStates(newState); const layout = newState.noteVisiblePanes[0];
this.updateMenuItemStates(layout, newState);
} }
if (['NOTE_DEVTOOLS_TOGGLE', 'NOTE_DEVTOOLS_SET'].indexOf(action.type) >= 0) { if (['NOTE_DEVTOOLS_TOGGLE', 'NOTE_DEVTOOLS_SET'].indexOf(action.type) >= 0) {
@ -1166,7 +1169,7 @@ class Application extends BaseApplication {
this.lastMenuScreen_ = screen; this.lastMenuScreen_ = screen;
} }
async updateMenuItemStates(state = null) { async updateMenuItemStates(layout, state = null) {
if (!this.lastMenuScreen_) return; if (!this.lastMenuScreen_) return;
if (!this.store() && !state) return; if (!this.store() && !state) return;
@ -1178,7 +1181,8 @@ class Application extends BaseApplication {
for (const itemId of ['copy', 'paste', 'cut', 'selectAll', 'bold', 'italic', 'link', 'code', 'insertDateTime', 'commandStartExternalEditing', 'showLocalSearch']) { for (const itemId of ['copy', 'paste', 'cut', 'selectAll', 'bold', 'italic', 'link', 'code', 'insertDateTime', 'commandStartExternalEditing', 'showLocalSearch']) {
const menuItem = Menu.getApplicationMenu().getMenuItemById(`edit:${itemId}`); const menuItem = Menu.getApplicationMenu().getMenuItemById(`edit:${itemId}`);
if (!menuItem) continue; if (!menuItem) continue;
menuItem.enabled = !!note && note.markup_language === MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN; const isHtmlNote = !!note && note.markup_language === MarkupToHtml.MARKUP_LANGUAGE_HTML;
menuItem.enabled = !isHtmlNote && layout !== 'viewer' && !!note;
} }
const menuItem = Menu.getApplicationMenu().getMenuItemById('help:toggleDevTools'); const menuItem = Menu.getApplicationMenu().getMenuItemById('help:toggleDevTools');