Commit c800b262 authored by Jehan's avatar Jehan

app, pdb, libgimp: new PDB call gimp-image-set-selected-layers.

parent 02fa3542
......@@ -1991,6 +1991,40 @@ image_get_selected_layers_invoker (GimpProcedure *procedure,
return return_vals;
}
static GimpValueArray *
image_set_selected_layers_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpImage *image;
gint num_layers;
const GimpLayer **layers;
image = g_value_get_object (gimp_value_array_index (args, 0));
num_layers = g_value_get_int (gimp_value_array_index (args, 1));
layers = (const GimpLayer **) gimp_value_get_object_array (gimp_value_array_index (args, 2));
if (success)
{
GList *selected_layers = NULL;
gint i;
for (i = 0; i < num_layers; i++)
selected_layers = g_list_prepend (selected_layers,
GIMP_LAYER (layers[i]));
gimp_image_set_selected_layers (image, selected_layers);
g_list_free (selected_layers);
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GimpValueArray *
image_get_selection_invoker (GimpProcedure *procedure,
Gimp *gimp,
......@@ -4706,6 +4740,41 @@ register_image_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-set-selected-layers
*/
procedure = gimp_procedure_new (image_set_selected_layers_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-image-set-selected-layers");
gimp_procedure_set_static_help (procedure,
"Sets the specified image's selected layers.",
"The layers are set as the selected layers in the image. Any previous selected layers or channels are unselected. An exception is a previously existing floating selection, in which case this procedure will return an execution error.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Jehan",
"Jehan",
"2021");
gimp_procedure_add_argument (procedure,
gimp_param_spec_image ("image",
"image",
"The image",
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_int ("num-layers",
"num layers",
"The number of layers to select",
0, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_object_array ("layers",
"layers",
"The list of layers to select",
GIMP_TYPE_LAYER,
GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-get-selection
*/
......
......@@ -28,7 +28,7 @@
#include "internal-procs.h"
/* 755 procedures registered total */
/* 756 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
......
......@@ -485,6 +485,7 @@ EXPORTS
gimp_image_set_file
gimp_image_set_metadata
gimp_image_set_resolution
gimp_image_set_selected_layers
gimp_image_set_tattoo_state
gimp_image_set_unit
gimp_image_thaw_channels
......
......@@ -2311,7 +2311,7 @@ gimp_image_set_active_vectors (GimpImage *image,
* The list of selected layers in the image.
* The returned value must be freed with g_free().
*
* Since: 2.10.20
* Since: 3.0.0
**/
GimpLayer **
gimp_image_get_selected_layers (GimpImage *image,
......@@ -2343,6 +2343,51 @@ gimp_image_get_selected_layers (GimpImage *image,
return layers;
}
/**
* gimp_image_set_selected_layers:
* @image: The image.
* @num_layers: The number of layers to select.
* @layers: (array length=num_layers) (element-type GimpLayer): The list of layers to select.
*
* Sets the specified image's selected layers.
*
* The layers are set as the selected layers in the image. Any previous
* selected layers or channels are unselected. An exception is a
* previously existing floating selection, in which case this procedure
* will return an execution error.
*
* Returns: TRUE on success.
*
* Since: 3.0.0
**/
gboolean
gimp_image_set_selected_layers (GimpImage *image,
gint num_layers,
const GimpLayer **layers)
{
GimpValueArray *args;
GimpValueArray *return_vals;
gboolean success = TRUE;
args = gimp_value_array_new_from_types (NULL,
GIMP_TYPE_IMAGE, image,
G_TYPE_INT, num_layers,
GIMP_TYPE_OBJECT_ARRAY, NULL,
G_TYPE_NONE);
gimp_value_set_object_array (gimp_value_array_index (args, 2), GIMP_TYPE_LAYER, (GObject **) layers, num_layers);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-image-set-selected-layers",
args);
gimp_value_array_unref (args);
success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
gimp_value_array_unref (return_vals);
return success;
}
/**
* gimp_image_get_selection:
* @image: The image.
......
......@@ -145,6 +145,9 @@ gboolean gimp_image_set_active_vectors (GimpImage
GimpVectors *active_vectors);
GimpLayer** gimp_image_get_selected_layers (GimpImage *image,
gint *num_layers);
gboolean gimp_image_set_selected_layers (GimpImage *image,
gint num_layers,
const GimpLayer **layers);
GimpSelection* gimp_image_get_selection (GimpImage *image);
gboolean gimp_image_get_component_active (GimpImage *image,
GimpChannelType component);
......
......@@ -1824,7 +1824,7 @@ sub image_get_selected_layers {
This procedure returns the list of selected layers in the specified image.
HELP
&jehan_pdb_misc('2020', '2.10.20');
&jehan_pdb_misc('2020', '3.0.0');
@inargs = (
{ name => 'image', type => 'image',
......@@ -1889,6 +1889,46 @@ CODE
);
}
sub image_set_selected_layers {
$blurb = "Sets the specified image's selected layers.";
$help = <<'HELP';
The layers are set as the selected layers in the image. Any previous
selected layers or channels are unselected. An exception is a previously
existing floating selection, in which case this procedure will return an
execution error.
HELP
&jehan_pdb_misc('2021', '3.0.0');
@inargs = (
{ name => 'image', type => 'image',
desc => 'The image' },
{ name => 'layers', type => 'layerarray',
desc => 'The list of layers to select',
no_validate => 1,
array => { name => 'num_layers',
type => '0 <= int32',
desc => 'The number of layers to select' } }
);
%invoke = (
code => <<'CODE'
{
GList *selected_layers = NULL;
gint i;
for (i = 0; i < num_layers; i++)
selected_layers = g_list_prepend (selected_layers,
GIMP_LAYER (layers[i]));
gimp_image_set_selected_layers (image, selected_layers);
g_list_free (selected_layers);
}
CODE
);
}
sub image_set_active_layer {
$blurb = "Sets the specified image's active layer.";
......@@ -3116,7 +3156,7 @@ CODE
image_get_active_layer image_set_active_layer
image_get_active_channel image_set_active_channel
image_get_active_vectors image_set_active_vectors
image_get_selected_layers
image_get_selected_layers image_set_selected_layers
image_get_selection
image_get_component_active image_set_component_active
image_get_component_visible image_set_component_visible
......
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