1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-30 10:36:35 +02:00
joplin/ElectronClient/gui/MainScreen/commands/newFolder.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

44 lines
1.1 KiB
TypeScript

import { CommandContext, CommandDeclaration, CommandRuntime } from 'lib/services/CommandService';
import { _ } from 'lib/locale';
const Folder = require('lib/models/Folder');
const bridge = require('electron').remote.require('./bridge').default;
export const declaration:CommandDeclaration = {
name: 'newFolder',
label: () => _('New notebook'),
iconName: 'fa-book',
};
export const runtime = (comp:any):CommandRuntime => {
return {
execute: async (_context:CommandContext, parentId:string = null) => {
comp.setState({
promptOptions: {
label: _('Notebook title:'),
onClose: async (answer:string) => {
if (answer) {
let folder = null;
try {
const toSave:any = { title: answer };
if (parentId) toSave.parent_id = parentId;
folder = await Folder.save(toSave, { userSideValidation: true });
} catch (error) {
bridge().showErrorMessageBox(error.message);
}
if (folder) {
comp.props.dispatch({
type: 'FOLDER_SELECT',
id: folder.id,
});
}
}
comp.setState({ promptOptions: null });
},
},
});
},
};
};