[gimp] pdb: add proper error messages for gimp_image_reorder_item()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] pdb: add proper error messages for gimp_image_reorder_item()
- Date: Tue, 31 Aug 2010 15:07:59 +0000 (UTC)
commit ab852d74095acd4e2ae7f53f204762b59e28531c
Author: Michael Natterer <mitch gimp org>
Date: Tue Aug 31 17:07:27 2010 +0200
pdb: add proper error messages for gimp_image_reorder_item()
app/pdb/gimppdb-utils.c | 83 +++++++++++++++++++++++++++++++++++++++++--
app/pdb/gimppdb-utils.h | 9 +++++
app/pdb/image-cmds.c | 11 ++----
tools/pdbgen/pdb/image.pdb | 11 ++----
4 files changed, 94 insertions(+), 20 deletions(-)
---
diff --git a/app/pdb/gimppdb-utils.c b/app/pdb/gimppdb-utils.c
index 76b298d..cb45070 100644
--- a/app/pdb/gimppdb-utils.c
+++ b/app/pdb/gimppdb-utils.c
@@ -315,7 +315,7 @@ gimp_pdb_item_is_attached (GimpItem *item,
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 "
+ _("Item '%s' (%d) cannot be used because it has not "
"been added to an image"),
gimp_object_get_name (item),
gimp_item_get_ID (item));
@@ -325,7 +325,7 @@ gimp_pdb_item_is_attached (GimpItem *item,
if (image && image != gimp_item_get_image (item))
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
- _("Item '%s' (%d) can not be used because it is "
+ _("Item '%s' (%d) cannot be used because it is "
"attached to another image"),
gimp_object_get_name (item),
gimp_item_get_ID (item));
@@ -354,7 +354,7 @@ gimp_pdb_item_is_in_tree (GimpItem *item,
if (! gimp_item_get_tree (item))
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
- _("Item '%s' (%d) can not be used because it is not "
+ _("Item '%s' (%d) cannot be used because it is not "
"a direct child of an item tree"),
gimp_object_get_name (item),
gimp_item_get_ID (item));
@@ -365,6 +365,61 @@ gimp_pdb_item_is_in_tree (GimpItem *item,
}
gboolean
+gimp_pdb_item_is_in_same_tree (GimpItem *item,
+ GimpItem *item2,
+ GimpImage *image,
+ GError **error)
+{
+ g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
+ g_return_val_if_fail (GIMP_IS_ITEM (item2), FALSE);
+ g_return_val_if_fail (image == NULL || GIMP_IS_IMAGE (image), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ if (! gimp_pdb_item_is_in_tree (item, image, FALSE, error) ||
+ ! gimp_pdb_item_is_in_tree (item2, image, FALSE, error))
+ return FALSE;
+
+ if (gimp_item_get_tree (item) != gimp_item_get_tree (item2))
+ {
+ g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
+ _("Items '%s' (%d) and '%s' (%d) cannot be used "
+ "because they are not part of the same item tree"),
+ gimp_object_get_name (item),
+ gimp_item_get_ID (item),
+ gimp_object_get_name (item2),
+ gimp_item_get_ID (item2));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+gboolean
+gimp_pdb_item_is_not_ancestor (GimpItem *item,
+ GimpItem *not_descendant,
+ GError **error)
+{
+ g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
+ g_return_val_if_fail (GIMP_IS_ITEM (not_descendant), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ if (gimp_viewable_is_ancestor (GIMP_VIEWABLE (item),
+ GIMP_VIEWABLE (not_descendant)))
+ {
+ g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
+ _("Item '%s' (%d) must not be an ancestor of "
+ "'%s' (%d)"),
+ gimp_object_get_name (item),
+ gimp_item_get_ID (item),
+ gimp_object_get_name (not_descendant),
+ gimp_item_get_ID (not_descendant));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+gboolean
gimp_pdb_item_is_floating (GimpItem *item,
GimpImage *dest_image,
GError **error)
@@ -414,6 +469,26 @@ gimp_pdb_item_is_writable (GimpItem *item,
}
gboolean
+gimp_pdb_item_is_group (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 (! gimp_viewable_get_children (GIMP_VIEWABLE (item)))
+ {
+ g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
+ _("Item '%s' (%d) cannot be used because it is "
+ "not a group item"),
+ gimp_object_get_name (item),
+ gimp_item_get_ID (item));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+gboolean
gimp_pdb_item_is_not_group (GimpItem *item,
GError **error)
{
@@ -444,7 +519,7 @@ gimp_pdb_layer_is_text_layer (GimpLayer *layer,
if (! gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)))
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
- _("Layer '%s' (%d) can not be used because it is not "
+ _("Layer '%s' (%d) cannot be used because it is not "
"a text layer"),
gimp_object_get_name (layer),
gimp_item_get_ID (GIMP_ITEM (layer)));
diff --git a/app/pdb/gimppdb-utils.h b/app/pdb/gimppdb-utils.h
index f5a8a59..d25a23a 100644
--- a/app/pdb/gimppdb-utils.h
+++ b/app/pdb/gimppdb-utils.h
@@ -56,11 +56,20 @@ gboolean gimp_pdb_item_is_in_tree (GimpItem *item,
GimpImage *image,
gboolean writable,
GError **error);
+gboolean gimp_pdb_item_is_in_same_tree (GimpItem *item,
+ GimpItem *item2,
+ GimpImage *image,
+ GError **error);
+gboolean gimp_pdb_item_is_not_ancestor (GimpItem *item,
+ GimpItem *not_descendant,
+ GError **error);
gboolean gimp_pdb_item_is_floating (GimpItem *item,
GimpImage *dest_image,
GError **error);
gboolean gimp_pdb_item_is_writable (GimpItem *item,
GError **error);
+gboolean gimp_pdb_item_is_group (GimpItem *item,
+ GError **error);
gboolean gimp_pdb_item_is_not_group (GimpItem *item,
GError **error);
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index 145b73d..df4c6cb 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -1246,14 +1246,9 @@ image_reorder_item_invoker (GimpProcedure *procedure,
{
if (gimp_pdb_item_is_in_tree (item, image, FALSE, error) &&
(parent == NULL ||
- gimp_pdb_item_is_in_tree (parent, image, FALSE, error)) &&
- (parent == NULL ||
- gimp_item_get_tree (item) == gimp_item_get_tree (parent)) &&
- (parent == NULL ||
- gimp_viewable_get_children (GIMP_VIEWABLE (parent))) &&
- (parent == NULL ||
- ! gimp_viewable_is_ancestor (GIMP_VIEWABLE (item),
- GIMP_VIEWABLE (parent))))
+ (gimp_pdb_item_is_in_same_tree (item, parent, image, error) &&
+ gimp_pdb_item_is_group (parent, error) &&
+ gimp_pdb_item_is_not_ancestor (item, parent, error))))
{
success = gimp_image_reorder_item (image, item, parent, position,
TRUE, NULL);
diff --git a/tools/pdbgen/pdb/image.pdb b/tools/pdbgen/pdb/image.pdb
index 8dbb515..730e0f7 100644
--- a/tools/pdbgen/pdb/image.pdb
+++ b/tools/pdbgen/pdb/image.pdb
@@ -903,14 +903,9 @@ HELP
{
if (gimp_pdb_item_is_in_tree (item, image, FALSE, error) &&
(parent == NULL ||
- gimp_pdb_item_is_in_tree (parent, image, FALSE, error)) &&
- (parent == NULL ||
- gimp_item_get_tree (item) == gimp_item_get_tree (parent)) &&
- (parent == NULL ||
- gimp_viewable_get_children (GIMP_VIEWABLE (parent))) &&
- (parent == NULL ||
- ! gimp_viewable_is_ancestor (GIMP_VIEWABLE (item),
- GIMP_VIEWABLE (parent))))
+ (gimp_pdb_item_is_in_same_tree (item, parent, image, error) &&
+ gimp_pdb_item_is_group (parent, error) &&
+ gimp_pdb_item_is_not_ancestor (item, parent, error))))
{
success = gimp_image_reorder_item (image, item, parent, position,
TRUE, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]