From 18d88c207c78a7deab0a66b6b782df6592f0caae Mon Sep 17 00:00:00 2001 From: Jehan Date: Mon, 20 Jan 2025 22:33:48 +0100 Subject: [PATCH] app, libgimp, pdb, plug-ins: PDB (gimp-group-layer-new) made public. --- app/pdb/group-layer-cmds.c | 25 ++++++++++++-- libgimp/gimpgrouplayer.c | 34 ------------------- libgimp/gimpgrouplayer.h | 3 -- libgimp/gimpgrouplayer_pdb.c | 21 ++++++++---- libgimp/gimpgrouplayer_pdb.h | 5 +-- pdb/groups/group_layer.pdb | 28 +++++++++++---- .../tests/PDB/item/item-layer-group-2.scm | 4 +-- .../test/tests/PDB/item/item-layer-group.scm | 2 +- 8 files changed, 64 insertions(+), 58 deletions(-) diff --git a/app/pdb/group-layer-cmds.c b/app/pdb/group-layer-cmds.c index 0d7c2a3df7..65f5e59b8a 100644 --- a/app/pdb/group-layer-cmds.c +++ b/app/pdb/group-layer-cmds.c @@ -59,16 +59,24 @@ group_layer_new_invoker (GimpProcedure *procedure, gboolean success = TRUE; GimpValueArray *return_vals; GimpImage *image; + const gchar *name; GimpGroupLayer *group_layer = NULL; image = g_value_get_object (gimp_value_array_index (args, 0)); + name = g_value_get_string (gimp_value_array_index (args, 1)); if (success) { group_layer = GIMP_GROUP_LAYER (gimp_group_layer_new (image)); if (! group_layer) - success = FALSE; + { + success = FALSE; + } + else if (name != NULL && strlen (name) > 0) + { + gimp_item_rename (GIMP_ITEM (group_layer), name, error); + } } return_vals = gimp_procedure_get_return_values (procedure, success, @@ -128,12 +136,16 @@ register_group_layer_procs (GimpPDB *pdb) /* * gimp-group-layer-new */ - procedure = gimp_procedure_new (group_layer_new_invoker, TRUE, TRUE); + procedure = gimp_procedure_new (group_layer_new_invoker, TRUE, FALSE); gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-group-layer-new"); gimp_procedure_set_static_help (procedure, "Create a new group layer.", - "This procedure creates a new group layer. Attributes such as layer mode and opacity should be set with explicit procedure calls. Add the new group layer (which is a kind of layer) with [method@image.insert_layer].\n" + "This procedure creates a new group layer with a given @name. If @name is %NULL, GIMP will choose a name using its default layer name algorithm.\n" + "\n" + "The new group layer still needs to be added to the image, as this is not automatic. Add the new layer with the [method@Image.insert_layer] method.\n" + "Other attributes such as layer mask, modes and offsets should be set with explicit procedure calls.\n" + "\n" "Other procedures useful with group layers: [method@image_reorder_item], [method@item.get_parent], [method@item.get_children], [method@item.is_group].", NULL); gimp_procedure_set_static_attribution (procedure, @@ -146,6 +158,13 @@ register_group_layer_procs (GimpPDB *pdb) "The image to which to add the group layer", FALSE, GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + gimp_param_spec_string ("name", + "name", + "The group layer name", + FALSE, TRUE, FALSE, + NULL, + GIMP_PARAM_READWRITE)); gimp_procedure_add_return_value (procedure, gimp_param_spec_group_layer ("group-layer", "group layer", diff --git a/libgimp/gimpgrouplayer.c b/libgimp/gimpgrouplayer.c index 5a5b7c59cc..4946f8f36b 100644 --- a/libgimp/gimpgrouplayer.c +++ b/libgimp/gimpgrouplayer.c @@ -73,37 +73,3 @@ gimp_group_layer_get_by_id (gint32 layer_id) return NULL; } - -/** - * gimp_group_layer_new: - * @image: The image to which to add the layer. - * @name: (nullable): The group layer name. - * - * Create a new group layer. - * - * This procedure creates a new group layer with a given @name. If @name is - * %NULL, GIMP will choose a name using its default layer name algorithm. - * - * The new group layer still needs to be added to the image, as this is - * not automatic. Add the new layer with the [method@Image.insert_layer] - * method. - * - * Other attributes such as layer mask modes, and offsets should be set - * with explicit procedure calls. - * - * Returns: (transfer none): The newly created group layer. - * The object belongs to libgimp and you should not free it. - * - * Since: 3.0 - */ -GimpGroupLayer * -gimp_group_layer_new (GimpImage *image, - const gchar *name) -{ - GimpGroupLayer *layer = _gimp_group_layer_new (image); - - if (name != NULL) - gimp_item_set_name (GIMP_ITEM (layer), name); - - return layer; -} diff --git a/libgimp/gimpgrouplayer.h b/libgimp/gimpgrouplayer.h index e039a4bfd3..8a19cc5bee 100644 --- a/libgimp/gimpgrouplayer.h +++ b/libgimp/gimpgrouplayer.h @@ -40,9 +40,6 @@ G_DECLARE_FINAL_TYPE (GimpGroupLayer, gimp_group_layer, GIMP, GROUP_LAYER, GimpL GimpGroupLayer * gimp_group_layer_get_by_id (gint32 layer_id); -GimpGroupLayer * gimp_group_layer_new (GimpImage *image, - const gchar *name) G_GNUC_WARN_UNUSED_RESULT; - G_END_DECLS diff --git a/libgimp/gimpgrouplayer_pdb.c b/libgimp/gimpgrouplayer_pdb.c index 898dded76a..b9b1fc2ad8 100644 --- a/libgimp/gimpgrouplayer_pdb.c +++ b/libgimp/gimpgrouplayer_pdb.c @@ -37,15 +37,22 @@ /** - * _gimp_group_layer_new: + * gimp_group_layer_new: * @image: The image to which to add the group layer. + * @name: (nullable): The group layer name. * * Create a new group layer. * - * This procedure creates a new group layer. Attributes such as layer - * mode and opacity should be set with explicit procedure calls. Add - * the new group layer (which is a kind of layer) with - * [method@image.insert_layer]. + * This procedure creates a new group layer with a given @name. If + * @name is %NULL, GIMP will choose a name using its default layer name + * algorithm. + * + * The new group layer still needs to be added to the image, as this is + * not automatic. Add the new layer with the + * [method@Image.insert_layer] method. + * Other attributes such as layer mask, modes and offsets should be set + * with explicit procedure calls. + * * Other procedures useful with group layers: * [method@image_reorder_item], [method@item.get_parent], * [method@item.get_children], [method@item.is_group]. @@ -55,7 +62,8 @@ * Since: 2.8 **/ GimpGroupLayer * -_gimp_group_layer_new (GimpImage *image) +gimp_group_layer_new (GimpImage *image, + const gchar *name) { GimpValueArray *args; GimpValueArray *return_vals; @@ -63,6 +71,7 @@ _gimp_group_layer_new (GimpImage *image) args = gimp_value_array_new_from_types (NULL, GIMP_TYPE_IMAGE, image, + G_TYPE_STRING, name, G_TYPE_NONE); return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), diff --git a/libgimp/gimpgrouplayer_pdb.h b/libgimp/gimpgrouplayer_pdb.h index 04c7a83a5a..7699b7a84b 100644 --- a/libgimp/gimpgrouplayer_pdb.h +++ b/libgimp/gimpgrouplayer_pdb.h @@ -32,8 +32,9 @@ G_BEGIN_DECLS /* For information look into the C source or the html documentation */ -G_GNUC_INTERNAL GimpGroupLayer* _gimp_group_layer_new (GimpImage *image); -GimpLayer* gimp_group_layer_merge (GimpGroupLayer *group_layer); +GimpGroupLayer* gimp_group_layer_new (GimpImage *image, + const gchar *name); +GimpLayer* gimp_group_layer_merge (GimpGroupLayer *group_layer); G_END_DECLS diff --git a/pdb/groups/group_layer.pdb b/pdb/groups/group_layer.pdb index a1fe84789e..570c24f318 100644 --- a/pdb/groups/group_layer.pdb +++ b/pdb/groups/group_layer.pdb @@ -19,9 +19,17 @@ sub group_layer_new { $blurb = 'Create a new group layer.'; $help = <<'HELP'; -This procedure creates a new group layer. Attributes such as layer mode -and opacity should be set with explicit procedure calls. Add the new -group layer (which is a kind of layer) with [method@image.insert_layer]. +This procedure creates a new group layer with a given @name. If @name is +%NULL, GIMP will choose a name using its default layer name algorithm. + + +The new group layer still needs to be added to the image, as this is +not automatic. Add the new layer with the [method@Image.insert_layer] +method. + +Other attributes such as layer mask, modes and offsets should be set +with explicit procedure calls. + Other procedures useful with group layers: [method@image_reorder_item], [method@item.get_parent], [method@item.get_children], [method@item.is_group]. @@ -29,11 +37,11 @@ HELP &barak_pdb_misc('2010', '2.8'); - $lib_private = 1; - @inargs = ( { name => 'image', type => 'image', - desc => 'The image to which to add the group layer' } + desc => 'The image to which to add the group layer' }, + { name => 'name', type => 'string', none_ok => 1, + desc => "The group layer name" } ); @outargs = ( @@ -46,7 +54,13 @@ HELP group_layer = GIMP_GROUP_LAYER (gimp_group_layer_new (image)); if (! group_layer) - success = FALSE; + { + success = FALSE; + } + else if (name != NULL && strlen (name) > 0) + { + gimp_item_rename (GIMP_ITEM (group_layer), name, error); + } } CODE ); diff --git a/plug-ins/script-fu/test/tests/PDB/item/item-layer-group-2.scm b/plug-ins/script-fu/test/tests/PDB/item/item-layer-group-2.scm index 47a41b6a13..9a34a1ea44 100644 --- a/plug-ins/script-fu/test/tests/PDB/item/item-layer-group-2.scm +++ b/plug-ins/script-fu/test/tests/PDB/item/item-layer-group-2.scm @@ -27,8 +27,8 @@ ; group-new not throw ; This is setup, not an assert, because we need to capture the group's ID ; Note the ID is not wrapped in list -(define testGroup (gimp-group-layer-new testImage)) -(define testGroup2 (gimp-group-layer-new testImage)) +(define testGroup (gimp-group-layer-new testImage "")) +(define testGroup2 (gimp-group-layer-new testImage "")) diff --git a/plug-ins/script-fu/test/tests/PDB/item/item-layer-group.scm b/plug-ins/script-fu/test/tests/PDB/item/item-layer-group.scm index 17f8a8e652..650e10a619 100644 --- a/plug-ins/script-fu/test/tests/PDB/item/item-layer-group.scm +++ b/plug-ins/script-fu/test/tests/PDB/item/item-layer-group.scm @@ -26,7 +26,7 @@ ; group-new not throw ; This is setup, not an assert, because we need to capture the group's ID ; Note the ID is not wrapped in list -(define testGroup (gimp-group-layer-new testImage)) +(define testGroup (gimp-group-layer-new testImage ""))