app: add member "default_run_mode" to GimpGeglProcedure

which determines if a filter is applied directly (RUN_NONINTERACTIVE)
or asynchronously using GimpOperationTool (RUN_INTERACTIVE).

Split filter actions in two groups, one for direct apply and one for
interactive apply, which have separate callbacks that create
GimpGeglProcedures with the right default_run_mode set.

(After doing this distinction automatically based on the existance of
editable properties, I figured will might want direct apply also for
filters that do have properties, such as e.g. dilate and erode, which
are just value-propagate with some constant property values)
This commit is contained in:
Michael Natterer 2017-05-31 23:41:37 +02:00
parent 320a3db133
commit 383419926b
5 changed files with 123 additions and 40 deletions

View File

@ -96,6 +96,24 @@ static const GimpActionEntry filters_menu_actions[] =
};
static const GimpStringActionEntry filters_actions[] =
{
{ "filters-invert-linear", GIMP_ICON_INVERT,
NC_("filters-action", "_Linear Invert"), NULL, NULL,
"gegl:invert-linear",
GIMP_HELP_FILTER_INVERT_LINEAR },
{ "filters-invert-perceptual", GIMP_ICON_INVERT,
NC_("filters-action", "In_vert"), NULL, NULL,
"gegl:invert-gamma",
GIMP_HELP_FILTER_INVERT_PERCEPTUAL },
{ "filters-invert-value", GIMP_ICON_GEGL,
NC_("filters-action", "_Value Invert"), NULL, NULL,
"gegl:value-invert",
GIMP_HELP_FILTER_INVERT_VALUE }
};
static const GimpStringActionEntry filters_interactive_actions[] =
{
{ "filters-alien-map", GIMP_ICON_GEGL,
NC_("filters-action", "_Alien Map..."), NULL, NULL,
@ -307,21 +325,6 @@ static const GimpStringActionEntry filters_actions[] =
"gegl:image-gradient",
GIMP_HELP_FILTER_IMAGE_GRADIENT },
{ "filters-invert-linear", GIMP_ICON_INVERT,
NC_("filters-action", "_Linear Invert"), NULL, NULL,
"gegl:invert-linear",
GIMP_HELP_FILTER_INVERT_LINEAR },
{ "filters-invert-perceptual", GIMP_ICON_INVERT,
NC_("filters-action", "In_vert"), NULL, NULL,
"gegl:invert-gamma",
GIMP_HELP_FILTER_INVERT_PERCEPTUAL },
{ "filters-invert-value", GIMP_ICON_GEGL,
NC_("filters-action", "_Value Invert"), NULL, NULL,
"gegl:value-invert",
GIMP_HELP_FILTER_INVERT_VALUE },
{ "filters-kaleidoscope", GIMP_ICON_GEGL,
NC_("filters-action", "_Kaleidoscope..."), NULL, NULL,
"gegl:mirrors",
@ -639,7 +642,12 @@ filters_actions_setup (GimpActionGroup *group)
gimp_action_group_add_string_actions (group, "filters-action",
filters_actions,
G_N_ELEMENTS (filters_actions),
G_CALLBACK (filters_filter_cmd_callback));
G_CALLBACK (filters_apply_cmd_callback));
gimp_action_group_add_string_actions (group, "filters-action",
filters_interactive_actions,
G_N_ELEMENTS (filters_interactive_actions),
G_CALLBACK (filters_apply_interactive_cmd_callback));
gimp_action_group_add_enum_actions (group, "filters-action",
filters_repeat_actions,
@ -658,6 +666,18 @@ filters_actions_setup (GimpActionGroup *group)
description);
}
for (i = 0; i < G_N_ELEMENTS (filters_interactive_actions); i++)
{
const GimpStringActionEntry *entry = &filters_interactive_actions[i];
const gchar *description;
description = gegl_operation_get_key (entry->value, "description");
if (description)
gimp_action_group_set_action_tooltip (group, entry->name,
description);
}
n_entries = gimp_filter_history_size (group->gimp);
entries = g_new0 (GimpProcedureActionEntry, n_entries);

View File

@ -38,15 +38,41 @@
/* public functions */
void
filters_filter_cmd_callback (GtkAction *action,
const gchar *operation,
gpointer data)
filters_apply_cmd_callback (GtkAction *action,
const gchar *operation,
gpointer data)
{
GimpDisplay *display;
GimpProcedure *procedure;
return_if_no_display (display, data);
procedure = gimp_gegl_procedure_new (action_data_get_gimp (data),
GIMP_RUN_NONINTERACTIVE,
operation,
gtk_action_get_name (action),
gtk_action_get_label (action),
gtk_action_get_tooltip (action),
gtk_action_get_icon_name (action),
g_object_get_qdata (G_OBJECT (action),
GIMP_HELP_ID));
gimp_filter_history_add (action_data_get_gimp (data), procedure);
filters_history_cmd_callback (NULL, procedure, data);
g_object_unref (procedure);
}
void
filters_apply_interactive_cmd_callback (GtkAction *action,
const gchar *operation,
gpointer data)
{
GimpDisplay *display;
GimpProcedure *procedure;
return_if_no_display (display, data);
procedure = gimp_gegl_procedure_new (action_data_get_gimp (data),
GIMP_RUN_INTERACTIVE,
operation,
gtk_action_get_name (action),
gtk_action_get_label (action),
@ -80,18 +106,32 @@ filters_repeat_cmd_callback (GtkAction *action,
if (procedure)
{
GimpValueArray *args;
gboolean success = FALSE;
args = procedure_commands_get_display_args (procedure, display, NULL);
if (args)
{
if (procedure_commands_run_procedure_async (procedure, gimp,
GIMP_PROGRESS (display),
run_mode, args,
display))
if (GIMP_IS_GEGL_PROCEDURE (procedure) &&
GIMP_GEGL_PROCEDURE (procedure)->default_run_mode ==
GIMP_RUN_NONINTERACTIVE)
{
gimp_filter_history_add (gimp, procedure);
success =
procedure_commands_run_procedure (procedure, gimp,
GIMP_PROGRESS (display),
args);
}
else
{
success =
procedure_commands_run_procedure_async (procedure, gimp,
GIMP_PROGRESS (display),
run_mode, args,
display);
}
if (success)
gimp_filter_history_add (gimp, procedure);
gimp_value_array_unref (args);
}
@ -113,13 +153,28 @@ filters_history_cmd_callback (GtkAction *action,
if (args)
{
if (procedure_commands_run_procedure_async (procedure, gimp,
GIMP_PROGRESS (display),
GIMP_RUN_INTERACTIVE, args,
display))
gboolean success = FALSE;
if (GIMP_IS_GEGL_PROCEDURE (procedure) &&
GIMP_GEGL_PROCEDURE (procedure)->default_run_mode ==
GIMP_RUN_NONINTERACTIVE)
{
gimp_filter_history_add (gimp, procedure);
success =
procedure_commands_run_procedure (procedure, gimp,
GIMP_PROGRESS (display),
args);
}
else
{
success =
procedure_commands_run_procedure_async (procedure, gimp,
GIMP_PROGRESS (display),
GIMP_RUN_INTERACTIVE, args,
display);
}
if (success)
gimp_filter_history_add (gimp, procedure);
gimp_value_array_unref (args);
}

View File

@ -19,16 +19,19 @@
#define __FILTERS_COMMANDS_H__
void filters_filter_cmd_callback (GtkAction *action,
const gchar *operation,
gpointer data);
void filters_apply_cmd_callback (GtkAction *action,
const gchar *operation,
gpointer data);
void filters_apply_interactive_cmd_callback (GtkAction *action,
const gchar *operation,
gpointer data);
void filters_repeat_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void filters_history_cmd_callback (GtkAction *action,
GimpProcedure *procedure,
gpointer data);
void filters_repeat_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void filters_history_cmd_callback (GtkAction *action,
GimpProcedure *procedure,
gpointer data);
#endif /* __FILTERS_COMMANDS_H__ */

View File

@ -373,6 +373,7 @@ gimp_gegl_procedure_execute_async (GimpProcedure *procedure,
GimpProcedure *
gimp_gegl_procedure_new (Gimp *gimp,
GimpRunMode default_run_mode,
const gchar *operation,
const gchar *name,
const gchar *menu_label,
@ -393,8 +394,9 @@ gimp_gegl_procedure_new (Gimp *gimp,
procedure = g_object_new (GIMP_TYPE_GEGL_PROCEDURE, NULL);
GIMP_GEGL_PROCEDURE (procedure)->menu_label = g_strdup (menu_label);
GIMP_GEGL_PROCEDURE (procedure)->help_id = g_strdup (help_id);
GIMP_GEGL_PROCEDURE (procedure)->default_run_mode = default_run_mode;
GIMP_GEGL_PROCEDURE (procedure)->menu_label = g_strdup (menu_label);
GIMP_GEGL_PROCEDURE (procedure)->help_id = g_strdup (help_id);
gimp_object_set_name (GIMP_OBJECT (procedure), name);
gimp_viewable_set_icon_name (GIMP_VIEWABLE (procedure), icon_name);

View File

@ -40,6 +40,8 @@ struct _GimpGeglProcedure
{
GimpProcedure parent_instance;
GimpRunMode default_run_mode;
gchar *menu_label;
gchar *label;
gchar *help_id;
@ -54,6 +56,7 @@ struct _GimpGeglProcedureClass
GType gimp_gegl_procedure_get_type (void) G_GNUC_CONST;
GimpProcedure * gimp_gegl_procedure_new (Gimp *gimp,
GimpRunMode default_run_mode,
const gchar *operation,
const gchar *name,
const gchar *menu_label,