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

Desktop: Simplified and improve command service, and added command palette

- Commands "enabled" state is now expressed using a "when-clause" like in VSCode
- A command palette has been added to the Tools menu
This commit is contained in:
Laurent Cozic
2020-10-18 21:52:10 +01:00
parent f529adac99
commit 3a57cfea02
78 changed files with 897 additions and 756 deletions

View File

@ -1,4 +1,4 @@
import { CommandRuntime, CommandDeclaration } from '../../../lib/services/CommandService';
import { CommandRuntime, CommandDeclaration, CommandContext } from 'lib/services/CommandService';
import shim from 'lib/shim';
import InteropServiceHelper from '../../../InteropServiceHelper';
import { _ } from 'lib/locale';
@ -12,8 +12,10 @@ export const declaration:CommandDeclaration = {
export const runtime = (comp:any):CommandRuntime => {
return {
execute: async ({ noteIds }:any) => {
execute: async (context:CommandContext, noteIds:string[] = null) => {
try {
noteIds = noteIds || context.state.selectedNoteIds;
if (!noteIds.length) throw new Error('No notes selected for pdf export');
let path = null;
@ -22,7 +24,6 @@ export const runtime = (comp:any):CommandRuntime => {
filters: [{ name: _('PDF File'), extensions: ['pdf'] }],
defaultPath: await InteropServiceHelper.defaultFilename(noteIds[0], 'pdf'),
});
} else {
path = bridge().showOpenDialog({
properties: ['openDirectory', 'createDirectory'],
@ -50,13 +51,7 @@ export const runtime = (comp:any):CommandRuntime => {
bridge().showErrorMessageBox(error.message);
}
},
isEnabled: (props:any):boolean => {
return !!props.noteIds.length;
},
mapStateToProps: (state:any):any => {
return {
noteIds: state.selectedNoteIds,
};
},
enabledCondition: 'someNotesSelected',
};
};