[gimp] Add gimp_item_get_path(), to be used in XCF saving



commit 3d547c0a7032e633fd0fa9b86f5f55a5f47f79e6
Author: Michael Natterer <mitch gimp org>
Date:   Sun Aug 30 20:56:39 2009 +0200

    Add gimp_item_get_path(), to be used in XCF saving
    
    Returns a GList of guint indices that describe the path to an item in
    an item tree, pretty much like GtkTreePath does for GtkTreeModels.

 app/core/gimpitem.c |   29 +++++++++++++++++++++++++++++
 app/core/gimpitem.h |    1 +
 2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/app/core/gimpitem.c b/app/core/gimpitem.c
index 2f20051..05f3bd2 100644
--- a/app/core/gimpitem.c
+++ b/app/core/gimpitem.c
@@ -733,6 +733,35 @@ gimp_item_get_index (GimpItem *item)
   return -1;
 }
 
+GList *
+gimp_item_get_path (GimpItem *item)
+{
+  GimpContainer *container;
+  GList         *path = NULL;
+
+  g_return_val_if_fail (GIMP_IS_ITEM (item), NULL);
+  g_return_val_if_fail (gimp_item_is_attached (item), NULL);
+
+  container = gimp_item_get_container (item);
+
+  while (container)
+    {
+      guint32 index = gimp_container_get_child_index (container,
+                                                      GIMP_OBJECT (item));
+
+      path = g_list_prepend (path, GUINT_TO_POINTER (index));
+
+      item = GIMP_ITEM (gimp_viewable_get_parent (GIMP_VIEWABLE (item)));
+
+      if (item)
+        container = gimp_item_get_container (item);
+      else
+        container = NULL;
+    }
+
+  return path;
+}
+
 /**
  * gimp_item_duplicate:
  * @item:     The #GimpItem to duplicate.
diff --git a/app/core/gimpitem.h b/app/core/gimpitem.h
index 82989c0..082498d 100644
--- a/app/core/gimpitem.h
+++ b/app/core/gimpitem.h
@@ -146,6 +146,7 @@ gboolean        gimp_item_is_attached        (const GimpItem     *item);
 GimpContainer * gimp_item_get_container      (GimpItem           *item);
 GList         * gimp_item_get_container_iter (GimpItem           *item);
 gint            gimp_item_get_index          (GimpItem           *item);
+GList         * gimp_item_get_path           (GimpItem           *item);
 
 void            gimp_item_configure          (GimpItem           *item,
                                               GimpImage          *image,



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