views:

214

answers:

2

I'm testing a window that looks something like this:

alt text

Dragging a Tag to a Card links the Tag to the Card. So does dragging a Card to a Tag.

It's meaningless to drop a tag between two cards, or a card between two tags. I can ignore these outcomes in the Handle...DataReceived function like this:

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

However, when dragging, the user still sees the option to insert:

alt text

How do I prevent this from happening?

A: 

You can define different targets for tags and cards, and on the left widget accept only the target that represents the tags. Use 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 make the destination 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 it correctly, it should work. But I couldn't make it fire motion events :(

silk
Thanks--I might not have been clear: My problem is not that I don't want the left side to accept both cards and tags (I already use different targets). It's that I only want to be able to drop directly on tags, rather than in between them.
Matthew
+2  A: 

You need to connect to the drag-motion signal and change the default behaviour so it never indicates a before/after drop:

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
Johannes Sasongko
Thanks--I've ported most of this, but I'm having trouble finding a Gtk# equivalent to pygtk's DragContext.drag_status. Here's the documentation: http://www.go-mono.org/docs/index.aspx?link=T:Gdk.DragContext/*
Matthew
That link is broken--the * is supposed to be part of it.
Matthew
Took me a while to find it, too: apparently it's Gdk.Drag.Status in Gtk# (gdk_drag_status in C).
Johannes Sasongko