Mercurial > geeqie
changeset 1320:055ed09d5a03
improved bar_sort configuration
author | nadvornik |
---|---|
date | Tue, 24 Feb 2009 22:21:28 +0000 |
parents | 358685fb9dc9 |
children | 50b325a2386e |
files | src/bar_sort.c src/bar_sort.h src/layout.c src/layout_util.c src/layout_util.h src/options.c src/rcfile.c src/typedefs.h |
diffstat | 8 files changed, 122 insertions(+), 76 deletions(-) [+] |
line wrap: on
line diff
--- a/src/bar_sort.c Tue Feb 24 21:08:16 2009 +0000 +++ b/src/bar_sort.c Tue Feb 24 22:21:28 2009 +0000 @@ -26,6 +26,7 @@ #include "ui_fileops.h" #include "ui_menu.h" #include "ui_misc.h" +#include "rcfile.h" /* @@ -171,7 +172,6 @@ { bar_sort_mode_sync(sd, BAR_SORT_MODE_COLLECTION); } - options->layout.panels.sort.mode_state = sd->mode; } /* this takes control of src_list */ @@ -351,19 +351,15 @@ static void bar_sort_set_action(SortData *sd, SortActionType action, const gchar *filter_key) { - options->layout.panels.sort.action_state = sd->action = action; + sd->action = action; if (action == BAR_SORT_FILTER) { if (!filter_key) filter_key = ""; sd->filter_key = filter_key; - g_free(options->layout.panels.sort.action_filter); - options->layout.panels.sort.action_filter = g_strdup(filter_key); } else { sd->filter_key = NULL; - g_free(options->layout.panels.sort.action_filter); - options->layout.panels.sort.action_filter = g_strdup(""); } } @@ -393,7 +389,7 @@ static void bar_sort_set_selection(SortData *sd, SortSelectionType selection) { - options->layout.panels.sort.selection_state = sd->selection = selection; + sd->selection = selection; } static void bar_sort_set_selection_image_cb(GtkWidget *button, gpointer data) @@ -555,14 +551,13 @@ g_free(sd); } -GtkWidget *bar_sort_new(LayoutWindow *lw) +static GtkWidget *bar_sort_new(LayoutWindow *lw, SortActionType action, SortModeType mode, SortSelectionType selection, const gchar *filter_key) { SortData *sd; GtkWidget *buttongrp; GtkWidget *label; GtkWidget *tbar; GtkWidget *combo; - SortModeType mode; GList *editors_list, *work; gboolean have_filter; @@ -572,14 +567,14 @@ sd->lw = lw; - mode = CLAMP(options->layout.panels.sort.mode_state, 0, BAR_SORT_MODE_COUNT - 1); - sd->action = CLAMP(options->layout.panels.sort.action_state, 0, BAR_SORT_ACTION_COUNT - 1); + sd->action = action; - if (sd->action == BAR_SORT_FILTER && - (!options->layout.panels.sort.action_filter || !options->layout.panels.sort.action_filter[0])) + if (sd->action == BAR_SORT_FILTER && (!filter_key || !filter_key[0])) + { sd->action = BAR_SORT_COPY; + } - sd->selection = CLAMP(options->layout.panels.sort.selection_state, 0, BAR_SORT_SELECTION_COUNT - 1); + sd->selection = selection; sd->undo_src = NULL; sd->undo_dest = NULL; @@ -625,7 +620,7 @@ if (!editor_is_filter(editor->key)) continue; - if (sd->action == BAR_SORT_FILTER && strcmp(editor->key, options->layout.panels.sort.action_filter) == 0) + if (sd->action == BAR_SORT_FILTER && strcmp(editor->key, filter_key) == 0) { bar_sort_set_action(sd, sd->action, editor->key); select = TRUE; @@ -671,4 +666,60 @@ return sd->vbox; } + +GtkWidget *bar_sort_new_from_config(LayoutWindow *lw, const gchar **attribute_names, const gchar **attribute_values) +{ + GtkWidget *bar; + + gboolean enabled = TRUE; + gint action = 0; + gint mode = 0; + gint selection = 0; + gchar *filter_key = NULL; + + while (attribute_names && *attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; + + if (READ_BOOL_FULL("enabled", enabled)) continue; + if (READ_INT_CLAMP_FULL("action", action, 0, BAR_SORT_ACTION_COUNT - 1)) continue; + if (READ_INT_CLAMP_FULL("mode", mode, 0, BAR_SORT_MODE_COUNT - 1)) continue; + if (READ_INT_CLAMP_FULL("selection", selection, 0, BAR_SORT_SELECTION_COUNT - 1)) continue; + if (READ_CHAR_FULL("filter_key", filter_key)) continue; + + DEBUG_1("unknown attribute %s = %s", option, value); + } + bar = bar_sort_new(lw, action, mode, selection, filter_key); + + g_free(filter_key); + if (enabled) gtk_widget_show(bar); + return bar; +} + +GtkWidget *bar_sort_new_default(LayoutWindow *lw) +{ + return bar_sort_new_from_config(lw, NULL, NULL); +} + +void bar_sort_write_config(GtkWidget *bar, GString *outstr, gint indent) +{ + SortData *sd; + + if (!bar) return; + sd = g_object_get_data(G_OBJECT(bar), "bar_sort_data"); + if (!sd) return; + + WRITE_STRING("<bar_sort\n"); + indent++; + write_bool_option(outstr, indent, "enabled", GTK_WIDGET_VISIBLE(bar)); + WRITE_INT(*sd, mode); + WRITE_INT(*sd, action); + WRITE_INT(*sd, selection); + WRITE_CHAR(*sd, filter_key); + indent--; + WRITE_STRING("/>\n"); +} + + /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/bar_sort.h Tue Feb 24 21:08:16 2009 +0000 +++ b/src/bar_sort.h Tue Feb 24 22:21:28 2009 +0000 @@ -15,9 +15,11 @@ #define BAR_SORT_H -GtkWidget *bar_sort_new(LayoutWindow *lw); +GtkWidget *bar_sort_new_default(LayoutWindow *lw); +GtkWidget *bar_sort_new_from_config(LayoutWindow *lw, const gchar **attribute_names, const gchar **attribute_values); void bar_sort_close(GtkWidget *bar); +void bar_sort_write_config(GtkWidget *bar, GString *outstr, gint indent); #endif /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/layout.c Tue Feb 24 21:08:16 2009 +0000 +++ b/src/layout.c Tue Feb 24 22:21:28 2009 +0000 @@ -35,6 +35,7 @@ #include "metadata.h" #include "rcfile.h" #include "bar.h" +#include "bar_sort.h" #ifdef HAVE_LIRC #include "lirc.h" @@ -2157,12 +2158,6 @@ WRITE_SEPARATOR(); WRITE_BOOL(*layout, toolbar_hidden); - - WRITE_BOOL(*layout, panels.sort.enabled); - WRITE_INT(*layout, panels.sort.action_state); - WRITE_INT(*layout, panels.sort.mode_state); - WRITE_INT(*layout, panels.sort.selection_state); - WRITE_CHAR(*layout, panels.sort.action_filter); } @@ -2173,6 +2168,7 @@ layout_write_attributes(&lw->options, outstr, indent + 1); WRITE_STRING(">\n"); + bar_sort_write_config(lw->bar_sort, outstr, indent + 1); bar_write_config(lw->bar, outstr, indent + 1); WRITE_STRING("</layout>\n"); @@ -2224,14 +2220,6 @@ if (READ_BOOL(*layout, tools_restore_state)) continue; if (READ_BOOL(*layout, toolbar_hidden)) continue; - /* panels */ - if (READ_BOOL(*layout, panels.sort.enabled)) continue; - if (READ_INT(*layout, panels.sort.action_state)) continue; - if (READ_INT(*layout, panels.sort.mode_state)) continue; - if (READ_INT(*layout, panels.sort.selection_state)) continue; - if (READ_CHAR(*layout, panels.sort.action_filter)) continue; - - DEBUG_1("unknown attribute %s = %s", option, value); }
--- a/src/layout_util.c Tue Feb 24 21:08:16 2009 +0000 +++ b/src/layout_util.c Tue Feb 24 22:21:28 2009 +0000 @@ -50,6 +50,7 @@ #define MENU_EDIT_ACTION_OFFSET 16 static gboolean layout_bar_enabled(LayoutWindow *lw); +static gboolean layout_bar_sort_enabled(LayoutWindow *lw); /* *----------------------------------------------------------------------------- @@ -688,7 +689,7 @@ { LayoutWindow *lw = data; - if (lw->options.panels.sort.enabled == gtk_toggle_action_get_active(action)) return; + if (layout_bar_sort_enabled(lw) == gtk_toggle_action_get_active(action)) return; layout_exit_fullscreen(lw); layout_bar_sort_toggle(lw); @@ -1867,7 +1868,7 @@ gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_enabled(lw)); action = gtk_action_group_get_action(lw->action_group, "SBarSort"); - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.panels.sort.enabled); + gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), layout_bar_sort_enabled(lw)); action = gtk_action_group_get_action(lw->action_group, "HideToolbar"); gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.toolbar_hidden); @@ -2040,32 +2041,35 @@ // bar_info_selection(lw->bar_info, count - 1); } +static gboolean layout_bar_sort_enabled(LayoutWindow *lw) +{ + return lw->bar_sort && GTK_WIDGET_VISIBLE(lw->bar_sort); +} + + static void layout_bar_sort_destroyed(GtkWidget *widget, gpointer data) { LayoutWindow *lw = data; lw->bar_sort = NULL; - if (lw->utility_box) - { - /* destroyed from within itself */ - lw->options.panels.sort.enabled = FALSE; +/* + do not call layout_util_sync_views(lw) here + this is called either when whole layout is destroyed - no need for update + or when the bar is replaced - sync is called by upper function at the end of whole operation - layout_util_sync_views(lw); - } +*/ } -static void layout_bar_sort_new(LayoutWindow *lw) +static void layout_bar_sort_set_default(LayoutWindow *lw) { + GtkWidget *bar; + if (!lw->utility_box) return; - lw->bar_sort = bar_sort_new(lw); - g_signal_connect(G_OBJECT(lw->bar_sort), "destroy", - G_CALLBACK(layout_bar_sort_destroyed), lw); - lw->options.panels.sort.enabled = TRUE; - - gtk_box_pack_end(GTK_BOX(lw->utility_box), lw->bar_sort, FALSE, FALSE, 0); - gtk_widget_show(lw->bar_sort); + bar = bar_sort_new_default(lw); + + layout_bar_sort_set(lw, bar); } static void layout_bar_sort_close(LayoutWindow *lw) @@ -2075,19 +2079,38 @@ bar_sort_close(lw->bar_sort); lw->bar_sort = NULL; } - lw->options.panels.sort.enabled = FALSE; +} + +void layout_bar_sort_set(LayoutWindow *lw, GtkWidget *bar) +{ + if (!lw->utility_box) return; + + layout_bar_sort_close(lw); /* if any */ + + if (!bar) return; + lw->bar_sort = bar; + + g_signal_connect(G_OBJECT(lw->bar_sort), "destroy", + G_CALLBACK(layout_bar_sort_destroyed), lw); + + gtk_box_pack_end(GTK_BOX(lw->utility_box), lw->bar_sort, FALSE, FALSE, 0); } void layout_bar_sort_toggle(LayoutWindow *lw) { - if (lw->options.panels.sort.enabled) + if (layout_bar_sort_enabled(lw)) { - layout_bar_sort_close(lw); + gtk_widget_hide(lw->bar_sort); } else { - layout_bar_sort_new(lw); + if (!lw->bar_sort) + { + layout_bar_sort_set_default(lw); + } + gtk_widget_show(lw->bar_sort); } + layout_util_sync_views(lw); } void layout_bars_new_image(LayoutWindow *lw) @@ -2112,11 +2135,6 @@ gtk_box_pack_start(GTK_BOX(lw->utility_box), image, TRUE, TRUE, 0); gtk_widget_show(image); - if (lw->options.panels.sort.enabled) - { - layout_bar_sort_new(lw); - } - return lw->utility_box; }
--- a/src/layout_util.h Tue Feb 24 21:08:16 2009 +0000 +++ b/src/layout_util.h Tue Feb 24 22:21:28 2009 +0000 @@ -47,8 +47,8 @@ void layout_bar_toggle(LayoutWindow *lw); void layout_bar_set(LayoutWindow *lw, GtkWidget *bar); -void layout_bar_exif_toggle(LayoutWindow *lw); void layout_bar_sort_toggle(LayoutWindow *lw); +void layout_bar_sort_set(LayoutWindow *lw, GtkWidget *bar); void layout_bars_new_image(LayoutWindow *lw); void layout_bars_new_selection(LayoutWindow *lw, gint count);
--- a/src/options.c Tue Feb 24 21:08:16 2009 +0000 +++ b/src/options.c Tue Feb 24 22:21:28 2009 +0000 @@ -120,12 +120,6 @@ options->open_recent_list_maxsize = 10; options->place_dialogs_under_mouse = FALSE; - options->layout.panels.sort.action_state = 0; - options->layout.panels.sort.enabled = FALSE; - options->layout.panels.sort.mode_state = 0; - options->layout.panels.sort.selection_state = 0; - options->layout.panels.sort.action_filter = NULL; - options->progressive_key_scrolling = TRUE; options->metadata.enable_metadata_dirs = FALSE; @@ -205,14 +199,12 @@ *dest = *src; dest->order = g_strdup(src->order); dest->home_path = g_strdup(src->home_path); - dest->panels.sort.action_filter = g_strdup(src->panels.sort.action_filter); } void free_layout_options_content(LayoutOptions *dest) { if (dest->order) g_free(dest->order); if (dest->home_path) g_free(dest->home_path); - if (dest->panels.sort.action_filter) g_free(dest->panels.sort.action_filter); } static void sync_options_with_current_state(ConfOptions *options)
--- a/src/rcfile.c Tue Feb 24 21:08:16 2009 +0000 +++ b/src/rcfile.c Tue Feb 24 22:21:28 2009 +0000 @@ -21,6 +21,7 @@ #include "bar_exif.h" #include "bar_histogram.h" #include "bar_keywords.h" +#include "bar_sort.h" #include "editors.h" #include "filefilter.h" #include "misc.h" @@ -881,6 +882,12 @@ layout_bar_set(lw, bar); options_parse_func_push(parser_data, options_parse_bar, NULL, lw->bar); } + else if (g_ascii_strcasecmp(element_name, "bar_sort") == 0) + { + GtkWidget *bar = bar_sort_new_from_config(lw, attribute_names, attribute_values); + layout_bar_sort_set(lw, bar); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } else { DEBUG_1("unexpected in <layout>: <%s>", element_name);
--- a/src/typedefs.h Tue Feb 24 21:08:16 2009 +0000 +++ b/src/typedefs.h Tue Feb 24 22:21:28 2009 +0000 @@ -513,18 +513,6 @@ gboolean toolbar_hidden; gchar *home_path; - - /* panels */ - struct { - struct { - gboolean enabled; - gint mode_state; - gint action_state; - gint selection_state; - gchar *action_filter; - } sort; - } panels; - }; struct _LayoutWindow