app: remove some procedure code duplication

Move the mnemonic and ellipsis removal code to
gimp_procedure_real_get_label() and cache the generated label in
GimpProcedure. Remove the same code from GimpPlugInProcedure and
GimpGeglProcedure.
This commit is contained in:
Michael Natterer 2019-09-09 00:05:13 +02:00
parent 5341c42852
commit 5f60f5422b
6 changed files with 25 additions and 57 deletions

View File

@ -62,7 +62,6 @@ static gint64 gimp_gegl_procedure_get_memsize (GimpObject *object,
static gchar * gimp_gegl_procedure_get_description (GimpViewable *viewable,
gchar **tooltip);
static const gchar * gimp_gegl_procedure_get_label (GimpProcedure *procedure);
static const gchar * gimp_gegl_procedure_get_menu_label (GimpProcedure *procedure);
static gboolean gimp_gegl_procedure_get_sensitive (GimpProcedure *procedure,
GimpObject *object,
@ -102,7 +101,6 @@ gimp_gegl_procedure_class_init (GimpGeglProcedureClass *klass)
viewable_class->default_icon_name = "gimp-gegl";
viewable_class->get_description = gimp_gegl_procedure_get_description;
proc_class->get_label = gimp_gegl_procedure_get_label;
proc_class->get_menu_label = gimp_gegl_procedure_get_menu_label;
proc_class->get_sensitive = gimp_gegl_procedure_get_sensitive;
proc_class->execute = gimp_gegl_procedure_execute;
@ -123,7 +121,6 @@ gimp_gegl_procedure_finalize (GObject *object)
g_clear_pointer (&proc->operation, g_free);
g_clear_pointer (&proc->menu_label, g_free);
g_clear_pointer (&proc->label, g_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -137,7 +134,6 @@ gimp_gegl_procedure_get_memsize (GimpObject *object,
memsize += gimp_string_get_memsize (proc->operation);
memsize += gimp_string_get_memsize (proc->menu_label);
memsize += gimp_string_get_memsize (proc->label);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
@ -155,31 +151,6 @@ gimp_gegl_procedure_get_description (GimpViewable *viewable,
return g_strdup (gimp_procedure_get_label (procedure));
}
static const gchar *
gimp_gegl_procedure_get_label (GimpProcedure *procedure)
{
GimpGeglProcedure *proc = GIMP_GEGL_PROCEDURE (procedure);
gchar *ellipsis;
gchar *label;
if (proc->label)
return proc->label;
label = gimp_strip_uline (gimp_procedure_get_menu_label (procedure));
ellipsis = strstr (label, "...");
if (! ellipsis)
ellipsis = strstr (label, "\342\200\246" /* U+2026 HORIZONTAL ELLIPSIS */);
if (ellipsis && ellipsis == (label + strlen (label) - 3))
*ellipsis = '\0';
proc->label = label;
return proc->label;
}
static const gchar *
gimp_gegl_procedure_get_menu_label (GimpProcedure *procedure)
{

View File

@ -46,7 +46,6 @@ struct _GimpGeglProcedure
GimpObject *default_settings;
gchar *menu_label;
gchar *label;
};
struct _GimpGeglProcedureClass

View File

@ -120,6 +120,7 @@ gimp_procedure_finalize (GObject *object)
gimp_procedure_free_attribution (procedure);
g_clear_pointer (&procedure->deprecated, g_free);
g_clear_pointer (&procedure->label, g_free);
if (procedure->args)
{
@ -181,13 +182,31 @@ gimp_procedure_get_memsize (GimpObject *object,
static const gchar *
gimp_procedure_real_get_label (GimpProcedure *procedure)
{
return gimp_object_get_name (procedure); /* lame fallback */
gchar *ellipsis;
gchar *label;
if (procedure->label)
return procedure->label;
label = gimp_strip_uline (gimp_procedure_get_menu_label (procedure));
ellipsis = strstr (label, "...");
if (! ellipsis)
ellipsis = strstr (label, "\342\200\246" /* U+2026 HORIZONTAL ELLIPSIS */);
if (ellipsis && ellipsis == (label + strlen (label) - 3))
*ellipsis = '\0';
procedure->label = label;
return procedure->label;
}
static const gchar *
gimp_procedure_real_get_menu_label (GimpProcedure *procedure)
{
return gimp_procedure_get_label (procedure);
return gimp_object_get_name (procedure); /* lame fallback */
}
static const gchar *

View File

@ -58,6 +58,8 @@ struct _GimpProcedure
gchar *deprecated; /* Replacement if deprecated */
gchar *label; /* Cached label string */
gint32 num_args; /* Number of procedure arguments */
GParamSpec **args; /* Array of procedure arguments */

View File

@ -155,7 +155,6 @@ gimp_plug_in_procedure_finalize (GObject *object)
g_list_free_full (proc->menu_paths, (GDestroyNotify) g_free);
g_free (proc->label);
g_free (proc->help_id_with_domain);
g_free (proc->icon_data);
@ -242,32 +241,11 @@ static const gchar *
gimp_plug_in_procedure_get_label (GimpProcedure *procedure)
{
GimpPlugInProcedure *proc = GIMP_PLUG_IN_PROCEDURE (procedure);
const gchar *translated;
gchar *ellipsis;
gchar *label;
if (proc->label)
return proc->label;
if (! proc->menu_label)
return NULL;
translated = dgettext (gimp_plug_in_procedure_get_locale_domain (proc),
proc->menu_label);
label = gimp_strip_uline (translated);
ellipsis = strstr (label, "...");
if (! ellipsis)
ellipsis = strstr (label, "\342\200\246" /* U+2026 HORIZONTAL ELLIPSIS */);
if (ellipsis && ellipsis == (label + strlen (label) - 3))
*ellipsis = '\0';
proc->label = label;
return proc->label;
return GIMP_PROCEDURE_CLASS (parent_class)->get_label (procedure);
}
static const gchar *
@ -616,7 +594,7 @@ gimp_plug_in_procedure_set_menu_label (GimpPlugInProcedure *proc,
return FALSE;
}
g_clear_pointer (&proc->label, g_free);
g_clear_pointer (&GIMP_PROCEDURE (proc)->label, g_free);
g_free (proc->menu_label);
proc->menu_label = g_strdup (menu_label);

View File

@ -44,7 +44,6 @@ struct _GimpPlugInProcedure
GQuark help_domain;
gchar *menu_label;
GList *menu_paths;
gchar *label;
gchar *help_id_with_domain;
GimpIconType icon_type;
gint icon_data_length;