mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Electron: Resolves #619: Context menu to cut, copy and paste. Also added menu to copy link in web view
This commit is contained in:
parent
595fd7a9aa
commit
187fb1b85d
@ -60,6 +60,12 @@ class ElectronAppWrapper {
|
||||
// Fix: https://github.com/electron-userland/electron-builder/issues/2269
|
||||
if (shim.isLinux()) windowOptions.icon = __dirname + '/build/icons/128x128.png';
|
||||
|
||||
require('electron-context-menu')({
|
||||
shouldShowMenu: (event, params) => {
|
||||
return params.isEditable;
|
||||
},
|
||||
});
|
||||
|
||||
this.win_ = new BrowserWindow(windowOptions)
|
||||
|
||||
this.win_.loadURL(url.format({
|
||||
|
@ -20,7 +20,6 @@ const MenuItem = bridge().MenuItem;
|
||||
const { shim } = require('lib/shim.js');
|
||||
const eventManager = require('../eventManager');
|
||||
const fs = require('fs-extra');
|
||||
const {clipboard} = require('electron')
|
||||
const md5 = require('md5');
|
||||
const mimeUtils = require('lib/mime-utils.js').mime;
|
||||
const ArrayUtils = require('lib/ArrayUtils');
|
||||
@ -29,6 +28,7 @@ const dialogs = require('./dialogs');
|
||||
const markdownUtils = require('lib/markdownUtils');
|
||||
const ExternalEditWatcher = require('lib/services/ExternalEditWatcher');
|
||||
const { toSystemSlashes, safeFilename } = require('lib/path-utils');
|
||||
const { clipboard } = require('electron');
|
||||
|
||||
require('brace/mode/markdown');
|
||||
// https://ace.c9.io/build/kitchen-sink.html
|
||||
@ -467,7 +467,9 @@ class NoteTextComponent extends React.Component {
|
||||
|
||||
const menu = new Menu()
|
||||
|
||||
if (itemType === "image" || itemType === "link") {
|
||||
console.info(itemType);
|
||||
|
||||
if (itemType === "image" || itemType === "resource") {
|
||||
const resource = await Resource.load(arg0.resourceId);
|
||||
const resourcePath = Resource.fullPath(resource);
|
||||
|
||||
@ -485,9 +487,16 @@ class NoteTextComponent extends React.Component {
|
||||
}}));
|
||||
|
||||
menu.append(new MenuItem({label: _('Copy path to clipboard'), click: async () => {
|
||||
const { clipboard } = require('electron');
|
||||
clipboard.writeText(toSystemSlashes(resourcePath));
|
||||
}}));
|
||||
} else if (itemType === "text") {
|
||||
menu.append(new MenuItem({label: _('Copy'), click: async () => {
|
||||
clipboard.writeText(arg0.textToCopy);
|
||||
}}));
|
||||
} else if (itemType === "link") {
|
||||
menu.append(new MenuItem({label: _('Copy Link Address'), click: async () => {
|
||||
clipboard.writeText(arg0.textToCopy);
|
||||
}}));
|
||||
} else {
|
||||
reg.logger().error('Unhandled item type: ' + itemType);
|
||||
return;
|
||||
|
@ -229,9 +229,23 @@
|
||||
|
||||
if (element && element.getAttribute('data-resource-id')) {
|
||||
ipcRenderer.sendToHost('contextMenu', {
|
||||
type: element.getAttribute('src') ? 'image' : 'link',
|
||||
type: element.getAttribute('src') ? 'image' : 'resource',
|
||||
resourceId: element.getAttribute('data-resource-id'),
|
||||
});
|
||||
} else {
|
||||
const selectedText = window.getSelection().toString();
|
||||
|
||||
if (selectedText) {
|
||||
ipcRenderer.sendToHost('contextMenu', {
|
||||
type: 'text',
|
||||
textToCopy: selectedText,
|
||||
});
|
||||
} else if (event.target.getAttribute('href')) {
|
||||
ipcRenderer.sendToHost('contextMenu', {
|
||||
type: 'link',
|
||||
textToCopy: event.target.getAttribute('href'),
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
12
ElectronClient/app/package-lock.json
generated
12
ElectronClient/app/package-lock.json
generated
@ -2051,9 +2051,9 @@
|
||||
}
|
||||
},
|
||||
"electron-dl": {
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/electron-dl/-/electron-dl-1.10.0.tgz",
|
||||
"integrity": "sha1-+UQWBkBW/G8qhq5JhhTJNSaJCvk=",
|
||||
"version": "1.12.0",
|
||||
"resolved": "https://registry.npmjs.org/electron-dl/-/electron-dl-1.12.0.tgz",
|
||||
"integrity": "sha512-UMc2CL45Ybpvu66LDPYzwmDRmYK4Ivz+wdnTM0eXcNMztvQwhixAk2UPme1c7McqG8bAlKEkQpZn3epmQy4EWg==",
|
||||
"requires": {
|
||||
"ext-name": "^5.0.0",
|
||||
"pupa": "^1.0.0",
|
||||
@ -4345,9 +4345,9 @@
|
||||
"integrity": "sha512-OEUllcVoydBHGN1z84yfQDimn58pZNNNXgZlHXSboxMlFvgI6MXSWpWKpFRra7H1HxpVhHTkrghfRW49k6yjeg=="
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.31.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.31.0.tgz",
|
||||
"integrity": "sha512-oB3w9lx50CMd6nfonoV5rBRUbJtjMifUHaFb5MfzjC8ksAIfVjT0BsX46SjjqBz7n9JGTrTX3paIeLSK+rS5fQ=="
|
||||
"version": "1.34.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.34.0.tgz",
|
||||
"integrity": "sha1-RS0Oz/XDA0am3B5kseruDTcZ/5o="
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.18",
|
||||
|
Loading…
Reference in New Issue
Block a user