1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Desktop: Improved menu enabled states when not in main screen

This commit is contained in:
Laurent Cozic
2020-09-21 17:09:57 +01:00
parent 3ac4fbeee5
commit 7a4c97618d
4 changed files with 13 additions and 5 deletions

View File

@ -377,7 +377,7 @@ class Application extends BaseApplication {
await this.updateMenu(screen);
}
async updateMenu(screen) {
async updateMenu(screen, updateStates = true) {
if (this.lastMenuScreen_ === screen) return;
const cmdService = CommandService.instance();
@ -740,7 +740,6 @@ class Application extends BaseApplication {
const separator = () => {
return {
type: 'separator',
screens: ['Main'],
};
};
@ -988,6 +987,8 @@ class Application extends BaseApplication {
Menu.setApplicationMenu(menu);
this.lastMenuScreen_ = screen;
if (updateStates) await this.updateMenuItemStates();
}
async updateMenuItemStates(state = null) {
@ -1130,7 +1131,7 @@ class Application extends BaseApplication {
CommandService.instance().registerDeclaration(declaration);
}
this.updateMenu('Main');
this.updateMenu('Main', false);
// Since the settings need to be loaded before the store is created, it will never
// receive the SETTING_UPDATE_ALL even, which mean state.settings will not be

View File

@ -27,10 +27,14 @@ export const runtime = ():CommandRuntime => {
// await comp.saveNoteAndWait(comp.formNote);
},
isEnabled: (props:any) => {
if (props.routeName !== 'Main') return false;
return !!props.noteId;
},
mapStateToProps: (state:any) => {
return { noteId: state.selectedNoteIds.length === 1 ? state.selectedNoteIds[0] : null };
return {
noteId: state.selectedNoteIds.length === 1 ? state.selectedNoteIds[0] : null,
routeName: state.route.routeName,
};
},
};
};

View File

@ -18,10 +18,11 @@ export const runtime = ():CommandRuntime => {
ExternalEditWatcher.instance().stopWatching(props.noteId);
},
isEnabled: (props:any) => {
if (props.routeName !== 'Main') return false;
return !!props.noteId;
},
mapStateToProps: (state:any) => {
return { noteId: state.selectedNoteIds.length === 1 ? state.selectedNoteIds[0] : null };
return { noteId: state.selectedNoteIds.length === 1 ? state.selectedNoteIds[0] : null, routeName: state.route.routeName };
},
};
};

View File

@ -44,6 +44,7 @@ function editorCommandRuntime(declaration:CommandDeclaration, editorRef:any):Com
}
},
isEnabled: (props:any) => {
if (props.routeName !== 'Main') return false;
if (props.markdownEditorViewerOnly) return false;
if (!props.noteId) return false;
const note = BaseModel.byId(props.notes, props.noteId);
@ -58,6 +59,7 @@ function editorCommandRuntime(declaration:CommandDeclaration, editorRef:any):Com
noteVisiblePanes: state.noteVisiblePanes,
notes: state.notes,
noteId: state.selectedNoteIds.length === 1 ? state.selectedNoteIds[0] : null,
routeName: state.route.routeName,
};
},
};