2020-07-03 23:32:39 +02:00
|
|
|
import { CommandRuntime, CommandDeclaration } from '../lib/services/CommandService';
|
2020-10-09 19:35:46 +02:00
|
|
|
import { _ } from 'lib/locale';
|
2020-07-03 23:32:39 +02:00
|
|
|
const Note = require('lib/models/Note');
|
|
|
|
const ExternalEditWatcher = require('lib/services/ExternalEditWatcher');
|
2020-10-09 19:35:46 +02:00
|
|
|
const bridge = require('electron').remote.require('./bridge').default;
|
2020-07-03 23:32:39 +02:00
|
|
|
|
|
|
|
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',
|
2020-07-03 23:32:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
isEnabled: (props:any) => {
|
|
|
|
return !!props.noteId;
|
|
|
|
},
|
|
|
|
mapStateToProps: (state:any) => {
|
2020-09-21 18:09:57 +02:00
|
|
|
return {
|
|
|
|
noteId: state.selectedNoteIds.length === 1 ? state.selectedNoteIds[0] : null,
|
|
|
|
};
|
2020-07-03 23:32:39 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|