Files: 4aa133a211115e9955380ca246d7ad14324aed7b / lib / context-menu-and-spellcheck.js
2478 bytesRaw
1 | var {remote, shell, clipboard, ipcRenderer} = require('electron') |
2 | var {SpellCheckHandler, ContextMenuListener, ContextMenuBuilder} = require('electron-spellchecker') |
3 | var {MenuItem, Menu} = remote |
4 | |
5 | window.spellCheckHandler = new SpellCheckHandler() |
6 | window.spellCheckHandler.attachToInput() |
7 | |
8 | // Start off as US English, America #1 (lol) |
9 | window.spellCheckHandler.switchLanguage('en-US') |
10 | |
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 | |
49 | module.exports = new ContextMenuListener((info) => { |
50 | contextMenuBuilder.buildMenuForElement(info).then((menu) => { |
51 | var element = document.elementFromPoint(info.x, info.y) |
52 | while (element && !element.msg) { |
53 | element = element.parentNode |
54 | } |
55 | |
56 | menu.append(new MenuItem({ |
57 | label: 'Inspect Server Process', |
58 | click: function () { |
59 | ipcRenderer.send('open-background-devtools') |
60 | } |
61 | })) |
62 | |
63 | menu.append(new MenuItem({ |
64 | type: 'separator' |
65 | })) |
66 | |
67 | menu.append(new MenuItem({ |
68 | label: 'Reload', |
69 | click: function (item, focusedWindow) { |
70 | if (focusedWindow) { |
71 | focusedWindow.reload() |
72 | } |
73 | } |
74 | })) |
75 | |
76 | if (element && element.msg) { |
77 | menu.append(new MenuItem({ |
78 | type: 'separator' |
79 | })) |
80 | menu.append(new MenuItem({ |
81 | label: 'Copy Message ID', |
82 | click: function () { |
83 | clipboard.writeText(element.msg.key) |
84 | } |
85 | })) |
86 | } |
87 | menu.popup(remote.getCurrentWindow()) |
88 | }).catch((err) => { |
89 | throw err |
90 | }) |
91 | }) |
92 |
Built with git-ssb-web