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
|
* 2) adds actual args image, drawable, etc. for GimpImageProcedure
|
||||||
*/
|
*/
|
||||||
GimpValueArray *
|
GimpValueArray *
|
||||||
script_fu_interpret_image_proc (
|
script_fu_interpret_image_proc (GimpProcedure *procedure,
|
||||||
GimpProcedure *procedure,
|
|
||||||
SFScript *script,
|
SFScript *script,
|
||||||
GimpImage *image,
|
GimpImage *image,
|
||||||
guint n_drawables,
|
guint n_drawables,
|
||||||
GimpDrawable **drawables,
|
GimpDrawable **drawables,
|
||||||
const GimpValueArray *args)
|
GimpProcedureConfig *config)
|
||||||
{
|
{
|
||||||
gchar *command;
|
gchar *command;
|
||||||
GimpValueArray *result = NULL;
|
GimpValueArray *result = NULL;
|
||||||
gboolean interpretation_result;
|
gboolean interpretation_result;
|
||||||
GError *error = NULL;
|
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);
|
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_plug_in_set_pdb_error_handler (gimp_get_plug_in (),
|
||||||
GIMP_PDB_ERROR_HANDLER_INTERNAL);
|
GIMP_PDB_ERROR_HANDLER_INTERNAL);
|
||||||
|
|
||||||
|
gimp_value_array_unref (args);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,6 @@ GimpValueArray *script_fu_interpret_image_proc (GimpProcedure *procedure,
|
|||||||
GimpImage *image,
|
GimpImage *image,
|
||||||
guint n_drawables,
|
guint n_drawables,
|
||||||
GimpDrawable **drawables,
|
GimpDrawable **drawables,
|
||||||
const GimpValueArray *args);
|
GimpProcedureConfig *config);
|
||||||
|
|
||||||
#endif /* __SCRIPT_FU_COMMAND_H__ */
|
#endif /* __SCRIPT_FU_COMMAND_H__ */
|
||||||
|
@ -148,18 +148,19 @@ script_fu_dialog_run (GimpProcedure *procedure,
|
|||||||
GimpImage *image,
|
GimpImage *image,
|
||||||
guint n_drawables,
|
guint n_drawables,
|
||||||
GimpDrawable **drawables,
|
GimpDrawable **drawables,
|
||||||
const GimpValueArray *initial_args)
|
GimpProcedureConfig *config)
|
||||||
|
|
||||||
{
|
{
|
||||||
GimpValueArray *result = NULL;
|
GimpValueArray *result = NULL;
|
||||||
GimpProcedureDialog *dialog = NULL;
|
GimpProcedureDialog *dialog = NULL;
|
||||||
GimpProcedureConfig *config = NULL;
|
|
||||||
gboolean not_canceled;
|
gboolean not_canceled;
|
||||||
|
guint n_specs;
|
||||||
|
|
||||||
if ( (! G_IS_OBJECT (procedure)) || script == NULL)
|
if ( (! G_IS_OBJECT (procedure)) || script == NULL)
|
||||||
return gimp_procedure_new_return_values (procedure, GIMP_PDB_EXECUTION_ERROR, 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);
|
return gimp_procedure_new_return_values (procedure, GIMP_PDB_EXECUTION_ERROR, NULL);
|
||||||
|
|
||||||
/* We don't prevent concurrent dialogs as in script-fu-interface.c.
|
/* We don't prevent concurrent dialogs as in script-fu-interface.c.
|
||||||
@ -175,21 +176,11 @@ script_fu_dialog_run (GimpProcedure *procedure,
|
|||||||
/* Script's menu label */
|
/* Script's menu label */
|
||||||
gimp_ui_init (script_fu_script_get_title (script));
|
gimp_ui_init (script_fu_script_get_title (script));
|
||||||
|
|
||||||
config = gimp_procedure_create_config (procedure);
|
|
||||||
#if DEBUG_CONFIG_PROPERTIES
|
#if DEBUG_CONFIG_PROPERTIES
|
||||||
dump_properties (config);
|
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);
|
||||||
#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);
|
dump_objects (config);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Create a dialog having properties (describing arguments of the procedure)
|
/* Create a dialog having properties (describing arguments of the procedure)
|
||||||
* taken from the config.
|
* taken from the config.
|
||||||
@ -216,22 +207,15 @@ script_fu_dialog_run (GimpProcedure *procedure,
|
|||||||
not_canceled = gimp_procedure_dialog_run (dialog);
|
not_canceled = gimp_procedure_dialog_run (dialog);
|
||||||
/* Assert config holds validated arg values from a user interaction. */
|
/* Assert config holds validated arg values from a user interaction. */
|
||||||
|
|
||||||
#if DEBUG_CONFIG_PROPERTIES
|
#if DEBUG_CONFIG_PROPERTIES
|
||||||
dump_objects (config);
|
dump_objects (config);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (not_canceled)
|
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,
|
result = script_fu_interpret_image_proc (procedure, script,
|
||||||
image, n_drawables, drawables,
|
image, n_drawables, drawables,
|
||||||
final_args);
|
config);
|
||||||
|
|
||||||
gimp_value_array_unref (final_args);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -240,13 +224,5 @@ script_fu_dialog_run (GimpProcedure *procedure,
|
|||||||
|
|
||||||
gtk_widget_destroy ((GtkWidget*) dialog);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,6 @@ GimpValueArray *script_fu_dialog_run (GimpProcedure *procedure,
|
|||||||
GimpImage *image,
|
GimpImage *image,
|
||||||
guint n_drawables,
|
guint n_drawables,
|
||||||
GimpDrawable **drawables,
|
GimpDrawable **drawables,
|
||||||
const GimpValueArray *args);
|
GimpProcedureConfig *config);
|
||||||
|
|
||||||
#endif /* __SCRIPT_FU_DIALOG_H__ */
|
#endif /* __SCRIPT_FU_DIALOG_H__ */
|
||||||
|
@ -53,12 +53,12 @@
|
|||||||
* Since 3.0
|
* Since 3.0
|
||||||
*/
|
*/
|
||||||
GimpValueArray *
|
GimpValueArray *
|
||||||
script_fu_run_image_procedure ( GimpProcedure *procedure, /* GimpImageProcedure */
|
script_fu_run_image_procedure (GimpProcedure *procedure, /* GimpImageProcedure */
|
||||||
GimpRunMode run_mode,
|
GimpRunMode run_mode,
|
||||||
GimpImage *image,
|
GimpImage *image,
|
||||||
guint n_drawables,
|
guint n_drawables,
|
||||||
GimpDrawable **drawables,
|
GimpDrawable **drawables,
|
||||||
const GimpValueArray *other_args,
|
GimpProcedureConfig *config,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -77,33 +77,36 @@ script_fu_run_image_procedure ( GimpProcedure *procedure, /* GimpImagePr
|
|||||||
{
|
{
|
||||||
case GIMP_RUN_INTERACTIVE:
|
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. */
|
/* 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
|
else
|
||||||
{
|
{
|
||||||
/* No "other" args for user to choose. No config to maintain. */
|
/* 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;
|
break;
|
||||||
}
|
}
|
||||||
case GIMP_RUN_NONINTERACTIVE:
|
case GIMP_RUN_NONINTERACTIVE:
|
||||||
{
|
{
|
||||||
/* A call from another PDB procedure.
|
/* 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.
|
* 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;
|
break;
|
||||||
}
|
}
|
||||||
case GIMP_RUN_WITH_LAST_VALS:
|
case GIMP_RUN_WITH_LAST_VALS:
|
||||||
{
|
{
|
||||||
/* User invoked from a menu "Filter>Run with last values".
|
/* 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;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
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);
|
result = gimp_procedure_new_return_values (procedure, GIMP_PDB_CALLING_ERROR, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ GimpValueArray *script_fu_run_image_procedure (GimpProcedure *procedure,
|
|||||||
GimpImage *image,
|
GimpImage *image,
|
||||||
guint n_drawables,
|
guint n_drawables,
|
||||||
GimpDrawable **drawables,
|
GimpDrawable **drawables,
|
||||||
const GimpValueArray *args,
|
GimpProcedureConfig *config,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
|
|
||||||
#endif /* __SCRIPT_FU_RUN_FUNC__ */
|
#endif /* __SCRIPT_FU_RUN_FUNC__ */
|
||||||
|
@ -160,10 +160,9 @@ script_fu_script_create_PDB_procedure (GimpPlugIn *plug_in,
|
|||||||
g_debug ("script_fu_script_create_PDB_procedure: %s, plugin type %i, image_proc",
|
g_debug ("script_fu_script_create_PDB_procedure: %s, plugin type %i, image_proc",
|
||||||
script->name, plug_in_type);
|
script->name, plug_in_type);
|
||||||
|
|
||||||
procedure = gimp_image_procedure_new (
|
procedure = gimp_image_procedure_new2 (plug_in, script->name,
|
||||||
plug_in, script->name,
|
|
||||||
plug_in_type,
|
plug_in_type,
|
||||||
(GimpRunImageFunc) script_fu_run_image_procedure,
|
(GimpRunImageFunc2) script_fu_run_image_procedure,
|
||||||
script, /* user_data, pointer in extension-script-fu process */
|
script, /* user_data, pointer in extension-script-fu process */
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user