diff options
author | Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com> | 2021-05-15 05:09:12 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-15 01:39:12 +0200 |
commit | 1af5bb9ab679653dca436493133e6d0ee8a8fb36 (patch) | |
tree | 4543a26c81f3ad1da15938ff7b73dfa7990431d9 /src | |
parent | New Crowdin updates (Portuguese, Brazilian) (#1411) (diff) | |
download | ferdium-app-1af5bb9ab679653dca436493133e6d0ee8a8fb36.tar.gz ferdium-app-1af5bb9ab679653dca436493133e6d0ee8a8fb36.tar.zst ferdium-app-1af5bb9ab679653dca436493133e6d0ee8a8fb36.zip |
Enhancing context menu: goBack, goForward & openInBrowser (#1413)
Diffstat (limited to 'src')
-rw-r--r-- | src/webview/contextMenuBuilder.js | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/src/webview/contextMenuBuilder.js b/src/webview/contextMenuBuilder.js index f7d552ddd..b5095915c 100644 --- a/src/webview/contextMenuBuilder.js +++ b/src/webview/contextMenuBuilder.js | |||
@@ -29,10 +29,14 @@ const contextMenuStringTable = { | |||
29 | paste: () => 'Paste', | 29 | paste: () => 'Paste', |
30 | searchGoogle: () => 'Search with Google', | 30 | searchGoogle: () => 'Search with Google', |
31 | openLinkUrl: () => 'Open Link', | 31 | openLinkUrl: () => 'Open Link', |
32 | openLinkInFerdiUrl: () => 'Open Link in Ferdi', | ||
33 | openInBrowser: () => 'Open in Browser', | ||
32 | copyLinkUrl: () => 'Copy Link', | 34 | copyLinkUrl: () => 'Copy Link', |
33 | copyImageUrl: () => 'Copy Image Address', | 35 | copyImageUrl: () => 'Copy Image Address', |
34 | copyImage: () => 'Copy Image', | 36 | copyImage: () => 'Copy Image', |
35 | addToDictionary: () => 'Add to Dictionary', | 37 | addToDictionary: () => 'Add to Dictionary', |
38 | goBack: () => 'Go Back', | ||
39 | goForward: () => 'Go Forward', | ||
36 | goToHomePage: () => 'Go to Home Page', | 40 | goToHomePage: () => 'Go to Home Page', |
37 | copyMail: () => 'Copy Email Address', | 41 | copyMail: () => 'Copy Email Address', |
38 | inspectElement: () => 'Inspect Element', | 42 | inspectElement: () => 'Inspect Element', |
@@ -134,6 +138,7 @@ module.exports = class ContextMenuBuilder { | |||
134 | this.processMenu(menu, menuInfo); | 138 | this.processMenu(menu, menuInfo); |
135 | 139 | ||
136 | this.goToHomePage(menu, menuInfo); | 140 | this.goToHomePage(menu, menuInfo); |
141 | this.openInBrowser(menu, menuInfo); | ||
137 | 142 | ||
138 | return menu; | 143 | return menu; |
139 | } | 144 | } |
@@ -164,7 +169,7 @@ module.exports = class ContextMenuBuilder { | |||
164 | }); | 169 | }); |
165 | 170 | ||
166 | const openInFerdiLink = new MenuItem({ | 171 | const openInFerdiLink = new MenuItem({ |
167 | label: 'Open Link in Ferdi', | 172 | label: this.stringTable.openLinkInFerdiUrl(), |
168 | click: () => { | 173 | click: () => { |
169 | window.location.href = menuInfo.linkURL; | 174 | window.location.href = menuInfo.linkURL; |
170 | }, | 175 | }, |
@@ -182,7 +187,10 @@ module.exports = class ContextMenuBuilder { | |||
182 | this.addInspectElement(menu, menuInfo); | 187 | this.addInspectElement(menu, menuInfo); |
183 | this.processMenu(menu, menuInfo); | 188 | this.processMenu(menu, menuInfo); |
184 | 189 | ||
190 | this.goBack(menu); | ||
191 | this.goForward(menu); | ||
185 | this.goToHomePage(menu, menuInfo); | 192 | this.goToHomePage(menu, menuInfo); |
193 | this.openInBrowser(menu, menuInfo); | ||
186 | 194 | ||
187 | return menu; | 195 | return menu; |
188 | } | 196 | } |
@@ -200,7 +208,10 @@ module.exports = class ContextMenuBuilder { | |||
200 | this.addInspectElement(menu, menuInfo); | 208 | this.addInspectElement(menu, menuInfo); |
201 | this.processMenu(menu, menuInfo); | 209 | this.processMenu(menu, menuInfo); |
202 | 210 | ||
211 | this.goBack(menu); | ||
212 | this.goForward(menu); | ||
203 | this.goToHomePage(menu, menuInfo); | 213 | this.goToHomePage(menu, menuInfo); |
214 | this.openInBrowser(menu, menuInfo); | ||
204 | 215 | ||
205 | return menu; | 216 | return menu; |
206 | } | 217 | } |
@@ -429,7 +440,37 @@ module.exports = class ContextMenuBuilder { | |||
429 | } | 440 | } |
430 | 441 | ||
431 | /** | 442 | /** |
432 | * Adds the go to home menu item. | 443 | * Adds the 'go back' menu item |
444 | */ | ||
445 | goBack(menu) { | ||
446 | const webContents = this.getWebContents(); | ||
447 | menu.append(new MenuItem({ | ||
448 | label: this.stringTable.goBack(), | ||
449 | accelerator: 'CommandOrControl+left', | ||
450 | enabled: webContents.canGoBack(), | ||
451 | click: () => webContents.goBack(), | ||
452 | })); | ||
453 | |||
454 | return menu; | ||
455 | } | ||
456 | |||
457 | /** | ||
458 | * Adds the 'go forward' menu item | ||
459 | */ | ||
460 | goForward(menu) { | ||
461 | const webContents = this.getWebContents(); | ||
462 | menu.append(new MenuItem({ | ||
463 | label: this.stringTable.goForward(), | ||
464 | accelerator: 'CommandOrControl+right', | ||
465 | enabled: webContents.canGoForward(), | ||
466 | click: () => webContents.goForward(), | ||
467 | })); | ||
468 | |||
469 | return menu; | ||
470 | } | ||
471 | |||
472 | /** | ||
473 | * Adds the 'go to home' menu item. | ||
433 | */ | 474 | */ |
434 | goToHomePage(menu, menuInfo) { | 475 | goToHomePage(menu, menuInfo) { |
435 | const baseURL = new URL(menuInfo.pageURL); | 476 | const baseURL = new URL(menuInfo.pageURL); |
@@ -445,4 +486,19 @@ module.exports = class ContextMenuBuilder { | |||
445 | 486 | ||
446 | return menu; | 487 | return menu; |
447 | } | 488 | } |
489 | |||
490 | /** | ||
491 | * Adds the 'open in browser' menu item. | ||
492 | */ | ||
493 | openInBrowser(menu, menuInfo) { | ||
494 | menu.append(new MenuItem({ | ||
495 | label: this.stringTable.openInBrowser(), | ||
496 | enabled: true, | ||
497 | click: () => { | ||
498 | shell.openExternal(menuInfo.pageURL); | ||
499 | }, | ||
500 | })); | ||
501 | |||
502 | return menu; | ||
503 | } | ||
448 | }; | 504 | }; |