From b7459d50f947a080418a0c83e110b1b8c85d2dec Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 3 Jul 2016 15:26:22 +0900 Subject: [PATCH] docs: Dragging files out of the window --- .../desktop-environment-integration.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/tutorial/desktop-environment-integration.md b/docs/tutorial/desktop-environment-integration.md index adb08ad5dc40..e430cb4235d9 100644 --- a/docs/tutorial/desktop-environment-integration.md +++ b/docs/tutorial/desktop-environment-integration.md @@ -321,6 +321,32 @@ win.setRepresentedFilename('/etc/passwd'); win.setDocumentEdited(true); ``` +## Dragging files out of the window + +For certain kinds of apps that manipulate on files, it is important to be able +to drag files from Electron to other apps. To implement this feature in your +app, you need to call `webContents.startDrag(item)` API on `ondragstart` event. + +In web page: + +```javascript +document.getElementById('targetItem').ondragstart = (event) => { + event.preventDefault() + ipcRenderer.send('ondragstart', '/path/to/item') +} +``` + +In the main process: + +```javascript +ipcMain.on('ondragstart', (event, filePath) => { + event.sender.startDrag({ + file: filePath, + icon: '/path/to/icon.png' + }) +}) +``` + [addrecentdocument]: ../api/app.md#appaddrecentdocumentpath-os-x-windows [clearrecentdocuments]: ../api/app.md#appclearrecentdocuments-os-x-windows [setusertaskstasks]: ../api/app.md#appsetusertaskstasks-windows