Add infrastructure for dragging things between branches of a tree

* app/widgets/gimpcontainertreeview-dnd.c
  (gimp_container_tree_view_real_drop_possible): support DND within a
  tree and make sure a group item is not dropped into itself.

* app/widgets/gimpitemtreeview.c (gimp_item_tree_view_drop_viewable):
  implement intra-container reordering within all branches; print a
  message for inter-container reordering because that's not yet
  implemented in the core.
This commit is contained in:
Michael Natterer 2009-08-05 18:57:08 +02:00
parent fe99eff373
commit b2c7c4f61b
2 changed files with 81 additions and 51 deletions

View File

@ -481,10 +481,38 @@ gimp_container_tree_view_real_drop_possible (GimpContainerTreeView *tree_view,
GtkTreeViewDropPosition *return_drop_pos,
GdkDragAction *return_drag_action)
{
GimpContainerView *view = GIMP_CONTAINER_VIEW (tree_view);
GimpContainer *container = gimp_container_view_get_container (view);
gint src_index = -1;
gint dest_index = -1;
GimpContainerView *view = GIMP_CONTAINER_VIEW (tree_view);
GimpContainer *container = gimp_container_view_get_container (view);
GimpContainer *src_container = NULL;
GimpContainer *dest_container = NULL;
gint src_index = -1;
gint dest_index = -1;
if (src_viewable)
{
GimpViewable *parent = gimp_viewable_get_parent (src_viewable);
if (parent)
src_container = gimp_viewable_get_children (parent);
else if (gimp_container_have (container, GIMP_OBJECT (src_viewable)))
src_container = container;
src_index = gimp_container_get_child_index (src_container,
GIMP_OBJECT (src_viewable));
}
if (dest_viewable)
{
GimpViewable *parent = gimp_viewable_get_parent (dest_viewable);
if (parent)
dest_container = gimp_viewable_get_children (parent);
else if (gimp_container_have (container, GIMP_OBJECT (dest_viewable)))
dest_container = container;
dest_index = gimp_container_get_child_index (dest_container,
GIMP_OBJECT (dest_viewable));
}
if (src_viewable && g_type_is_a (G_TYPE_FROM_INSTANCE (src_viewable),
gimp_container_get_children_type (container)))
@ -492,33 +520,27 @@ gimp_container_tree_view_real_drop_possible (GimpContainerTreeView *tree_view,
if (src_viewable == dest_viewable)
return FALSE;
src_index = gimp_container_get_child_index (container,
GIMP_OBJECT (src_viewable));
if (src_index == -1)
return FALSE;
if (dest_viewable)
{
dest_index = gimp_container_get_child_index (container,
GIMP_OBJECT (dest_viewable));
if (dest_index == -1)
return FALSE;
}
if (src_index == -1 || dest_index == -1)
return FALSE;
/* don't allow dropping a parent node onto one of its descendants
*/
if (gimp_viewable_is_ancestor (src_viewable, dest_viewable))
return FALSE;
}
if (drop_pos == GTK_TREE_VIEW_DROP_BEFORE)
if (src_container == dest_container)
{
if (dest_index == (src_index + 1))
return FALSE;
}
else
{
if (dest_index == (src_index - 1))
return FALSE;
if (drop_pos == GTK_TREE_VIEW_DROP_BEFORE)
{
if (dest_index == (src_index + 1))
return FALSE;
}
else
{
if (dest_index == (src_index - 1))
return FALSE;
}
}
if (return_drop_pos)

View File

@ -784,17 +784,9 @@ gimp_item_tree_view_drop_viewable (GimpContainerTreeView *tree_view,
GimpViewable *dest_viewable,
GtkTreeViewDropPosition drop_pos)
{
GimpContainerView *container_view = GIMP_CONTAINER_VIEW (tree_view);
GimpItemTreeView *item_view = GIMP_ITEM_TREE_VIEW (tree_view);
GimpItemTreeViewClass *item_view_class;
GimpContainer *container;
gint dest_index = -1;
container = gimp_container_view_get_container (container_view);
if (dest_viewable)
dest_index = gimp_container_get_child_index (container,
GIMP_OBJECT (dest_viewable));
GimpItemTreeView *item_view = GIMP_ITEM_TREE_VIEW (tree_view);
gint dest_index = -1;
item_view_class = GIMP_ITEM_TREE_VIEW_GET_CLASS (item_view);
@ -823,25 +815,41 @@ gimp_item_tree_view_drop_viewable (GimpContainerTreeView *tree_view,
}
else if (dest_viewable)
{
gint src_index;
GimpContainer *src_container;
GimpContainer *dest_container;
gint src_index;
gint dest_index;
src_index = gimp_container_get_child_index (container,
GIMP_OBJECT (src_viewable));
src_container = gimp_item_get_container (GIMP_ITEM (src_viewable));
src_index = gimp_item_get_index (GIMP_ITEM (src_viewable));
if (drop_pos == GTK_TREE_VIEW_DROP_AFTER && src_index > dest_index)
dest_container = gimp_item_get_container (GIMP_ITEM (dest_viewable));
dest_index = gimp_item_get_index (GIMP_ITEM (dest_viewable));
if (src_container == dest_container)
{
dest_index++;
}
else if (drop_pos == GTK_TREE_VIEW_DROP_BEFORE && src_index < dest_index)
{
dest_index--;
}
if (drop_pos == GTK_TREE_VIEW_DROP_AFTER &&
src_index > dest_index)
{
dest_index++;
}
else if (drop_pos == GTK_TREE_VIEW_DROP_BEFORE &&
src_index < dest_index)
{
dest_index--;
}
item_view_class->reorder_item (item_view->priv->image,
GIMP_ITEM (src_viewable),
dest_index,
TRUE,
item_view_class->reorder_desc);
item_view_class->reorder_item (item_view->priv->image,
GIMP_ITEM (src_viewable),
dest_index,
TRUE,
item_view_class->reorder_desc);
}
else
{
g_printerr ("%s: dnd between containers (%d -> %d)\n",
G_STRFUNC, src_index, dest_index);
}
}
gimp_image_flush (item_view->priv->image);