Bug 558794 - [DND] Add API to query drag data before drop
Summary: [DND] Add API to query drag data before drop
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.14   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 513075
  Show dependency tree
 
Reported: 2020-01-03 17:18 EST by Paul Pazderski CLA
Modified: 2020-01-03 17:21 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Pazderski CLA 2020-01-03 17:18:04 EST
Requesting the dragged data before the drop (e.g. in dragOver) can be useful to give feedback whether the DropTarget can accept the data or not. At the moment a target can give feedback based on data type and transfer method (copy, move, link). A simple example where inspecting the data might be useful is a target accepting files but limited to images. With API to get data before drop it could inspect the filenames (or even the files) and give appropriate feedback.

In fact while preparing this bug text I found that ResourceDropAdapterAssistant (part of navigator framework) is doing such pre-drop verification already.

There exist no specific API yet to this but a 'rather official' workaround to archive this but only on Windows. This workaround is described in [1] and referenced in bug 145587.

This workaround has some drawbacks:
 - It requires the transfer type to be public which is not the default, is often the case but should in my opinion never be the case.
 - Misuse can be fatal as seen in bug 513075. There is no documentation when it is Ok to request the data and when not and there is no good and no perfect way to guard against misuse.
 - It works only on Windows and from my current understanding of GTK it cannot work there or would be unnecessary complicate. And the same possibility for misuse would arise.


The method I like to add is rather simple (will provide a proposal for Windows). DropTarget gets a peekDragData(DropTargetEvent) method which either returns the currently dragged data or null. This is closed to the used workaround which used a field of the event object and had the same return value behaviour.

With such a method we could control when it is save to query for the data and when not. We could cut off the existing workaround and prevent crash situations as described in bug 513075 on Windows.
While it is fine and easy on Windows to query data any time the drag operation is active it is not so easy (or impossible; not sure yet) to do the same on GTK. Therefor the official supported and documented usage is to call this method from within a DropTarget event.


Regards the implementation: I can provide an implementation for Windows and will work on an implementation for Linux if I find time for it.
I cannot provide an implementation for Mac and not even estimate if it is possible. 

[1] https://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.html#_dt43C
Comment 1 Eclipse Genie CLA 2020-01-03 17:21:24 EST
New Gerrit change created: https://git.eclipse.org/r/155188