core, pdb, xcf: Only load explicitly set filter names

We always save the filter name in XCFs,
even if the user did not intentionally set
it. This means that "default" names like
Gaussian Blur are not translated when
saved and loaded in XCFs.

This patch adds a new property,
"custom-name", to GimpDrawableFilter.
It is FALSE by default, and only set to
TRUE if the user provides a custom filter
name (currently only possible in the
public filter API). Based off this value,
we either use the saved filter name or
get it from the operation when saving and
loading a filter from the XCF.
This commit is contained in:
Alx Sa 2025-01-11 21:28:41 +00:00
parent 73f30b0dc6
commit b78f3dadc6
2 changed files with 45 additions and 13 deletions

View file

@ -66,6 +66,7 @@ enum
PROP_ID, PROP_ID,
PROP_DRAWABLE, PROP_DRAWABLE,
PROP_MASK, PROP_MASK,
PROP_CUSTOM_NAME,
N_PROPS N_PROPS
}; };
@ -81,6 +82,7 @@ struct _GimpDrawableFilter
GeglNode *operation; GeglNode *operation;
gboolean has_input; gboolean has_input;
gboolean has_custom_name;
gboolean clip; gboolean clip;
GimpFilterRegion region; GimpFilterRegion region;
@ -204,6 +206,12 @@ gimp_drawable_filter_class_init (GimpDrawableFilterClass *klass)
GIMP_TYPE_DRAWABLE, GIMP_TYPE_DRAWABLE,
GIMP_PARAM_READWRITE); GIMP_PARAM_READWRITE);
drawable_filter_props[PROP_CUSTOM_NAME] = g_param_spec_boolean ("custom-name",
NULL, NULL,
FALSE,
GIMP_PARAM_READWRITE);
g_object_class_install_properties (object_class, N_PROPS, drawable_filter_props); g_object_class_install_properties (object_class, N_PROPS, drawable_filter_props);
} }
@ -255,6 +263,10 @@ gimp_drawable_filter_set_property (GObject *object,
} }
break; break;
case PROP_CUSTOM_NAME:
filter->has_custom_name = g_value_get_boolean (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -277,6 +289,9 @@ gimp_drawable_filter_get_property (GObject *object,
case PROP_MASK: case PROP_MASK:
g_value_set_object (value, gimp_drawable_filter_get_mask (filter)); g_value_set_object (value, gimp_drawable_filter_get_mask (filter));
break; break;
case PROP_CUSTOM_NAME:
g_value_set_boolean (value, filter->has_custom_name);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -324,24 +339,30 @@ gimp_drawable_filter_new (GimpDrawable *drawable,
GimpDrawableFilter *filter; GimpDrawableFilter *filter;
GimpImage *image; GimpImage *image;
GeglNode *node; GeglNode *node;
GeglOperation *op;
GeglOperationClass *opclass;
gboolean custom_name = TRUE;
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL); g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
g_return_val_if_fail (GEGL_IS_NODE (operation), NULL); g_return_val_if_fail (GEGL_IS_NODE (operation), NULL);
g_return_val_if_fail (gegl_node_has_pad (operation, "output"), NULL); g_return_val_if_fail (gegl_node_has_pad (operation, "output"), NULL);
if (undo_desc == NULL || strlen (undo_desc) == 0)
{
GeglOperation *op;
GeglOperationClass *opclass;
op = gegl_node_get_gegl_operation (operation); op = gegl_node_get_gegl_operation (operation);
opclass = GEGL_OPERATION_GET_CLASS (op); opclass = GEGL_OPERATION_GET_CLASS (op);
if (undo_desc == NULL || strlen (undo_desc) == 0)
{
undo_desc = gegl_operation_class_get_key (opclass, "title"); undo_desc = gegl_operation_class_get_key (opclass, "title");
custom_name = FALSE;
} }
if (! g_strcmp0 (undo_desc, gegl_operation_class_get_key (opclass, "title")))
custom_name = FALSE;
filter = g_object_new (GIMP_TYPE_DRAWABLE_FILTER, filter = g_object_new (GIMP_TYPE_DRAWABLE_FILTER,
"name", undo_desc, "name", undo_desc,
"icon-name", icon_name, "icon-name", icon_name,
"custom-name", custom_name,
"drawable", drawable, "drawable", drawable,
"mask", NULL, "mask", NULL,
NULL); NULL);

View file

@ -2128,6 +2128,7 @@ xcf_save_effect (XcfInfo *info,
{ {
gchar *name; gchar *name;
gchar *icon; gchar *icon;
gboolean has_custom_name;
GimpDrawableFilter *filter_drawable; GimpDrawableFilter *filter_drawable;
GeglNode *node; GeglNode *node;
gchar *operation; gchar *operation;
@ -2146,10 +2147,20 @@ xcf_save_effect (XcfInfo *info,
g_object_get (filter, g_object_get (filter,
"name", &name, "name", &name,
"icon-name", &icon, "icon-name", &icon,
"custom-name", &has_custom_name,
NULL); NULL);
/* Write out effect name */ /* Write out effect name */
if (has_custom_name)
{
xcf_write_string_check_error (info, (gchar **) &name, 1, ;); xcf_write_string_check_error (info, (gchar **) &name, 1, ;);
}
else
{
gchar *empty = NULL;
xcf_write_string_check_error (info, (gchar **) &empty, 1, ;);
}
g_free (name); g_free (name);
/* Write out effect icon */ /* Write out effect icon */