1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/ElectronClient/gui/MainScreen/commands/selectTemplate.ts

34 lines
1.0 KiB
TypeScript
Raw Normal View History

import CommandService, { CommandRuntime, CommandDeclaration } from '../../../lib/services/CommandService';
const { _ } = require('lib/locale');
const TemplateUtils = require('lib/TemplateUtils');
export const declaration:CommandDeclaration = {
name: 'selectTemplate',
};
export const runtime = (comp:any):CommandRuntime => {
return {
execute: async ({ noteType }:any) => {
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', { template: answer.value, isTodo: noteType === 'todo' });
} else {
CommandService.instance().execute('insertText', { value: TemplateUtils.render(answer.value) });
}
}
comp.setState({ promptOptions: null });
},
},
});
},
};
};