changeset 731:fa8f7d7396cf

Introduce an helper function that returns the name of an editor. It helps to reduce code redundancy.
author zas_
date Thu, 22 May 2008 09:12:36 +0000
parents 2d8a8e892b5e
children 8256c74730e2
files src/editors.c src/editors.h src/layout_util.c src/menu.c
diffstat 4 files changed, 30 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- 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)");
+}
--- 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
--- 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);
--- 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);
+		
 		}
 }