1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/packages/app-desktop/commands/toggleExternalEditing.ts
2023-07-16 17:42:42 +01:00

33 lines
1.2 KiB
TypeScript

import CommandService, { CommandRuntime, CommandDeclaration } from '@joplin/lib/services/CommandService';
import { _ } from '@joplin/lib/locale';
import { stateUtils } from '@joplin/lib/reducer';
import { DesktopCommandContext } from '../services/commands/types';
import { enabledCondition } from '../gui/NoteEditor/editorCommandDeclarations';
export const declaration: CommandDeclaration = {
name: 'toggleExternalEditing',
label: () => _('Toggle external editing'),
iconName: 'icon-share',
};
export const runtime = (): CommandRuntime => {
return {
execute: async (context: DesktopCommandContext, noteId: string = null) => {
noteId = noteId || stateUtils.selectedNoteId(context.state);
if (!noteId) return;
if (context.state.watchedNoteFiles.includes(noteId)) {
void CommandService.instance().execute('stopExternalEditing', noteId);
} else {
void CommandService.instance().execute('startExternalEditing', noteId);
}
},
enabledCondition: enabledCondition(declaration.name),
mapStateToTitle: (state: any) => {
const noteId = stateUtils.selectedNoteId(state);
return state.watchedNoteFiles.includes(noteId) ? _('Stop') : '';
},
};
};