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

40 lines
1.1 KiB
TypeScript

import { CommandRuntime, CommandDeclaration, CommandContext } 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: 'renameFolder',
label: () => _('Rename'),
};
export const runtime = (comp:any):CommandRuntime => {
return {
execute: async (context:CommandContext, folderId:string = null) => {
folderId = folderId || context.state.selectedFolderId;
const folder = await Folder.load(folderId);
if (folder) {
comp.setState({
promptOptions: {
label: _('Rename notebook:'),
value: folder.title,
onClose: async (answer:string) => {
if (answer !== null) {
try {
folder.title = answer;
await Folder.save(folder, { fields: ['title'], userSideValidation: true });
} catch (error) {
bridge().showErrorMessageBox(error.message);
}
}
comp.setState({ promptOptions: null });
},
},
});
}
},
};
};