1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-30 08:26:59 +02:00

Desktop: Add external editor actions to the note context menu. (#2214)

* Add external editor actions to the note context menu.

Also start up external editor on note double click.

These changes enhance user experience by placing the actions where
they feel natural.

* Remove double-click behaviour and change menu text.

Changes in response to review comments.

* Move handling of external editor actions to main screen from note text

This is to ensure correct behaviour even when the user launches the
action on a note in the list that is under the pointer, but not selected.

* Move external edit actions to NoteListUtils from MainScreen.

* Reconnect external edit action in main edit menu.
This commit is contained in:
mic704b 2020-01-07 08:16:39 +11:00 committed by Laurent Cozic
parent 6d9f73eef7
commit 42ada7123c
3 changed files with 46 additions and 9 deletions

View File

@ -87,6 +87,7 @@ class NoteListComponent extends React.Component {
const menu = NoteListUtils.makeContextMenu(noteIds, {
notes: this.props.notes,
dispatch: this.props.dispatch,
watchedNoteFiles: this.props.watchedNoteFiles,
});
menu.popup(bridge().window());

View File

@ -1129,6 +1129,8 @@ class NoteTextComponent extends React.Component {
fn = this.commandDateTime;
} else if (command.name === 'commandStartExternalEditing') {
fn = this.commandStartExternalEditing;
} else if (command.name === 'commandStopExternalEditing') {
fn = this.commandStopExternalEditing;
} else if (command.name === 'showLocalSearch') {
fn = this.commandShowLocalSearch;
} else if (command.name === 'textCode') {
@ -1308,18 +1310,14 @@ class NoteTextComponent extends React.Component {
}
async commandStartExternalEditing() {
try {
await this.saveIfNeeded(true, {
autoTitle: false,
});
await ExternalEditWatcher.instance().openAndWatch(this.state.note);
} catch (error) {
bridge().showErrorMessageBox(_('Error opening note in editor: %s', error.message));
}
await this.saveIfNeeded(true, {
autoTitle: false,
});
NoteListUtils.startExternalEditing(this.state.note.id);
}
async commandStopExternalEditing() {
ExternalEditWatcher.instance().stopWatching(this.state.note.id);
NoteListUtils.stopExternalEditing(this.state.note.id);
}
async commandSetTags() {
@ -1825,6 +1823,7 @@ class NoteTextComponent extends React.Component {
const menu = NoteListUtils.makeContextMenu(this.props.selectedNoteIds, {
notes: this.props.notes,
dispatch: this.props.dispatch,
watchedNoteFiles: this.props.watchedNoteFiles,
});
const buttonStyle = Object.assign({}, theme.buttonStyle, {

View File

@ -7,6 +7,7 @@ const eventManager = require('../../eventManager');
const InteropService = require('lib/services/InteropService');
const InteropServiceHelper = require('../../InteropServiceHelper.js');
const Note = require('lib/models/Note');
const ExternalEditWatcher = require('lib/services/ExternalEditWatcher');
const { substrWithEllipsis } = require('lib/string-utils');
class NoteListUtils {
@ -49,6 +50,28 @@ class NoteListUtils {
})
);
if (props.watchedNoteFiles.indexOf(noteIds[0]) < 0) {
menu.append(
new MenuItem({
label: _('Edit in external editor'),
enabled: noteIds.length === 1,
click: async () => {
this.startExternalEditing(noteIds[0]);
},
})
);
} else {
menu.append(
new MenuItem({
label: _('Stop external editing'),
enabled: noteIds.length === 1,
click: async () => {
this.stopExternalEditing(noteIds[0]);
},
})
);
}
if (noteIds.length <= 1) {
menu.append(
new MenuItem({
@ -191,6 +214,20 @@ class NoteListUtils {
if (!ok) return;
await Note.batchDelete(noteIds);
}
static async startExternalEditing(noteId) {
try {
const note = await Note.load(noteId);
ExternalEditWatcher.instance().openAndWatch(note);
} catch (error) {
bridge().showErrorMessageBox(_('Error opening note in editor: %s', error.message));
}
}
static async stopExternalEditing(noteId) {
ExternalEditWatcher.instance().stopWatching(noteId);
}
}
module.exports = NoteListUtils;