How to get DnD to work in GTKD?

Joseph JE342 at gmail.com
Fri Sep 22 03:50:44 UTC 2017


On Friday, 22 September 2017 at 02:57:32 UTC, Joseph wrote:
> On Saturday, 16 September 2017 at 14:33:53 UTC, Mike Wey wrote:
>> On 16-09-17 06:33, Joseph wrote:
>>> 
>>> I've used null in place of [te]. I'm not sure what target 
>>> entry is for and if that is the problem or what. I am trying 
>>> to drag files from windows explorer to a grid or label(I 
>>> duplicated the code above for the label) and none the 
>>> callbacks are ever called. I only need the filename of the 
>>> file being dragged.
>>> 
>>> I will eventually also need to drag one list element to 
>>> another(virtually so, I just need to know the index that was 
>>> dragged).
>>> 
>>> Thanks.
>>
>> You will also need to set an TargetList to tell gtk that you 
>> want to receive text:
>>
>> ```
>> TargetList lst = new TargetList([]);
>> lst.addTextTargets(0);
>>
>> w..dragDestSetTargetList(lst);
>> ```
>>
>> for simple cases only `addOnDragDataReceived` will be needed, 
>> `addOnDragDataGet` is only used for the source and 
>> `addOnDragDrop` can be used to filter the things that can be 
>> droped.
>>
>> List and Treeviews there are funtions like `getDragDestRow` 
>> available with the TreeView widget.
>
> Any ideas on this? I can drag text in the app itself to the app 
> but I can't drag outside of the app, e.g., a file from windows 
> explorer.
>
> This is the code:
>
> 	TargetEntry te = new TargetEntry("audio", 
> GtkTargetFlags.OTHER_APP, 0);
> 	TargetList lst = new TargetList([]);
> 	lst.addImageTargets(1, false);
> 	lst.addTextTargets(0);
>
> 	// Add drag and drop for audio files
>
> 	w.dragDestSet(GtkDestDefaults.ALL, null, GdkDragAction.COPY);
> 	w.dragDestSetTargetList(lst);
> 	w.addOnDragDataReceived((dragContext, x, y, selectionData, 
> info, time, widget)
> 														  {
> 															// TODO: Add drag and drop
> 															writeln("ok2");
> 														  });
>
> ok2 is printed only when I drag from inside the app to inside 
> the app(works with text, not sure if anything else as I didn't 
> try it) but can't seem to get anything from the outside to come 
> in ;/ Give that OTHER_APP is set I'd expect at least text 
> outside the app to be draggable in to it, but that is not the 
> case(I get the 'no sign' for that one, while for files I get 
> the drag icon).

Ok, I had to use the following

auto tel = [new TargetEntry("text/plain", 
GtkTargetFlags.OTHER_APP, 0),new TargetEntry("text/uri-list", 
GtkTargetFlags.OTHER_APP, 1),
	new TargetEntry("image/jpeg", GtkTargetFlags.OTHER_APP, 2),new 
TargetEntry("text/csv", GtkTargetFlags.OTHER_APP, 3)];

The file entries are passed as text/uri-list. I cannot drag text 
to the app but luckily I don't really need that.


More information about the Digitalmars-d-learn mailing list