Add gimp_item_stack_get_parent_by_path(), for use un XCF loading

The opposite of gimp_item_get_path(), just that it doesn't return an
item, it returns a parent item and an index that can be used to add
the item to an item tree.
This commit is contained in:
Michael Natterer 2009-08-30 20:58:24 +02:00
parent 3d547c0a70
commit f9c8bea368
2 changed files with 46 additions and 0 deletions

View File

@ -247,6 +247,49 @@ gimp_item_stack_get_item_by_name (GimpItemStack *stack,
return NULL;
}
GimpItem *
gimp_item_stack_get_parent_by_path (GimpItemStack *stack,
GList *path,
gint *index)
{
GimpItem *parent = NULL;
guint32 i;
g_return_val_if_fail (GIMP_IS_ITEM_STACK (stack), NULL);
g_return_val_if_fail (path != NULL, NULL);
i = GPOINTER_TO_UINT (path->data);
if (index)
*index = i;
while (path->next)
{
GimpObject *child;
GimpContainer *children;
child = gimp_container_get_child_by_index (GIMP_CONTAINER (stack), i);
g_return_val_if_fail (GIMP_IS_ITEM (child), parent);
children = gimp_viewable_get_children (GIMP_VIEWABLE (child));
g_return_val_if_fail (GIMP_IS_ITEM_STACK (children), parent);
parent = GIMP_ITEM (child);
stack = GIMP_ITEM_STACK (children);
path = path->next;
i = GPOINTER_TO_UINT (path->data);
if (index)
*index = i;
}
return parent;
}
static void
gimp_item_stack_invalidate_preview (GimpViewable *viewable)
{

View File

@ -54,6 +54,9 @@ GimpItem * gimp_item_stack_get_item_by_tattoo (GimpItemStack *stack,
GimpTattoo tattoo);
GimpItem * gimp_item_stack_get_item_by_name (GimpItemStack *stack,
const gchar *name);
GimpItem * gimp_item_stack_get_parent_by_path (GimpItemStack *stack,
GList *path,
gint *index);
void gimp_item_stack_invalidate_previews (GimpItemStack *stack);