gimp r25356 - in trunk: . app/pdb tools/pdbgen/pdb



Author: neo
Date: Fri Apr  4 08:21:27 2008
New Revision: 25356
URL: http://svn.gnome.org/viewvc/gimp?rev=25356&view=rev

Log:
2008-04-04  Sven Neumann  <sven gimp org>

	* app/pdb/gimppdb-utils.[ch]: added test for floating items.

	* tools/pdbgen/pdb/image.pdb: use it to improve error handling.

	* app/pdb/image_cmds.c: regenerated.



Modified:
   trunk/ChangeLog
   trunk/app/pdb/gimppdb-utils.c
   trunk/app/pdb/gimppdb-utils.h
   trunk/app/pdb/image_cmds.c
   trunk/tools/pdbgen/pdb/image.pdb

Modified: trunk/app/pdb/gimppdb-utils.c
==============================================================================
--- trunk/app/pdb/gimppdb-utils.c	(original)
+++ trunk/app/pdb/gimppdb-utils.c	Fri Apr  4 08:21:27 2008
@@ -299,18 +299,34 @@
   g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-  if (! gimp_item_is_attached (item))
-    {
-      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
-                   _("Item '%s' (%d) can not be used because it has not "
-                     "been added to an image"),
-                   gimp_object_get_name (GIMP_OBJECT (item)),
-                   gimp_item_get_ID (item));
+  if (gimp_item_is_attached (item))
+    return TRUE;
 
-      return FALSE;
-    }
+  g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
+               _("Item '%s' (%d) can not be used because it has not "
+                 "been added to an image"),
+               gimp_object_get_name (GIMP_OBJECT (item)),
+               gimp_item_get_ID (item));
 
-  return TRUE;
+  return FALSE;
+}
+
+gboolean
+gimp_pdb_item_is_floating (GimpItem  *item,
+                           GError   **error)
+{
+  g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  if (g_object_is_floating (item))
+    return TRUE;
+
+  g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
+               _("Item '%s' (%d) has already been added to an image"),
+               gimp_object_get_name (GIMP_OBJECT (item)),
+               gimp_item_get_ID (item));
+
+  return FALSE;
 }
 
 gboolean

Modified: trunk/app/pdb/gimppdb-utils.h
==============================================================================
--- trunk/app/pdb/gimppdb-utils.h	(original)
+++ trunk/app/pdb/gimppdb-utils.h	Fri Apr  4 08:21:27 2008
@@ -51,6 +51,8 @@
 
 gboolean        gimp_pdb_item_is_attached       (GimpItem           *item,
                                                  GError            **error);
+gboolean        gimp_pdb_item_is_floating       (GimpItem           *item,
+                                                 GError            **error);
 gboolean        gimp_pdb_layer_is_text_layer    (GimpLayer          *layer,
                                                  GError            **error);
 gboolean        gimp_pdb_image_is_base_type     (GimpImage          *image,

Modified: trunk/app/pdb/image_cmds.c
==============================================================================
--- trunk/app/pdb/image_cmds.c	(original)
+++ trunk/app/pdb/image_cmds.c	Fri Apr  4 08:21:27 2008
@@ -842,25 +842,16 @@
 
   if (success)
     {
-      success = gimp_pdb_image_is_base_type (image,
-                                             GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (GIMP_DRAWABLE (layer))),
-                                             error);
-
-      if (success)
+      if (gimp_pdb_item_is_floating (GIMP_ITEM (layer), error) &&
+          gimp_pdb_image_is_base_type (image,
+                                       GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (GIMP_DRAWABLE (layer))),
+                                       error))
         {
-          if (g_object_is_floating (layer))
-            {
-              success = gimp_image_add_layer (image, layer, MAX (position, -1));
-            }
-          else
-            {
-              g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
-                           _("Layer '%s' (%d) has already been added to an image"),
-                           gimp_object_get_name (GIMP_OBJECT (layer)),
-                           gimp_item_get_ID (GIMP_ITEM (layer)));
-
-              success = FALSE;
-            }
+          success = gimp_image_add_layer (image, layer, MAX (position, -1));
+        }
+      else
+        {
+          success = FALSE;
         }
     }
 
@@ -1034,10 +1025,14 @@
 
   if (success)
     {
-      if (g_object_is_floating (channel))
-        success = gimp_image_add_channel (image, channel, MAX (position, -1));
+      if (gimp_pdb_item_is_floating (GIMP_ITEM (channel), error))
+        {
+          success = gimp_image_add_channel (image, channel, MAX (position, -1));
+        }
       else
-        success = FALSE;
+        {
+          success = FALSE;
+        }
     }
 
   return gimp_procedure_get_return_values (procedure, success);
@@ -1164,10 +1159,14 @@
 
   if (success)
     {
-      if (g_object_is_floating (vectors))
-        success = gimp_image_add_vectors (image, vectors, MAX (position, -1));
+      if (gimp_pdb_item_is_floating (GIMP_ITEM (vectors), error))
+        {
+          success = gimp_image_add_vectors (image, vectors, MAX (position, -1));
+        }
       else
-        success = FALSE;
+        {
+          success = FALSE;
+        }
     }
 
   return gimp_procedure_get_return_values (procedure, success);

Modified: trunk/tools/pdbgen/pdb/image.pdb
==============================================================================
--- trunk/tools/pdbgen/pdb/image.pdb	(original)
+++ trunk/tools/pdbgen/pdb/image.pdb	Fri Apr  4 08:21:27 2008
@@ -963,25 +963,16 @@
 
     $invoke{code} = <<'CODE';
 {
-  success = gimp_pdb_image_is_base_type (image,
-                                         GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (GIMP_DRAWABLE (layer))),
-                                         error);
-
-  if (success)
+  if (gimp_pdb_item_is_floating (GIMP_ITEM (layer), error) &&
+      gimp_pdb_image_is_base_type (image,
+				   GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (GIMP_DRAWABLE (layer))),
+				   error))
     {
-      if (g_object_is_floating (layer))
-        {
-          success = gimp_image_add_layer (image, layer, MAX (position, -1));
-        }
-      else
-        {
-	  g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
-                       _("Layer '%s' (%d) has already been added to an image"),
-		       gimp_object_get_name (GIMP_OBJECT (layer)),
-		       gimp_item_get_ID (GIMP_ITEM (layer)));
-
-	  success = FALSE;
-	}
+      success = gimp_image_add_layer (image, layer, MAX (position, -1));
+    }
+  else
+    {
+      success = FALSE;
     }
 }
 CODE
@@ -1170,10 +1161,14 @@
     %invoke = (
 	code => <<'CODE'
 {
-  if (g_object_is_floating (channel))
-    success = gimp_image_add_channel (image, channel, MAX (position, -1));
+  if (gimp_pdb_item_is_floating (GIMP_ITEM (channel), error))
+    {
+      success = gimp_image_add_channel (image, channel, MAX (position, -1));
+    }
   else
-    success = FALSE;
+    {
+      success = FALSE;
+    }
 }
 CODE
     );
@@ -1227,10 +1222,14 @@
 
     $invoke{code} = <<'CODE';
 {
-  if (g_object_is_floating (vectors))
-    success = gimp_image_add_vectors (image, vectors, MAX (position, -1));
+  if (gimp_pdb_item_is_floating (GIMP_ITEM (vectors), error))
+    {
+      success = gimp_image_add_vectors (image, vectors, MAX (position, -1));
+    }
   else
-    success = FALSE;
+    {
+      success = FALSE;
+    }
 }
 CODE
 }



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