git ssb

10+

Matt McKegg / patchwork



Commit 731f7fef3b396f2bcfd92c8d02413ac6908684d4

add "Copy External Link" to message context menu

similar to https://github.com/ssbc/patchbay/pull/107
Michael Williams committed on 4/20/2017, 12:00:52 PM
Parent: e0a3d8fc98c17511ce174fb697bb8c117b8de5e1

Files changed

lib/context-menu-and-spellcheck.jschanged
main-window.jschanged
lib/context-menu-and-spellcheck.jsView
@@ -2,111 +2,125 @@
22 var {SpellCheckHandler, ContextMenuListener, ContextMenuBuilder} = require('electron-spellchecker')
33 var {MenuItem, Menu} = remote
44 var ref = require('ssb-ref')
55
6-window.spellCheckHandler = new SpellCheckHandler()
7-window.spellCheckHandler.attachToInput()
6+module.exports = setupContextMenuAndSpellCheck
87
9-// Start off as US English, America #1 (lol)
10-window.spellCheckHandler.switchLanguage('en-US')
8+function setupContextMenuAndSpellCheck (config) {
9+ window.spellCheckHandler = new SpellCheckHandler()
10+ window.spellCheckHandler.attachToInput()
1111
12-var contextMenuBuilder = new ContextMenuBuilder(window.spellCheckHandler, null, true)
12+ // Start off as US English, America #1 (lol)
13+ window.spellCheckHandler.switchLanguage('en-US')
1314
14-contextMenuBuilder.buildMenuForLink = function (menuInfo) {
15- var menu = new Menu()
16- var isEmailAddress = menuInfo.linkURL.startsWith('mailto:')
17- var isFile = menuInfo.linkURL.startsWith('file:')
18- var extractedRef = ref.extract(menuInfo.linkURL)
15+ var contextMenuBuilder = new ContextMenuBuilder(window.spellCheckHandler, null, true)
1916
20- if (!isFile) {
21- var copyLink = new MenuItem({
22- label: isEmailAddress ? this.stringTable.copyMail() : this.stringTable.copyLinkUrl(),
23- click: () => {
24- // Omit the mailto: portion of the link; we just want the address
25- clipboard.writeText(isEmailAddress ? menuInfo.linkText : menuInfo.linkURL)
26- }
27- })
17+ contextMenuBuilder.buildMenuForLink = function (menuInfo) {
18+ var menu = new Menu()
19+ var isEmailAddress = menuInfo.linkURL.startsWith('mailto:')
20+ var isFile = menuInfo.linkURL.startsWith('file:')
21+ var extractedRef = ref.extract(menuInfo.linkURL)
2822
29- var openLink = new MenuItem({
30- label: this.stringTable.openLinkUrl(),
31- click: () => {
32- shell.openExternal(menuInfo.linkURL)
33- }
34- })
23+ if (!isFile) {
24+ var copyLink = new MenuItem({
25+ label: isEmailAddress ? this.stringTable.copyMail() : this.stringTable.copyLinkUrl(),
26+ click: () => {
27+ // Omit the mailto: portion of the link; we just want the address
28+ clipboard.writeText(isEmailAddress ? menuInfo.linkText : menuInfo.linkURL)
29+ }
30+ })
3531
36- menu.append(copyLink)
37- menu.append(openLink)
38- }
32+ var openLink = new MenuItem({
33+ label: this.stringTable.openLinkUrl(),
34+ click: () => {
35+ shell.openExternal(menuInfo.linkURL)
36+ }
37+ })
3938
40- if (extractedRef) {
41- var copyRef = new MenuItem({
42- label: `Copy Link Ref (${extractedRef.slice(0, 10)}...)`,
43- click: () => {
44- // Omit the mailto: portion of the link; we just want the address
45- clipboard.writeText(extractedRef)
46- }
47- })
48- menu.append(copyRef)
49- }
39+ menu.append(copyLink)
40+ menu.append(openLink)
41+ }
5042
51- if (this.isSrcUrlValid(menuInfo)) {
52- if (!isFile) this.addSeparator(menu)
53- this.addImageItems(menu, menuInfo)
54- }
43+ if (extractedRef) {
44+ var copyRef = new MenuItem({
45+ label: `Copy Link Ref (${extractedRef.slice(0, 10)}...)`,
46+ click: () => {
47+ // Omit the mailto: portion of the link; we just want the address
48+ clipboard.writeText(extractedRef)
49+ }
50+ })
51+ menu.append(copyRef)
52+ }
5553
56- this.addInspectElement(menu, menuInfo)
57- this.processMenu(menu, menuInfo)
54+ if (this.isSrcUrlValid(menuInfo)) {
55+ if (!isFile) this.addSeparator(menu)
56+ this.addImageItems(menu, menuInfo)
57+ }
5858
59- return menu
60-}
59+ this.addInspectElement(menu, menuInfo)
60+ this.processMenu(menu, menuInfo)
6161
62-module.exports = new ContextMenuListener((info) => {
63- contextMenuBuilder.buildMenuForElement(info).then((menu) => {
64- var element = document.elementFromPoint(info.x, info.y)
65- while (element && !element.msg) {
66- element = element.parentNode
67- }
62+ return menu
63+ }
6864
69- menu.append(new MenuItem({
70- label: 'Inspect Server Process',
71- click: function () {
72- ipcRenderer.send('open-background-devtools')
65+ module.exports = new ContextMenuListener((info) => {
66+ contextMenuBuilder.buildMenuForElement(info).then((menu) => {
67+ var element = document.elementFromPoint(info.x, info.y)
68+ while (element && !element.msg) {
69+ element = element.parentNode
7370 }
74- }))
7571
76- menu.append(new MenuItem({
77- type: 'separator'
78- }))
79-
80- menu.append(new MenuItem({
81- label: 'Reload',
82- click: function (item, focusedWindow) {
83- if (focusedWindow) {
84- focusedWindow.reload()
72+ menu.append(new MenuItem({
73+ label: 'Inspect Server Process',
74+ click: function () {
75+ ipcRenderer.send('open-background-devtools')
8576 }
86- }
87- }))
77+ }))
8878
89- if (element && element.msg) {
9079 menu.append(new MenuItem({
9180 type: 'separator'
9281 }))
82+
9383 menu.append(new MenuItem({
94- label: 'Copy Message ID',
95- click: function () {
96- clipboard.writeText(element.msg.key)
84+ label: 'Reload',
85+ click: function (item, focusedWindow) {
86+ if (focusedWindow) {
87+ focusedWindow.reload()
88+ }
9789 }
9890 }))
99- if (element.msg.value.content.text) {
91+
92+ if (element && element.msg) {
10093 menu.append(new MenuItem({
101- label: 'Copy Message Text',
94+ type: 'separator'
95+ }))
96+ menu.append(new MenuItem({
97+ label: 'Copy Message ID',
10298 click: function () {
103- clipboard.writeText(element.msg.value.content.text)
99+ clipboard.writeText(element.msg.key)
104100 }
105101 }))
102+ if (element.msg.value.content.text) {
103+ menu.append(new MenuItem({
104+ label: 'Copy Message Text',
105+ click: function () {
106+ clipboard.writeText(element.msg.value.content.text)
107+ }
108+ }))
109+ }
110+ menu.append(new MenuItem({
111+ label: 'Copy External Link',
112+ click: function () {
113+ const key = element.msg.key
114+ const gateway = config.gateway ||
115+ 'https://viewer.scuttlebot.io'
116+ const url = `${gateway}/${encodeURIComponent(key)}`
117+ clipboard.writeText(url)
118+ }
119+ }))
106120 }
107- }
108- menu.popup(remote.getCurrentWindow())
109- }).catch((err) => {
110- throw err
121+ menu.popup(remote.getCurrentWindow())
122+ }).catch((err) => {
123+ throw err
124+ })
111125 })
112-})
126+}
main-window.jsView
@@ -9,11 +9,10 @@
99 var insertCss = require('insert-css')
1010 var nest = require('depnest')
1111 var LatestUpdate = require('./lib/latest-update')
1212 var ref = require('ssb-ref')
13+var setupContextMenuAndSpellCheck = require('./lib/context-menu-and-spellcheck')
1314
14-require('./lib/context-menu-and-spellcheck.js')
15-
1615 module.exports = function (config) {
1716 var sockets = combine(
1817 overrideConfig(config),
1918 require('./modules'),
@@ -22,8 +21,9 @@
2221 require('./overrides')
2322 )
2423
2524 var api = entry(sockets, nest({
25+ 'config.sync.load': 'first',
2626 'keys.sync.id': 'first',
2727 'sbot.obs.connection': 'first',
2828 'sbot.async.get': 'first',
2929 'blob.sync.url': 'first',
@@ -34,8 +34,10 @@
3434 'app.html.progressNotifier': 'first',
3535 'profile.sheet.edit': 'first'
3636 }))
3737
38+ setupContextMenuAndSpellCheck(api.config.sync.load())
39+
3840 var id = api.keys.sync.id()
3941 var latestUpdate = LatestUpdate()
4042
4143 // prompt to setup profile on first use

Built with git-ssb-web