libgimp: temporary gimp_image_procedure_new2() until port is over.

Same as with gimp_procedure_new2(), I will end up renaming the function to
gimp_image_procedure_new() once all usage of this function will have been ported
to the new function using GimpProcedureConfig instead of GimpValueArray
arguments.
This commit is contained in:
Jehan 2023-06-17 00:25:12 +02:00
parent 3806b46fc5
commit 8c8c64a9ee
3 changed files with 92 additions and 5 deletions

View File

@ -466,6 +466,7 @@ EXPORTS
gimp_image_policy_rotate
gimp_image_procedure_get_type
gimp_image_procedure_new
gimp_image_procedure_new2
gimp_image_raise_item
gimp_image_raise_item_to_top
gimp_image_remove_channel

View File

@ -48,6 +48,7 @@
struct _GimpImageProcedurePrivate
{
GimpRunImageFunc run_func;
GimpRunImageFunc2 run_func2;
gpointer run_data;
GDestroyNotify run_data_destroy;
};
@ -167,11 +168,36 @@ gimp_image_procedure_run (GimpProcedure *procedure,
gimp_value_array_append (remaining, value);
}
return_values = image_proc->priv->run_func (procedure,
run_mode,
image, n_drawables, drawables,
remaining,
image_proc->priv->run_data);
if (image_proc->priv->run_func2)
{
GimpProcedureConfig *config;
GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR;
config = gimp_procedure_create_config (procedure);
gimp_procedure_config_begin_run (config, image, run_mode, remaining);
return_values = image_proc->priv->run_func2 (procedure,
run_mode,
image, n_drawables, drawables,
config,
image_proc->priv->run_data);
if (return_values != NULL &&
gimp_value_array_length (return_values) > 0 &&
G_VALUE_HOLDS_ENUM (gimp_value_array_index (return_values, 0)))
status = GIMP_VALUES_GET_ENUM (return_values, 0);
gimp_procedure_config_end_run (config, status);
g_object_unref (config);
}
else
{
return_values = image_proc->priv->run_func (procedure,
run_mode,
image, n_drawables, drawables,
remaining,
image_proc->priv->run_data);
}
gimp_value_array_unref (remaining);
@ -266,3 +292,32 @@ gimp_image_procedure_new (GimpPlugIn *plug_in,
return GIMP_PROCEDURE (procedure);
}
GimpProcedure *
gimp_image_procedure_new2 (GimpPlugIn *plug_in,
const gchar *name,
GimpPDBProcType proc_type,
GimpRunImageFunc2 run_func,
gpointer run_data,
GDestroyNotify run_data_destroy)
{
GimpImageProcedure *procedure;
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), NULL);
g_return_val_if_fail (gimp_is_canonical_identifier (name), NULL);
g_return_val_if_fail (proc_type != GIMP_PDB_PROC_TYPE_INTERNAL, NULL);
g_return_val_if_fail (proc_type != GIMP_PDB_PROC_TYPE_EXTENSION, NULL);
g_return_val_if_fail (run_func != NULL, NULL);
procedure = g_object_new (GIMP_TYPE_IMAGE_PROCEDURE,
"plug-in", plug_in,
"name", name,
"procedure-type", proc_type,
NULL);
procedure->priv->run_func2 = run_func;
procedure->priv->run_data = run_data;
procedure->priv->run_data_destroy = run_data_destroy;
return GIMP_PROCEDURE (procedure);
}

View File

@ -54,6 +54,31 @@ typedef GimpValueArray * (* GimpRunImageFunc) (GimpProcedure *procedure,
const GimpValueArray *args,
gpointer run_data);
/**
* GimpRunImageFunc2:
* @procedure: the #GimpProcedure that runs.
* @run_mode: the #GimpRunMode.
* @image: the #GimpImage.
* @n_drawables: the number of #GimpDrawable-s.
* @drawables: (array length=n_drawables): the input #GimpDrawable-s.
* @config: the @procedure's remaining arguments.
* @run_data: (closure): the run_data given in gimp_image_procedure_new().
*
* The image function is run during the lifetime of the GIMP session,
* each time a plug-in image procedure is called.
*
* Returns: (transfer full): the @procedure's return values.
*
* Since: 3.0
**/
typedef GimpValueArray * (* GimpRunImageFunc2) (GimpProcedure *procedure,
GimpRunMode run_mode,
GimpImage *image,
gint n_drawables,
GimpDrawable **drawables,
GimpProcedureConfig *config,
gpointer run_data);
#define GIMP_TYPE_IMAGE_PROCEDURE (gimp_image_procedure_get_type ())
#define GIMP_IMAGE_PROCEDURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_IMAGE_PROCEDURE, GimpImageProcedure))
@ -88,6 +113,12 @@ GimpProcedure * gimp_image_procedure_new (GimpPlugIn *plug_in,
GimpRunImageFunc run_func,
gpointer run_data,
GDestroyNotify run_data_destroy);
GimpProcedure * gimp_image_procedure_new2 (GimpPlugIn *plug_in,
const gchar *name,
GimpPDBProcType proc_type,
GimpRunImageFunc2 run_func,
gpointer run_data,
GDestroyNotify run_data_destroy);
G_END_DECLS