1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/ElectronClient/commands/startExternalEditing.ts

41 lines
1.1 KiB
TypeScript
Raw Normal View History

import { CommandRuntime, CommandDeclaration } from '../lib/services/CommandService';
const { _ } = require('lib/locale');
const Note = require('lib/models/Note');
const ExternalEditWatcher = require('lib/services/ExternalEditWatcher');
const { bridge } = require('electron').remote.require('./bridge');
interface Props {
noteId: string
}
export const declaration:CommandDeclaration = {
name: 'startExternalEditing',
label: () => _('Edit in external editor'),
2020-09-15 15:01:07 +02:00
iconName: 'icon-share',
};
export const runtime = ():CommandRuntime => {
return {
execute: async (props:Props) => {
try {
const note = await Note.load(props.noteId);
ExternalEditWatcher.instance().openAndWatch(note);
} catch (error) {
bridge().showErrorMessageBox(_('Error opening note in editor: %s', error.message));
}
// await comp.saveNoteAndWait(comp.formNote);
},
isEnabled: (props:any) => {
if (props.routeName !== 'Main') return false;
return !!props.noteId;
},
mapStateToProps: (state:any) => {
return {
noteId: state.selectedNoteIds.length === 1 ? state.selectedNoteIds[0] : null,
routeName: state.route.routeName,
};
},
};
};