From 3ccb4bed31a1617e9a2cadd1c4cfccad521ea4b2 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Tue, 18 May 2004 09:04:12 +0000 Subject: [PATCH] new function which returns a newly allocated string which is the menu 2004-05-18 Michael Natterer * app/plug-in/plug-in-proc.[ch] (plug_in_proc_def_get_label): new function which returns a newly allocated string which is the menu item's name stripped of mnemonics an ellipses. * app/actions/plug-in-actions.c (plug_in_actions_update) * app/plug-in/plug-in.c (plug_in_get_undo_desc): use the function instead of implementing the same twice slightly different. --- ChangeLog | 10 ++++++++ app/actions/plug-in-actions.c | 27 ++++++--------------- app/pdb/gimppluginprocedure.c | 37 +++++++++++++++++++++++++++++ app/pdb/gimppluginprocedure.h | 2 ++ app/plug-in/gimpplugin.c | 39 +++++++------------------------ app/plug-in/gimppluginprocedure.c | 37 +++++++++++++++++++++++++++++ app/plug-in/gimppluginprocedure.h | 2 ++ app/plug-in/plug-in-proc-def.c | 37 +++++++++++++++++++++++++++++ app/plug-in/plug-in-proc-def.h | 2 ++ app/plug-in/plug-in-proc.c | 37 +++++++++++++++++++++++++++++ app/plug-in/plug-in-proc.h | 2 ++ app/plug-in/plug-in.c | 39 +++++++------------------------ 12 files changed, 189 insertions(+), 82 deletions(-) diff --git a/ChangeLog b/ChangeLog index 376468614d..8a129666a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2004-05-18 Michael Natterer + + * app/plug-in/plug-in-proc.[ch] (plug_in_proc_def_get_label): new + function which returns a newly allocated string which is the menu + item's name stripped of mnemonics an ellipses. + + * app/actions/plug-in-actions.c (plug_in_actions_update) + * app/plug-in/plug-in.c (plug_in_get_undo_desc): use the function + instead of implementing the same twice slightly different. + 2004-05-17 Sven Neumann * plug-ins/common/CEL.c diff --git a/app/actions/plug-in-actions.c b/app/actions/plug-in-actions.c index f3cf0a8bd8..484be6fb65 100644 --- a/app/actions/plug-in-actions.c +++ b/app/actions/plug-in-actions.c @@ -193,33 +193,20 @@ plug_in_actions_update (GimpActionGroup *group, group->gimp->last_plug_in == &proc_def->db_info) { const gchar *progname; - const gchar *path; - gchar *stripped; - gchar *basename; - gchar *ellipses; + const gchar *domain; + gchar *label; gchar *repeat; gchar *reshow; progname = plug_in_proc_def_get_progname (proc_def); + domain = plug_ins_locale_domain (group->gimp, progname, NULL); - path = dgettext (plug_ins_locale_domain (group->gimp, - progname, NULL), - proc_def->menu_paths->data); + label = plug_in_proc_def_get_label (proc_def, domain); - stripped = gimp_strip_uline (path); - basename = g_path_get_basename (stripped); + repeat = g_strdup_printf (_("Re_peat \"%s\""), label); + reshow = g_strdup_printf (_("R_e-show \"%s\""), label); - g_free (stripped); - - ellipses = strstr (basename, "..."); - - if (ellipses && ellipses == (basename + strlen (basename) - 3)) - *ellipses = '\0'; - - repeat = g_strdup_printf (_("Re_peat \"%s\""), basename); - reshow = g_strdup_printf (_("R_e-show \"%s\""), basename); - - g_free (basename); + g_free (label); gimp_action_group_set_action_label (group, "plug-in-repeat", repeat); diff --git a/app/pdb/gimppluginprocedure.c b/app/pdb/gimppluginprocedure.c index 6e7b8114d3..f176a1b920 100644 --- a/app/pdb/gimppluginprocedure.c +++ b/app/pdb/gimppluginprocedure.c @@ -18,6 +18,8 @@ #include "config.h" +#include + #include #include "libgimpbase/gimpbase.h" @@ -112,6 +114,41 @@ plug_in_proc_def_get_progname (const PlugInProcDef *proc_def) return NULL; } +gchar * +plug_in_proc_def_get_label (const PlugInProcDef *proc_def, + const gchar *locale_domain) +{ + const gchar *path; + gchar *stripped; + gchar *ellipses; + gchar *label; + + g_return_val_if_fail (proc_def != NULL, NULL); + + if (proc_def->menu_label) + path = dgettext (locale_domain, proc_def->menu_label); + else if (proc_def->menu_paths) + path = dgettext (locale_domain, proc_def->menu_paths->data); + else + return NULL; + + stripped = gimp_strip_uline (path); + + if (proc_def->menu_label) + label = g_strdup (stripped); + else + label = g_path_get_basename (stripped); + + g_free (stripped); + + ellipses = strstr (label, "..."); + + if (ellipses && ellipses == (label + strlen (label) - 3)) + *ellipses = '\0'; + + return label; +} + gchar * plug_in_proc_def_get_help_id (const PlugInProcDef *proc_def, const gchar *help_domain) diff --git a/app/pdb/gimppluginprocedure.h b/app/pdb/gimppluginprocedure.h index bfde5e9a31..ba92b7145b 100644 --- a/app/pdb/gimppluginprocedure.h +++ b/app/pdb/gimppluginprocedure.h @@ -49,6 +49,8 @@ void plug_in_proc_def_free (PlugInProcDef *proc_def) const ProcRecord * plug_in_proc_def_get_proc (const PlugInProcDef *proc_def); const gchar * plug_in_proc_def_get_progname (const PlugInProcDef *proc_def); +gchar * plug_in_proc_def_get_label (const PlugInProcDef *proc_def, + const gchar *locale_domain); gchar * plug_in_proc_def_get_help_id (const PlugInProcDef *proc_def, const gchar *help_domain); diff --git a/app/plug-in/gimpplugin.c b/app/plug-in/gimpplugin.c index 8dbe72d7c8..f8a000646f 100644 --- a/app/plug-in/gimpplugin.c +++ b/app/plug-in/gimpplugin.c @@ -890,7 +890,7 @@ gchar * plug_in_get_undo_desc (PlugIn *plug_in) { PlugInProcDef *proc_def; - gchar *undo_desc; + gchar *undo_desc = NULL; g_return_val_if_fail (plug_in != NULL, NULL); @@ -903,39 +903,16 @@ plug_in_get_undo_desc (PlugIn *plug_in) else proc_def = NULL; - if (proc_def && (proc_def->menu_label || proc_def->menu_paths)) + if (proc_def) { - const gchar *path; - gchar *stripped; - gchar *ellipses; + const gchar *domain = plug_ins_locale_domain (plug_in->gimp, + plug_in->prog, NULL); - if (proc_def->menu_label) - path = dgettext (plug_ins_locale_domain (plug_in->gimp, - plug_in->prog, NULL), - proc_def->menu_label); - else - path = dgettext (plug_ins_locale_domain (plug_in->gimp, - plug_in->prog, NULL), - proc_def->menu_paths->data); - - stripped = gimp_strip_uline (path); - - if (proc_def->menu_label) - undo_desc = g_strdup (stripped); - else - undo_desc = g_strdup (strrchr (stripped, '/') + 1); - - g_free (stripped); - - ellipses = strstr (undo_desc, "..."); - - if (ellipses && ellipses == (undo_desc + strlen (undo_desc) - 3)) - *ellipses = '\0'; - } - else - { - undo_desc = g_filename_to_utf8 (plug_in->name, -1, NULL, NULL, NULL); + undo_desc = plug_in_proc_def_get_label (proc_def, domain); } + if (! undo_desc) + undo_desc = g_filename_to_utf8 (plug_in->name, -1, NULL, NULL, NULL); + return undo_desc; } diff --git a/app/plug-in/gimppluginprocedure.c b/app/plug-in/gimppluginprocedure.c index 6e7b8114d3..f176a1b920 100644 --- a/app/plug-in/gimppluginprocedure.c +++ b/app/plug-in/gimppluginprocedure.c @@ -18,6 +18,8 @@ #include "config.h" +#include + #include #include "libgimpbase/gimpbase.h" @@ -112,6 +114,41 @@ plug_in_proc_def_get_progname (const PlugInProcDef *proc_def) return NULL; } +gchar * +plug_in_proc_def_get_label (const PlugInProcDef *proc_def, + const gchar *locale_domain) +{ + const gchar *path; + gchar *stripped; + gchar *ellipses; + gchar *label; + + g_return_val_if_fail (proc_def != NULL, NULL); + + if (proc_def->menu_label) + path = dgettext (locale_domain, proc_def->menu_label); + else if (proc_def->menu_paths) + path = dgettext (locale_domain, proc_def->menu_paths->data); + else + return NULL; + + stripped = gimp_strip_uline (path); + + if (proc_def->menu_label) + label = g_strdup (stripped); + else + label = g_path_get_basename (stripped); + + g_free (stripped); + + ellipses = strstr (label, "..."); + + if (ellipses && ellipses == (label + strlen (label) - 3)) + *ellipses = '\0'; + + return label; +} + gchar * plug_in_proc_def_get_help_id (const PlugInProcDef *proc_def, const gchar *help_domain) diff --git a/app/plug-in/gimppluginprocedure.h b/app/plug-in/gimppluginprocedure.h index bfde5e9a31..ba92b7145b 100644 --- a/app/plug-in/gimppluginprocedure.h +++ b/app/plug-in/gimppluginprocedure.h @@ -49,6 +49,8 @@ void plug_in_proc_def_free (PlugInProcDef *proc_def) const ProcRecord * plug_in_proc_def_get_proc (const PlugInProcDef *proc_def); const gchar * plug_in_proc_def_get_progname (const PlugInProcDef *proc_def); +gchar * plug_in_proc_def_get_label (const PlugInProcDef *proc_def, + const gchar *locale_domain); gchar * plug_in_proc_def_get_help_id (const PlugInProcDef *proc_def, const gchar *help_domain); diff --git a/app/plug-in/plug-in-proc-def.c b/app/plug-in/plug-in-proc-def.c index 6e7b8114d3..f176a1b920 100644 --- a/app/plug-in/plug-in-proc-def.c +++ b/app/plug-in/plug-in-proc-def.c @@ -18,6 +18,8 @@ #include "config.h" +#include + #include #include "libgimpbase/gimpbase.h" @@ -112,6 +114,41 @@ plug_in_proc_def_get_progname (const PlugInProcDef *proc_def) return NULL; } +gchar * +plug_in_proc_def_get_label (const PlugInProcDef *proc_def, + const gchar *locale_domain) +{ + const gchar *path; + gchar *stripped; + gchar *ellipses; + gchar *label; + + g_return_val_if_fail (proc_def != NULL, NULL); + + if (proc_def->menu_label) + path = dgettext (locale_domain, proc_def->menu_label); + else if (proc_def->menu_paths) + path = dgettext (locale_domain, proc_def->menu_paths->data); + else + return NULL; + + stripped = gimp_strip_uline (path); + + if (proc_def->menu_label) + label = g_strdup (stripped); + else + label = g_path_get_basename (stripped); + + g_free (stripped); + + ellipses = strstr (label, "..."); + + if (ellipses && ellipses == (label + strlen (label) - 3)) + *ellipses = '\0'; + + return label; +} + gchar * plug_in_proc_def_get_help_id (const PlugInProcDef *proc_def, const gchar *help_domain) diff --git a/app/plug-in/plug-in-proc-def.h b/app/plug-in/plug-in-proc-def.h index bfde5e9a31..ba92b7145b 100644 --- a/app/plug-in/plug-in-proc-def.h +++ b/app/plug-in/plug-in-proc-def.h @@ -49,6 +49,8 @@ void plug_in_proc_def_free (PlugInProcDef *proc_def) const ProcRecord * plug_in_proc_def_get_proc (const PlugInProcDef *proc_def); const gchar * plug_in_proc_def_get_progname (const PlugInProcDef *proc_def); +gchar * plug_in_proc_def_get_label (const PlugInProcDef *proc_def, + const gchar *locale_domain); gchar * plug_in_proc_def_get_help_id (const PlugInProcDef *proc_def, const gchar *help_domain); diff --git a/app/plug-in/plug-in-proc.c b/app/plug-in/plug-in-proc.c index 6e7b8114d3..f176a1b920 100644 --- a/app/plug-in/plug-in-proc.c +++ b/app/plug-in/plug-in-proc.c @@ -18,6 +18,8 @@ #include "config.h" +#include + #include #include "libgimpbase/gimpbase.h" @@ -112,6 +114,41 @@ plug_in_proc_def_get_progname (const PlugInProcDef *proc_def) return NULL; } +gchar * +plug_in_proc_def_get_label (const PlugInProcDef *proc_def, + const gchar *locale_domain) +{ + const gchar *path; + gchar *stripped; + gchar *ellipses; + gchar *label; + + g_return_val_if_fail (proc_def != NULL, NULL); + + if (proc_def->menu_label) + path = dgettext (locale_domain, proc_def->menu_label); + else if (proc_def->menu_paths) + path = dgettext (locale_domain, proc_def->menu_paths->data); + else + return NULL; + + stripped = gimp_strip_uline (path); + + if (proc_def->menu_label) + label = g_strdup (stripped); + else + label = g_path_get_basename (stripped); + + g_free (stripped); + + ellipses = strstr (label, "..."); + + if (ellipses && ellipses == (label + strlen (label) - 3)) + *ellipses = '\0'; + + return label; +} + gchar * plug_in_proc_def_get_help_id (const PlugInProcDef *proc_def, const gchar *help_domain) diff --git a/app/plug-in/plug-in-proc.h b/app/plug-in/plug-in-proc.h index bfde5e9a31..ba92b7145b 100644 --- a/app/plug-in/plug-in-proc.h +++ b/app/plug-in/plug-in-proc.h @@ -49,6 +49,8 @@ void plug_in_proc_def_free (PlugInProcDef *proc_def) const ProcRecord * plug_in_proc_def_get_proc (const PlugInProcDef *proc_def); const gchar * plug_in_proc_def_get_progname (const PlugInProcDef *proc_def); +gchar * plug_in_proc_def_get_label (const PlugInProcDef *proc_def, + const gchar *locale_domain); gchar * plug_in_proc_def_get_help_id (const PlugInProcDef *proc_def, const gchar *help_domain); diff --git a/app/plug-in/plug-in.c b/app/plug-in/plug-in.c index 8dbe72d7c8..f8a000646f 100644 --- a/app/plug-in/plug-in.c +++ b/app/plug-in/plug-in.c @@ -890,7 +890,7 @@ gchar * plug_in_get_undo_desc (PlugIn *plug_in) { PlugInProcDef *proc_def; - gchar *undo_desc; + gchar *undo_desc = NULL; g_return_val_if_fail (plug_in != NULL, NULL); @@ -903,39 +903,16 @@ plug_in_get_undo_desc (PlugIn *plug_in) else proc_def = NULL; - if (proc_def && (proc_def->menu_label || proc_def->menu_paths)) + if (proc_def) { - const gchar *path; - gchar *stripped; - gchar *ellipses; + const gchar *domain = plug_ins_locale_domain (plug_in->gimp, + plug_in->prog, NULL); - if (proc_def->menu_label) - path = dgettext (plug_ins_locale_domain (plug_in->gimp, - plug_in->prog, NULL), - proc_def->menu_label); - else - path = dgettext (plug_ins_locale_domain (plug_in->gimp, - plug_in->prog, NULL), - proc_def->menu_paths->data); - - stripped = gimp_strip_uline (path); - - if (proc_def->menu_label) - undo_desc = g_strdup (stripped); - else - undo_desc = g_strdup (strrchr (stripped, '/') + 1); - - g_free (stripped); - - ellipses = strstr (undo_desc, "..."); - - if (ellipses && ellipses == (undo_desc + strlen (undo_desc) - 3)) - *ellipses = '\0'; - } - else - { - undo_desc = g_filename_to_utf8 (plug_in->name, -1, NULL, NULL, NULL); + undo_desc = plug_in_proc_def_get_label (proc_def, domain); } + if (! undo_desc) + undo_desc = g_filename_to_utf8 (plug_in->name, -1, NULL, NULL, NULL); + return undo_desc; }