1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/packages/app-desktop/gui/MainScreen/commands/selectTemplate.ts
2020-11-25 14:40:25 +00:00

34 lines
1.0 KiB
TypeScript

import CommandService, { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
import { _ } from '@joplin/lib/locale';
const TemplateUtils = require('@joplin/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') {
void CommandService.instance().execute('newNote', answer.value, noteType === 'todo');
} else {
void CommandService.instance().execute('insertText', TemplateUtils.render(answer.value));
}
}
comp.setState({ promptOptions: null });
},
},
});
},
};
};