GNOME Bugzilla – Bug 742865
feature: Add support for files drag and drop
Last modified: 2015-01-19 01:51:04 UTC
We should allow drag and drop of files onto the editor
This sounds like a good idea. So that we can drop a file on an empty workspace, I think we'll want the DnD target to be on GbEditorWorkspace. It is also convenient to put it there since that is where the "open" action lives.
Disclaimer: I may be wrong since I am talking about code written a decade ago and because so much changed in gtk If I recall correctly this is trickier than it looks, because the TextView will eat the drop and decide to insert the filename as a string in the textview: if I am right, then beside handling the drop in GbEditorWorkspace you will also need to override the behavior of GbSourceView. The corresponding code in gedit is around https://git.gnome.org/browse/gedit/tree/gedit/gedit-view.c#n346 (It also implements the directsave support, which is not a bad thing to have)
We had some work around code for it when we were doing drag-n-drop tabs, but I ripped that out. The gedit code does in fact look more resilient.
This is more difficult that I thought.Adding drag and drop support on GbEditorWorkspace was easy but we also need a drag_data_received handler on GbSourceView. By looking gedit code, gedit-view catches the drag_data_received and emits a drop_uri which is then caught by gedit_tab which transmits another drop_uri which is then caught from gedit-window and finally open the files This approach does not look good and also in gnome-builder we have a much longer abstraction.I cannot assume that every GbDocument will have a DROP_URI that I can connect to it from GbEditorWorkspace Is there any way I can let the drag_data_received event to propagate from GbSourceView up to GbEditorWorkspace (other than catch and re-fire)
Created attachment 294735 [details] [review] Implement dnd support This patch adds support for "text/uri-list" drop type on GbEditorWorkspace and GbSourceView. This patch does not: -support dnd on GbDevhelpView -support dnd on GbHtmlView -support XdndDirectSave0 drop type
Please review tha patch and if everything is ok I will continue on to implementing the missing staff as well.
Looks good. Pushed with a follow up commit for style and to use gb_widget_activate_action() (which I just added as well). Should simplify resolving GActions in the future. Thanks again!