From 5d5aa0c5bc3602fdf4deec4d0046ce02ddf70090 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Tue, 4 Dec 2018 14:14:37 +0100 Subject: feat(Context Menu): Add Lookup, Search Google for --- src/webview/contextMenu.js | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'src/webview/contextMenu.js') 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 @@ import { clipboard, remote, ipcRenderer, shell } from 'electron'; -import { isDevMode } from '../environment'; +import { isDevMode, isMac } from '../environment'; const debug = require('debug')('Franz:contextMenu'); @@ -23,19 +23,28 @@ function delUnusedElements(menuTpl) { const buildMenuTpl = (props, suggestions) => { const { editFlags } = props; - const hasText = props.selectionText.trim().length > 0; + const textSelection = props.selectionText.trim(); + const hasText = textSelection.length > 0; const can = type => editFlags[`can${type}`] && hasText; - console.log(props); - let menuTpl = [ { type: 'separator', + }, { + id: 'lookup', + label: `Look Up "${textSelection.length > 15 ? `${textSelection.slice(0, 15)}...` : textSelection}"`, + visible: isMac && props.mediaType === 'none' && hasText, + click() { + debug('Show definition for selection', textSelection); + webContents.showDefinitionForSelection(); + }, + }, { + type: 'separator', }, { id: 'cut', role: can('Cut') ? 'cut' : '', enabled: can('Cut'), - visible: !!props.selectionText.trim() && props.isEditable, + visible: hasText && props.isEditable, }, { id: 'copy', label: 'Copy', @@ -48,6 +57,18 @@ const buildMenuTpl = (props, suggestions) => { role: editFlags.canPaste ? 'paste' : '', enabled: editFlags.canPaste, visible: props.isEditable, + }, { + type: 'separator', + visible: props.isEditable && hasText, + }, { + id: 'searchTextSelection', + label: `Search Google for "${textSelection.length > 15 ? `${textSelection.slice(0, 15)}...` : textSelection}"`, + visible: hasText, + click() { + const url = `https://www.google.com/search?q=${textSelection}`; + debug('Search on Google', url); + shell.openExternal(url); + }, }, { type: 'separator', }, @@ -60,6 +81,7 @@ const buildMenuTpl = (props, suggestions) => { id: 'openLink', label: 'Open Link in Browser', click() { + debug('Open link in Browser', props.linkURL); shell.openExternal(props.linkURL); }, }, { @@ -83,6 +105,7 @@ const buildMenuTpl = (props, suggestions) => { id: 'openImage', label: 'Open Image in Browser', click() { + debug('Open image in Browser', props.srcURL); shell.openExternal(props.srcURL); }, }, { @@ -132,7 +155,6 @@ const buildMenuTpl = (props, suggestions) => { }); } - console.log('suggestions', suggestions.length, suggestions); if (suggestions.length > 0) { suggestions.reverse().map(suggestion => menuTpl.unshift({ id: `suggestion-${suggestion}`, -- cgit v1.2.3-54-g00ecf