[gimp] app: add gimp_item_stack_get_item_by_path()



commit b2642272a41fa006f0584af75104909f5944aa50
Author: Michael Natterer <mitch gimp org>
Date:   Sun Aug 8 17:31:39 2010 +0200

    app: add gimp_item_stack_get_item_by_path()
    
    which finds an item by its path as returned by gimp_item_get_path().

 app/core/gimpitemstack.c |   33 +++++++++++++++++++++++++++++++++
 app/core/gimpitemstack.h |    2 ++
 2 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/app/core/gimpitemstack.c b/app/core/gimpitemstack.c
index 0a3cec4..0da89da 100644
--- a/app/core/gimpitemstack.c
+++ b/app/core/gimpitemstack.c
@@ -234,6 +234,39 @@ gimp_item_stack_get_item_by_tattoo (GimpItemStack *stack,
 }
 
 GimpItem *
+gimp_item_stack_get_item_by_path (GimpItemStack *stack,
+                                  GList         *path)
+{
+  GimpContainer *container;
+  GimpItem      *item = NULL;
+
+  g_return_val_if_fail (GIMP_IS_ITEM_STACK (stack), NULL);
+  g_return_val_if_fail (path != NULL, NULL);
+
+  container = GIMP_CONTAINER (stack);
+
+  while (path)
+    {
+      guint32 i = GPOINTER_TO_UINT (path->data);
+
+      item = GIMP_ITEM (gimp_container_get_child_by_index (container, i));
+
+      g_return_val_if_fail (GIMP_IS_ITEM (item), item);
+
+      if (path->next)
+        {
+          container = gimp_viewable_get_children (GIMP_VIEWABLE (item));
+
+          g_return_val_if_fail (GIMP_IS_ITEM_STACK (container), item);
+        }
+
+      path = path->next;
+    }
+
+  return item;
+}
+
+GimpItem *
 gimp_item_stack_get_parent_by_path (GimpItemStack *stack,
                                     GList         *path,
                                     gint          *index)
diff --git a/app/core/gimpitemstack.h b/app/core/gimpitemstack.h
index f86aa45..195ec4e 100644
--- a/app/core/gimpitemstack.h
+++ b/app/core/gimpitemstack.h
@@ -53,6 +53,8 @@ GList         * gimp_item_stack_get_item_iter       (GimpItemStack *stack);
 GList         * gimp_item_stack_get_item_list       (GimpItemStack *stack);
 GimpItem      * gimp_item_stack_get_item_by_tattoo  (GimpItemStack *stack,
                                                      GimpTattoo     tattoo);
+GimpItem      * gimp_item_stack_get_item_by_path    (GimpItemStack *stack,
+                                                     GList         *path);
 GimpItem      * gimp_item_stack_get_parent_by_path  (GimpItemStack *stack,
                                                      GList         *path,
                                                      gint          *index);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]