app: add a "Filters > Generic > GEGL Operations" submenu with generated actions.

Since we now generate actions for GEGL ops, we might as well generate menu items
for these too.

What I did:

- Move the "GEGL Operation…" tool (generic dialog with a drop-down list of all
  non-ignored GEGL ops) to Tools menu.
- Create a "GEGL Operations" submenu in Filters > Generic.
- Move "GEGL Graph" to the top of this new submenu.
- Generate a new menu item for each generated action tied to a GEGL plug-in,
  alphabetically sorted.
This commit is contained in:
Jehan 2023-04-13 22:58:28 +02:00
parent 0568866871
commit 747cbf70db
15 changed files with 89 additions and 40 deletions

View File

@ -24,7 +24,7 @@
#include "actions-types.h"
#include "core/gimp-filter-history.h"
#include "core/gimp-filter.h"
#include "core/gimpimage.h"
#include "core/gimplayermask.h"

View File

@ -32,7 +32,7 @@
#include "operations/gimpoperationsettings.h"
#include "core/gimp.h"
#include "core/gimp-filter-history.h"
#include "core/gimp-filter.h"
#include "core/gimpimage.h"
#include "core/gimpprogress.h"

View File

@ -26,7 +26,7 @@
#include "actions-types.h"
#include "core/gimp.h"
#include "core/gimp-filter-history.h"
#include "core/gimp-filter.h"
#include "core/gimpcontainer.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"

View File

@ -54,8 +54,8 @@ libappcore_a_sources = \
gimp-data-factories.h \
gimp-edit.c \
gimp-edit.h \
gimp-filter-history.c \
gimp-filter-history.h \
gimp-filter.c \
gimp-filter.h \
gimp-gradients.c \
gimp-gradients.h \
gimp-gui.c \

View File

@ -1,7 +1,7 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
*
* gimp-filter-history.c
* gimp-filter.c
*
* 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
@ -31,7 +31,7 @@
#include "config/gimpcoreconfig.h"
#include "gimp.h"
#include "gimp-filter-history.h"
#include "gimp-filter.h"
#include "pdb/gimpprocedure.h"
@ -143,6 +143,40 @@ gimp_filter_history_clear (Gimp *gimp)
}
}
void
gimp_filter_gegl_ops_add (Gimp *gimp,
const gchar *action_name,
const gchar *op_name)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (action_name != NULL);
g_return_if_fail (op_name != NULL);
g_hash_table_replace (gimp->filter_gegl_ops, g_strdup (action_name), g_strdup (op_name));
}
const gchar *
gimp_filter_gegl_ops_get (Gimp *gimp,
const gchar *action_name)
{
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (action_name != NULL, NULL);
return g_hash_table_lookup (gimp->filter_gegl_ops, action_name);
}
GList *
gimp_filter_gegl_ops_list (Gimp *gimp)
{
GList *actions;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
actions = g_hash_table_get_keys (gimp->filter_gegl_ops);
return g_list_sort (actions, (GCompareFunc) g_strcmp0);
}
/* private functions */

View File

@ -1,7 +1,7 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimp-filter-history.h
* gimp-filter.h
*
* 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
@ -17,8 +17,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_FILTER_HISTORY_H__
#define __GIMP_FILTER_HISTORY_H__
#ifndef __GIMP__FILTER_H__
#define __GIMP__FILTER_H__
gint gimp_filter_history_size (Gimp *gimp);
@ -31,5 +31,12 @@ void gimp_filter_history_remove (Gimp *gimp,
GimpProcedure *procedure);
void gimp_filter_history_clear (Gimp *gimp);
void gimp_filter_gegl_ops_add (Gimp *gimp,
const gchar *action_name,
const gchar *op_name);
const gchar * gimp_filter_gegl_ops_get (Gimp *gimp,
const gchar *action_name);
GList * gimp_filter_gegl_ops_list (Gimp *gimp);
#endif /* __GIMP_FILTER_HISTORY_H__ */
#endif /* __GIMP__FILTER_H__ */

View File

@ -47,7 +47,7 @@
#include "gimp.h"
#include "gimp-contexts.h"
#include "gimp-data-factories.h"
#include "gimp-filter-history.h"
#include "gimp-filter.h"
#include "gimp-memsize.h"
#include "gimp-modules.h"
#include "gimp-parasites.h"
@ -303,6 +303,8 @@ gimp_constructed (GObject *object)
gimp->plug_in_manager = gimp_plug_in_manager_new (gimp);
gimp->pdb = gimp_pdb_new (gimp);
gimp->filter_gegl_ops = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
xcf_init (gimp);
file_data_init (gimp);
@ -434,6 +436,8 @@ gimp_finalize (GObject *object)
if (gimp->module_db)
gimp_modules_exit (gimp);
g_hash_table_unref (gimp->filter_gegl_ops);
gimp_paint_exit (gimp);
g_clear_object (&gimp->parasites);
@ -486,6 +490,7 @@ gimp_get_memsize (GimpObject *object,
(GimpMemsizeFunc)
gimp_object_get_memsize,
gui_size);
/* TODO: get memsize of gimp->filter_gegl_ops */
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->image_table), 0);
memsize += gimp_object_get_memsize (GIMP_OBJECT (gimp->item_table), 0);

View File

@ -83,6 +83,7 @@ struct _Gimp
GimpPlugInManager *plug_in_manager;
GList *filter_history;
GHashTable *filter_gegl_ops; /* Map generated action names to GEGL operation names. */
GimpContainer *images;
guint32 next_guide_id;

View File

@ -30,7 +30,7 @@ libappcore_sources = [
'gimp-contexts.c',
'gimp-data-factories.c',
'gimp-edit.c',
'gimp-filter-history.c',
'gimp-filter.c',
'gimp-gradients.c',
'gimp-gui.c',
'gimp-internal-data.c',

View File

@ -32,7 +32,7 @@
#include "config/gimpdisplayconfig.h"
#include "core/gimp.h"
#include "core/gimp-filter-history.h"
#include "core/gimp-filter.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpimage-pick-item.h"

View File

@ -23,7 +23,7 @@
#include "menus-types.h"
#include "core/gimp.h"
#include "core/gimp-filter-history.h"
#include "core/gimp-filter.h"
#include "widgets/gimpuimanager.h"
@ -36,7 +36,8 @@ void
filters_menu_setup (GimpUIManager *manager,
const gchar *ui_path)
{
gint i;
GList *actions;
gint i;
g_return_if_fail (GIMP_IS_UI_MANAGER (manager));
g_return_if_fail (ui_path != NULL);
@ -52,4 +53,10 @@ filters_menu_setup (GimpUIManager *manager,
g_free (action_name);
}
actions = gimp_filter_gegl_ops_list (manager->gimp);
for (GList *iter = actions; iter; iter = iter->next)
gimp_ui_manager_add_ui (manager, "/Filters/Generic/GEGL Operations",
iter->data, NULL, FALSE);
g_list_free (actions);
}

View File

@ -32,7 +32,7 @@
#include "config/gimpcoreconfig.h"
#include "core/gimp.h"
#include "core/gimp-filter-history.h"
#include "core/gimp-filter.h"
#include "core/gimp-memsize.h"
#include "core/gimpmarshal.h"

View File

@ -30,6 +30,7 @@
#include "tools-types.h"
#include "core/gimp.h"
#include "core/gimp-filter.h"
#include "core/gimptoolinfo.h"
#include "widgets/gimphelp-ids.h"
@ -57,7 +58,7 @@ static void gimp_gegl_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *display);
static GList * gimp_get_geglopclasses (void);
static GList * gimp_get_geglopclasses (void);
static void gimp_gegl_tool_dialog (GimpFilterTool *filter_tool);
@ -76,12 +77,9 @@ void
gimp_gegl_tool_register (GimpToolRegisterCallback callback,
gpointer data)
{
GimpGeglToolClass *klass;
Gimp *gimp = GIMP (data);
GList *opclasses;
GList *iter;
klass = g_type_class_ref (GIMP_TYPE_GEGL_TOOL);
Gimp *gimp = GIMP (data);
GList *opclasses;
GList *iter;
(* callback) (GIMP_TYPE_GEGL_TOOL,
GIMP_TYPE_FILTER_OPTIONS,
@ -131,7 +129,8 @@ gimp_gegl_tool_register (GimpToolRegisterCallback callback,
* and ending with "-tool".
*/
identifier = g_strdup_printf ("gimp-%s-tool", action_name + strlen ("tools-"));
g_hash_table_replace (klass->generated_ops, action_name, g_strdup (op_name));
gimp_filter_gegl_ops_add (gimp, action_name, op_name);
g_free (action_name);
if (g_str_has_prefix (op_name, "gegl:"))
icon_name = GIMP_ICON_GEGL;
@ -163,7 +162,6 @@ gimp_gegl_tool_register (GimpToolRegisterCallback callback,
}
g_list_free (opclasses);
g_type_class_unref (klass);
}
static void
@ -175,12 +173,6 @@ gimp_gegl_tool_class_init (GimpGeglToolClass *klass)
tool_class->control = gimp_gegl_tool_control;
filter_tool_class->dialog = gimp_gegl_tool_dialog;
/* Store the mapping from tool identifier to operation name.
* This data is leaking, otherwise we'd have to register a dynamic type with a
* class_finalize() class method.
**/
klass->generated_ops = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
}
static void
@ -502,12 +494,10 @@ gimp_gegl_tool_dialog (GimpFilterTool *filter_tool)
GList *opclasses;
GList *iter;
gchar *action_name;
gchar *show_op_name = NULL;
GimpGeglToolClass *klass;
const gchar *show_op_name;
klass = GIMP_GEGL_TOOL_GET_CLASS (tool);
action_name = gimp_tool_info_get_action_name (tool_info);
show_op_name = g_hash_table_lookup (klass->generated_ops, action_name);
show_op_name = gimp_filter_gegl_ops_get (tool_info->gimp, action_name);
g_free (action_name);
GIMP_FILTER_TOOL_CLASS (parent_class)->dialog (filter_tool);

View File

@ -45,8 +45,6 @@ struct _GimpGeglTool
struct _GimpGeglToolClass
{
GimpOperationToolClass parent_class;
GHashTable *generated_ops;
};

View File

@ -605,6 +605,9 @@
<item><attribute name="action">app.tools-measure</attribute></item>
<item><attribute name="action">app.tools-zoom</attribute></item>
</section>
<section>
<item><attribute name="action">app.tools-gegl</attribute></item>
</section>
<section>
<item><attribute name="action">app.dialogs-toolbox</attribute></item>
<item><attribute name="action">app.context-colors-default</attribute></item>
@ -711,11 +714,15 @@
<attribute name="label" translatable="yes" context="filters-action">_Generic</attribute>
<item><attribute name="action">app.filters-convolution-matrix</attribute></item>
<item><attribute name="action">app.filters-distance-map</attribute></item>
<item><attribute name="action">app.tools-gegl</attribute></item>
<item><attribute name="action">app.filters-gegl-graph</attribute></item>
<item><attribute name="action">app.filters-normal-map</attribute></item>
<item><attribute name="action">app.filters-dilate</attribute></item>
<item><attribute name="action">app.filters-erode</attribute></item>
<submenu>
<attribute name="label" translatable="yes" context="filters-action">_GEGL Operations</attribute>
<section>
<item><attribute name="action">app.filters-gegl-graph</attribute></item>
</section>
</submenu>
</submenu>
<submenu>
<attribute name="label" translatable="yes" context="filters-action">C_ombine</attribute>