libgimp, plug-ins: rename gimp_procedure_new2() as gimp_procedure_new() and…

… remove the latter.

Now all GimpProcedure use this new implementation with use a config object.
This commit is contained in:
Jehan 2023-06-16 18:34:53 +02:00
parent f6f622b93d
commit 2b38a2df86
23 changed files with 120 additions and 217 deletions

View File

@ -767,7 +767,6 @@ EXPORTS
gimp_procedure_get_sensitivity_mask
gimp_procedure_get_type
gimp_procedure_new
gimp_procedure_new2
gimp_procedure_new_arguments
gimp_procedure_new_return_values
gimp_procedure_run

View File

@ -84,7 +84,6 @@ struct _GimpProcedurePrivate
GParamSpec **values;
GimpRunFunc run_func;
GimpRunConfigFunc run_config_func;
gpointer run_data;
GDestroyNotify run_data_destroy;
@ -481,44 +480,36 @@ static GimpValueArray *
gimp_procedure_real_run (GimpProcedure *procedure,
const GimpValueArray *args)
{
if (procedure->priv->run_config_func)
GimpProcedureConfig *config;
GimpImage *image = NULL;
GimpRunMode run_mode = GIMP_RUN_NONINTERACTIVE;
GimpValueArray *retvals;
GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR;
if (gimp_value_array_length (args) > 0 &&
G_VALUE_HOLDS_ENUM (gimp_value_array_index (args, 0)))
{
GimpProcedureConfig *config;
GimpImage *image = NULL;
GimpRunMode run_mode = GIMP_RUN_NONINTERACTIVE;
GimpValueArray *retvals;
GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR;
run_mode = GIMP_VALUES_GET_ENUM (args, 0);
if (gimp_value_array_length (args) > 0 &&
G_VALUE_HOLDS_ENUM (gimp_value_array_index (args, 0)))
{
run_mode = GIMP_VALUES_GET_ENUM (args, 0);
if (gimp_value_array_length (args) > 1 &&
GIMP_VALUE_HOLDS_IMAGE (gimp_value_array_index (args, 1)))
image = GIMP_VALUES_GET_IMAGE (args, 1);
}
config = gimp_procedure_create_config (procedure);
gimp_procedure_config_begin_run (config, image, run_mode, args);
retvals = procedure->priv->run_config_func (procedure, config,
procedure->priv->run_data);
if (retvals != NULL &&
gimp_value_array_length (retvals) > 0 &&
G_VALUE_HOLDS_ENUM (gimp_value_array_index (retvals, 0)))
status = GIMP_VALUES_GET_ENUM (retvals, 0);
gimp_procedure_config_end_run (config, status);
g_object_unref (config);
return retvals;
}
else
{
return procedure->priv->run_func (procedure, args,
procedure->priv->run_data);
if (gimp_value_array_length (args) > 1 &&
GIMP_VALUE_HOLDS_IMAGE (gimp_value_array_index (args, 1)))
image = GIMP_VALUES_GET_IMAGE (args, 1);
}
config = gimp_procedure_create_config (procedure);
gimp_procedure_config_begin_run (config, image, run_mode, args);
retvals = procedure->priv->run_func (procedure, config,
procedure->priv->run_data);
if (retvals != NULL &&
gimp_value_array_length (retvals) > 0 &&
G_VALUE_HOLDS_ENUM (gimp_value_array_index (retvals, 0)))
status = GIMP_VALUES_GET_ENUM (retvals, 0);
gimp_procedure_config_end_run (config, status);
g_object_unref (config);
return retvals;
}
static GimpProcedureConfig *
@ -615,12 +606,12 @@ gimp_procedure_real_create_config (GimpProcedure *procedure,
* Since: 3.0
**/
GimpProcedure *
gimp_procedure_new (GimpPlugIn *plug_in,
const gchar *name,
GimpPDBProcType proc_type,
GimpRunFunc run_func,
gpointer run_data,
GDestroyNotify run_data_destroy)
gimp_procedure_new (GimpPlugIn *plug_in,
const gchar *name,
GimpPDBProcType proc_type,
GimpRunFunc run_func,
gpointer run_data,
GDestroyNotify run_data_destroy)
{
GimpProcedure *procedure;
@ -641,84 +632,6 @@ gimp_procedure_new (GimpPlugIn *plug_in,
return procedure;
}
/**
* gimp_procedure_new2:
* @plug_in: a #GimpPlugIn.
* @name: the new procedure's name.
* @proc_type: the new procedure's #GimpPDBProcType.
* @run_func: the run function for the new procedure.
* @run_data: user data passed to @run_func.
* @run_data_destroy: (nullable): free function for @run_data, or %NULL.
*
* Creates a new procedure named @name which will call @run_func when
* invoked.
*
* The @name parameter is mandatory and should be unique, or it will
* overwrite an already existing procedure (overwrite procedures only
* if you know what you're doing).
*
* @proc_type should be %GIMP_PDB_PROC_TYPE_PLUGIN for "normal" plug-ins.
*
* Using %GIMP_PDB_PROC_TYPE_EXTENSION means that the plug-in will add
* temporary procedures. Therefore, the GIMP core will wait until the
* %GIMP_PDB_PROC_TYPE_EXTENSION procedure has called
* [method@Procedure.extension_ready], which means that the procedure
* has done its initialization, installed its temporary procedures and
* is ready to run.
*
* *Not calling [method@Procedure.extension_ready] from a
* %GIMP_PDB_PROC_TYPE_EXTENSION procedure will cause the GIMP core to
* lock up.*
*
* Additionally, a %GIMP_PDB_PROC_TYPE_EXTENSION procedure with no
* arguments added is an "automatic" extension that will be
* automatically started on each GIMP startup.
*
* %GIMP_PDB_PROC_TYPE_TEMPORARY must be used for temporary procedures
* that are created during a plug-ins lifetime. They must be added to
* the #GimpPlugIn using [method@PlugIn.add_temp_procedure].
*
* @run_func is called via [method@Procedure.run].
*
* For %GIMP_PDB_PROC_TYPE_PLUGIN and %GIMP_PDB_PROC_TYPE_EXTENSION
* procedures the call of @run_func is basically the lifetime of the
* plug-in.
*
* TODO: when all plug-ins have been ported to gimp_procedure_new2(), it must be
* renamed and gimp_procedure_new() removed.
*
* Returns: a new #GimpProcedure.
*
* Since: 3.0
**/
GimpProcedure *
gimp_procedure_new2 (GimpPlugIn *plug_in,
const gchar *name,
GimpPDBProcType proc_type,
GimpRunConfigFunc run_func,
gpointer run_data,
GDestroyNotify run_data_destroy)
{
GimpProcedure *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 (run_func != NULL, NULL);
procedure = g_object_new (GIMP_TYPE_PROCEDURE,
"plug-in", plug_in,
"name", name,
"procedure-type", proc_type,
NULL);
procedure->priv->run_config_func = run_func;
procedure->priv->run_data = run_data;
procedure->priv->run_data_destroy = run_data_destroy;
return procedure;
}
/**
* gimp_procedure_get_plug_in:
* @procedure: A #GimpProcedure.

View File

@ -34,7 +34,7 @@ G_BEGIN_DECLS
/**
* GimpRunFunc:
* @procedure: the #GimpProcedure that runs.
* @args: the @procedure's arguments.
* @config: the @procedure's arguments in a config object.
* @run_data: (closure): the run_data given in gimp_procedure_new().
*
* The run function is run during the lifetime of the GIMP session,
@ -44,12 +44,9 @@ G_BEGIN_DECLS
*
* Since: 3.0
**/
typedef GimpValueArray * (* GimpRunFunc) (GimpProcedure *procedure,
const GimpValueArray *args,
gpointer run_data);
typedef GimpValueArray * (* GimpRunConfigFunc) (GimpProcedure *procedure,
GimpProcedureConfig *config,
gpointer run_data);
typedef GimpValueArray * (* GimpRunFunc) (GimpProcedure *procedure,
GimpProcedureConfig *config,
gpointer run_data);
/**
@ -141,12 +138,6 @@ GimpProcedure * gimp_procedure_new (GimpPlugIn *plug_i
GimpRunFunc run_func,
gpointer run_data,
GDestroyNotify run_data_destroy);
GimpProcedure * gimp_procedure_new2 (GimpPlugIn *plug_in,
const gchar *name,
GimpPDBProcType proc_type,
GimpRunConfigFunc run_func,
gpointer run_data,
GDestroyNotify run_data_destroy);
GimpPlugIn * gimp_procedure_get_plug_in (GimpProcedure *procedure);
const gchar * gimp_procedure_get_name (GimpProcedure *procedure);

View File

@ -99,13 +99,13 @@ gimp_progress_install_vtable (const GimpProgressVtable *vtable,
progress_data->data = user_data;
progress_data->data_destroy = user_data_destroy;
procedure = gimp_procedure_new2 (plug_in,
progress_callback,
GIMP_PDB_PROC_TYPE_TEMPORARY,
gimp_temp_progress_run,
progress_data,
(GDestroyNotify)
gimp_progress_data_free);
procedure = gimp_procedure_new (plug_in,
progress_callback,
GIMP_PDB_PROC_TYPE_TEMPORARY,
gimp_temp_progress_run,
progress_data,
(GDestroyNotify)
gimp_progress_data_free);
GIMP_PROC_ARG_ENUM (procedure, "command",
"Command",

View File

@ -365,12 +365,12 @@ gimp_resource_select_new (const gchar *title,
/* !!! Only part of the adaption has been initialized. */
procedure = gimp_procedure_new2 (plug_in,
temp_PDB_callback_name,
GIMP_PDB_PROC_TYPE_TEMPORARY,
gimp_temp_resource_run,
adaption,
(GDestroyNotify) gimp_resource_data_free);
procedure = gimp_procedure_new (plug_in,
temp_PDB_callback_name,
GIMP_PDB_PROC_TYPE_TEMPORARY,
gimp_temp_resource_run,
adaption,
(GDestroyNotify) gimp_resource_data_free);
create_callback_PDB_procedure_params (procedure, resource_type);

View File

@ -116,9 +116,9 @@ busy_dialog_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, PLUG_IN_PROC))
{
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
busy_dialog_run, NULL, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
busy_dialog_run, NULL, NULL);
gimp_procedure_set_documentation (procedure,
"Show a dialog while waiting for an "

View File

@ -96,9 +96,9 @@ glob_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, PLUG_IN_PROC))
{
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
glob_run, NULL, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
glob_run, NULL, NULL);
gimp_procedure_set_documentation (procedure,
"Returns a list of matching filenames",

View File

@ -385,9 +385,9 @@ pdf_create_procedure (GimpPlugIn *plug_in,
}
else if (! strcmp (name, SAVE_MULTI_PROC))
{
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
pdf_save_multi, NULL, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
pdf_save_multi, NULL, NULL);
gimp_procedure_set_image_types (procedure, "*");

View File

@ -162,9 +162,9 @@ browser_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (procedure_name, PLUG_IN_PROC))
{
procedure = gimp_procedure_new2 (plug_in, procedure_name,
GIMP_PDB_PROC_TYPE_PLUGIN,
browser_run, NULL, NULL);
procedure = gimp_procedure_new (plug_in, procedure_name,
GIMP_PDB_PROC_TYPE_PLUGIN,
browser_run, NULL, NULL);
gimp_procedure_set_menu_label (procedure, _("_Plug-In Browser"));
gimp_procedure_set_icon_name (procedure, GIMP_ICON_PLUGIN);

View File

@ -119,9 +119,9 @@ browser_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, PLUG_IN_PROC))
{
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
browser_run, NULL, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
browser_run, NULL, NULL);
gimp_procedure_set_menu_label (procedure, _("Procedure _Browser"));
gimp_procedure_add_menu_path (procedure, "<Image>/Help/[Programming]");

View File

@ -168,9 +168,9 @@ editor_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, PLUG_IN_PROC))
{
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
editor_run, plug_in, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
editor_run, plug_in, NULL);
gimp_procedure_set_menu_label (procedure, _("U_nits"));
gimp_procedure_set_icon_name (procedure, GIMP_ICON_TOOL_MEASURE);

View File

@ -110,9 +110,9 @@ browser_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, PLUG_IN_PROC))
{
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
browser_run, NULL, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
browser_run, NULL, NULL);
gimp_procedure_set_documentation (procedure,
"Open an URL in the user specified "

View File

@ -111,9 +111,9 @@ webpage_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, PLUG_IN_PROC))
{
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
webpage_run, NULL, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
webpage_run, NULL, NULL);
gimp_procedure_set_menu_label (procedure, _("From _Webpage..."));
gimp_procedure_add_menu_path (procedure, "<Image>/File/Create");

View File

@ -248,9 +248,9 @@ fli_create_procedure (GimpPlugIn *plug_in,
}
else if (! strcmp (name, INFO_PROC))
{
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
fli_info, NULL, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
fli_info, NULL, NULL);
gimp_procedure_set_documentation (procedure,
"Get information about a Fli movie",

View File

@ -85,9 +85,9 @@ help_browser_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, GIMP_HELP_BROWSER_EXT_PROC))
{
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_EXTENSION,
help_browser_run, plug_in, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_EXTENSION,
help_browser_run, plug_in, NULL);
gimp_procedure_set_documentation (procedure,
"Browse the GIMP user manual",
@ -197,9 +197,9 @@ temp_proc_install (GimpPlugIn *plug_in)
{
GimpProcedure *procedure;
procedure = gimp_procedure_new2 (plug_in, GIMP_HELP_BROWSER_TEMP_EXT_PROC,
GIMP_PDB_PROC_TYPE_TEMPORARY,
temp_proc_run, plug_in, NULL);
procedure = gimp_procedure_new (plug_in, GIMP_HELP_BROWSER_TEMP_EXT_PROC,
GIMP_PDB_PROC_TYPE_TEMPORARY,
temp_proc_run, plug_in, NULL);
gimp_procedure_set_documentation (procedure,
"DON'T USE THIS ONE",

View File

@ -126,9 +126,9 @@ help_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, GIMP_HELP_EXT_PROC))
{
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_EXTENSION,
help_run, NULL, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_EXTENSION,
help_run, NULL, NULL);
gimp_procedure_set_attribution (procedure,
"Sven Neumann <sven@gimp.org>, "
@ -198,9 +198,9 @@ help_temp_proc_install (GimpPlugIn *plug_in)
{
GimpProcedure *procedure;
procedure = gimp_procedure_new2 (plug_in, GIMP_HELP_TEMP_EXT_PROC,
GIMP_PDB_PROC_TYPE_TEMPORARY,
help_temp_run, NULL, NULL);
procedure = gimp_procedure_new (plug_in, GIMP_HELP_TEMP_EXT_PROC,
GIMP_PDB_PROC_TYPE_TEMPORARY,
help_temp_run, NULL, NULL);
gimp_procedure_set_attribution (procedure,
"Sven Neumann <sven@gimp.org>, "

View File

@ -743,9 +743,9 @@ metadata_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, PLUG_IN_PROC))
{
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
metadata_run, NULL, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
metadata_run, NULL, NULL);
gimp_procedure_set_image_types (procedure, "*");

View File

@ -168,9 +168,9 @@ metadata_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, PLUG_IN_PROC))
{
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
metadata_run, NULL, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
metadata_run, NULL, NULL);
gimp_procedure_set_image_types (procedure, "*");

View File

@ -533,9 +533,9 @@ print_temp_proc_install (GimpImage *image)
gchar *name = print_temp_proc_name (image);
GimpProcedure *procedure;
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_TEMPORARY,
print_temp_proc_run, NULL, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_TEMPORARY,
print_temp_proc_run, NULL, NULL);
gimp_procedure_set_documentation (procedure,
"DON'T USE THIS ONE",

View File

@ -117,9 +117,9 @@ screenshot_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, PLUG_IN_PROC))
{
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
screenshot_run, NULL, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
screenshot_run, NULL, NULL);
gimp_procedure_set_menu_label (procedure, _("_Screenshot..."));
gimp_procedure_add_menu_path (procedure, "<Image>/File/Create");

View File

@ -185,10 +185,10 @@ script_fu_script_create_PDB_procedure (GimpPlugIn *plug_in,
g_debug ("script_fu_script_create_PDB_procedure: %s, plugin type %i, ordinary proc",
script->name, plug_in_type);
procedure = gimp_procedure_new2 (plug_in, script->name,
plug_in_type,
script_fu_run_procedure,
script, NULL);
procedure = gimp_procedure_new (plug_in, script->name,
plug_in_type,
script_fu_run_procedure,
script, NULL);
script_fu_script_set_proc_metadata (procedure, script);

View File

@ -99,9 +99,9 @@ script_fu_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, "extension-script-fu"))
{
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_EXTENSION,
script_fu_run, NULL, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_EXTENSION,
script_fu_run, NULL, NULL);
gimp_procedure_set_documentation (procedure,
"A scheme interpreter for scripting "
@ -115,9 +115,9 @@ script_fu_create_procedure (GimpPlugIn *plug_in,
}
else if (! strcmp (name, "plug-in-script-fu-console"))
{
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
script_fu_run, NULL, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
script_fu_run, NULL, NULL);
gimp_procedure_set_menu_label (procedure, _("Script-Fu _Console"));
gimp_procedure_add_menu_path (procedure,
@ -147,9 +147,9 @@ script_fu_create_procedure (GimpPlugIn *plug_in,
}
else if (! strcmp (name, "plug-in-script-fu-text-console"))
{
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
script_fu_run, NULL, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
script_fu_run, NULL, NULL);
gimp_procedure_set_documentation (procedure,
"Provides a text console mode for "
@ -338,9 +338,9 @@ script_fu_extension_init (GimpPlugIn *plug_in)
gimp_plug_in_add_menu_branch (plug_in, "<Image>/Filters",
N_("Alpha to _Logo"));
procedure = gimp_procedure_new2 (plug_in, "script-fu-refresh",
GIMP_PDB_PROC_TYPE_TEMPORARY,
script_fu_refresh_proc, NULL, NULL);
procedure = gimp_procedure_new (plug_in, "script-fu-refresh",
GIMP_PDB_PROC_TYPE_TEMPORARY,
script_fu_refresh_proc, NULL, NULL);
gimp_procedure_set_menu_label (procedure, _("_Refresh Scripts"));
gimp_procedure_add_menu_path (procedure,

View File

@ -84,9 +84,9 @@ script_fu_server_create_procedure (GimpPlugIn *plug_in,
GimpProcedure *procedure = NULL;
/* The run func script_fu_server_outer_run is defined in this source file. */
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
script_fu_server_outer_run, NULL, NULL);
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
script_fu_server_outer_run, NULL, NULL);
gimp_procedure_set_menu_label (procedure, _("_Start Server..."));
gimp_procedure_add_menu_path (procedure,