Bug 792470 - Some filters e.g. "Levels" are not added to "Repeat last" history

The four remaining "classic" color tools (Brightness-Contrast, Curves,
Levels and Threshold) are in fact just special UIs for otherwise
completely normal filter ops.

Add normal filter actions for them and invoke them like all
other filters, which makes them show up in the filter history
automatically.

The only small hack needed is to special case them in
gimp_gegl_procedure_execute_async() so the right tools are created
instead of the default GimpOperationTool. Also, blacklist the
automatically generated tools actions from action search and the
shortcut editor.
This commit is contained in:
Michael Natterer 2018-01-14 15:42:29 +01:00
parent 458e313000
commit b23f231a1a
13 changed files with 99 additions and 28 deletions

View File

@ -183,6 +183,11 @@ static const GimpStringActionEntry filters_interactive_actions[] =
"gegl:apply-lens",
GIMP_HELP_FILTER_APPLY_LENS },
{ "filters-brightness-contrast", GIMP_ICON_TOOL_BRIGHTNESS_CONTRAST,
NC_("filters-action", "B_rightness-Contrast..."), NULL, NULL,
"gimp:brightness-contrast",
GIMP_HELP_TOOL_BRIGHTNESS_CONTRAST },
{ "filters-bump-map", GIMP_ICON_GEGL,
NC_("filters-action", "_Bump Map..."), NULL, NULL,
"gegl:bump-map",
@ -258,6 +263,11 @@ static const GimpStringActionEntry filters_interactive_actions[] =
"gegl:cubism",
GIMP_HELP_FILTER_CUBISM },
{ "filters-curves", GIMP_ICON_TOOL_CURVES,
NC_("filters-action", "_Curves..."), NULL, NULL,
"gimp:curves",
GIMP_HELP_TOOL_CURVES },
{ "filters-deinterlace", GIMP_ICON_GEGL,
NC_("filters-action", "_Deinterlace..."), NULL, NULL,
"gegl:deinterlace",
@ -398,6 +408,11 @@ static const GimpStringActionEntry filters_interactive_actions[] =
"gegl:lens-flare",
GIMP_HELP_FILTER_LENS_FLARE },
{ "filters-levels", GIMP_ICON_TOOL_LEVELS,
NC_("filters-action", "_Levels..."), NULL, NULL,
"gimp:levels",
GIMP_HELP_TOOL_LEVELS },
{ "filters-mantiuk-2006", GIMP_ICON_GEGL,
NC_("filters-action", "_Mantiuk 2006..."), NULL, NULL,
"gegl:mantiuk06",
@ -618,6 +633,11 @@ static const GimpStringActionEntry filters_interactive_actions[] =
"gegl:supernova",
GIMP_HELP_FILTER_SUPERNOVA },
{ "filters-threshold", GIMP_ICON_TOOL_THRESHOLD,
NC_("filters-action", "_Threshold..."), NULL, NULL,
"gimp:threshold",
GIMP_HELP_TOOL_THRESHOLD },
{ "filters-threshold-alpha", GIMP_ICON_GEGL,
NC_("filters-action", "_Threshold Alpha..."), NULL, NULL,
"gimp:threshold-alpha",
@ -808,6 +828,7 @@ filters_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("filters-antialias", writable);
SET_SENSITIVE ("filters-apply-canvas", writable);
SET_SENSITIVE ("filters-apply-lens", writable);
SET_SENSITIVE ("filters-brightness-contrast", writable);
SET_SENSITIVE ("filters-bump-map", writable);
SET_SENSITIVE ("filters-c2g", writable && !gray);
SET_SENSITIVE ("filters-cartoon", writable);
@ -824,6 +845,7 @@ filters_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("filters-component-extract", writable);
SET_SENSITIVE ("filters-convolution-matrix", writable);
SET_SENSITIVE ("filters-cubism", writable);
SET_SENSITIVE ("filters-curves", writable);
SET_SENSITIVE ("filters-deinterlace", writable);
SET_SENSITIVE ("filters-desaturate", writable && !gray);
SET_SENSITIVE ("filters-difference-of-gaussians", writable);
@ -857,6 +879,7 @@ filters_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("filters-kaleidoscope", writable);
SET_SENSITIVE ("filters-lens-distortion", writable);
SET_SENSITIVE ("filters-lens-flare", writable);
SET_SENSITIVE ("filters-levels", writable);
SET_SENSITIVE ("filters-mantiuk-2006", writable);
SET_SENSITIVE ("filters-maze", writable);
SET_SENSITIVE ("filters-median-blur", writable);
@ -901,6 +924,7 @@ filters_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("filters-stretch-contrast-hsv", writable);
SET_SENSITIVE ("filters-stress", writable);
SET_SENSITIVE ("filters-supernova", writable);
SET_SENSITIVE ("filters-threshold", writable);
SET_SENSITIVE ("filters-threshold-alpha", writable && alpha);
SET_SENSITIVE ("filters-tile-glass", writable);
SET_SENSITIVE ("filters-tile-paper", writable);

View File

@ -2,7 +2,7 @@
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpgeglprocedure.c
* Copyright (C) 2016 Michael Natterer <mitch@gimp.org>
* Copyright (C) 2016-2018 Michael Natterer <mitch@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -272,6 +272,7 @@ gimp_gegl_procedure_execute_async (GimpProcedure *procedure,
GimpRunMode run_mode;
GimpObject *settings;
GimpTool *active_tool;
const gchar *tool_name;
run_mode = g_value_get_int (gimp_value_array_index (args, 0));
settings = g_value_get_object (gimp_value_array_index (args, 3));
@ -321,6 +322,27 @@ gimp_gegl_procedure_execute_async (GimpProcedure *procedure,
gimp_procedure_get_label (procedure));
}
if (! strcmp (procedure->original_name, "gimp:brightness-contrast"))
{
tool_name = "gimp-brightness-contrast-tool";
}
else if (! strcmp (procedure->original_name, "gimp:curves"))
{
tool_name = "gimp-curves-tool";
}
else if (! strcmp (procedure->original_name, "gimp:levels"))
{
tool_name = "gimp-levels-tool";
}
else if (! strcmp (procedure->original_name, "gimp:threshold"))
{
tool_name = "gimp-threshold-tool";
}
else
{
tool_name = "gimp-operation-tool";
}
active_tool = tool_manager_get_active (gimp);
/* do not use the passed context because we need to set the active
@ -328,10 +350,9 @@ gimp_gegl_procedure_execute_async (GimpProcedure *procedure,
*/
context = gimp_get_user_context (gimp);
if (G_TYPE_FROM_INSTANCE (active_tool) != GIMP_TYPE_OPERATION_TOOL)
if (strcmp (gimp_object_get_name (active_tool->tool_info), tool_name))
{
GimpToolInfo *tool_info = gimp_get_tool_info (gimp,
"gimp-operation-tool");
GimpToolInfo *tool_info = gimp_get_tool_info (gimp, tool_name);
if (GIMP_IS_TOOL_INFO (tool_info))
gimp_context_set_tool (context, tool_info);
@ -343,25 +364,28 @@ gimp_gegl_procedure_execute_async (GimpProcedure *procedure,
active_tool = tool_manager_get_active (gimp);
if (GIMP_IS_OPERATION_TOOL (active_tool))
if (! strcmp (gimp_object_get_name (active_tool->tool_info), tool_name))
{
/* Remember the prodecure that created this tool, because we
* can't just switch to an operation tool using
/* Remember the prodecure that created this tool, because
* we can't just switch to an operation tool using
* gimp_context_set_tool(), we also have to go through the
* initialization code below, otherwise we end up with a dummy
* tool that does nothing. See bug #776370.
* initialization code below, otherwise we end up with a
* dummy tool that does nothing. See bug #776370.
*/
g_object_set_data_full (G_OBJECT (active_tool), "gimp-gegl-procedure",
g_object_ref (procedure),
(GDestroyNotify) g_object_unref);
gimp_operation_tool_set_operation (GIMP_OPERATION_TOOL (active_tool),
procedure->original_name,
gimp_procedure_get_label (procedure),
gimp_procedure_get_label (procedure),
gimp_procedure_get_label (procedure),
gimp_viewable_get_icon_name (GIMP_VIEWABLE (procedure)),
gimp_procedure_get_help_id (procedure));
if (! strcmp (tool_name, "gimp-operation-tool"))
{
gimp_operation_tool_set_operation (GIMP_OPERATION_TOOL (active_tool),
procedure->original_name,
gimp_procedure_get_label (procedure),
gimp_procedure_get_label (procedure),
gimp_procedure_get_label (procedure),
gimp_viewable_get_icon_name (GIMP_VIEWABLE (procedure)),
gimp_procedure_get_help_id (procedure));
}
tool_manager_initialize_active (gimp, GIMP_DISPLAY (display));

View File

@ -32,6 +32,8 @@
#include "gimpbrightnesscontrastconfig.h"
#include "gimpoperationbrightnesscontrast.h"
#include "gimp-intl.h"
static gboolean gimp_operation_brightness_contrast_process (GeglOperation *operation,
void *in_buf,
@ -60,7 +62,7 @@ gimp_operation_brightness_contrast_class_init (GimpOperationBrightnessContrastCl
gegl_operation_class_set_keys (operation_class,
"name", "gimp:brightness-contrast",
"categories", "color",
"description", "GIMP Brightness-Contrast operation",
"description", _("Adjust brightness and contrast"),
NULL);
point_class->process = gimp_operation_brightness_contrast_process;

View File

@ -34,6 +34,8 @@
#include "gimpcurvesconfig.h"
#include "gimpoperationcurves.h"
#include "gimp-intl.h"
static gboolean gimp_operation_curves_process (GeglOperation *operation,
void *in_buf,
@ -62,7 +64,7 @@ gimp_operation_curves_class_init (GimpOperationCurvesClass *klass)
gegl_operation_class_set_keys (operation_class,
"name", "gimp:curves",
"categories", "color",
"description", "GIMP Curves operation",
"description", _("Adjust color curves"),
NULL);
point_class->process = gimp_operation_curves_process;

View File

@ -31,6 +31,8 @@
#include "gimplevelsconfig.h"
#include "gimpoperationlevels.h"
#include "gimp-intl.h"
static gboolean gimp_operation_levels_process (GeglOperation *operation,
void *in_buf,
@ -59,7 +61,7 @@ gimp_operation_levels_class_init (GimpOperationLevelsClass *klass)
gegl_operation_class_set_keys (operation_class,
"name", "gimp:levels",
"categories", "color",
"description", "GIMP Levels operation",
"description", _("Adjust color levels"),
NULL);
point_class->process = gimp_operation_levels_process;

View File

@ -81,7 +81,7 @@ gimp_operation_threshold_class_init (GimpOperationThresholdClass *klass)
gegl_operation_class_set_keys (operation_class,
"name", "gimp:threshold",
"categories", "color",
"description", "GIMP Threshold operation",
"description", _("Reduce image to two colors using a threshold"),
NULL);
GIMP_CONFIG_PROP_ENUM (object_class, PROP_CHANNEL,

View File

@ -95,7 +95,7 @@ gimp_brightness_contrast_tool_register (GimpToolRegisterCallback callback,
0,
"gimp-brightness-contrast-tool",
_("Brightness-Contrast"),
_("Brightness/Contrast Tool: Adjust brightness and contrast"),
_("Adjust brightness and contrast"),
N_("B_rightness-Contrast..."), NULL,
NULL, GIMP_HELP_TOOL_BRIGHTNESS_CONTRAST,
GIMP_ICON_TOOL_BRIGHTNESS_CONTRAST,

View File

@ -140,7 +140,7 @@ gimp_curves_tool_register (GimpToolRegisterCallback callback,
0,
"gimp-curves-tool",
_("Curves"),
_("Curves Tool: Adjust color curves"),
_("Adjust color curves"),
N_("_Curves..."), NULL,
NULL, GIMP_HELP_TOOL_CURVES,
GIMP_ICON_TOOL_CURVES,

View File

@ -130,7 +130,7 @@ gimp_levels_tool_register (GimpToolRegisterCallback callback,
0,
"gimp-levels-tool",
_("Levels"),
_("Levels Tool: Adjust color levels"),
_("Adjust color levels"),
N_("_Levels..."), NULL,
NULL, GIMP_HELP_TOOL_LEVELS,
GIMP_ICON_TOOL_LEVELS,

View File

@ -85,7 +85,7 @@ gimp_threshold_tool_register (GimpToolRegisterCallback callback,
0,
"gimp-threshold-tool",
_("Threshold"),
_("Threshold Tool: Reduce image to two colors using a threshold"),
_("Reduce image to two colors using a threshold"),
N_("_Threshold..."), NULL,
NULL, GIMP_HELP_TOOL_THRESHOLD,
GIMP_ICON_TOOL_THRESHOLD,

View File

@ -330,6 +330,14 @@ gimp_action_is_gui_blacklisted (const gchar *action_name)
"tools-warp-effect-hardness-"
};
static const gchar *actions[] =
{
"tools-brightness-contrast",
"tools-curves",
"tools-levels",
"tools-threshold"
};
gint i;
if (! (action_name && *action_name))
@ -347,6 +355,12 @@ gimp_action_is_gui_blacklisted (const gchar *action_name)
return TRUE;
}
for (i = 0; i < G_N_ELEMENTS (actions); i++)
{
if (! strcmp (action_name, actions[i]))
return TRUE;
}
return FALSE;
}

View File

@ -569,9 +569,9 @@
<menuitem action="filters-saturation" />
<menuitem action="filters-exposure" />
<menuitem action="filters-shadows-highlights" />
<menuitem action="tools-brightness-contrast" />
<menuitem action="tools-levels" />
<menuitem action="tools-curves" />
<menuitem action="filters-brightness-contrast" />
<menuitem action="filters-levels" />
<menuitem action="filters-curves" />
<separator />
<placeholder name="Invert">
<menuitem action="filters-invert-perceptual" />
@ -616,7 +616,7 @@
<menuitem action="dialogs-histogram" />
</menu>
<separator />
<menuitem action="tools-threshold" />
<menuitem action="filters-threshold" />
<menuitem action="filters-colorize" />
<menuitem action="filters-posterize" />
<menuitem action="filters-color-to-alpha" />

View File

@ -280,12 +280,15 @@ app/operations/gimpcolorbalanceconfig.c
app/operations/gimpcurvesconfig.c
app/operations/gimphuesaturationconfig.c
app/operations/gimplevelsconfig.c
app/operations/gimpoperationbrightnesscontrast.c
app/operations/gimpoperationcagecoefcalc.c
app/operations/gimpoperationcagetransform.c
app/operations/gimpoperationcolorbalance.c
app/operations/gimpoperationcolorize.c
app/operations/gimpoperationcurves.c
app/operations/gimpoperationdesaturate.c
app/operations/gimpoperationhuesaturation.c
app/operations/gimpoperationlevels.c
app/operations/gimpoperationposterize.c
app/operations/gimpoperationsemiflatten.c
app/operations/gimpoperationthreshold.c