plug-ins: port script-fu-script.c to gimp_image_procedure_new2().
This commit is contained in:
@ -94,18 +94,26 @@ script_fu_run_command (const gchar *command,
|
||||
* 2) adds actual args image, drawable, etc. for GimpImageProcedure
|
||||
*/
|
||||
GimpValueArray *
|
||||
script_fu_interpret_image_proc (
|
||||
GimpProcedure *procedure,
|
||||
SFScript *script,
|
||||
GimpImage *image,
|
||||
guint n_drawables,
|
||||
GimpDrawable **drawables,
|
||||
const GimpValueArray *args)
|
||||
script_fu_interpret_image_proc (GimpProcedure *procedure,
|
||||
SFScript *script,
|
||||
GimpImage *image,
|
||||
guint n_drawables,
|
||||
GimpDrawable **drawables,
|
||||
GimpProcedureConfig *config)
|
||||
{
|
||||
gchar *command;
|
||||
GimpValueArray *result = NULL;
|
||||
gboolean interpretation_result;
|
||||
GError *error = NULL;
|
||||
GimpValueArray *args = gimp_procedure_new_arguments (procedure);
|
||||
guint n_specs;
|
||||
|
||||
g_free (g_object_class_list_properties (G_OBJECT_GET_CLASS (config), &n_specs));
|
||||
while (gimp_value_array_length (args) > n_specs - 1)
|
||||
gimp_value_array_remove (args, 0);
|
||||
|
||||
/* Store config's values into args. */
|
||||
gimp_procedure_config_get_values (config, args);
|
||||
|
||||
command = script_fu_script_get_command_for_image_proc (script, image, n_drawables, drawables, args);
|
||||
|
||||
@ -146,5 +154,7 @@ script_fu_interpret_image_proc (
|
||||
gimp_plug_in_set_pdb_error_handler (gimp_get_plug_in (),
|
||||
GIMP_PDB_ERROR_HANDLER_INTERNAL);
|
||||
|
||||
gimp_value_array_unref (args);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -26,6 +26,6 @@ GimpValueArray *script_fu_interpret_image_proc (GimpProcedure *procedure,
|
||||
GimpImage *image,
|
||||
guint n_drawables,
|
||||
GimpDrawable **drawables,
|
||||
const GimpValueArray *args);
|
||||
GimpProcedureConfig *config);
|
||||
|
||||
#endif /* __SCRIPT_FU_COMMAND_H__ */
|
||||
|
@ -148,18 +148,19 @@ script_fu_dialog_run (GimpProcedure *procedure,
|
||||
GimpImage *image,
|
||||
guint n_drawables,
|
||||
GimpDrawable **drawables,
|
||||
const GimpValueArray *initial_args)
|
||||
GimpProcedureConfig *config)
|
||||
|
||||
{
|
||||
GimpValueArray *result = NULL;
|
||||
GimpProcedureDialog *dialog = NULL;
|
||||
GimpProcedureConfig *config = NULL;
|
||||
gboolean not_canceled;
|
||||
guint n_specs;
|
||||
|
||||
if ( (! G_IS_OBJECT (procedure)) || script == NULL)
|
||||
return gimp_procedure_new_return_values (procedure, GIMP_PDB_EXECUTION_ERROR, NULL);
|
||||
|
||||
if ( gimp_value_array_length (initial_args) < 1)
|
||||
g_free (g_object_class_list_properties (G_OBJECT_GET_CLASS (config), &n_specs));
|
||||
if (n_specs < 2)
|
||||
return gimp_procedure_new_return_values (procedure, GIMP_PDB_EXECUTION_ERROR, NULL);
|
||||
|
||||
/* We don't prevent concurrent dialogs as in script-fu-interface.c.
|
||||
@ -175,22 +176,12 @@ script_fu_dialog_run (GimpProcedure *procedure,
|
||||
/* Script's menu label */
|
||||
gimp_ui_init (script_fu_script_get_title (script));
|
||||
|
||||
config = gimp_procedure_create_config (procedure);
|
||||
#if DEBUG_CONFIG_PROPERTIES
|
||||
dump_properties (config);
|
||||
g_debug ("Len of initial_args %i", gimp_value_array_length (initial_args) );
|
||||
g_debug ("Len of initial_args %i", n_specs - 1);
|
||||
dump_objects (config);
|
||||
#endif
|
||||
|
||||
/* Get saved settings (last values) into the config.
|
||||
* Since run mode is INTERACTIVE, initial_args is moot.
|
||||
* Instead, last used values or default values populate the config.
|
||||
*/
|
||||
gimp_procedure_config_begin_run (config, NULL, GIMP_RUN_INTERACTIVE, initial_args);
|
||||
#if DEBUG_CONFIG_PROPERTIES
|
||||
|
||||
dump_objects (config);
|
||||
#endif
|
||||
|
||||
/* Create a dialog having properties (describing arguments of the procedure)
|
||||
* taken from the config.
|
||||
*
|
||||
@ -216,22 +207,15 @@ script_fu_dialog_run (GimpProcedure *procedure,
|
||||
not_canceled = gimp_procedure_dialog_run (dialog);
|
||||
/* Assert config holds validated arg values from a user interaction. */
|
||||
|
||||
#if DEBUG_CONFIG_PROPERTIES
|
||||
dump_objects (config);
|
||||
#endif
|
||||
#if DEBUG_CONFIG_PROPERTIES
|
||||
dump_objects (config);
|
||||
#endif
|
||||
|
||||
if (not_canceled)
|
||||
{
|
||||
GimpValueArray *final_args = gimp_value_array_copy (initial_args);
|
||||
|
||||
/* Store config's values into final_args. */
|
||||
gimp_procedure_config_get_values (config, final_args);
|
||||
|
||||
result = script_fu_interpret_image_proc (procedure, script,
|
||||
image, n_drawables, drawables,
|
||||
final_args);
|
||||
|
||||
gimp_value_array_unref (final_args);
|
||||
config);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -240,13 +224,5 @@ script_fu_dialog_run (GimpProcedure *procedure,
|
||||
|
||||
gtk_widget_destroy ((GtkWidget*) dialog);
|
||||
|
||||
/* Persist config aka settings for the next run of the plugin.
|
||||
* Passing the GimpPDBStatus from result[0].
|
||||
* We must have a matching end_run for the begin_run, regardless of status.
|
||||
*/
|
||||
gimp_procedure_config_end_run (config, g_value_get_enum (gimp_value_array_index (result, 0)));
|
||||
|
||||
g_object_unref (config);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -26,6 +26,6 @@ GimpValueArray *script_fu_dialog_run (GimpProcedure *procedure,
|
||||
GimpImage *image,
|
||||
guint n_drawables,
|
||||
GimpDrawable **drawables,
|
||||
const GimpValueArray *args);
|
||||
GimpProcedureConfig *config);
|
||||
|
||||
#endif /* __SCRIPT_FU_DIALOG_H__ */
|
||||
|
@ -53,17 +53,17 @@
|
||||
* Since 3.0
|
||||
*/
|
||||
GimpValueArray *
|
||||
script_fu_run_image_procedure ( GimpProcedure *procedure, /* GimpImageProcedure */
|
||||
GimpRunMode run_mode,
|
||||
GimpImage *image,
|
||||
guint n_drawables,
|
||||
GimpDrawable **drawables,
|
||||
const GimpValueArray *other_args,
|
||||
gpointer data)
|
||||
script_fu_run_image_procedure (GimpProcedure *procedure, /* GimpImageProcedure */
|
||||
GimpRunMode run_mode,
|
||||
GimpImage *image,
|
||||
guint n_drawables,
|
||||
GimpDrawable **drawables,
|
||||
GimpProcedureConfig *config,
|
||||
gpointer data)
|
||||
{
|
||||
|
||||
GimpValueArray *result = NULL;
|
||||
SFScript *script;
|
||||
GimpValueArray *result = NULL;
|
||||
SFScript *script;
|
||||
|
||||
g_debug ("script_fu_run_image_procedure");
|
||||
script = script_fu_find_script (gimp_procedure_get_name (procedure));
|
||||
@ -77,33 +77,36 @@ script_fu_run_image_procedure ( GimpProcedure *procedure, /* GimpImagePr
|
||||
{
|
||||
case GIMP_RUN_INTERACTIVE:
|
||||
{
|
||||
if (gimp_value_array_length (other_args) > 0)
|
||||
guint n_specs;
|
||||
|
||||
g_free (g_object_class_list_properties (G_OBJECT_GET_CLASS (config), &n_specs));
|
||||
if (n_specs > 1)
|
||||
{
|
||||
/* Let user choose "other" args in a dialog, then interpret. Maintain a config. */
|
||||
result = script_fu_dialog_run (procedure, script, image, n_drawables, drawables, other_args);
|
||||
result = script_fu_dialog_run (procedure, script, image, n_drawables, drawables, config);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No "other" args for user to choose. No config to maintain. */
|
||||
result = script_fu_interpret_image_proc (procedure, script, image, n_drawables, drawables, other_args);
|
||||
result = script_fu_interpret_image_proc (procedure, script, image, n_drawables, drawables, config);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GIMP_RUN_NONINTERACTIVE:
|
||||
{
|
||||
/* A call from another PDB procedure.
|
||||
* Use the given other_args, without interacting with user.
|
||||
* Use the given config, without interacting with user.
|
||||
* Since no user interaction, no config to maintain.
|
||||
*/
|
||||
result = script_fu_interpret_image_proc (procedure, script, image, n_drawables, drawables, other_args);
|
||||
result = script_fu_interpret_image_proc (procedure, script, image, n_drawables, drawables, config);
|
||||
break;
|
||||
}
|
||||
case GIMP_RUN_WITH_LAST_VALS:
|
||||
{
|
||||
/* User invoked from a menu "Filter>Run with last values".
|
||||
* Do not show dialog. other_args are already last values, from a config.
|
||||
* Do not show dialog. config are already last values.
|
||||
*/
|
||||
result = script_fu_interpret_image_proc (procedure, script, image, n_drawables, drawables, other_args);
|
||||
result = script_fu_interpret_image_proc (procedure, script, image, n_drawables, drawables, config);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -111,6 +114,7 @@ script_fu_run_image_procedure ( GimpProcedure *procedure, /* GimpImagePr
|
||||
result = gimp_procedure_new_return_values (procedure, GIMP_PDB_CALLING_ERROR, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ GimpValueArray *script_fu_run_image_procedure (GimpProcedure *procedure,
|
||||
GimpImage *image,
|
||||
guint n_drawables,
|
||||
GimpDrawable **drawables,
|
||||
const GimpValueArray *args,
|
||||
GimpProcedureConfig *config,
|
||||
gpointer data);
|
||||
|
||||
#endif /* __SCRIPT_FU_RUN_FUNC__ */
|
||||
|
@ -160,12 +160,11 @@ script_fu_script_create_PDB_procedure (GimpPlugIn *plug_in,
|
||||
g_debug ("script_fu_script_create_PDB_procedure: %s, plugin type %i, image_proc",
|
||||
script->name, plug_in_type);
|
||||
|
||||
procedure = gimp_image_procedure_new (
|
||||
plug_in, script->name,
|
||||
plug_in_type,
|
||||
(GimpRunImageFunc) script_fu_run_image_procedure,
|
||||
script, /* user_data, pointer in extension-script-fu process */
|
||||
NULL);
|
||||
procedure = gimp_image_procedure_new2 (plug_in, script->name,
|
||||
plug_in_type,
|
||||
(GimpRunImageFunc2) script_fu_run_image_procedure,
|
||||
script, /* user_data, pointer in extension-script-fu process */
|
||||
NULL);
|
||||
|
||||
script_fu_script_set_proc_metadata (procedure, script);
|
||||
|
||||
|
Reference in New Issue
Block a user