added GErrors when functions can fail.

2007-12-14  Michael Natterer  <mitch@gimp.org>

	* app/core/gimp-edit.[ch]: added GErrors when functions can fail.

	* app/actions/edit-commands.c: handle the returned errors.

	* tools/pdbgen/pdb/edit.pdb: same here (*don't* pass the error as
	usual since these functions never fail but have a boolean return
	value indicating success instead; ugly, but better than having the
	gimp_message() calls in the core). Also changed the named buffer
	cut and copy functions to do the same (never fail but return a
	NULL buffer name on failure), so they behave as documented.

	* app/pdb/edit_cmds.c: regenerated.


svn path=/trunk/; revision=24362
This commit is contained in:
Michael Natterer 2007-12-14 13:58:10 +00:00 committed by Michael Natterer
parent 146067d737
commit db553767cd
6 changed files with 301 additions and 132 deletions

View File

@ -1,3 +1,18 @@
2007-12-14 Michael Natterer <mitch@gimp.org>
* app/core/gimp-edit.[ch]: added GErrors when functions can fail.
* app/actions/edit-commands.c: handle the returned errors.
* tools/pdbgen/pdb/edit.pdb: same here (*don't* pass the error as
usual since these functions never fail but have a boolean return
value indicating success instead; ugly, but better than having the
gimp_message() calls in the core). Also changed the named buffer
cut and copy functions to do the same (never fail but return a
NULL buffer name on failure), so they behave as documented.
* app/pdb/edit_cmds.c: regenerated.
2007-12-14 Sven Neumann <sven@gimp.org>
* app/base/tile-pyramid.c: reduced rounding errors.

View File

@ -188,10 +188,19 @@ edit_cut_cmd_callback (GtkAction *action,
{
GimpImage *image;
GimpDrawable *drawable;
GError *error = NULL;
return_if_no_drawable (image, drawable, data);
if (gimp_edit_cut (image, drawable, action_data_get_context (data)))
if (gimp_edit_cut (image, drawable, action_data_get_context (data), &error))
{
gimp_image_flush (image);
}
else
{
gimp_message (image->gimp, G_OBJECT (action_data_get_display (data)),
GIMP_MESSAGE_WARNING, "%s", error->message);
g_clear_error (&error);
}
}
void
@ -200,9 +209,10 @@ edit_copy_cmd_callback (GtkAction *action,
{
GimpImage *image;
GimpDrawable *drawable;
GError *error = NULL;
return_if_no_drawable (image, drawable, data);
if (gimp_edit_copy (image, drawable, action_data_get_context (data)))
if (gimp_edit_copy (image, drawable, action_data_get_context (data), &error))
{
GimpDisplay *display = action_data_get_display (data);
@ -212,6 +222,12 @@ edit_copy_cmd_callback (GtkAction *action,
gimp_image_flush (image);
}
else
{
gimp_message (image->gimp, G_OBJECT (action_data_get_display (data)),
GIMP_MESSAGE_WARNING, "%s", error->message);
g_clear_error (&error);
}
}
void
@ -219,10 +235,19 @@ edit_copy_visible_cmd_callback (GtkAction *action,
gpointer data)
{
GimpImage *image;
GError *error = NULL;
return_if_no_image (image, data);
if (gimp_edit_copy_visible (image, action_data_get_context (data)))
if (gimp_edit_copy_visible (image, action_data_get_context (data), &error))
{
gimp_image_flush (image);
}
else
{
gimp_message (image->gimp, G_OBJECT (action_data_get_display (data)),
GIMP_MESSAGE_WARNING, "%s", error->message);
g_clear_error (&error);
}
}
void
@ -463,6 +488,7 @@ cut_named_buffer_callback (GtkWidget *widget,
{
GimpImage *image = GIMP_IMAGE (data);
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
GError *error = NULL;
if (! drawable)
{
@ -475,10 +501,16 @@ cut_named_buffer_callback (GtkWidget *widget,
name = _("(Unnamed Buffer)");
if (gimp_edit_named_cut (image, name, drawable,
gimp_get_user_context (image->gimp)))
gimp_get_user_context (image->gimp), &error))
{
gimp_image_flush (image);
}
else
{
gimp_message (image->gimp, NULL, GIMP_MESSAGE_WARNING,
"%s", error->message);
g_clear_error (&error);
}
}
static void
@ -488,6 +520,7 @@ copy_named_buffer_callback (GtkWidget *widget,
{
GimpImage *image = GIMP_IMAGE (data);
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
GError *error = NULL;
if (! drawable)
{
@ -500,10 +533,16 @@ copy_named_buffer_callback (GtkWidget *widget,
name = _("(Unnamed Buffer)");
if (gimp_edit_named_copy (image, name, drawable,
gimp_get_user_context (image->gimp)))
gimp_get_user_context (image->gimp), &error))
{
gimp_image_flush (image);
}
else
{
gimp_message (image->gimp, NULL, GIMP_MESSAGE_WARNING,
"%s", error->message);
g_clear_error (&error);
}
}
static void
@ -512,13 +551,21 @@ copy_named_visible_buffer_callback (GtkWidget *widget,
gpointer data)
{
GimpImage *image = GIMP_IMAGE (data);
GError *error = NULL;
if (! (name && strlen (name)))
name = _("(Unnamed Buffer)");
if (gimp_edit_named_copy_visible (image, name,
gimp_get_user_context (image->gimp)))
gimp_get_user_context (image->gimp),
&error))
{
gimp_image_flush (image);
}
else
{
gimp_message (image->gimp, NULL, GIMP_MESSAGE_WARNING,
"%s", error->message);
g_clear_error (&error);
}
}

View File

@ -56,7 +56,8 @@
static GimpBuffer * gimp_edit_extract (GimpImage *image,
GimpPickable *pickable,
GimpContext *context,
gboolean cut_pixels);
gboolean cut_pixels,
GError **error);
static GimpBuffer * gimp_edit_make_buffer (Gimp *gimp,
TileManager *tiles);
static gboolean gimp_edit_fill_internal (GimpImage *image,
@ -73,7 +74,8 @@ static gboolean gimp_edit_fill_internal (GimpImage *image,
const GimpBuffer *
gimp_edit_cut (GimpImage *image,
GimpDrawable *drawable,
GimpContext *context)
GimpContext *context,
GError **error)
{
GimpBuffer *buffer;
@ -81,9 +83,10 @@ gimp_edit_cut (GimpImage *image,
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
buffer = gimp_edit_extract (image, GIMP_PICKABLE (drawable),
context, TRUE);
context, TRUE, error);
if (buffer)
{
@ -99,7 +102,8 @@ gimp_edit_cut (GimpImage *image,
const GimpBuffer *
gimp_edit_copy (GimpImage *image,
GimpDrawable *drawable,
GimpContext *context)
GimpContext *context,
GError **error)
{
GimpBuffer *buffer;
@ -107,9 +111,10 @@ gimp_edit_copy (GimpImage *image,
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
buffer = gimp_edit_extract (image, GIMP_PICKABLE (drawable),
context, FALSE);
context, FALSE, error);
if (buffer)
{
@ -124,15 +129,17 @@ gimp_edit_copy (GimpImage *image,
const GimpBuffer *
gimp_edit_copy_visible (GimpImage *image,
GimpContext *context)
GimpContext *context,
GError **error)
{
GimpBuffer *buffer;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
buffer = gimp_edit_extract (image, GIMP_PICKABLE (image->projection),
context, FALSE);
context, FALSE, error);
if (buffer)
{
@ -334,7 +341,8 @@ const gchar *
gimp_edit_named_cut (GimpImage *image,
const gchar *name,
GimpDrawable *drawable,
GimpContext *context)
GimpContext *context,
GError **error)
{
GimpBuffer *buffer;
@ -343,9 +351,10 @@ gimp_edit_named_cut (GimpImage *image,
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
buffer = gimp_edit_extract (image, GIMP_PICKABLE (drawable),
context, TRUE);
context, TRUE, error);
if (buffer)
{
@ -363,7 +372,8 @@ const gchar *
gimp_edit_named_copy (GimpImage *image,
const gchar *name,
GimpDrawable *drawable,
GimpContext *context)
GimpContext *context,
GError **error)
{
GimpBuffer *buffer;
@ -372,9 +382,10 @@ gimp_edit_named_copy (GimpImage *image,
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
buffer = gimp_edit_extract (image, GIMP_PICKABLE (drawable),
context, FALSE);
context, FALSE, error);
if (buffer)
{
@ -391,16 +402,18 @@ gimp_edit_named_copy (GimpImage *image,
const gchar *
gimp_edit_named_copy_visible (GimpImage *image,
const gchar *name,
GimpContext *context)
GimpContext *context,
GError **error)
{
GimpBuffer *buffer;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
buffer = gimp_edit_extract (image, GIMP_PICKABLE (image->projection),
context, FALSE);
context, FALSE, error);
if (buffer)
{
@ -532,24 +545,17 @@ static GimpBuffer *
gimp_edit_extract (GimpImage *image,
GimpPickable *pickable,
GimpContext *context,
gboolean cut_pixels)
gboolean cut_pixels,
GError **error)
{
TileManager *tiles;
GError *error = NULL;
if (cut_pixels)
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_CUT, _("Cut"));
/* Cut/copy the mask portion from the image */
tiles = gimp_selection_extract (gimp_image_get_mask (image), pickable,
context, cut_pixels, FALSE, FALSE, &error);
if (! tiles)
{
gimp_message (image->gimp, NULL, GIMP_MESSAGE_WARNING,
"%s", error->message);
g_clear_error (&error);
}
context, cut_pixels, FALSE, FALSE, error);
if (cut_pixels)
gimp_image_undo_group_end (image);

View File

@ -22,12 +22,15 @@
const GimpBuffer * gimp_edit_cut (GimpImage *image,
GimpDrawable *drawable,
GimpContext *context);
GimpContext *context,
GError **error);
const GimpBuffer * gimp_edit_copy (GimpImage *image,
GimpDrawable *drawable,
GimpContext *context);
GimpContext *context,
GError **error);
const GimpBuffer * gimp_edit_copy_visible (GimpImage *image,
GimpContext *context);
GimpContext *context,
GError **error);
GimpLayer * gimp_edit_paste (GimpImage *image,
GimpDrawable *drawable,
GimpBuffer *paste,
@ -43,14 +46,17 @@ GimpImage * gimp_edit_paste_as_new (Gimp *gimp,
const gchar * gimp_edit_named_cut (GimpImage *image,
const gchar *name,
GimpDrawable *drawable,
GimpContext *context);
GimpContext *context,
GError **error);
const gchar * gimp_edit_named_copy (GimpImage *image,
const gchar *name,
GimpDrawable *drawable,
GimpContext *context);
GimpContext *context,
GError **error);
const gchar * gimp_edit_named_copy_visible (GimpImage *image,
const gchar *name,
GimpContext *context);
GimpContext *context,
GError **error);
gboolean gimp_edit_clear (GimpImage *image,
GimpDrawable *drawable,

View File

@ -66,8 +66,16 @@ edit_cut_invoker (GimpProcedure *procedure,
if (gimp_item_is_attached (GIMP_ITEM (drawable)))
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GError *my_error = NULL;
non_empty = gimp_edit_cut (image, drawable, context) != NULL;
non_empty = gimp_edit_cut (image, drawable, context, &my_error) != NULL;
if (! non_empty)
{
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
"%s", my_error->message);
g_clear_error (&my_error);
}
}
else
success = FALSE;
@ -101,8 +109,16 @@ edit_copy_invoker (GimpProcedure *procedure,
if (gimp_item_is_attached (GIMP_ITEM (drawable)))
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GError *my_error = NULL;
non_empty = gimp_edit_copy (image, drawable, context) != NULL;
non_empty = gimp_edit_copy (image, drawable, context, &my_error) != NULL;
if (! non_empty)
{
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
"%s", my_error->message);
g_clear_error (&my_error);
}
}
else
success = FALSE;
@ -133,7 +149,16 @@ edit_copy_visible_invoker (GimpProcedure *procedure,
if (success)
{
non_empty = gimp_edit_copy_visible (image, context) != NULL;
GError *my_error = NULL;
non_empty = gimp_edit_copy_visible (image, context, &my_error) != NULL;
if (! non_empty)
{
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
"%s", my_error->message);
g_clear_error (&my_error);
}
}
return_vals = gimp_procedure_get_return_values (procedure, success);
@ -238,14 +263,21 @@ edit_named_cut_invoker (GimpProcedure *procedure,
if (gimp_item_is_attached (GIMP_ITEM (drawable)))
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GError *my_error = NULL;
real_name = (gchar *) gimp_edit_named_cut (image, buffer_name,
drawable, context);
drawable, context, &my_error);
if (real_name)
{
real_name = g_strdup (real_name);
}
else
success = FALSE;
{
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
"%s", my_error->message);
g_clear_error (&my_error);
}
}
else
success = FALSE;
@ -281,14 +313,21 @@ edit_named_copy_invoker (GimpProcedure *procedure,
if (gimp_item_is_attached (GIMP_ITEM (drawable)))
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GError *my_error = NULL;
real_name = (gchar *) gimp_edit_named_copy (image, buffer_name,
drawable, context);
drawable, context, &my_error);
if (real_name)
{
real_name = g_strdup (real_name);
}
else
success = FALSE;
{
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
"%s", my_error->message);
g_clear_error (&my_error);
}
}
else
success = FALSE;
@ -321,13 +360,21 @@ edit_named_copy_visible_invoker (GimpProcedure *procedure,
if (success)
{
GError *my_error = NULL;
real_name = (gchar *) gimp_edit_named_copy_visible (image, buffer_name,
context);
context, &my_error);
if (real_name)
{
real_name = g_strdup (real_name);
}
else
success = FALSE;
{
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
"%s", my_error->message);
g_clear_error (&my_error);
}
}
return_vals = gimp_procedure_get_return_values (procedure, success);
@ -984,7 +1031,7 @@ register_edit_procs (GimpPDB *pdb)
gimp_procedure_add_return_value (procedure,
gimp_param_spec_string ("real-name",
"real name",
"The real name given to the buffer",
"The real name given to the buffer, or NULL if the selection contained only transparent pixels",
FALSE, FALSE, FALSE,
NULL,
GIMP_PARAM_READWRITE));

View File

@ -48,8 +48,16 @@ HELP
if (gimp_item_is_attached (GIMP_ITEM (drawable)))
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GError *my_error = NULL;
non_empty = gimp_edit_cut (image, drawable, context) != NULL;
non_empty = gimp_edit_cut (image, drawable, context, &my_error) != NULL;
if (! non_empty)
{
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
"%s", my_error->message);
g_clear_error (&my_error);
}
}
else
success = FALSE;
@ -89,8 +97,16 @@ HELP
if (gimp_item_is_attached (GIMP_ITEM (drawable)))
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GError *my_error = NULL;
non_empty = gimp_edit_copy (image, drawable, context) != NULL;
non_empty = gimp_edit_copy (image, drawable, context, &my_error) != NULL;
if (! non_empty)
{
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
"%s", my_error->message);
g_clear_error (&my_error);
}
}
else
success = FALSE;
@ -126,7 +142,16 @@ HELP
%invoke = (
code => <<CODE
{
non_empty = gimp_edit_copy_visible (image, context) != NULL;
GError *my_error = NULL;
non_empty = gimp_edit_copy_visible (image, context, &my_error) != NULL;
if (! non_empty)
{
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
"%s", my_error->message);
g_clear_error (&my_error);
}
}
CODE
);
@ -249,14 +274,21 @@ HELP
if (gimp_item_is_attached (GIMP_ITEM (drawable)))
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GError *my_error = NULL;
real_name = (gchar *) gimp_edit_named_cut (image, buffer_name,
drawable, context);
drawable, context, &my_error);
if (real_name)
{
real_name = g_strdup (real_name);
}
else
success = FALSE;
{
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
"%s", my_error->message);
g_clear_error (&my_error);
}
}
else
success = FALSE;
@ -294,14 +326,21 @@ HELP
if (gimp_item_is_attached (GIMP_ITEM (drawable)))
{
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
GError *my_error = NULL;
real_name = (gchar *) gimp_edit_named_copy (image, buffer_name,
drawable, context);
drawable, context, &my_error);
if (real_name)
{
real_name = g_strdup (real_name);
}
else
success = FALSE;
{
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
"%s", my_error->message);
g_clear_error (&my_error);
}
}
else
success = FALSE;
@ -331,19 +370,28 @@ HELP
@outargs = (
{ name => 'real_name', type => 'string',
desc => 'The real name given to the buffer' }
desc => 'The real name given to the buffer, or NULL if the
selection contained only transparent pixels' }
);
%invoke = (
code => <<CODE
{
GError *my_error = NULL;
real_name = (gchar *) gimp_edit_named_copy_visible (image, buffer_name,
context);
context, &my_error);
if (real_name)
{
real_name = g_strdup (real_name);
}
else
success = FALSE;
{
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_WARNING,
"%s", my_error->message);
g_clear_error (&my_error);
}
}
CODE
);