[gimp] libgimp: add gimp_image_reorder_item() for arbitrary reordering in a tree
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimp: add gimp_image_reorder_item() for arbitrary reordering in a tree
- Date: Tue, 31 Aug 2010 14:30:24 +0000 (UTC)
commit b24de26791b9f27914b3002aa5caf3842d423317
Author: Michael Natterer <mitch gimp org>
Date: Mon Aug 30 20:36:11 2010 +0200
libgimp: add gimp_image_reorder_item() for arbitrary reordering in a tree
app/pdb/image-cmds.c | 84 ++++++++++++++++++++++++++++++++++++++++++++
app/pdb/internal-procs.c | 2 +-
libgimp/gimpimage_pdb.c | 40 +++++++++++++++++++++
libgimp/gimpimage_pdb.h | 4 ++
tools/pdbgen/pdb/image.pdb | 47 ++++++++++++++++++++++++-
5 files changed, 175 insertions(+), 2 deletions(-)
---
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index e5a6918..145b73d 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -1224,6 +1224,49 @@ image_lower_item_to_bottom_invoker (GimpProcedure *procedure,
}
static GValueArray *
+image_reorder_item_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GimpImage *image;
+ GimpItem *item;
+ GimpItem *parent;
+ gint32 position;
+
+ image = gimp_value_get_image (&args->values[0], gimp);
+ item = gimp_value_get_item (&args->values[1], gimp);
+ parent = gimp_value_get_item (&args->values[2], gimp);
+ position = g_value_get_int (&args->values[3]);
+
+ if (success)
+ {
+ 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))))
+ {
+ success = gimp_image_reorder_item (image, item, parent, position,
+ TRUE, NULL);
+ }
+ else
+ success = FALSE;
+ }
+
+ return gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+}
+
+static GValueArray *
image_get_layer_position_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
@@ -3880,6 +3923,47 @@ register_image_procs (GimpPDB *pdb)
g_object_unref (procedure);
/*
+ * gimp-image-reorder-item
+ */
+ procedure = gimp_procedure_new (image_reorder_item_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-image-reorder-item");
+ gimp_procedure_set_static_strings (procedure,
+ "gimp-image-reorder-item",
+ "Reorder the specified item within its item tree",
+ "This procedure reorders the specified item within its item tree.",
+ "Michael Natterer <mitch gimp org>",
+ "Michael Natterer",
+ "2010",
+ NULL);
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_image_id ("image",
+ "image",
+ "The image",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_item_id ("item",
+ "item",
+ "The item to reorder",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_item_id ("parent",
+ "parent",
+ "The new parent item",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_int32 ("position",
+ "position",
+ "The new position of the item",
+ G_MININT32, G_MAXINT32, 0,
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
+ /*
* gimp-image-get-layer-position
*/
procedure = gimp_procedure_new (image_get_layer_position_invoker);
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index eaae2fc..593cfac 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
#include "internal-procs.h"
-/* 629 procedures registered total */
+/* 630 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c
index 55469ae..6f13e69 100644
--- a/libgimp/gimpimage_pdb.c
+++ b/libgimp/gimpimage_pdb.c
@@ -1365,6 +1365,46 @@ gimp_image_lower_item_to_bottom (gint32 image_ID,
}
/**
+ * gimp_image_reorder_item:
+ * @image_ID: The image.
+ * @item_ID: The item to reorder.
+ * @parent_ID: The new parent item.
+ * @position: The new position of the item.
+ *
+ * Reorder the specified item within its item tree
+ *
+ * This procedure reorders the specified item within its item tree.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: GIMP 2.8
+ */
+gboolean
+gimp_image_reorder_item (gint32 image_ID,
+ gint32 item_ID,
+ gint32 parent_ID,
+ gint position)
+{
+ GimpParam *return_vals;
+ gint nreturn_vals;
+ gboolean success = TRUE;
+
+ return_vals = gimp_run_procedure ("gimp-image-reorder-item",
+ &nreturn_vals,
+ GIMP_PDB_IMAGE, image_ID,
+ GIMP_PDB_ITEM, item_ID,
+ GIMP_PDB_ITEM, parent_ID,
+ GIMP_PDB_INT32, position,
+ GIMP_PDB_END);
+
+ success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
+
+ gimp_destroy_params (return_vals, nreturn_vals);
+
+ return success;
+}
+
+/**
* gimp_image_get_layer_position:
* @image_ID: The image.
* @layer_ID: The layer.
diff --git a/libgimp/gimpimage_pdb.h b/libgimp/gimpimage_pdb.h
index 611d9b4..e903f19 100644
--- a/libgimp/gimpimage_pdb.h
+++ b/libgimp/gimpimage_pdb.h
@@ -109,6 +109,10 @@ gboolean gimp_image_raise_item_to_top (gint32
gint32 item_ID);
gboolean gimp_image_lower_item_to_bottom (gint32 image_ID,
gint32 item_ID);
+gboolean gimp_image_reorder_item (gint32 image_ID,
+ gint32 item_ID,
+ gint32 parent_ID,
+ gint position);
#ifndef GIMP_DISABLE_DEPRECATED
gint gimp_image_get_layer_position (gint32 image_ID,
gint32 layer_ID);
diff --git a/tools/pdbgen/pdb/image.pdb b/tools/pdbgen/pdb/image.pdb
index 94d4262..8dbb515 100644
--- a/tools/pdbgen/pdb/image.pdb
+++ b/tools/pdbgen/pdb/image.pdb
@@ -878,6 +878,50 @@ CODE
);
}
+sub image_reorder_item {
+ $blurb = "Reorder the specified item within its item tree";
+
+ $help = <<'HELP';
+This procedure reorders the specified item within its item tree.
+HELP
+
+ &mitch_pdb_misc('2010', '2.8');
+
+ @inargs = (
+ { name => 'image', type => 'image',
+ desc => 'The image' },
+ { name => 'item', type => 'item',
+ desc => 'The item to reorder' },
+ { name => 'parent', type => 'item',
+ desc => 'The new parent item' },
+ { name => 'position', type => 'int32',
+ desc => 'The new position of the item' }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ 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))))
+ {
+ success = gimp_image_reorder_item (image, item, parent, position,
+ TRUE, NULL);
+ }
+ else
+ success = FALSE;
+}
+CODE
+ );
+}
+
sub image_get_layer_position {
&std_pdb_deprecated('gimp-image-get-item-position');
&simon_pdb_misc('2006', '2.4');
@@ -2783,6 +2827,7 @@ CODE
image_get_item_position
image_raise_item image_lower_item
image_raise_item_to_top image_lower_item_to_bottom
+ image_reorder_item
image_get_layer_position
image_raise_layer image_lower_layer
image_raise_layer_to_top image_lower_layer_to_bottom
@@ -2812,7 +2857,7 @@ CODE
image_get_channel_by_tattoo
image_get_vectors_by_tattoo);
-%exports = (app => [ procs], lib => [ procs[0 51,54..82]]);
+%exports = (app => [ procs], lib => [ procs[0 52,55..83]]);
$desc = 'Image';
$doc_title = 'gimpimage';
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]