added test for floating items.

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.


svn path=/trunk/; revision=25356
This commit is contained in:
Sven Neumann 2008-04-04 07:21:27 +00:00 committed by Sven Neumann
parent 472fa72b12
commit 62e6240b04
5 changed files with 82 additions and 58 deletions

View File

@ -1,3 +1,11 @@
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.
2008-04-04 Sven Neumann <sven@gimp.org>
* tools/pdbgen/pdb/image.pdb: improved error handling.

View File

@ -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

View File

@ -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,

View File

@ -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);

View File

@ -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
}