1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/ElectronClient/gui/MainScreen/commands/newNote.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

39 lines
1.1 KiB
TypeScript

import { utils, CommandRuntime, CommandDeclaration, CommandContext } from 'lib/services/CommandService';
import { _ } from 'lib/locale';
const Setting = require('lib/models/Setting').default;
const Note = require('lib/models/Note');
const TemplateUtils = require('lib/TemplateUtils');
export const declaration:CommandDeclaration = {
name: 'newNote',
label: () => _('New note'),
iconName: 'fa-file',
};
export const runtime = ():CommandRuntime => {
return {
execute: async (_context:CommandContext, template:string = null, isTodo:boolean = false) => {
const folderId = Setting.value('activeFolderId');
if (!folderId) return;
const body = template ? TemplateUtils.render(template) : '';
const defaultValues = Note.previewFieldsWithDefaultValues({ includeTimestamps: false });
let newNote = Object.assign({}, defaultValues, {
parent_id: folderId,
is_todo: isTodo ? 1 : 0,
body: body,
});
newNote = await Note.save(newNote, { provisional: true });
utils.store.dispatch({
type: 'NOTE_SELECT',
id: newNote.id,
});
},
enabledCondition: 'oneFolderSelected && !inConflictFolder',
};
};