From 62e6240b04f70773a95ecdfcc2328783f9fef73b Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Fri, 4 Apr 2008 07:21:27 +0000 Subject: [PATCH] added test for floating items. 2008-04-04 Sven Neumann * 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. svn path=/trunk/; revision=25356 --- ChangeLog | 8 +++++++ app/pdb/gimppdb-utils.c | 36 +++++++++++++++++++++-------- app/pdb/gimppdb-utils.h | 2 ++ app/pdb/image_cmds.c | 47 +++++++++++++++++++------------------- tools/pdbgen/pdb/image.pdb | 47 +++++++++++++++++++------------------- 5 files changed, 82 insertions(+), 58 deletions(-) diff --git a/ChangeLog b/ChangeLog index 69ae319196..81d0f2aaf4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-04-04 Sven Neumann + + * 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. + 2008-04-04 Sven Neumann * tools/pdbgen/pdb/image.pdb: improved error handling. diff --git a/app/pdb/gimppdb-utils.c b/app/pdb/gimppdb-utils.c index e0946d2498..a9a7e5ed71 100644 --- a/app/pdb/gimppdb-utils.c +++ b/app/pdb/gimppdb-utils.c @@ -299,18 +299,34 @@ gimp_pdb_item_is_attached (GimpItem *item, 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 diff --git a/app/pdb/gimppdb-utils.h b/app/pdb/gimppdb-utils.h index 31c9471eba..180a0dd349 100644 --- a/app/pdb/gimppdb-utils.h +++ b/app/pdb/gimppdb-utils.h @@ -51,6 +51,8 @@ GimpPaintInfo * gimp_pdb_get_paint_info (Gimp *gimp, 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, diff --git a/app/pdb/image_cmds.c b/app/pdb/image_cmds.c index 5d3eefa7f7..7d901b24eb 100644 --- a/app/pdb/image_cmds.c +++ b/app/pdb/image_cmds.c @@ -842,25 +842,16 @@ image_add_layer_invoker (GimpProcedure *procedure, 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 @@ image_add_channel_invoker (GimpProcedure *procedure, 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 @@ image_add_vectors_invoker (GimpProcedure *procedure, 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); diff --git a/tools/pdbgen/pdb/image.pdb b/tools/pdbgen/pdb/image.pdb index c14f210c9d..88d297c982 100644 --- a/tools/pdbgen/pdb/image.pdb +++ b/tools/pdbgen/pdb/image.pdb @@ -963,25 +963,16 @@ HELP $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 @@ HELP %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 @@ HELP $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 }