From 79868f1eb45bed0c2d891547ffdde28e3f7d3b5c Mon Sep 17 00:00:00 2001 From: Daniel Andrei Date: Fri, 30 Aug 2019 07:42:46 +0300 Subject: [PATCH] Add `Copy Image` option (#79) Co-authored-by: Sindre Sorhus --- index.d.ts | 16 +++++++++++++++- index.js | 9 +++++++++ readme.md | 9 +++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index e1cc78e..a80e258 100644 --- a/index.d.ts +++ b/index.d.ts @@ -47,6 +47,11 @@ declare namespace contextMenu { */ readonly copyLink?: string; + /** + @default 'Copy Image' + */ + readonly copyImage?: string; + /** @default 'Copy Image Address' */ @@ -78,6 +83,7 @@ declare namespace contextMenu { readonly paste: (options: ActionOptions) => MenuItem; readonly saveImage: (options: ActionOptions) => MenuItem; readonly saveImageAs: (options: ActionOptions) => MenuItem; + readonly copyImage: (options: ActionOptions) => MenuItem; readonly copyImageAddress: (options: ActionOptions) => MenuItem; readonly inspect: () => MenuItem; readonly services: () => MenuItem; @@ -119,6 +125,13 @@ declare namespace contextMenu { */ readonly showLookUpSelection?: boolean; + /** + Show the `Copy Image` menu item when right-clicking on an image. + + @default true + */ + readonly showCopyImage?: boolean; + /** Show the `Copy Image Address` menu item when right-clicking on an image. @@ -194,11 +207,12 @@ declare namespace contextMenu { The following options are ignored when `menu` is used: + - `showCopyImage` - `showCopyImageAddress` - `showSaveImageAs` - `showInspectElement` - @default [defaultActions.cut(), defaultActions.copy(), defaultActions.paste(), defaultActions.separator(), defaultActions.saveImage(), defaultActions.saveImageAs(), defaultActions.copyImageAddress(), defaultActions.separator(), defaultActions.copyLink(), defaultActions.separator(), defaultActions.inspect()] + @default [defaultActions.cut(), defaultActions.copy(), defaultActions.paste(), defaultActions.separator(), defaultActions.saveImage(), defaultActions.saveImageAs(), defaultActions.copyImage(), defaultActions.copyImageAddress(), defaultActions.separator(), defaultActions.copyLink(), defaultActions.separator(), defaultActions.inspect()] */ readonly menu?: ( defaultActions: Actions, diff --git a/index.js b/index.js index c63502c..5931c21 100644 --- a/index.js +++ b/index.js @@ -114,6 +114,14 @@ const create = (win, options) => { }); } }), + copyImage: decorateMenuItem({ + id: 'copyImage', + label: 'Copy Image', + visible: props.mediaType === 'image', + click() { + webContents(win).copyImageAt(props.x, props.y); + } + }), copyImageAddress: decorateMenuItem({ id: 'copyImageAddress', label: 'Copy Image Address', @@ -157,6 +165,7 @@ const create = (win, options) => { defaultActions.separator(), defaultActions.saveImage(), options.showSaveImageAs && defaultActions.saveImageAs(), + options.showCopyImage !== false && defaultActions.copyImage(), options.showCopyImageAddress && defaultActions.copyImageAddress(), defaultActions.separator(), defaultActions.copyLink(), diff --git a/readme.md b/readme.md index 78828be..d9698ff 100644 --- a/readme.md +++ b/readme.md @@ -93,6 +93,13 @@ Default: `true` Show the `Look Up {selection}` menu item when right-clicking text on macOS. +#### showCopyImage + +Type: `boolean`
+Default: `true` + +Show the `Copy Image` menu item when right-clicking on an image. + #### showCopyImageAddress Type: `boolean`
@@ -176,6 +183,7 @@ Even though you include an action, it will still only be shown/enabled when appr The following options are ignored when `menu` is used: - `showLookUpSelection` +- `showCopyImage` - `showCopyImageAddress` - `showSaveImageAs` - `showInspectElement` @@ -190,6 +198,7 @@ Default actions: - `paste` - `saveImage` - `saveImageAs` +- `copyImage` - `copyImageAddress` - `copyLink` - `inspect`