Introduce an helper function that returns the name of an editor.
authorLaurent Monin <geeqie@norz.org>
Thu, 22 May 2008 09:12:36 +0000 (09:12 +0000)
committerLaurent Monin <geeqie@norz.org>
Thu, 22 May 2008 09:12:36 +0000 (09:12 +0000)
It helps to reduce code redundancy.

src/editors.c
src/editors.h
src/layout_util.c
src/menu.c

index 718eb9d..bfb57bc 100644 (file)
@@ -866,3 +866,13 @@ const gchar *editor_get_error_str(gint flags)
        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)");
+}
index c4dd2d0..b0acefc 100644 (file)
@@ -71,4 +71,6 @@ gint start_editor_from_filelist_full(gint n, GList *list, EditorCallback cb, gpo
 gint editor_window_flag_set(gint n);
 const gchar *editor_get_error_str(gint flags);
 
+const gchar *editor_get_name(gint n);
+
 #endif
index 191391c..374938a 100644 (file)
@@ -873,24 +873,18 @@ static void layout_menu_edit_update(LayoutWindow *lw)
                {
                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);
index 15d748a..976e571 100644 (file)
@@ -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 @@ static void add_edit_items(GtkWidget *menu, GCallback func, GtkAccelGroup *accel
 
        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);
+               
                }
 }