Skip to content

Commit

Permalink
Add Copy Image option (#79)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
whitecrownclown and sindresorhus committed Aug 30, 2019
1 parent 1310a1d commit 79868f1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
16 changes: 15 additions & 1 deletion index.d.ts
Expand Up @@ -47,6 +47,11 @@ declare namespace contextMenu {
*/
readonly copyLink?: string;

/**
@default 'Copy Image'
*/
readonly copyImage?: string;

/**
@default 'Copy Image Address'
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions index.js
Expand Up @@ -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',
Expand Down Expand Up @@ -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(),
Expand Down
9 changes: 9 additions & 0 deletions readme.md
Expand Up @@ -93,6 +93,13 @@ Default: `true`

Show the `Look Up {selection}` menu item when right-clicking text on macOS.

#### showCopyImage

Type: `boolean`<br>
Default: `true`

Show the `Copy Image` menu item when right-clicking on an image.

#### showCopyImageAddress

Type: `boolean`<br>
Expand Down Expand Up @@ -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`
Expand All @@ -190,6 +198,7 @@ Default actions:
- `paste`
- `saveImage`
- `saveImageAs`
- `copyImage`
- `copyImageAddress`
- `copyLink`
- `inspect`
Expand Down

0 comments on commit 79868f1

Please sign in to comment.