2023-07-16 18:42:42 +02:00
|
|
|
import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
|
|
|
|
import { _ } from '@joplin/lib/locale';
|
|
|
|
import Note from '@joplin/lib/models/Note';
|
|
|
|
|
|
|
|
export const declaration: CommandDeclaration = {
|
|
|
|
name: 'deleteNote',
|
|
|
|
label: () => _('Delete note'),
|
|
|
|
iconName: 'fa-times',
|
|
|
|
};
|
|
|
|
|
|
|
|
export const runtime = (): CommandRuntime => {
|
|
|
|
return {
|
|
|
|
execute: async (context: CommandContext, noteIds: string[] = null) => {
|
|
|
|
if (noteIds === null) noteIds = context.state.selectedNoteIds;
|
|
|
|
if (!noteIds.length) return;
|
2024-03-02 16:25:27 +02:00
|
|
|
await Note.batchDelete(noteIds, { toTrash: true });
|
2023-07-16 18:42:42 +02:00
|
|
|
|
2024-03-02 16:25:27 +02:00
|
|
|
context.dispatch({
|
|
|
|
type: 'ITEMS_TRASHED',
|
|
|
|
value: {
|
|
|
|
noteIds,
|
|
|
|
folderIds: [],
|
|
|
|
},
|
2023-07-16 18:42:42 +02:00
|
|
|
});
|
|
|
|
},
|
2024-03-02 16:25:27 +02:00
|
|
|
enabledCondition: '!noteIsReadOnly && !inTrash && someNotesSelected',
|
2023-07-16 18:42:42 +02:00
|
|
|
};
|
|
|
|
};
|