[gimp] app: add new parameter check function gimp_pdb_item_is_in_tree()



commit f60d456e61ba3e243a9b094719a7951558dc8705
Author: Michael Natterer <mitch gimp org>
Date:   Fri Jul 23 22:08:28 2010 +0200

    app: add new parameter check function gimp_pdb_item_is_in_tree()
    
    which makes sure the passed item is part of an item hierarchy
    (and not for example a selection or a layer mask)

 app/pdb/gimppdb-utils.c |   26 ++++++++++++++++++++++++++
 app/pdb/gimppdb-utils.h |    4 ++++
 2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/app/pdb/gimppdb-utils.c b/app/pdb/gimppdb-utils.c
index 0a1dac5..76b298d 100644
--- a/app/pdb/gimppdb-utils.c
+++ b/app/pdb/gimppdb-utils.c
@@ -339,6 +339,32 @@ gimp_pdb_item_is_attached (GimpItem  *item,
 }
 
 gboolean
+gimp_pdb_item_is_in_tree (GimpItem   *item,
+                          GimpImage  *image,
+                          gboolean    writable,
+                          GError    **error)
+{
+  g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
+  g_return_val_if_fail (image == NULL || GIMP_IS_IMAGE (image), FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  if (! gimp_pdb_item_is_attached (item, image, writable, error))
+    return FALSE;
+
+  if (! gimp_item_get_tree (item))
+    {
+      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
+                   _("Item '%s' (%d) can not be used because it is not "
+                     "a direct child of an item tree"),
+                   gimp_object_get_name (item),
+                   gimp_item_get_ID (item));
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
+gboolean
 gimp_pdb_item_is_floating (GimpItem  *item,
                            GimpImage *dest_image,
                            GError   **error)
diff --git a/app/pdb/gimppdb-utils.h b/app/pdb/gimppdb-utils.h
index 9036306..f5a8a59 100644
--- a/app/pdb/gimppdb-utils.h
+++ b/app/pdb/gimppdb-utils.h
@@ -52,6 +52,10 @@ gboolean        gimp_pdb_item_is_attached       (GimpItem           *item,
                                                  GimpImage          *image,
                                                  gboolean            writable,
                                                  GError            **error);
+gboolean        gimp_pdb_item_is_in_tree        (GimpItem           *item,
+                                                 GimpImage          *image,
+                                                 gboolean            writable,
+                                                 GError            **error);
 gboolean        gimp_pdb_item_is_floating       (GimpItem           *item,
                                                  GimpImage          *dest_image,
                                                  GError            **error);



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