You've already forked joplin
							
							
				mirror of
				https://github.com/laurent22/joplin.git
				synced 2025-10-31 00:07:48 +02:00 
			
		
		
		
	Desktop: Right click on image to copy it to clipboard
This commit is contained in:
		| @@ -1,22 +1,18 @@ | ||||
| import ElectronAppWrapper from './ElectronAppWrapper'; | ||||
| import shim from '@joplin/lib/shim'; | ||||
| import { _, setLocale } from '@joplin/lib/locale'; | ||||
| import { BrowserWindow, nativeTheme, nativeImage } from 'electron'; | ||||
| const { dirname, toSystemSlashes } = require('@joplin/lib/path-utils'); | ||||
| const { BrowserWindow, nativeTheme } = require('electron'); | ||||
|  | ||||
| interface LastSelectedPath { | ||||
| 	file: string; | ||||
| 	directory: string; | ||||
| } | ||||
|  | ||||
| interface LastSelectedPaths { | ||||
| 	[key: string]: LastSelectedPath; | ||||
| } | ||||
|  | ||||
| export class Bridge { | ||||
|  | ||||
| 	private electronWrapper_: ElectronAppWrapper; | ||||
| 	private lastSelectedPaths_: LastSelectedPaths; | ||||
| 	private lastSelectedPaths_: LastSelectedPath; | ||||
|  | ||||
| 	constructor(electronWrapper: ElectronAppWrapper) { | ||||
| 		this.electronWrapper_ = electronWrapper; | ||||
| @@ -164,11 +160,11 @@ export class Bridge { | ||||
| 		if (!options) options = {}; | ||||
| 		let fileType = 'file'; | ||||
| 		if (options.properties && options.properties.includes('openDirectory')) fileType = 'directory'; | ||||
| 		if (!('defaultPath' in options) && this.lastSelectedPaths_[fileType]) options.defaultPath = this.lastSelectedPaths_[fileType]; | ||||
| 		if (!('defaultPath' in options) && (this.lastSelectedPaths_ as any)[fileType]) options.defaultPath = (this.lastSelectedPaths_ as any)[fileType]; | ||||
| 		if (!('createDirectory' in options)) options.createDirectory = true; | ||||
| 		const { filePaths } = await dialog.showOpenDialog(this.window(), options); | ||||
| 		if (filePaths && filePaths.length) { | ||||
| 			this.lastSelectedPaths_[fileType] = dirname(filePaths[0]); | ||||
| 			(this.lastSelectedPaths_ as any)[fileType] = dirname(filePaths[0]); | ||||
| 		} | ||||
| 		return filePaths; | ||||
| 	} | ||||
| @@ -282,6 +278,10 @@ export class Bridge { | ||||
| 		app.exit(); | ||||
| 	} | ||||
|  | ||||
| 	public createImageFromPath(path: string) { | ||||
| 		return nativeImage.createFromPath(path); | ||||
| 	} | ||||
|  | ||||
| } | ||||
|  | ||||
| let bridge_: Bridge = null; | ||||
|   | ||||
| @@ -1,8 +1,7 @@ | ||||
| import ResourceEditWatcher from '@joplin/lib/services/ResourceEditWatcher/index'; | ||||
| import { _ } from '@joplin/lib/locale'; | ||||
| import { copyHtmlToClipboard } from './clipboardUtils'; | ||||
|  | ||||
| const bridge = require('@electron/remote').require('./bridge').default; | ||||
| import bridge from '../../../services/bridge'; | ||||
| const Menu = bridge().Menu; | ||||
| const MenuItem = bridge().MenuItem; | ||||
| import Resource from '@joplin/lib/models/Resource'; | ||||
| @@ -131,6 +130,15 @@ export function menuItems(dispatch: Function): ContextMenuItems { | ||||
| 			}, | ||||
| 			isActive: (itemType: ContextMenuItemType) => itemType === ContextMenuItemType.Image || itemType === ContextMenuItemType.Resource, | ||||
| 		}, | ||||
| 		copyImage: { | ||||
| 			label: _('Copy image'), | ||||
| 			onAction: async (options: ContextMenuOptions) => { | ||||
| 				const { resourcePath } = await resourceInfo(options); | ||||
| 				const image = bridge().createImageFromPath(resourcePath); | ||||
| 				clipboard.writeImage(image); | ||||
| 			}, | ||||
| 			isActive: (itemType: ContextMenuItemType) => itemType === ContextMenuItemType.Image, | ||||
| 		}, | ||||
| 		cut: { | ||||
| 			label: _('Cut'), | ||||
| 			onAction: async (options: ContextMenuOptions) => { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user