# HG changeset patch # User zas_ # Date 1211447556 0 # Node ID fa8f7d7396cff020da36fea1ada158f919eec290 # Parent 2d8a8e892b5e903c2ec67f458dcf2f264b7c5903 Introduce an helper function that returns the name of an editor. It helps to reduce code redundancy. diff -r 2d8a8e892b5e -r fa8f7d7396cf src/editors.c --- a/src/editors.c Thu May 22 08:49:52 2008 +0000 +++ b/src/editors.c Thu May 22 09:12:36 2008 +0000 @@ -866,3 +866,13 @@ if (flags & EDITOR_ERROR_SKIPPED) return _("File was skipped."); return _("Unknown error."); } + +const gchar *editor_get_name(gint n) +{ + if (!is_valid_editor_command(n)) return NULL; + + if (options->editor[n].name && strlen(options->editor[n].name) > 0) + return options->editor[n].name; + + return _("(unknown)"); +} diff -r 2d8a8e892b5e -r fa8f7d7396cf src/editors.h --- a/src/editors.h Thu May 22 08:49:52 2008 +0000 +++ b/src/editors.h Thu May 22 09:12:36 2008 +0000 @@ -71,4 +71,6 @@ gint editor_window_flag_set(gint n); const gchar *editor_get_error_str(gint flags); +const gchar *editor_get_name(gint n); + #endif diff -r 2d8a8e892b5e -r fa8f7d7396cf src/layout_util.c --- a/src/layout_util.c Thu May 22 08:49:52 2008 +0000 +++ b/src/layout_util.c Thu May 22 09:12:36 2008 +0000 @@ -873,24 +873,18 @@ { gchar *key; GtkAction *action; - + const gchar *name; + key = g_strdup_printf("Editor%d", i); action = gtk_action_group_get_action(lw->action_group, key); g_object_set_data(G_OBJECT(action), "edit_index", GINT_TO_POINTER(i)); - if (options->editor[i].command && strlen(options->editor[i].command) > 0) + name = editor_get_name(i); + if (name) { - gchar *text; + gchar *text = g_strdup_printf(_("_%d %s..."), i, name); - if (options->editor[i].name && strlen(options->editor[i].name) > 0) - { - text = g_strdup_printf(_("_%d %s..."), i, options->editor[i].name); - } - else - { - text = g_strdup_printf(_("_%d (unknown)..."), i); - } g_object_set(action, "label", text, "sensitive", TRUE, NULL); g_free(text); diff -r 2d8a8e892b5e -r fa8f7d7396cf src/menu.c --- a/src/menu.c Thu May 22 08:49:52 2008 +0000 +++ b/src/menu.c Thu May 22 09:12:36 2008 +0000 @@ -18,6 +18,7 @@ #include "collect.h" #include "collect-dlg.h" #include "dupe.h" +#include "editors.h" #include "filedata.h" #include "img-view.h" #include "preferences.h" @@ -69,19 +70,18 @@ for (i = 0; i < GQ_EDITOR_GENERIC_SLOTS; i++) { - if (options->editor[i].command && strlen(options->editor[i].command) > 0) - { - gchar *text; - if (options->editor[i].name && strlen(options->editor[i].name) > 0) - text = g_strdup_printf(_("_%d %s..."), i, options->editor[i].name); - else - text = g_strdup_printf(_("_%d (unknown)..."), i); - if (accel_grp) - add_menu_item(menu, text, accel_grp, i + 49, GDK_CONTROL_MASK, func, GINT_TO_POINTER(i)); - else - menu_item_add(menu, text, func, GINT_TO_POINTER(i)); - g_free(text); - } + gchar *text; + const gchar *name = editor_get_name(i); + + if (!name) continue; + + text = g_strdup_printf(_("_%d %s..."), i, name); + if (accel_grp) + add_menu_item(menu, text, accel_grp, i + 49, GDK_CONTROL_MASK, func, GINT_TO_POINTER(i)); + else + menu_item_add(menu, text, func, GINT_TO_POINTER(i)); + g_free(text); + } }