Revision: 1562
          http://geeqie.svn.sourceforge.net/geeqie/?rev=1562&view=rev
Author:   nadvornik
Date:     2009-03-20 14:36:59 +0000 (Fri, 20 Mar 2009)

Log Message:
-----------
added possibility to update existing layout window from config

Modified Paths:
--------------
    trunk/src/layout.c
    trunk/src/layout.h
    trunk/src/options.c
    trunk/src/rcfile.c
    trunk/src/typedefs.h

Modified: trunk/src/layout.c
===================================================================
--- trunk/src/layout.c  2009-03-20 11:52:29 UTC (rev 1561)
+++ trunk/src/layout.c  2009-03-20 14:36:59 UTC (rev 1562)
@@ -114,6 +114,52 @@
        return NULL;
 }
 
+LayoutWindow *layout_find_by_layout_id(const gchar *id)
+{
+       GList *work;
+
+       if (!id || !id[0]) return NULL;
+       work = layout_window_list;
+       while (work)
+               {
+               LayoutWindow *lw = work->data;
+               work = work->next;
+
+               if (lw->options.id && strcmp(id, lw->options.id) == 0)
+                       return lw;
+               }
+
+       return NULL;
+}
+
+static void layout_set_unique_id(LayoutWindow *lw)
+{
+       char id[10];
+       gint i;
+       if (lw->options.id && lw->options.id[0]) return; /* id is already set */
+       
+       g_free(lw->options.id);
+       lw->options.id = NULL;
+       
+       if (!layout_find_by_layout_id("main"))
+               {
+               lw->options.id = g_strdup("main");
+               return;
+               }
+       
+       i = 1;
+       while (TRUE)
+               {
+               g_snprintf(id, sizeof(id), "lw%d", i);
+               if (!layout_find_by_layout_id(id))
+                       {
+                       lw->options.id = g_strdup(id);
+                       return;
+                       }
+               i++;
+               }
+}
+
 /*
  *-----------------------------------------------------------------------------
  * menu, toolbar, and dir view
@@ -2210,6 +2256,7 @@
        lw->sort_method = SORT_NAME;
        lw->sort_ascend = TRUE;
 
+       layout_set_unique_id(lw);
 //     lw->options.tools_float = popped;
 //     lw->options.tools_hidden = hidden;
 //     lw->bar_sort_enabled = options->panels.sort.enabled;
@@ -2328,6 +2375,8 @@
 
 void layout_write_attributes(LayoutOptions *layout, GString *outstr, gint 
indent)
 {
+       WRITE_NL(); WRITE_CHAR(*layout, id);
+
        WRITE_NL(); WRITE_INT(*layout, style);
        WRITE_NL(); WRITE_CHAR(*layout, order);
        WRITE_NL(); WRITE_UINT(*layout, dir_view_type);
@@ -2395,6 +2444,7 @@
                const gchar *value = *attribute_values++;
 
                /* layout options */
+               if (READ_CHAR(*layout, id)) continue;
 
                if (READ_INT(*layout, style)) continue;
                if (READ_CHAR(*layout, order)) continue;
@@ -2509,5 +2559,18 @@
        return lw;
 }
 
+void layout_update_from_config(LayoutWindow *lw, const gchar 
**attribute_names, const gchar **attribute_values)
+{
+       LayoutOptions lop;
+       
+       init_layout_options(&lop);
 
+       if (attribute_names) layout_load_attributes(&lop, attribute_names, 
attribute_values);
+
+       layout_apply_options(lw, &lop);
+               
+       free_layout_options_content(&lop);
+}
+
+
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */

Modified: trunk/src/layout.h
===================================================================
--- trunk/src/layout.h  2009-03-20 11:52:29 UTC (rev 1561)
+++ trunk/src/layout.h  2009-03-20 14:36:59 UTC (rev 1562)
@@ -21,6 +21,7 @@
 LayoutWindow *layout_new_with_geometry(FileData *dir_fd, LayoutOptions *lop,
                                       const gchar *geometry);
 LayoutWindow *layout_new_from_config(const gchar **attribute_names, const 
gchar **attribute_values, gboolean use_commandline);
+void layout_update_from_config(LayoutWindow *lw, const gchar 
**attribute_names, const gchar **attribute_values);
 
 void layout_close(LayoutWindow *lw);
 void layout_free(LayoutWindow *lw);
@@ -39,7 +40,9 @@
 
 LayoutWindow *layout_find_by_image(ImageWindow *imd);
 LayoutWindow *layout_find_by_image_fd(ImageWindow *imd);
+LayoutWindow *layout_find_by_layout_id(const gchar *id);
 
+
 const gchar *layout_get_path(LayoutWindow *lw);
 gboolean layout_set_path(LayoutWindow *lw, const gchar *path);
 gboolean layout_set_fd(LayoutWindow *lw, FileData *fd);

Modified: trunk/src/options.c
===================================================================
--- trunk/src/options.c 2009-03-20 11:52:29 UTC (rev 1561)
+++ trunk/src/options.c 2009-03-20 14:36:59 UTC (rev 1562)
@@ -170,14 +170,16 @@
        free_layout_options_content(dest);
        
        *dest = *src;
+       dest->id = g_strdup(src->id);
        dest->order = g_strdup(src->order);
        dest->home_path = g_strdup(src->home_path);
 }
 
 void free_layout_options_content(LayoutOptions *dest)
 {
-       if (dest->order) g_free(dest->order);
-       if (dest->home_path) g_free(dest->home_path);
+       g_free(dest->id);
+       g_free(dest->order);
+       g_free(dest->home_path);
 }
 
 LayoutOptions *init_layout_options(LayoutOptions *options)

Modified: trunk/src/rcfile.c
===================================================================
--- trunk/src/rcfile.c  2009-03-20 11:52:29 UTC (rev 1561)
+++ trunk/src/rcfile.c  2009-03-20 14:36:59 UTC (rev 1562)
@@ -777,7 +777,20 @@
        gboolean startup; /* reading config for the first time - add 
commandline and defaults */
 };
 
+static const gchar *options_get_id(const gchar **attribute_names, const gchar 
**attribute_values)
+{
+       while (*attribute_names)
+               {
+               const gchar *option = *attribute_names++;
+               const gchar *value = *attribute_values++;
+               
+               if (strcmp(option, "id") == 0) return value;
 
+               }
+       return NULL;
+}
+
+
 void options_parse_leaf(GQParserData *parser_data, GMarkupParseContext 
*context, const gchar *element_name, const gchar **attribute_names, const gchar 
**attribute_values, gpointer data, GError **error)
 {
        log_printf("unexpected: %s\n", element_name);
@@ -1001,7 +1014,15 @@
        if (g_ascii_strcasecmp(element_name, "layout") == 0)
                {
                LayoutWindow *lw;
-               lw = layout_new_from_config(attribute_names, attribute_values, 
parser_data->startup);
+               lw = layout_find_by_layout_id(options_get_id(attribute_names, 
attribute_values));
+               if (lw) 
+                       {
+                       layout_update_from_config(lw, attribute_names, 
attribute_values);
+                       }
+               else
+                       {
+                       lw = layout_new_from_config(attribute_names, 
attribute_values, parser_data->startup);
+                       }
                options_parse_func_push(parser_data, options_parse_layout, 
options_parse_layout_end, lw);
                }
        else

Modified: trunk/src/typedefs.h
===================================================================
--- trunk/src/typedefs.h        2009-03-20 11:52:29 UTC (rev 1561)
+++ trunk/src/typedefs.h        2009-03-20 14:36:59 UTC (rev 1562)
@@ -481,6 +481,8 @@
 
 struct _LayoutOptions
 {
+       gchar *id;
+
        gchar *order;
        gint style;
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Geeqie-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geeqie-svn

Reply via email to