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:
@ -481,10 +481,38 @@ gimp_container_tree_view_real_drop_possible (GimpContainerTreeView *tree_view,
|
|||||||
GtkTreeViewDropPosition *return_drop_pos,
|
GtkTreeViewDropPosition *return_drop_pos,
|
||||||
GdkDragAction *return_drag_action)
|
GdkDragAction *return_drag_action)
|
||||||
{
|
{
|
||||||
GimpContainerView *view = GIMP_CONTAINER_VIEW (tree_view);
|
GimpContainerView *view = GIMP_CONTAINER_VIEW (tree_view);
|
||||||
GimpContainer *container = gimp_container_view_get_container (view);
|
GimpContainer *container = gimp_container_view_get_container (view);
|
||||||
gint src_index = -1;
|
GimpContainer *src_container = NULL;
|
||||||
gint dest_index = -1;
|
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),
|
if (src_viewable && g_type_is_a (G_TYPE_FROM_INSTANCE (src_viewable),
|
||||||
gimp_container_get_children_type (container)))
|
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)
|
if (src_viewable == dest_viewable)
|
||||||
return FALSE;
|
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)
|
if (src_index == -1 || dest_index == -1)
|
||||||
return FALSE;
|
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))
|
if (drop_pos == GTK_TREE_VIEW_DROP_BEFORE)
|
||||||
return FALSE;
|
{
|
||||||
}
|
if (dest_index == (src_index + 1))
|
||||||
else
|
return FALSE;
|
||||||
{
|
}
|
||||||
if (dest_index == (src_index - 1))
|
else
|
||||||
return FALSE;
|
{
|
||||||
|
if (dest_index == (src_index - 1))
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (return_drop_pos)
|
if (return_drop_pos)
|
||||||
|
@ -784,17 +784,9 @@ gimp_item_tree_view_drop_viewable (GimpContainerTreeView *tree_view,
|
|||||||
GimpViewable *dest_viewable,
|
GimpViewable *dest_viewable,
|
||||||
GtkTreeViewDropPosition drop_pos)
|
GtkTreeViewDropPosition drop_pos)
|
||||||
{
|
{
|
||||||
GimpContainerView *container_view = GIMP_CONTAINER_VIEW (tree_view);
|
|
||||||
GimpItemTreeView *item_view = GIMP_ITEM_TREE_VIEW (tree_view);
|
|
||||||
GimpItemTreeViewClass *item_view_class;
|
GimpItemTreeViewClass *item_view_class;
|
||||||
GimpContainer *container;
|
GimpItemTreeView *item_view = GIMP_ITEM_TREE_VIEW (tree_view);
|
||||||
gint dest_index = -1;
|
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));
|
|
||||||
|
|
||||||
item_view_class = GIMP_ITEM_TREE_VIEW_GET_CLASS (item_view);
|
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)
|
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,
|
src_container = gimp_item_get_container (GIMP_ITEM (src_viewable));
|
||||||
GIMP_OBJECT (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++;
|
if (drop_pos == GTK_TREE_VIEW_DROP_AFTER &&
|
||||||
}
|
src_index > dest_index)
|
||||||
else if (drop_pos == GTK_TREE_VIEW_DROP_BEFORE && src_index < dest_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,
|
item_view_class->reorder_item (item_view->priv->image,
|
||||||
GIMP_ITEM (src_viewable),
|
GIMP_ITEM (src_viewable),
|
||||||
dest_index,
|
dest_index,
|
||||||
TRUE,
|
TRUE,
|
||||||
item_view_class->reorder_desc);
|
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);
|
gimp_image_flush (item_view->priv->image);
|
||||||
|
Reference in New Issue
Block a user