Save order of Properties dialog tabs to rc file.
authorLaurent Monin <geeqie@norz.org>
Sun, 18 May 2008 21:14:01 +0000 (21:14 +0000)
committerLaurent Monin <geeqie@norz.org>
Sun, 18 May 2008 21:14:01 +0000 (21:14 +0000)
Users of GTK+ <2.10 can set tabs order directly in the rc file,
others can move tabs using drag'n drop.
The option is named properties.tabs_order, its default value
is "123" which is General, Keywords, Exif tabs (left to right).

src/info.c
src/info.h
src/main.c
src/options.h
src/rcfile.c

index 5e90740..654135e 100644 (file)
@@ -488,20 +488,94 @@ static gint compare_info_tabs_pos(gconstpointer a, gconstpointer b)
        return -1;
 }
 
+static gpointer info_tab_new_funcs[] = {
+       info_tab_general_new,
+       info_tab_meta_new,
+       info_tab_exif_new,
+};
+
+gchar *info_tab_default_order(void)
+{
+       gint i;
+       static gchar str[G_N_ELEMENTS(info_tab_new_funcs) + 1];
+
+       for (i = 0; i < G_N_ELEMENTS(info_tab_new_funcs); i++)
+               str[i] = i + '1';
+       str[i] = '\0';
+
+       return str;
+}
+
+static void info_tab_get_order_string(gchar **dest)
+{
+       GList *work;
+       gchar str[G_N_ELEMENTS(info_tab_new_funcs) + 1];
+
+       g_assert(dest);
+
+       if (!info_tabs_pos_list)
+               return;
+       
+       memset(str, 0, G_N_ELEMENTS(info_tab_new_funcs) + 1);
+
+       work = info_tabs_pos_list;
+       while (work)
+               {
+               gint i;
+               InfoTabsPos *t = work->data;
+               work = work->next;
+
+               for (i = 0; i < G_N_ELEMENTS(info_tab_new_funcs); i++)
+                       {
+                       if (t->func == info_tab_new_funcs[i])
+                               {
+                               g_assert(t->pos >= 0 && t->pos < G_N_ELEMENTS(info_tab_new_funcs));
+                               str[t->pos] = i + '1';
+                               }
+                       }
+               }
+       
+       if (strlen(str) != G_N_ELEMENTS(info_tab_new_funcs)) return;
+
+       g_free(*dest);
+       *dest = g_strdup(str);
+}
+
 static void info_tabs_init(InfoData *id)
 {
        GList *work;
 
        if (!info_tabs_pos_list)
                {
-               /* First run, default tabs order is defined here. */
-               info_tabs_pos_list_append(info_tab_general_new);
-               info_tabs_pos_list_append(info_tab_meta_new);
-               info_tabs_pos_list_append(info_tab_exif_new);
+               gint count = 0;
+               gint i;
+               gchar *order = options->properties.tabs_order;
+               
+               for (i = 0; i < strlen(order); i++)
+                       {
+                       gint n = order[i] - '1';
+
+                       if (n < 0 || n >= G_N_ELEMENTS(info_tab_new_funcs)) break;
+                       count++;
+                       }
+
+               if (count != G_N_ELEMENTS(info_tab_new_funcs))
+                       order = info_tab_default_order();
+
+               for (i = 0; i < strlen(order); i++)
+                       {
+                       gint n = order[i] - '1';
+
+                       if (n < 0 || n >= G_N_ELEMENTS(info_tab_new_funcs)) continue;
+                       if (g_list_find(info_tabs_pos_list, info_tab_new_funcs[n])) continue;
+                       info_tabs_pos_list_append(info_tab_new_funcs[n]);
+                       }
                }
        else
                info_tabs_pos_list = g_list_sort(info_tabs_pos_list, compare_info_tabs_pos);
 
+       info_tab_get_order_string(&options->properties.tabs_order);
+
        work = info_tabs_pos_list;
        while (work)
                {
@@ -568,6 +642,9 @@ static void info_notebook_reordered_cb(GtkNotebook *notebook, GtkWidget *child,
                                }
                        }
                }
+       
+       info_tabs_pos_list = g_list_sort(info_tabs_pos_list, compare_info_tabs_pos);
+       info_tab_get_order_string(&options->properties.tabs_order);
 }
 
 /*
index b7a1912..167ac8b 100644 (file)
@@ -45,5 +45,6 @@ void info_window_new(FileData *fd, GList *list, GtkWidget *parent);
 GtkWidget *table_add_line(GtkWidget *table, gint x, gint y,
                          const gchar *description, const gchar *text);
 
+gchar *info_tab_default_order(void);
 
 #endif
index 232fbf3..caca9c6 100644 (file)
@@ -23,6 +23,7 @@
 #include "fullscreen.h"
 #include "image-overlay.h"
 #include "img-view.h"
+#include "info.h"
 #include "layout.h"
 #include "layout_image.h"
 #include "menu.h"
@@ -578,6 +579,7 @@ static void setup_default_options(void)
        set_default_image_overlay_template_string(options);
        sidecar_ext_add_defaults();
        options->layout.order = g_strdup("123");
+       options->properties.tabs_order = g_strdup(info_tab_default_order());
 }
 
 static void exit_program_final(void)
index 8eef3ea..571a545 100644 (file)
@@ -207,6 +207,10 @@ struct _ConfOptions
                } sort;
        } panels;
 
+       /* properties dialog */
+       struct {
+               gchar *tabs_order;
+       } properties;
 
        /* color profiles */
        struct {
index 3f60a8d..a921ecd 100644 (file)
@@ -418,6 +418,9 @@ void save_options(void)
        WRITE_INT(panels.sort.mode_state);
        WRITE_INT(panels.sort.selection_state);
 
+       WRITE_SUBTITLE("Properties dialog Options");
+       WRITE_CHAR(properties.tabs_order);
+
        WRITE_SUBTITLE("Image Options");
 
        secure_fprintf(ssi, "# image.zoom_mode possible values are:\n"
@@ -727,6 +730,9 @@ void load_options(void)
                READ_INT(panels.sort.mode_state);
                READ_INT(panels.sort.selection_state);
 
+               /* properties dialog options */
+               READ_CHAR(properties.tabs_order);
+
                /* image options */
                if (g_ascii_strcasecmp(option, "image.zoom_mode") == 0)
                        {