1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-30 23:44:55 +02:00
Files
joplin/ElectronClient/gui/MainScreen/commands/selectTemplate.ts
Laurent Cozic 3a57cfea02 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
2020-10-18 21:52:10 +01:00

34 lines
1.0 KiB
TypeScript

import CommandService, { CommandRuntime, CommandDeclaration, CommandContext } from 'lib/services/CommandService';
import { _ } from 'lib/locale';
const TemplateUtils = require('lib/TemplateUtils');
export const declaration:CommandDeclaration = {
name: 'selectTemplate',
};
export const runtime = (comp:any):CommandRuntime => {
return {
execute: async (_context:CommandContext, noteType:string) => {
comp.setState({
promptOptions: {
label: _('Template file:'),
inputType: 'dropdown',
value: comp.props.templates[0], // Need to start with some value
autocomplete: comp.props.templates,
onClose: async (answer:any) => {
if (answer) {
if (noteType === 'note' || noteType === 'todo') {
CommandService.instance().execute('newNote', answer.value, noteType === 'todo');
} else {
CommandService.instance().execute('insertText', TemplateUtils.render(answer.value));
}
}
comp.setState({ promptOptions: null });
},
},
});
},
};
};