From 58c2dd9bbab6d829360cd9c4b07a767f965c790f Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Fri, 7 Dec 2007 18:16:28 +0000 Subject: [PATCH] added GErrors to gimp_selection_extract() and gimp_selection_float(). 2007-12-07 Michael Natterer * app/core/gimpselection.[ch]: added GErrors to gimp_selection_extract() and gimp_selection_float(). * app/core/gimp-edit.c * app/tools/gimpeditselectiontool.c * app/actions/select-commands.c: handle the returned error. * app/core/gimpdrawable-transform.c: pass NULL errors since this file knows what it does and won't get errors. * tools/pdbgen/pdb/selection.pdb: pass the error. * app/pdb/selection_cmds.c: regenerated. svn path=/trunk/; revision=24286 --- ChangeLog | 16 +++++++++++++ app/actions/select-commands.c | 7 +++--- app/core/gimp-edit.c | 10 +++++++- app/core/gimpdrawable-transform.c | 6 ++--- app/core/gimpselection.c | 33 +++++++++++++++++---------- app/core/gimpselection.h | 38 ++++++++++++++++--------------- app/pdb/selection_cmds.c | 3 ++- app/tools/gimpeditselectiontool.c | 10 ++++++-- tools/pdbgen/pdb/selection.pdb | 3 ++- 9 files changed, 85 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index 70c8f5b932..e45b06633b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2007-12-07 Michael Natterer + + * app/core/gimpselection.[ch]: added GErrors to + gimp_selection_extract() and gimp_selection_float(). + + * app/core/gimp-edit.c + * app/tools/gimpeditselectiontool.c + * app/actions/select-commands.c: handle the returned error. + + * app/core/gimpdrawable-transform.c: pass NULL errors since this + file knows what it does and won't get errors. + + * tools/pdbgen/pdb/selection.pdb: pass the error. + + * app/pdb/selection_cmds.c: regenerated. + 2007-12-07 Sven Neumann * plug-ins/pygimp/gimpui.py (ColorSelector.__init__): accept a diff --git a/app/actions/select-commands.c b/app/actions/select-commands.c index a4d0b85eca..f573bd78fa 100644 --- a/app/actions/select-commands.c +++ b/app/actions/select-commands.c @@ -119,21 +119,22 @@ select_float_cmd_callback (GtkAction *action, { GimpImage *image; GtkWidget *widget; + GError *error = NULL; return_if_no_image (image, data); return_if_no_widget (widget, data); if (gimp_selection_float (gimp_image_get_mask (image), gimp_image_get_active_drawable (image), action_data_get_context (data), - TRUE, 0, 0)) + TRUE, 0, 0, &error)) { gimp_image_flush (image); } else { gimp_message (image->gimp, G_OBJECT (widget), GIMP_MESSAGE_WARNING, - _("Cannot float selection because the selected region " - "is empty.")); + "%s", error->message); + g_clear_error (&error); } } diff --git a/app/core/gimp-edit.c b/app/core/gimp-edit.c index c5b1b3cb37..14feb9e0a7 100644 --- a/app/core/gimp-edit.c +++ b/app/core/gimp-edit.c @@ -535,13 +535,21 @@ gimp_edit_extract (GimpImage *image, gboolean cut_pixels) { 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); + context, cut_pixels, FALSE, FALSE, &error); + + if (! tiles) + { + gimp_message (image->gimp, NULL, GIMP_MESSAGE_WARNING, + "%s", error->message); + g_clear_error (&error); + } if (cut_pixels) gimp_image_undo_group_end (image); diff --git a/app/core/gimpdrawable-transform.c b/app/core/gimpdrawable-transform.c index 73e00c2e4a..bb4a2f03c4 100644 --- a/app/core/gimpdrawable-transform.c +++ b/app/core/gimpdrawable-transform.c @@ -789,7 +789,7 @@ gimp_drawable_transform_cut (GimpDrawable *drawable, { tiles = gimp_selection_extract (gimp_image_get_mask (image), GIMP_PICKABLE (drawable), - context, TRUE, FALSE, TRUE); + context, TRUE, FALSE, TRUE, NULL); *new_layer = TRUE; } @@ -804,11 +804,11 @@ gimp_drawable_transform_cut (GimpDrawable *drawable, if (GIMP_IS_LAYER (drawable)) tiles = gimp_selection_extract (gimp_image_get_mask (image), GIMP_PICKABLE (drawable), - context, FALSE, TRUE, TRUE); + context, FALSE, TRUE, TRUE, NULL); else tiles = gimp_selection_extract (gimp_image_get_mask (image), GIMP_PICKABLE (drawable), - context, FALSE, TRUE, FALSE); + context, FALSE, TRUE, FALSE, NULL); *new_layer = FALSE; } diff --git a/app/core/gimpselection.c b/app/core/gimpselection.c index 319fa9748d..aa51ca205e 100644 --- a/app/core/gimpselection.c +++ b/app/core/gimpselection.c @@ -607,7 +607,8 @@ gimp_selection_extract (GimpChannel *selection, GimpContext *context, gboolean cut_image, gboolean keep_indexed, - gboolean add_alpha) + gboolean add_alpha, + GError **error) { GimpImage *image; TileManager *tiles; @@ -625,6 +626,7 @@ gimp_selection_extract (GimpChannel *selection, if (GIMP_IS_ITEM (pickable)) g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (pickable)), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); image = gimp_pickable_get_image (pickable); @@ -643,9 +645,9 @@ gimp_selection_extract (GimpChannel *selection, if (non_empty && ((x1 == x2) || (y1 == y2))) { - gimp_message (image->gimp, NULL, GIMP_MESSAGE_WARNING, - _("Unable to cut or copy because the " - "selected region is empty.")); + g_set_error (error, 0, 0, + _("Unable to cut or copy because the " + "selected region is empty.")); return NULL; } @@ -797,12 +799,13 @@ gimp_selection_extract (GimpChannel *selection, } GimpLayer * -gimp_selection_float (GimpChannel *selection, - GimpDrawable *drawable, - GimpContext *context, - gboolean cut_image, - gint off_x, - gint off_y) +gimp_selection_float (GimpChannel *selection, + GimpDrawable *drawable, + GimpContext *context, + gboolean cut_image, + gint off_x, + gint off_y, + GError **error) { GimpImage *image; GimpLayer *layer; @@ -814,13 +817,19 @@ gimp_selection_float (GimpChannel *selection, 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); image = gimp_item_get_image (GIMP_ITEM (selection)); /* Make sure there is a region to float... */ if (! gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2) || (x1 == x2 || y1 == y2)) - return NULL; + { + g_set_error (error, 0, 0, + _("Cannot float selection because the selected region " + "is empty.")); + return NULL; + } /* Start an undo group */ gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_FS_FLOAT, @@ -828,7 +837,7 @@ gimp_selection_float (GimpChannel *selection, /* Cut or copy the selected region */ tiles = gimp_selection_extract (selection, GIMP_PICKABLE (drawable), context, - cut_image, FALSE, TRUE); + cut_image, FALSE, TRUE, NULL); /* Clear the selection as if we had cut the pixels */ if (! cut_image) diff --git a/app/core/gimpselection.h b/app/core/gimpselection.h index 64d053c290..8cadb39c11 100644 --- a/app/core/gimpselection.h +++ b/app/core/gimpselection.h @@ -48,27 +48,29 @@ struct _GimpSelectionClass GType gimp_selection_get_type (void) G_GNUC_CONST; -GimpChannel * gimp_selection_new (GimpImage *image, - gint width, - gint height); +GimpChannel * gimp_selection_new (GimpImage *image, + gint width, + gint height); -void gimp_selection_load (GimpChannel *selection, - GimpChannel *channel); -GimpChannel * gimp_selection_save (GimpChannel *selection); +void gimp_selection_load (GimpChannel *selection, + GimpChannel *channel); +GimpChannel * gimp_selection_save (GimpChannel *selection); -TileManager * gimp_selection_extract (GimpChannel *selection, - GimpPickable *pickable, - GimpContext *context, - gboolean cut_image, - gboolean keep_indexed, - gboolean add_alpha); +TileManager * gimp_selection_extract (GimpChannel *selection, + GimpPickable *pickable, + GimpContext *context, + gboolean cut_image, + gboolean keep_indexed, + gboolean add_alpha, + GError **error); -GimpLayer * gimp_selection_float (GimpChannel *selection, - GimpDrawable *drawable, - GimpContext *context, - gboolean cut_image, - gint off_x, - gint off_y); +GimpLayer * gimp_selection_float (GimpChannel *selection, + GimpDrawable *drawable, + GimpContext *context, + gboolean cut_image, + gint off_x, + gint off_y, + GError **error); #endif /* __GIMP_SELECTION_H__ */ diff --git a/app/pdb/selection_cmds.c b/app/pdb/selection_cmds.c index 14c98aaa26..268ce59906 100644 --- a/app/pdb/selection_cmds.c +++ b/app/pdb/selection_cmds.c @@ -191,7 +191,8 @@ selection_float_invoker (GimpProcedure *procedure, GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable)); layer = gimp_selection_float (gimp_image_get_mask (image), - drawable, context, TRUE, offx, offy); + drawable, context, TRUE, offx, offy, + error); if (! layer) success = FALSE; } diff --git a/app/tools/gimpeditselectiontool.c b/app/tools/gimpeditselectiontool.c index 6a2de19d45..3e4d46767b 100644 --- a/app/tools/gimpeditselectiontool.c +++ b/app/tools/gimpeditselectiontool.c @@ -562,7 +562,9 @@ gimp_edit_selection_tool_motion (GimpTool *tool, /* if there has been movement, move the selection */ if (edit_select->origx != x || edit_select->origy != y) { - gint xoffset, yoffset; + gint xoffset; + gint yoffset; + GError *error = NULL; xoffset = x - edit_select->origx; yoffset = y - edit_select->origy; @@ -623,9 +625,13 @@ gimp_edit_selection_tool_motion (GimpTool *tool, gimp_get_user_context (display->image->gimp), edit_select->edit_mode == GIMP_TRANSLATE_MODE_MASK_TO_LAYER, - 0, 0)) + 0, 0, &error)) { /* no region to float, abort safely */ + gimp_message (display->image->gimp, G_OBJECT (display), + GIMP_MESSAGE_WARNING, + "%s", error->message); + g_clear_error (&error); gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); return; diff --git a/tools/pdbgen/pdb/selection.pdb b/tools/pdbgen/pdb/selection.pdb index cb4206756a..f81644fa1e 100644 --- a/tools/pdbgen/pdb/selection.pdb +++ b/tools/pdbgen/pdb/selection.pdb @@ -189,7 +189,8 @@ HELP GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable)); layer = gimp_selection_float (gimp_image_get_mask (image), - drawable, context, TRUE, offx, offy); + drawable, context, TRUE, offx, offy, + error); if (! layer) success = FALSE; }