git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 8665e16c051517ccfc22cad096c48bf2e476f5b7

Files: 8665e16c051517ccfc22cad096c48bf2e476f5b7 / lib / context-menu-and-spellcheck.js

2478 bytesRaw
1var {remote, shell, clipboard, ipcRenderer} = require('electron')
2var {SpellCheckHandler, ContextMenuListener, ContextMenuBuilder} = require('electron-spellchecker')
3var {MenuItem, Menu} = remote
4
5window.spellCheckHandler = new SpellCheckHandler()
6window.spellCheckHandler.attachToInput()
7
8// Start off as US English, America #1 (lol)
9window.spellCheckHandler.switchLanguage('en-US')
10
11var contextMenuBuilder = new ContextMenuBuilder(window.spellCheckHandler, null, true)
12
13contextMenuBuilder.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
49module.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