2020-11-05 16:58:23 +00:00
|
|
|
import CommandService, { CommandRuntime, CommandDeclaration } from '@joplinapp/lib/services/CommandService';
|
|
|
|
import { _ } from '@joplinapp/lib/locale';
|
|
|
|
import { stateUtils } from '@joplinapp/lib/reducer';
|
2020-10-18 21:52:10 +01:00
|
|
|
import { DesktopCommandContext } from '../services/commands/types';
|
2020-10-10 13:32:30 +01:00
|
|
|
|
|
|
|
export const declaration:CommandDeclaration = {
|
|
|
|
name: 'toggleExternalEditing',
|
|
|
|
label: () => _('Toggle external editing'),
|
|
|
|
iconName: 'icon-share',
|
|
|
|
};
|
|
|
|
|
|
|
|
export const runtime = ():CommandRuntime => {
|
|
|
|
return {
|
2020-10-18 21:52:10 +01:00
|
|
|
execute: async (context:DesktopCommandContext, noteId:string = null) => {
|
|
|
|
noteId = noteId || stateUtils.selectedNoteId(context.state);
|
|
|
|
|
|
|
|
if (!noteId) return;
|
2020-10-10 13:32:30 +01:00
|
|
|
|
2020-10-18 21:52:10 +01:00
|
|
|
if (context.state.watchedNoteFiles.includes(noteId)) {
|
|
|
|
CommandService.instance().execute('stopExternalEditing', noteId);
|
2020-10-10 13:32:30 +01:00
|
|
|
} else {
|
2020-10-18 21:52:10 +01:00
|
|
|
CommandService.instance().execute('startExternalEditing', noteId);
|
2020-10-10 13:32:30 +01:00
|
|
|
}
|
|
|
|
},
|
2020-10-18 21:52:10 +01:00
|
|
|
enabledCondition: 'oneNoteSelected',
|
|
|
|
mapStateToTitle: (state:any) => {
|
|
|
|
const noteId = stateUtils.selectedNoteId(state);
|
|
|
|
return state.watchedNoteFiles.includes(noteId) ? _('Stop') : '';
|
2020-10-10 13:32:30 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|