Commit 5a235fae authored by Michael Natterer's avatar Michael Natterer 😴

libgimp: add the concept of "argument sync" to GimpProcedure

which can be set to GIMP_ARGUMENT_SYNC_NONE (the default) or
GIMP_ARGUMENT_SYNC_PARASITE, which indicates that the argument should
be synced with an image parasite of the same name.
parent 89628627
......@@ -708,6 +708,7 @@ EXPORTS
gimp_procedure_find_argument
gimp_procedure_find_aux_argument
gimp_procedure_find_return_value
gimp_procedure_get_argument_sync
gimp_procedure_get_arguments
gimp_procedure_get_authors
gimp_procedure_get_aux_arguments
......@@ -732,6 +733,7 @@ EXPORTS
gimp_procedure_new_arguments
gimp_procedure_new_return_values
gimp_procedure_run
gimp_procedure_set_argument_sync
gimp_procedure_set_attribution
gimp_procedure_set_documentation
gimp_procedure_set_icon_file
......
......@@ -1537,6 +1537,93 @@ gimp_procedure_get_return_values (GimpProcedure *procedure,
return procedure->priv->values;
}
/**
* gimp_procedure_set_argument_sync:
* @procedure: a #GimpProcedure.
* @arg_name: the name of one of @procedure's arguments or auxiliary arguments.
* @sync: how to sync the argument or auxiliary argument.
*
* When using #GimpProcedureConfig, gimp_procedure_config_begin_run()
* and gimp_procedure_config_end_run(), a #GimpProcedure's arguments
* or auxiliary arguments can be automatically synced with a
* #GimpParasite of the #GimpImage the procedure is running on.
*
* In order to enable this, set @sync to %GIMP_ARGUMENT_SYNC_PARASITE.
*
* Currently, it is possible to sync a string argument of type
* #GParamSpecString with an image parasite of the same name, for
* example the "gimp-comment" parasite in file save procedures.
*
* Since: 3.0
**/
void
gimp_procedure_set_argument_sync (GimpProcedure *procedure,
const gchar *arg_name,
GimpArgumentSync sync)
{
GParamSpec *pspec;
g_return_if_fail (GIMP_IS_PROCEDURE (procedure));
g_return_if_fail (arg_name != NULL);
pspec = gimp_procedure_find_argument (procedure, arg_name);
if (! pspec)
pspec = gimp_procedure_find_aux_argument (procedure, arg_name);
g_return_if_fail (pspec != NULL);
switch (sync)
{
case GIMP_ARGUMENT_SYNC_NONE:
gegl_param_spec_set_property_key (pspec, "gimp-argument-sync", NULL);
break;
case GIMP_ARGUMENT_SYNC_PARASITE:
gegl_param_spec_set_property_key (pspec, "gimp-argument-sync", "parasite");
break;
}
}
/**
* gimp_procedure_get_argument_sync:
* @procedure: a #GimpProcedure
* @arg_name: the name of one of @procedure's arguments or auxiliary arguments
*
* Returns: The #GimpArgumentSync value set with
* gimp_procedure_set_argument_sync():
*
* Since: 3.0
**/
GimpArgumentSync
gimp_procedure_get_argument_sync (GimpProcedure *procedure,
const gchar *arg_name)
{
GParamSpec *pspec;
GimpArgumentSync sync = GIMP_ARGUMENT_SYNC_NONE;
const gchar *value;
g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), GIMP_ARGUMENT_SYNC_NONE);
g_return_val_if_fail (arg_name != NULL, GIMP_ARGUMENT_SYNC_NONE);
pspec = gimp_procedure_find_argument (procedure, arg_name);
if (! pspec)
pspec = gimp_procedure_find_aux_argument (procedure, arg_name);
g_return_val_if_fail (pspec != NULL, GIMP_ARGUMENT_SYNC_NONE);
value = gegl_param_spec_get_property_key (pspec, "gimp-argument-sync");
if (value)
{
if (! strcmp (value, "parasite"))
sync = GIMP_ARGUMENT_SYNC_PARASITE;
}
return sync;
}
GimpValueArray *
gimp_procedure_new_arguments (GimpProcedure *procedure)
{
......
......@@ -49,6 +49,22 @@ typedef GimpValueArray * (* GimpRunFunc) (GimpProcedure *procedure,
gpointer run_data);
/**
* GimpArgumentSync:
* @GIMP_ARGUMENT_SYNC_NONE: Don't sync this argument
* @GIMP_ARGUMENT_SYNC_PARASITE: Sync this argument with an image parasite
*
* Methods of syncing procedure arguments.
*
* Since: 3.0
**/
typedef enum
{
GIMP_ARGUMENT_SYNC_NONE,
GIMP_ARGUMENT_SYNC_PARASITE
} GimpArgumentSync;
#define GIMP_TYPE_PROCEDURE (gimp_procedure_get_type ())
#define GIMP_PROCEDURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_PROCEDURE, GimpProcedure))
#define GIMP_PROCEDURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_PROCEDURE, GimpProcedureClass))
......@@ -170,12 +186,14 @@ GParamSpec * gimp_procedure_add_argument_from_property
(GimpProcedure *procedure,
GObject *config,
const gchar *prop_name);
GParamSpec * gimp_procedure_add_aux_argument (GimpProcedure *procedure,
GParamSpec *pspec);
GParamSpec * gimp_procedure_add_aux_argument_from_property
(GimpProcedure *procedure,
GObject *config,
const gchar *prop_name);
GParamSpec * gimp_procedure_add_return_value (GimpProcedure *procedure,
GParamSpec *pspec);
GParamSpec * gimp_procedure_add_return_value_from_property
......@@ -197,6 +215,12 @@ GParamSpec ** gimp_procedure_get_aux_arguments (GimpProcedure *proced
GParamSpec ** gimp_procedure_get_return_values (GimpProcedure *procedure,
gint *n_return_values);
void gimp_procedure_set_argument_sync (GimpProcedure *procedure,
const gchar *arg_name,
GimpArgumentSync sync);
GimpArgumentSync gimp_procedure_get_argument_sync (GimpProcedure *procedure,
const gchar *arg_name);
GimpValueArray * gimp_procedure_new_arguments (GimpProcedure *procedure);
GimpValueArray * gimp_procedure_new_return_values (GimpProcedure *procedure,
GimpPDBStatusType status,
......
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