aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview
diff options
context:
space:
mode:
authorLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2024-05-06 19:25:31 +0530
committerLibravatar GitHub <noreply@github.com>2024-05-06 19:25:31 +0530
commitfce0db12d37587b0677df0e1a9bc2b87f09a2b0c (patch)
tree8c2e021307a4b35c0d5148a104f9565cb3347a8a /src/webview
parent6.7.4-nightly.4 [skip ci] (diff)
downloadferdium-app-fce0db12d37587b0677df0e1a9bc2b87f09a2b0c.tar.gz
ferdium-app-fce0db12d37587b0677df0e1a9bc2b87f09a2b0c.tar.zst
ferdium-app-fce0db12d37587b0677df0e1a9bc2b87f09a2b0c.zip
Refactor context menu to be more consistent across all contexts (#1745)
Diffstat (limited to 'src/webview')
-rw-r--r--src/webview/contextMenuBuilder.ts59
1 files changed, 39 insertions, 20 deletions
diff --git a/src/webview/contextMenuBuilder.ts b/src/webview/contextMenuBuilder.ts
index 0a8b9c57b..d92e18aa9 100644
--- a/src/webview/contextMenuBuilder.ts
+++ b/src/webview/contextMenuBuilder.ts
@@ -130,8 +130,8 @@ interface ContextMenuStringTable {
130 translatorLanguage: string; 130 translatorLanguage: string;
131 }) => string; 131 }) => string;
132 openLinkUrl: () => string; 132 openLinkUrl: () => string;
133 openLinkInFerdiumUrl: () => string;
134 openInBrowser: () => string; 133 openInBrowser: () => string;
134 openInFerdium: () => string;
135 copyLinkUrl: () => string; 135 copyLinkUrl: () => string;
136 copyImageUrl: () => string; 136 copyImageUrl: () => string;
137 copyImage: () => string; 137 copyImage: () => string;
@@ -158,8 +158,8 @@ const contextMenuStringTable: ContextMenuStringTable = {
158 `Translate to ${translatorLanguage}`, 158 `Translate to ${translatorLanguage}`,
159 translateLanguage: ({ translatorLanguage }) => `${translatorLanguage}`, 159 translateLanguage: ({ translatorLanguage }) => `${translatorLanguage}`,
160 openLinkUrl: () => 'Open Link', 160 openLinkUrl: () => 'Open Link',
161 openLinkInFerdiumUrl: () => 'Open Link in Ferdium',
162 openInBrowser: () => 'Open in Browser', 161 openInBrowser: () => 'Open in Browser',
162 openInFerdium: () => 'Open in Ferdium',
163 copyLinkUrl: () => 'Copy Link', 163 copyLinkUrl: () => 'Copy Link',
164 copyImageUrl: () => 'Copy Image Address', 164 copyImageUrl: () => 'Copy Image Address',
165 copyImage: () => 'Copy Image', 165 copyImage: () => 'Copy Image',
@@ -299,10 +299,13 @@ export class ContextMenuBuilder {
299 this.addPastePlain(menu, menuInfo); 299 this.addPastePlain(menu, menuInfo);
300 this.addInspectElement(menu, menuInfo); 300 this.addInspectElement(menu, menuInfo);
301 this.processMenu(menu); 301 this.processMenu(menu);
302 302 this.addSeparator(menu);
303 this.copyPageUrl(menu, menuInfo); 303 this.copyPageUrl(menu, menuInfo);
304 this.goToHomePage(menu, menuInfo); 304 this.addSeparator(menu);
305 this.openInBrowser(menu, menuInfo); 305 this.openInBrowser(menu, menuInfo);
306 this.openInFerdium(menu, menuInfo);
307 this.addSeparator(menu);
308 this.goToHomePage(menu, menuInfo);
306 309
307 return menu; 310 return menu;
308 } 311 }
@@ -340,16 +343,8 @@ export class ContextMenuBuilder {
340 }, 343 },
341 }); 344 });
342 345
343 const openInFerdiumLink = new MenuItem({
344 label: this.stringTable.openLinkInFerdiumUrl(),
345 click: () => {
346 window.location.href = menuInfo.linkURL;
347 },
348 });
349
350 menu.append(copyLink); 346 menu.append(copyLink);
351 menu.append(openLink); 347 menu.append(openLink);
352 menu.append(openInFerdiumLink);
353 348
354 if (this.isSrcUrlValid(menuInfo)) { 349 if (this.isSrcUrlValid(menuInfo)) {
355 this.addSeparator(menu); 350 this.addSeparator(menu);
@@ -358,13 +353,15 @@ export class ContextMenuBuilder {
358 353
359 this.addInspectElement(menu, menuInfo); 354 this.addInspectElement(menu, menuInfo);
360 this.processMenu(menu); 355 this.processMenu(menu);
361
362 this.addSeparator(menu); 356 this.addSeparator(menu);
363 this.goBack(menu); 357 this.goBack(menu);
364 this.goForward(menu); 358 this.goForward(menu);
365 this.copyPageUrl(menu, menuInfo); 359 this.copyPageUrl(menu, menuInfo);
366 this.goToHomePage(menu, menuInfo); 360 this.addSeparator(menu);
367 this.openInBrowser(menu, menuInfo); 361 this.openInBrowser(menu, menuInfo);
362 this.openInFerdium(menu, menuInfo);
363 this.addSeparator(menu);
364 this.goToHomePage(menu, menuInfo);
368 365
369 return menu; 366 return menu;
370 } 367 }
@@ -384,16 +381,19 @@ export class ContextMenuBuilder {
384 this.addTranslateItems(menu, menuInfo); 381 this.addTranslateItems(menu, menuInfo);
385 } 382 }
386 this.addCopy(menu, menuInfo); 383 this.addCopy(menu, menuInfo);
387 this.addInspectElement(menu, menuInfo);
388 // @ts-expect-error Expected 1 arguments, but got 2.
389 this.processMenu(menu, menuInfo);
390 384
385 this.addInspectElement(menu, menuInfo);
386 this.processMenu(menu);
391 this.addSeparator(menu); 387 this.addSeparator(menu);
392 this.goBack(menu); 388 this.goBack(menu);
393 this.goForward(menu); 389 this.goForward(menu);
390 this.addSeparator(menu);
394 this.copyPageUrl(menu, menuInfo); 391 this.copyPageUrl(menu, menuInfo);
395 this.goToHomePage(menu, menuInfo); 392 this.addSeparator(menu);
396 this.openInBrowser(menu, menuInfo); 393 this.openInBrowser(menu, menuInfo);
394 this.openInFerdium(menu, menuInfo);
395 this.addSeparator(menu);
396 this.goToHomePage(menu, menuInfo);
397 397
398 return menu; 398 return menu;
399 } 399 }
@@ -412,8 +412,7 @@ export class ContextMenuBuilder {
412 this.addImageItems(menu, menuInfo); 412 this.addImageItems(menu, menuInfo);
413 } 413 }
414 this.addInspectElement(menu, menuInfo); 414 this.addInspectElement(menu, menuInfo);
415 // @ts-expect-error Expected 1 arguments, but got 2. 415 this.processMenu(menu);
416 this.processMenu(menu, menuInfo);
417 416
418 return menu; 417 return menu;
419 } 418 }
@@ -970,6 +969,26 @@ export class ContextMenuBuilder {
970 return menu; 969 return menu;
971 } 970 }
972 971
972 /**
973 * Adds the 'open in ferdium' menu item.
974 */
975 openInFerdium(
976 menu: Electron.CrossProcessExports.Menu,
977 menuInfo: IContextMenuParams,
978 ) {
979 menu.append(
980 new MenuItem({
981 label: this.stringTable.openInFerdium(),
982 enabled: true,
983 click: () => {
984 window.location.href = menuInfo.linkURL;
985 },
986 }),
987 );
988
989 return menu;
990 }
991
973 _sendNotificationOnClipboardEvent( 992 _sendNotificationOnClipboardEvent(
974 isDisabled: boolean, 993 isDisabled: boolean,
975 notificationText: () => string, 994 notificationText: () => string,