Commit 0bc52a13a9c729a0b10e7f1bc22d167d5945ce75
remove Open Link and Copy Link when internal to patchwork
Matt McKegg committed on 2/19/2017, 1:37:01 PMParent: 350cc06021a41ffbb2830a1223d37e07b40a98ab
Files changed
lib/context-menu-and-spellcheck.js | changed |
lib/context-menu-and-spellcheck.js | ||
---|---|---|
@@ -1,15 +1,52 @@ | ||
1 | -var electron = require('electron') | |
1 … | +var {remote, shell, clipboard, ipcRenderer} = require('electron') | |
2 | 2 … | var {SpellCheckHandler, ContextMenuListener, ContextMenuBuilder} = require('electron-spellchecker') |
3 | -var MenuItem = electron.remote.MenuItem | |
3 … | +var {MenuItem, Menu} = remote | |
4 | 4 … | |
5 | 5 … | window.spellCheckHandler = new SpellCheckHandler() |
6 | 6 … | window.spellCheckHandler.attachToInput() |
7 | 7 … | |
8 | 8 … | // Start off as US English, America #1 (lol) |
9 | 9 … | window.spellCheckHandler.switchLanguage('en-US') |
10 | 10 … | |
11 | 11 … | var contextMenuBuilder = new ContextMenuBuilder(window.spellCheckHandler, null, true) |
12 … | + | |
13 … | +contextMenuBuilder.buildMenuForLink = function (menuInfo) { | |
14 … | + var menu = new Menu() | |
15 … | + var isEmailAddress = menuInfo.linkURL.startsWith('mailto:') | |
16 … | + var isFile = menuInfo.linkURL.startsWith('file:') | |
17 … | + | |
18 … | + if (!isFile) { | |
19 … | + var copyLink = new MenuItem({ | |
20 … | + label: isEmailAddress ? this.stringTable.copyMail() : this.stringTable.copyLinkUrl(), | |
21 … | + click: () => { | |
22 … | + // Omit the mailto: portion of the link; we just want the address | |
23 … | + clipboard.writeText(isEmailAddress ? menuInfo.linkText : menuInfo.linkURL) | |
24 … | + } | |
25 … | + }) | |
26 … | + | |
27 … | + var openLink = new MenuItem({ | |
28 … | + label: this.stringTable.openLinkUrl(), | |
29 … | + click: () => { | |
30 … | + shell.openExternal(menuInfo.linkURL) | |
31 … | + } | |
32 … | + }) | |
33 … | + | |
34 … | + menu.append(copyLink) | |
35 … | + menu.append(openLink) | |
36 … | + } | |
37 … | + | |
38 … | + if (this.isSrcUrlValid(menuInfo)) { | |
39 … | + if (!isFile) this.addSeparator(menu) | |
40 … | + this.addImageItems(menu, menuInfo) | |
41 … | + } | |
42 … | + | |
43 … | + this.addInspectElement(menu, menuInfo) | |
44 … | + this.processMenu(menu, menuInfo) | |
45 … | + | |
46 … | + return menu | |
47 … | +} | |
48 … | + | |
12 | 49 … | module.exports = new ContextMenuListener((info) => { |
13 | 50 … | contextMenuBuilder.buildMenuForElement(info).then((menu) => { |
14 | 51 … | var element = document.elementFromPoint(info.x, info.y) |
15 | 52 … | while (element && !element.msg) { |
@@ -18,9 +55,9 @@ | ||
18 | 55 … | |
19 | 56 … | menu.append(new MenuItem({ |
20 | 57 … | label: 'Inspect Server Process', |
21 | 58 … | click: function () { |
22 | - electron.ipcRenderer.send('open-background-devtools') | |
59 … | + ipcRenderer.send('open-background-devtools') | |
23 | 60 … | } |
24 | 61 … | })) |
25 | 62 … | |
26 | 63 … | menu.append(new MenuItem({ |
@@ -42,13 +79,13 @@ | ||
42 | 79 … | })) |
43 | 80 … | menu.append(new MenuItem({ |
44 | 81 … | label: 'Copy Message ID', |
45 | 82 … | click: function () { |
46 | - electron.clipboard.writeText(element.msg.key) | |
83 … | + clipboard.writeText(element.msg.key) | |
47 | 84 … | } |
48 | 85 … | })) |
49 | 86 … | } |
50 | - menu.popup(electron.remote.getCurrentWindow()) | |
87 … | + menu.popup(remote.getCurrentWindow()) | |
51 | 88 … | }).catch((err) => { |
52 | 89 … | throw err |
53 | 90 … | }) |
54 | 91 … | }) |
Built with git-ssb-web