Commit ed2fb294 authored by Michael Natterer's avatar Michael Natterer 😴

app: add a "settings" argument to GimpGeglProcedure

which gets added automatically by procedure_commands_get_display_args().

Move the non-interactive and run-with-last-vals code to
gimp_gegl_procedure_execute() (not execute_async()) because it makes
more sence to call it synchronously anyway (not implemented yet).

This commit should change no behavior.
parent 14bcde2c
......@@ -81,7 +81,7 @@ filters_repeat_cmd_callback (GtkAction *action,
{
GimpValueArray *args;
args = procedure_commands_get_display_args (procedure, display);
args = procedure_commands_get_display_args (procedure, display, NULL);
if (args)
{
......@@ -109,7 +109,7 @@ filters_history_cmd_callback (GtkAction *action,
return_if_no_gimp (gimp, data);
return_if_no_display (display, data);
args = procedure_commands_get_display_args (procedure, display);
args = procedure_commands_get_display_args (procedure, display, NULL);
if (args)
{
......
......@@ -233,9 +233,29 @@ gimp_gegl_procedure_execute (GimpProcedure *procedure,
GimpValueArray *args,
GError **error)
{
return GIMP_PROCEDURE_CLASS (parent_class)->execute (procedure, gimp,
context, progress,
args, error);
GimpImage *image;
GimpDrawable *drawable;
GimpObject *settings;
GeglNode *node;
image = gimp_value_get_image (gimp_value_array_index (args, 1), gimp);
drawable = gimp_value_get_drawable (gimp_value_array_index (args, 2), gimp);
settings = g_value_get_object (gimp_value_array_index (args, 3));
node = gegl_node_new_child (NULL,
"operation", procedure->original_name,
NULL);
if (settings)
gimp_operation_config_sync_node (settings, node);
gimp_drawable_apply_operation (drawable, progress,
gimp_procedure_get_label (procedure),
node);
g_object_unref (node);
gimp_image_flush (image);
return gimp_procedure_get_return_values (procedure, TRUE, NULL);
}
static void
......@@ -246,59 +266,48 @@ gimp_gegl_procedure_execute_async (GimpProcedure *procedure,
GimpValueArray *args,
GimpObject *display)
{
GimpRunMode run_mode = g_value_get_int (gimp_value_array_index (args, 0));
GimpObject *settings;
GimpContainer *container;
GimpTool *active_tool;
GType config_type;
config_type = gimp_operation_config_get_type (gimp,
procedure->original_name,
gimp_viewable_get_icon_name (GIMP_VIEWABLE (procedure)),
GIMP_TYPE_SETTINGS);
container =
gimp_operation_config_get_container (gimp, config_type,
(GCompareFunc) gimp_settings_compare);
GimpRunMode run_mode;
GimpObject *settings;
GimpTool *active_tool;
/* the last used settings */
settings = gimp_container_get_child_by_index (container, 0);
run_mode = g_value_get_int (gimp_value_array_index (args, 0));
settings = g_value_get_object (gimp_value_array_index (args, 3));
/* only use the settings if they are automatically created "last used"
* values, not if they were saved explicitly and have a zero timestamp;
* and if they are not a separator.
*/
if (settings &&
(GIMP_SETTINGS (settings)->time == 0 ||
! gimp_object_get_name (settings)))
if (! settings)
{
settings = NULL;
}
/* if we didn't get settings passed, get the last used settings */
if (run_mode == GIMP_RUN_WITH_LAST_VALS)
{
if (settings)
{
GimpImage *image;
GimpDrawable *drawable;
GeglNode *node;
GType config_type;
GimpContainer *container;
node = gegl_node_new_child (NULL,
"operation", procedure->original_name,
NULL);
gimp_operation_config_sync_node (settings, node);
config_type = G_VALUE_TYPE (gimp_value_array_index (args, 3));
image = gimp_value_get_image (gimp_value_array_index (args, 1),
gimp);
drawable = gimp_value_get_drawable (gimp_value_array_index (args, 2),
gimp);
container = gimp_operation_config_get_container (gimp, config_type,
(GCompareFunc)
gimp_settings_compare);
gimp_drawable_apply_operation (drawable, progress,
gimp_procedure_get_label (procedure),
node);
g_object_unref (node);
settings = gimp_container_get_child_by_index (container, 0);
/* only use the settings if they are automatically created
* "last used" values, not if they were saved explicitly and
* have a zero timestamp; and if they are not a separator.
*/
if (settings &&
(GIMP_SETTINGS (settings)->time == 0 ||
! gimp_object_get_name (settings)))
{
settings = NULL;
}
}
gimp_image_flush (image);
if (run_mode == GIMP_RUN_NONINTERACTIVE ||
run_mode == GIMP_RUN_WITH_LAST_VALS)
{
if (settings || run_mode == GIMP_RUN_NONINTERACTIVE)
{
g_value_set_object (gimp_value_array_index (args, 3), settings);
gimp_procedure_execute (procedure, gimp, context, progress,
args, NULL);
return;
}
......@@ -372,12 +381,16 @@ gimp_gegl_procedure_new (Gimp *gimp,
const gchar *help_id)
{
GimpProcedure *procedure;
GType config_type;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (operation != NULL, NULL);
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (menu_label != NULL, NULL);
config_type = gimp_operation_config_get_type (gimp, operation, icon_name,
GIMP_TYPE_SETTINGS);
procedure = g_object_new (GIMP_TYPE_GEGL_PROCEDURE, NULL);
GIMP_GEGL_PROCEDURE (procedure)->menu_label = g_strdup (menu_label);
......@@ -393,9 +406,9 @@ gimp_gegl_procedure_new (Gimp *gimp,
NULL);
gimp_procedure_add_argument (procedure,
gimp_param_spec_int32 ("dummy-param",
"Dummy Param",
"Dummy parameter",
gimp_param_spec_int32 ("run-mode",
"Run mode",
"Run mode",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
......@@ -410,6 +423,12 @@ gimp_gegl_procedure_new (Gimp *gimp,
"Input drawable",
gimp, TRUE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_object ("settings",
"Settings",
"Settings",
config_type,
GIMP_PARAM_READWRITE));
return procedure;
}
......@@ -130,7 +130,7 @@ plug_in_run_cmd_callback (GtkAction *action,
{
display = action_data_get_display (data);
args = procedure_commands_get_display_args (procedure, display);
args = procedure_commands_get_display_args (procedure, display, NULL);
}
break;
......
......@@ -180,7 +180,8 @@ procedure_commands_get_item_args (GimpProcedure *procedure,
GimpValueArray *
procedure_commands_get_display_args (GimpProcedure *procedure,
GimpDisplay *display)
GimpDisplay *display,
GimpObject *settings)
{
GimpValueArray *args;
gint n_args = 0;
......@@ -216,8 +217,7 @@ procedure_commands_get_display_args (GimpProcedure *procedure,
if (image)
{
gimp_value_set_image (gimp_value_array_index (args, n_args),
image);
gimp_value_set_image (gimp_value_array_index (args, n_args), image);
n_args++;
if (gimp_value_array_length (args) > n_args &&
......@@ -241,6 +241,14 @@ procedure_commands_get_display_args (GimpProcedure *procedure,
}
}
if (gimp_value_array_length (args) > n_args &&
g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (procedure->args[n_args]),
GIMP_TYPE_OBJECT))
{
g_value_set_object (gimp_value_array_index (args, n_args), settings);
n_args++;
}
gimp_value_array_truncate (args, n_args);
return args;
......
......@@ -28,7 +28,8 @@ GimpValueArray * procedure_commands_get_item_args (GimpProcedure *procedure,
GimpImage *image,
GimpItem *item);
GimpValueArray * procedure_commands_get_display_args (GimpProcedure *procedure,
GimpDisplay *display);
GimpDisplay *display,
GimpObject *settings);
gboolean procedure_commands_run_procedure (GimpProcedure *procedure,
Gimp *gimp,
......
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