www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to get DnD to work in GTKD?

reply Joseph <JE342 gmail.com> writes:
This is my code:

TargetEntry te = new TargetEntry("test", 
GtkTargetFlags.OTHER_APP, 0);


w.dragDestSet(GtkDestDefaults.ALL, [te], GdkDragAction.COPY);
w.addOnDragDataReceived((dragContext, x, y, selectionData, info, 
time, widget)
{
   writeln("ok1");
});

w.addOnDragDrop((dragContext, x, y, time, widget)
{
   writeln("ok2");
   return true;
});

w.addOnDragDataGet((dragContext, selectionData, info, time, 
widget)
{
   writeln("ok3");
});

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.
Sep 15
parent reply Mike Wey <mike-wey example.com> writes:
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. -- Mike Wey
Sep 16
next sibling parent reply Joseph <JE342 gmail.com> writes:
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.
Thanks, I added the code above but it didn't seem to get the handlers called. Is there anything else I'm suppose to be doing to initialize things or is it an issue with just getting the correct target setup? if I drag a file I get the drag icon but no "output" from the callbacks. If I drag selected text from firefox to it, I get the not valid drag sign.
Sep 16
parent Joseph <JE342 gmail.com> writes:
On Saturday, 16 September 2017 at 17:08:52 UTC, Joseph wrote:
 On Saturday, 16 September 2017 at 14:33:53 UTC, Mike Wey wrote:
 On 16-09-17 06:33, Joseph wrote:
 [...]
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.
Thanks, I added the code above but it didn't seem to get the handlers called. Is there anything else I'm suppose to be doing to initialize things or is it an issue with just getting the correct target setup? if I drag a file I get the drag icon but no "output" from the callbacks. If I drag selected text from firefox to it, I get the not valid drag sign.
Ok, so I dragged some text from the same app and it worked! Even though I set TargetEntry te = new TargetEntry("text", GtkTargetFlags.OTHER_APP, 0); So, seems to be a settings/setup issue.
Sep 16
prev sibling parent reply Joseph <JE342 gmail.com> writes:
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).
Sep 21
parent Joseph <JE342 gmail.com> writes:
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.
Sep 21