Mercurial > geeqie.yaz
changeset 1466:6e020d3ab168
added possibility to update existing layout window from config
author | nadvornik |
---|---|
date | Fri, 20 Mar 2009 14:36:59 +0000 |
parents | 400ecfc3d8b1 |
children | 2b95dbb20a87 |
files | src/layout.c src/layout.h src/options.c src/rcfile.c src/typedefs.h |
diffstat | 5 files changed, 94 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/layout.c Fri Mar 20 11:52:29 2009 +0000 +++ b/src/layout.c Fri Mar 20 14:36:59 2009 +0000 @@ -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: */
--- a/src/layout.h Fri Mar 20 11:52:29 2009 +0000 +++ b/src/layout.h Fri Mar 20 14:36:59 2009 +0000 @@ -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,6 +40,8 @@ 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);
--- a/src/options.c Fri Mar 20 11:52:29 2009 +0000 +++ b/src/options.c Fri Mar 20 14:36:59 2009 +0000 @@ -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)
--- a/src/rcfile.c Fri Mar 20 11:52:29 2009 +0000 +++ b/src/rcfile.c Fri Mar 20 14:36:59 2009 +0000 @@ -777,6 +777,19 @@ 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) { @@ -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