Commit 58c2dd9b authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

added GErrors to gimp_selection_extract() and gimp_selection_float().

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

	* 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
parent 021abe4a
2007-12-07 Michael Natterer <mitch@gimp.org>
* 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 <sven@gimp.org>
* plug-ins/pygimp/gimpui.py (ColorSelector.__init__): accept a
......
......@@ -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);
}
}
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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)
......
......@@ -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);
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);
GimpLayer * gimp_selection_float (GimpChannel *selection,
GimpDrawable *drawable,
GimpContext *context,
gboolean cut_image,
gint off_x,
gint off_y);
GimpChannel * gimp_selection_new (GimpImage *image,
gint width,
gint height);
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,
GError **error);
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__ */
......@@ -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;
}
......
......@@ -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;
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment