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

50 lines
1.4 KiB
TypeScript

import { CommandRuntime, CommandDeclaration, CommandContext } from 'lib/services/CommandService';
import { _ } from 'lib/locale';
const Folder = require('lib/models/Folder');
const Note = require('lib/models/Note');
export const declaration:CommandDeclaration = {
name: 'moveToFolder',
label: () => _('Move to notebook'),
};
export const runtime = (comp:any):CommandRuntime => {
return {
execute: async (context:CommandContext, noteIds:string[] = null) => {
noteIds = noteIds || context.state.selectedNoteIds;
const folders:any[] = await Folder.sortFolderTree();
const startFolders:any[] = [];
const maxDepth = 15;
const addOptions = (folders:any[], depth:number) => {
for (let i = 0; i < folders.length; i++) {
const folder = folders[i];
startFolders.push({ key: folder.id, value: folder.id, label: folder.title, indentDepth: depth });
if (folder.children) addOptions(folder.children, (depth + 1) < maxDepth ? depth + 1 : maxDepth);
}
};
addOptions(folders, 0);
comp.setState({
promptOptions: {
label: _('Move to notebook:'),
inputType: 'dropdown',
value: '',
autocomplete: startFolders,
onClose: async (answer:any) => {
if (answer != null) {
for (let i = 0; i < noteIds.length; i++) {
await Note.moveToFolder(noteIds[i], answer.value);
}
}
comp.setState({ promptOptions: null });
},
},
});
},
enabledCondition: 'someNotesSelected',
};
};