[gimp] Add GError reporting to gimp_image_merge_down()
- From: Michael Natterer <mitch src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gimp] Add GError reporting to gimp_image_merge_down()
- Date: Tue, 25 Aug 2009 20:03:24 +0000 (UTC)
commit d37dc64b1628ea5ad4794b80c2a69240442c70c6
Author: Michael Natterer <mitch gimp org>
Date: Tue Aug 25 22:02:02 2009 +0200
Add GError reporting to gimp_image_merge_down()
- turn g_return_if_fail() of more complex conditions into errors.
- change PDB wrapper accordingly instead of adding a ton of conditions
there.
app/actions/layers-commands.c | 2 +-
app/core/gimpimage-merge.c | 34 ++++++++++++++++++++++++++--------
app/core/gimpimage-merge.h | 3 ++-
app/pdb/image-cmds.c | 10 ++++++++--
tools/pdbgen/pdb/image.pdb | 10 ++++++++--
5 files changed, 45 insertions(+), 14 deletions(-)
---
diff --git a/app/actions/layers-commands.c b/app/actions/layers-commands.c
index 2499aac..5236eee 100644
--- a/app/actions/layers-commands.c
+++ b/app/actions/layers-commands.c
@@ -501,7 +501,7 @@ layers_merge_down_cmd_callback (GtkAction *action,
return_if_no_layer (image, layer, data);
gimp_image_merge_down (image, layer, action_data_get_context (data),
- GIMP_EXPAND_AS_NECESSARY);
+ GIMP_EXPAND_AS_NECESSARY, NULL);
gimp_image_flush (image);
}
diff --git a/app/core/gimpimage-merge.c b/app/core/gimpimage-merge.c
index e293b25..2d06c22 100644
--- a/app/core/gimpimage-merge.c
+++ b/app/core/gimpimage-merge.c
@@ -174,10 +174,11 @@ gimp_image_flatten (GimpImage *image,
}
GimpLayer *
-gimp_image_merge_down (GimpImage *image,
- GimpLayer *current_layer,
- GimpContext *context,
- GimpMergeType merge_type)
+gimp_image_merge_down (GimpImage *image,
+ GimpLayer *current_layer,
+ GimpContext *context,
+ GimpMergeType merge_type,
+ GError **error)
{
GimpLayer *layer;
GList *list;
@@ -187,9 +188,15 @@ gimp_image_merge_down (GimpImage *image,
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (GIMP_IS_LAYER (current_layer), NULL);
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (current_layer)), NULL);
- g_return_val_if_fail (gimp_viewable_get_children (GIMP_VIEWABLE (current_layer)) == NULL,
- NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ if (gimp_viewable_get_children (GIMP_VIEWABLE (current_layer)))
+ {
+ g_set_error_literal (error, 0, 0,
+ _("Cannot merge down a group layer."));
+ return NULL;
+ }
for (list = gimp_item_get_container_iter (GIMP_ITEM (current_layer));
list;
@@ -209,14 +216,25 @@ gimp_image_merge_down (GimpImage *image,
if (gimp_item_get_visible (GIMP_ITEM (layer)))
{
- g_return_val_if_fail (! gimp_item_get_lock_content (GIMP_ITEM (layer)),
- NULL);
+ if (gimp_item_get_lock_content (GIMP_ITEM (layer)))
+ {
+ g_set_error_literal (error, 0, 0,
+ _("The layer to merge down to is locked."));
+ return NULL;
+ }
merge_list = g_slist_append (NULL, layer);
break;
}
}
+ if (! merge_list)
+ {
+ g_set_error_literal (error, 0, 0,
+ _("There is no visible layer to merge down to."));
+ return NULL;
+ }
+
merge_list = g_slist_prepend (merge_list, current_layer);
gimp_set_busy (image->gimp);
diff --git a/app/core/gimpimage-merge.h b/app/core/gimpimage-merge.h
index fe290b2..32a3779 100644
--- a/app/core/gimpimage-merge.h
+++ b/app/core/gimpimage-merge.h
@@ -26,7 +26,8 @@ GimpLayer * gimp_image_merge_visible_layers (GimpImage *image,
GimpLayer * gimp_image_merge_down (GimpImage *image,
GimpLayer *current_layer,
GimpContext *context,
- GimpMergeType merge_type);
+ GimpMergeType merge_type,
+ GError **error);
GimpLayer * gimp_image_flatten (GimpImage *image,
GimpContext *context);
GimpVectors * gimp_image_merge_visible_vectors (GimpImage *image,
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index e0c123c..610b6ba 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -1508,9 +1508,15 @@ image_merge_down_invoker (GimpProcedure *procedure,
if (success)
{
- layer = gimp_image_merge_down (image, merge_layer, context, merge_type);
+ if (gimp_pdb_item_is_attached (GIMP_ITEM (merge_layer), FALSE, error))
+ {
+ layer = gimp_image_merge_down (image, merge_layer, context, merge_type,
+ error);
- if (! layer)
+ if (! layer)
+ success = FALSE;
+ }
+ else
success = FALSE;
}
diff --git a/tools/pdbgen/pdb/image.pdb b/tools/pdbgen/pdb/image.pdb
index 8585db2..3e4eba8 100644
--- a/tools/pdbgen/pdb/image.pdb
+++ b/tools/pdbgen/pdb/image.pdb
@@ -941,9 +941,15 @@ HELP
headers => [ qw("core/gimpimage-merge.h") ],
code => <<'CODE'
{
- layer = gimp_image_merge_down (image, merge_layer, context, merge_type);
+ if (gimp_pdb_item_is_attached (GIMP_ITEM (merge_layer), FALSE, error))
+ {
+ layer = gimp_image_merge_down (image, merge_layer, context, merge_type,
+ error);
- if (! layer)
+ if (! layer)
+ success = FALSE;
+ }
+ else
success = FALSE;
}
CODE
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]