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
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;
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);
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;
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: */
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);
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);
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)
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)
{
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
struct _LayoutOptions
{
+ gchar *id;
+
gchar *order;
gint style;