In Gtk, when you use Drag and Drop in a TreeView, how can I refuse dropping between lines?

I am testing a window that looks something like this:

alt text

Dragging a tag onto a map associates a tag with a map. Also drags the map into the tag.

It makes no sense to drop a tag between two cards or a card between two tags. I can ignore these results in the Handle...DataReceived function as follows:

 if (dropPos != TreeViewDropPosition.IntoOrAfter && dropPos != TreeViewDropPosition.IntoOrBefore) return; 

However, when dragging and dropping, the user still sees the ability to insert:

alt text

How to prevent this?

+6
c # drag-and-drop gtk gtk # gtktreeview
source share
2 answers

You need to hook into the drag-motion signal and change the default behavior so that it never indicates a fall before / after:

 def _drag_motion(self, widget, context, x, y, etime): drag_info = widget.get_dest_row_at_pos(x, y) if not drag_info: return False path, pos = drag_info if pos == gtk.TREE_VIEW_DROP_BEFORE: widget.set_drag_dest_row(path, gtk.TREE_VIEW_DROP_INTO_OR_BEFORE) elif pos == gtk.TREE_VIEW_DROP_AFTER: widget.set_drag_dest_row(path, gtk.TREE_VIEW_DROP_INTO_OR_AFTER) context.drag_status(context.suggested_action, etime) return True 
+3
source share

You can define different goals for tags and cards, and on the left widget accept only the target representing the tags. Use the Gtk.Drag.DestSet method. Maybe something like:

  Gtk.Drag.DestSet (widget, DestDefaults.All, new TargetEntry[1] { new TargetEntry ("MYAPP_TAGS", TargetFlags.App, 1) }, DragAction.Default); 

I tried to get the receiver to emit motion events with:

  Gtk.Drag.DestSet (widget, DestDefaults.Motion, new TargetEntry[1] { new TargetEntry ("MYAPP_TAGS", TargetFlags.App, 1) }, DragAction.Default); 

theoretically, if I understand correctly, it should work. But I could not make it fire events :(

+1
source share

All Articles