diff options
author | Stefan Malzner <stefan@adlk.io> | 2018-12-04 14:14:37 +0100 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2018-12-04 14:14:37 +0100 |
commit | 5d5aa0c5bc3602fdf4deec4d0046ce02ddf70090 (patch) | |
tree | fb1008b1af1d551e4cf42cc67cce1b4b545139ef /src | |
parent | Hide "cut" menu when text is not editable (diff) | |
download | ferdium-app-5d5aa0c5bc3602fdf4deec4d0046ce02ddf70090.tar.gz ferdium-app-5d5aa0c5bc3602fdf4deec4d0046ce02ddf70090.tar.zst ferdium-app-5d5aa0c5bc3602fdf4deec4d0046ce02ddf70090.zip |
feat(Context Menu): Add Lookup, Search Google for
Diffstat (limited to 'src')
-rw-r--r-- | src/webview/contextMenu.js | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/webview/contextMenu.js b/src/webview/contextMenu.js index 4f1984a5d..ff6d3b21a 100644 --- a/src/webview/contextMenu.js +++ b/src/webview/contextMenu.js | |||
@@ -3,7 +3,7 @@ | |||
3 | 3 | ||
4 | import { clipboard, remote, ipcRenderer, shell } from 'electron'; | 4 | import { clipboard, remote, ipcRenderer, shell } from 'electron'; |
5 | 5 | ||
6 | import { isDevMode } from '../environment'; | 6 | import { isDevMode, isMac } from '../environment'; |
7 | 7 | ||
8 | const debug = require('debug')('Franz:contextMenu'); | 8 | const debug = require('debug')('Franz:contextMenu'); |
9 | 9 | ||
@@ -23,19 +23,28 @@ function delUnusedElements(menuTpl) { | |||
23 | 23 | ||
24 | const buildMenuTpl = (props, suggestions) => { | 24 | const buildMenuTpl = (props, suggestions) => { |
25 | const { editFlags } = props; | 25 | const { editFlags } = props; |
26 | const hasText = props.selectionText.trim().length > 0; | 26 | const textSelection = props.selectionText.trim(); |
27 | const hasText = textSelection.length > 0; | ||
27 | const can = type => editFlags[`can${type}`] && hasText; | 28 | const can = type => editFlags[`can${type}`] && hasText; |
28 | 29 | ||
29 | console.log(props); | ||
30 | |||
31 | let menuTpl = [ | 30 | let menuTpl = [ |
32 | { | 31 | { |
33 | type: 'separator', | 32 | type: 'separator', |
34 | }, { | 33 | }, { |
34 | id: 'lookup', | ||
35 | label: `Look Up "${textSelection.length > 15 ? `${textSelection.slice(0, 15)}...` : textSelection}"`, | ||
36 | visible: isMac && props.mediaType === 'none' && hasText, | ||
37 | click() { | ||
38 | debug('Show definition for selection', textSelection); | ||
39 | webContents.showDefinitionForSelection(); | ||
40 | }, | ||
41 | }, { | ||
42 | type: 'separator', | ||
43 | }, { | ||
35 | id: 'cut', | 44 | id: 'cut', |
36 | role: can('Cut') ? 'cut' : '', | 45 | role: can('Cut') ? 'cut' : '', |
37 | enabled: can('Cut'), | 46 | enabled: can('Cut'), |
38 | visible: !!props.selectionText.trim() && props.isEditable, | 47 | visible: hasText && props.isEditable, |
39 | }, { | 48 | }, { |
40 | id: 'copy', | 49 | id: 'copy', |
41 | label: 'Copy', | 50 | label: 'Copy', |
@@ -50,6 +59,18 @@ const buildMenuTpl = (props, suggestions) => { | |||
50 | visible: props.isEditable, | 59 | visible: props.isEditable, |
51 | }, { | 60 | }, { |
52 | type: 'separator', | 61 | type: 'separator', |
62 | visible: props.isEditable && hasText, | ||
63 | }, { | ||
64 | id: 'searchTextSelection', | ||
65 | label: `Search Google for "${textSelection.length > 15 ? `${textSelection.slice(0, 15)}...` : textSelection}"`, | ||
66 | visible: hasText, | ||
67 | click() { | ||
68 | const url = `https://www.google.com/search?q=${textSelection}`; | ||
69 | debug('Search on Google', url); | ||
70 | shell.openExternal(url); | ||
71 | }, | ||
72 | }, { | ||
73 | type: 'separator', | ||
53 | }, | 74 | }, |
54 | ]; | 75 | ]; |
55 | 76 | ||
@@ -60,6 +81,7 @@ const buildMenuTpl = (props, suggestions) => { | |||
60 | id: 'openLink', | 81 | id: 'openLink', |
61 | label: 'Open Link in Browser', | 82 | label: 'Open Link in Browser', |
62 | click() { | 83 | click() { |
84 | debug('Open link in Browser', props.linkURL); | ||
63 | shell.openExternal(props.linkURL); | 85 | shell.openExternal(props.linkURL); |
64 | }, | 86 | }, |
65 | }, { | 87 | }, { |
@@ -83,6 +105,7 @@ const buildMenuTpl = (props, suggestions) => { | |||
83 | id: 'openImage', | 105 | id: 'openImage', |
84 | label: 'Open Image in Browser', | 106 | label: 'Open Image in Browser', |
85 | click() { | 107 | click() { |
108 | debug('Open image in Browser', props.srcURL); | ||
86 | shell.openExternal(props.srcURL); | 109 | shell.openExternal(props.srcURL); |
87 | }, | 110 | }, |
88 | }, { | 111 | }, { |
@@ -132,7 +155,6 @@ const buildMenuTpl = (props, suggestions) => { | |||
132 | }); | 155 | }); |
133 | } | 156 | } |
134 | 157 | ||
135 | console.log('suggestions', suggestions.length, suggestions); | ||
136 | if (suggestions.length > 0) { | 158 | if (suggestions.length > 0) { |
137 | suggestions.reverse().map(suggestion => menuTpl.unshift({ | 159 | suggestions.reverse().map(suggestion => menuTpl.unshift({ |
138 | id: `suggestion-${suggestion}`, | 160 | id: `suggestion-${suggestion}`, |