Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom drag and drop type #15361

Open
Gallienus opened this issue Oct 24, 2018 · 3 comments
Open

Custom drag and drop type #15361

Gallienus opened this issue Oct 24, 2018 · 3 comments

Comments

@Gallienus
Copy link

Problem
Right now, to start a file drag you call WebContents.startDrag({ file:<path>, icon:<path> }). This will spawn the following DataTransfer object:

DataTransfer {
  dropEffect: 'none',
  effectAllowed: 'copyLink', 
  files: FileList, 
  items: DataTransferItemList, 
  types:['Files',..]
}

with FileList containing the proper file(s).

The issue is the effectAllowed, which when set to 'copyLink' will not allow dragging and dropping files from the electron BrowserWindow to say Discord as they only allow dropped items with the 'move' effect from what I can see.

Solution
I propose allowing either changing the default from 'copyLink' to 'copyMove', OR allowing users to pass the drop effect as an argument to WebContents.startDrag.

File changes
drag_utils_views.cc (Line 20) - add argument for DragFileItems to accept a drop type (should be an int AFAIK, the Chromium DragOperations are defined here).
drag_utils_views.cc (Line 45) - ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK changed to a variable passed to the function.
drag_utils.h (Line 18) - add argument for DragFileItems to accept a drop type.
drag_util_mac.mm (Line 28) - may need to add argument to DragFileItems to accept a drop type too for compatibility with MACOSX. (I did not see how the drag type could be changed for osx, if they even use drag types the way windows does.)
atom_api_web_contents.cc (Line 1736) - get the drop type from item like

int item;
if (!item.Get("dropType", &item)) {
  item = <some default drop type value, like ui::DragDropTypes.DRAG_COPY | ui::DragDropTypes.DRAG_LINK as it was previously>
}

atom_api_web_contents.cc (Line 1754) - pass argument for drop type.

Outcome
Example usage of WebContents.startDrag could now be

contents.startDrag({
  file: 'C:/example/file.png',
  icon: 'myico.png',
  dropType: 3, // 3 for copyMove
})
@welcome
Copy link

welcome bot commented Oct 24, 2018

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

@Gallienus
Copy link
Author

Gallienus commented Oct 24, 2018

@mattetti initially implemented the WebContents.startDrag function over two years ago (from #4622)
@zcbenz seem to have worked on it too
Any of you know if the drop types can be changed from copyLink?

@andirsun
Copy link

It’s not possible to hold down modifier keys (Alt, Cmd etc) to control the type of the drag (copy, move, link etc.) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants