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:
parent
6d9f73eef7
commit
42ada7123c
@ -87,6 +87,7 @@ class NoteListComponent extends React.Component {
|
|||||||
const menu = NoteListUtils.makeContextMenu(noteIds, {
|
const menu = NoteListUtils.makeContextMenu(noteIds, {
|
||||||
notes: this.props.notes,
|
notes: this.props.notes,
|
||||||
dispatch: this.props.dispatch,
|
dispatch: this.props.dispatch,
|
||||||
|
watchedNoteFiles: this.props.watchedNoteFiles,
|
||||||
});
|
});
|
||||||
|
|
||||||
menu.popup(bridge().window());
|
menu.popup(bridge().window());
|
||||||
|
@ -1129,6 +1129,8 @@ class NoteTextComponent extends React.Component {
|
|||||||
fn = this.commandDateTime;
|
fn = this.commandDateTime;
|
||||||
} else if (command.name === 'commandStartExternalEditing') {
|
} else if (command.name === 'commandStartExternalEditing') {
|
||||||
fn = this.commandStartExternalEditing;
|
fn = this.commandStartExternalEditing;
|
||||||
|
} else if (command.name === 'commandStopExternalEditing') {
|
||||||
|
fn = this.commandStopExternalEditing;
|
||||||
} else if (command.name === 'showLocalSearch') {
|
} else if (command.name === 'showLocalSearch') {
|
||||||
fn = this.commandShowLocalSearch;
|
fn = this.commandShowLocalSearch;
|
||||||
} else if (command.name === 'textCode') {
|
} else if (command.name === 'textCode') {
|
||||||
@ -1308,18 +1310,14 @@ class NoteTextComponent extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async commandStartExternalEditing() {
|
async commandStartExternalEditing() {
|
||||||
try {
|
await this.saveIfNeeded(true, {
|
||||||
await this.saveIfNeeded(true, {
|
autoTitle: false,
|
||||||
autoTitle: false,
|
});
|
||||||
});
|
NoteListUtils.startExternalEditing(this.state.note.id);
|
||||||
await ExternalEditWatcher.instance().openAndWatch(this.state.note);
|
|
||||||
} catch (error) {
|
|
||||||
bridge().showErrorMessageBox(_('Error opening note in editor: %s', error.message));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async commandStopExternalEditing() {
|
async commandStopExternalEditing() {
|
||||||
ExternalEditWatcher.instance().stopWatching(this.state.note.id);
|
NoteListUtils.stopExternalEditing(this.state.note.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
async commandSetTags() {
|
async commandSetTags() {
|
||||||
@ -1825,6 +1823,7 @@ class NoteTextComponent extends React.Component {
|
|||||||
const menu = NoteListUtils.makeContextMenu(this.props.selectedNoteIds, {
|
const menu = NoteListUtils.makeContextMenu(this.props.selectedNoteIds, {
|
||||||
notes: this.props.notes,
|
notes: this.props.notes,
|
||||||
dispatch: this.props.dispatch,
|
dispatch: this.props.dispatch,
|
||||||
|
watchedNoteFiles: this.props.watchedNoteFiles,
|
||||||
});
|
});
|
||||||
|
|
||||||
const buttonStyle = Object.assign({}, theme.buttonStyle, {
|
const buttonStyle = Object.assign({}, theme.buttonStyle, {
|
||||||
|
@ -7,6 +7,7 @@ const eventManager = require('../../eventManager');
|
|||||||
const InteropService = require('lib/services/InteropService');
|
const InteropService = require('lib/services/InteropService');
|
||||||
const InteropServiceHelper = require('../../InteropServiceHelper.js');
|
const InteropServiceHelper = require('../../InteropServiceHelper.js');
|
||||||
const Note = require('lib/models/Note');
|
const Note = require('lib/models/Note');
|
||||||
|
const ExternalEditWatcher = require('lib/services/ExternalEditWatcher');
|
||||||
const { substrWithEllipsis } = require('lib/string-utils');
|
const { substrWithEllipsis } = require('lib/string-utils');
|
||||||
|
|
||||||
class NoteListUtils {
|
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) {
|
if (noteIds.length <= 1) {
|
||||||
menu.append(
|
menu.append(
|
||||||
new MenuItem({
|
new MenuItem({
|
||||||
@ -191,6 +214,20 @@ class NoteListUtils {
|
|||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
await Note.batchDelete(noteIds);
|
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;
|
module.exports = NoteListUtils;
|
||||||
|
Loading…
Reference in New Issue
Block a user