2024-09-21 14:05:27 +02:00
|
|
|
import { CommandRuntime, CommandDeclaration, CommandContext } from '../services/CommandService';
|
|
|
|
import { _ } from '../locale';
|
|
|
|
import Note from '../models/Note';
|
2024-11-16 23:09:50 +02:00
|
|
|
import shim, { MessageBoxType } from '../shim';
|
2024-03-02 16:25:27 +02:00
|
|
|
|
|
|
|
export const declaration: CommandDeclaration = {
|
|
|
|
name: 'permanentlyDeleteNote',
|
|
|
|
label: () => _('Permanently 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;
|
|
|
|
const msg = await Note.permanentlyDeleteMessage(noteIds);
|
|
|
|
|
2024-09-21 14:05:27 +02:00
|
|
|
const deleteIndex = 0;
|
|
|
|
const result = await shim.showMessageBox(msg, {
|
2024-03-02 16:25:27 +02:00
|
|
|
buttons: [_('Delete'), _('Cancel')],
|
|
|
|
defaultId: 1,
|
2024-09-21 14:05:27 +02:00
|
|
|
cancelId: 1,
|
2024-11-16 23:09:50 +02:00
|
|
|
type: MessageBoxType.Confirm,
|
2024-03-02 16:25:27 +02:00
|
|
|
});
|
|
|
|
|
2024-09-21 14:05:27 +02:00
|
|
|
if (result === deleteIndex) {
|
2024-03-09 12:33:05 +02:00
|
|
|
await Note.batchDelete(noteIds, { toTrash: false, sourceDescription: 'permanentlyDeleteNote command' });
|
|
|
|
}
|
2024-03-02 16:25:27 +02:00
|
|
|
},
|
|
|
|
enabledCondition: '(!noteIsReadOnly || inTrash) && someNotesSelected',
|
|
|
|
};
|
|
|
|
};
|