app: do not maintain manually the list of core ops with custom config object.

The list of objects where the config object is a dedicated custom class (instead
of a runtime-registered class) is well known. These are the operations
registered inside gimp_operations_init().

The list inside gimp_gegl_procedure_execute_async() which the previous commit
was updating was not right: it was still missing "gimp:hue-saturation" and
"gimp:threshold" should not have been on the list (this was generating a
CRITICAL when trying to get the "config" property on this object).

Instead let's add some init/exit() functions in gimp-operation-config API to
distinguish the operations with custom config (registered during init) with all
the others. Then we add gimp_operation_config_is_custom() which can be used
everywhere where we want to verify if an operation is using a custom-made config
object or a generated class just mirroring the operation properties.

This way, we should not get out-of-sync anymore.
This commit is contained in:
Jehan 2024-01-23 13:58:08 +01:00
parent 7a05a8956f
commit 3f54d83bac
5 changed files with 72 additions and 52 deletions

View File

@ -380,22 +380,20 @@ gimp_gegl_procedure_execute_async (GimpProcedure *procedure,
/* For GIMP-specific GEGL operations, we need to copy over the
* config object stored in the GeglNode */
if (gegl_procedure->filter &&
(! strcmp (gegl_procedure->operation, "gimp:brightness-contrast") ||
! strcmp (gegl_procedure->operation, "gimp:color-balance") ||
! strcmp (gegl_procedure->operation, "gimp:curves") ||
! strcmp (gegl_procedure->operation, "gimp:levels") ||
! strcmp (gegl_procedure->operation, "gimp:threshold")))
if (gegl_procedure->filter)
{
GeglNode *node;
GIMP_FILTER_TOOL (active_tool)->existing_filter = gegl_procedure->filter;
gimp_filter_set_active (GIMP_FILTER (gegl_procedure->filter), FALSE);
node = gimp_drawable_filter_get_operation (gegl_procedure->filter);
gegl_node_get (node,
"config", &settings,
NULL);
if (gimp_operation_config_is_custom (gimp, gegl_procedure->operation))
{
GeglNode *node;
node = gimp_drawable_filter_get_operation (gegl_procedure->filter);
gegl_node_get (node,
"config", &settings,
NULL);
}
}
if (settings)

View File

@ -36,6 +36,7 @@
#include "gegl/gimp-gegl-utils.h"
#include "gimpoperationsettings.h"
#include "gimp-operation-config.h"
@ -56,73 +57,80 @@ static void gimp_operation_config_add_sep (GimpContainer *container)
static void gimp_operation_config_remove_sep (GimpContainer *container);
/* public functions */
static GHashTable *
gimp_operation_config_get_type_table (Gimp *gimp)
{
static GHashTable *config_types = NULL;
if (! config_types)
config_types = g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify) g_free,
NULL);
return config_types;
}
static GHashTable *
gimp_operation_config_get_container_table (Gimp *gimp)
{
static GHashTable *config_containers = NULL;
if (! config_containers)
config_containers = g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
(GDestroyNotify) g_object_unref);
return config_containers;
}
static GHashTable *config_types = NULL;
static GHashTable *config_containers = NULL;
static GList *custom_config_ops = NULL;
static gboolean custom_init_done = FALSE;
/* public functions */
void
gimp_operation_config_init_start (Gimp *gimp)
{
config_types = g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify) g_free,
NULL);
config_containers = g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
(GDestroyNotify) g_object_unref);
}
void
gimp_operation_config_init_end (Gimp *gimp)
{
custom_init_done = TRUE;
}
void
gimp_operation_config_exit (Gimp *gimp)
{
g_hash_table_unref (config_types);
g_hash_table_unref (config_containers);
g_list_free (custom_config_ops);
}
void
gimp_operation_config_register (Gimp *gimp,
const gchar *operation,
GType config_type)
{
GHashTable *config_types;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (operation != NULL);
g_return_if_fail (g_type_is_a (config_type, GIMP_TYPE_OBJECT));
config_types = gimp_operation_config_get_type_table (gimp);
if (! custom_init_done)
/* Custom ops are registered with static string, not generated names. */
custom_config_ops = g_list_prepend (custom_config_ops, (gpointer) operation);
g_hash_table_insert (config_types,
g_strdup (operation),
(gpointer) config_type);
}
gboolean
gimp_operation_config_is_custom (Gimp *gimp,
const gchar *operation)
{
return (g_list_find_custom (custom_config_ops, operation, (GCompareFunc) g_strcmp0) != NULL);
}
GType
gimp_operation_config_get_type (Gimp *gimp,
const gchar *operation,
const gchar *icon_name,
GType parent_type)
{
GHashTable *config_types;
GType config_type;
GType config_type;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), G_TYPE_NONE);
g_return_val_if_fail (operation != NULL, G_TYPE_NONE);
g_return_val_if_fail (g_type_is_a (parent_type, GIMP_TYPE_OBJECT),
G_TYPE_NONE);
config_types = gimp_operation_config_get_type_table (gimp);
config_type = (GType) g_hash_table_lookup (config_types, operation);
if (! config_type)
@ -182,14 +190,11 @@ gimp_operation_config_get_container (Gimp *gimp,
GType config_type,
GCompareFunc sort_func)
{
GHashTable *config_containers;
GimpContainer *container;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (g_type_is_a (config_type, GIMP_TYPE_OBJECT), NULL);
config_containers = gimp_operation_config_get_container_table (gimp);
container = g_hash_table_lookup (config_containers, (gpointer) config_type);
if (! container)

View File

@ -19,6 +19,13 @@
#define __GIMP_OPERATION_CONFIG_H__
void gimp_operation_config_init_start (Gimp *gimp);
void gimp_operation_config_init_end (Gimp *gimp);
void gimp_operation_config_exit (Gimp *gimp);
gboolean gimp_operation_config_is_custom (Gimp *gimp,
const gchar *operation);
void gimp_operation_config_register (Gimp *gimp,
const gchar *operation,
GType config_type);

View File

@ -183,6 +183,8 @@ gimp_operations_init (Gimp *gimp)
g_type_class_ref (GIMP_TYPE_OPERATION_REPLACE);
g_type_class_ref (GIMP_TYPE_OPERATION_ANTI_ERASE);
gimp_operation_config_init_start (gimp);
gimp_operation_config_register (gimp,
"gimp:brightness-contrast",
GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG);
@ -222,6 +224,8 @@ gimp_operations_init (Gimp *gimp)
"gimp-levels-tool.settings");
set_settings_folder (GIMP_TYPE_LEVELS_CONFIG,
"levels");
gimp_operation_config_init_end (gimp);
}
void
@ -230,4 +234,5 @@ gimp_operations_exit (Gimp *gimp)
g_return_if_fail (GIMP_IS_GIMP (gimp));
gimp_layer_modes_exit ();
gimp_operation_config_exit (gimp);
}

View File

@ -1839,7 +1839,8 @@ gimp_filter_tool_get_operation (GimpFilterTool *filter_tool,
"operation", &name,
NULL);
if (! strcmp (gimp_object_get_name (tool->tool_info), "gimp-operation-tool"))
if (! strcmp (gimp_object_get_name (tool->tool_info), "gimp-operation-tool") &&
! gimp_operation_config_is_custom (tool->tool_info->gimp, operation_name))
{
GParamSpec **pspecs;
guint n_pspecs;
@ -1860,6 +1861,10 @@ gimp_filter_tool_get_operation (GimpFilterTool *filter_tool,
if (gimp_pspec)
g_object_set_property (G_OBJECT (filter_tool->config), gimp_pspec->name,
&value);
else
g_critical ("%s: property '%s' of operation '%s' doesn't exist in config %s",
G_STRFUNC, pspec->name, operation_name,
g_type_name (G_TYPE_FROM_INSTANCE (filter_tool->config)));
g_value_unset (&value);
}
g_free (pspecs);