Mercurial > geeqie
changeset 1317:cd7204a18f14
simplified and improved bar configuration
author | nadvornik |
---|---|
date | Tue, 24 Feb 2009 20:34:39 +0000 |
parents | 732083928afb |
children | fb76c291b00f |
files | src/bar.c src/bar.h src/layout.c src/layout_image.c src/layout_util.c src/layout_util.h src/options.c src/rcfile.c src/typedefs.h |
diffstat | 9 files changed, 118 insertions(+), 110 deletions(-) [+] |
line wrap: on
line diff
--- a/src/bar.c Tue Feb 24 18:00:45 2009 +0000 +++ b/src/bar.c Tue Feb 24 20:34:39 2009 +0000 @@ -43,6 +43,7 @@ GList *(*list_func)(gpointer); gpointer list_data; + gint width; }; static void bar_expander_move(GtkWidget *widget, gpointer data, gboolean up) @@ -156,7 +157,12 @@ bd = g_object_get_data(G_OBJECT(bar), "bar_data"); if (!bd) return; - WRITE_STRING("<bar>\n"); + WRITE_STRING("<bar\n"); + indent++; + write_bool_option(outstr, indent, "enabled", GTK_WIDGET_VISIBLE(bar)); + write_uint_option(outstr, indent, "width", bd->width); + indent--; + WRITE_STRING(">\n"); list = gtk_container_get_children(GTK_CONTAINER(bd->vbox)); work = list; @@ -250,7 +256,7 @@ } -void bar_populate_default(GtkWidget *bar) +static void bar_populate_default(GtkWidget *bar) { GtkWidget *widget; widget = bar_pane_histogram_new(_("Histogram"), 80, TRUE); @@ -269,6 +275,13 @@ bar_add(bar, widget); } +static void bar_sized(GtkWidget *widget, GtkAllocation *allocation, gpointer data) +{ + BarData *bd = data; + bd->width = allocation->width; +} + + static void bar_width(BarData *bd, gint val) { gint size; @@ -277,7 +290,6 @@ size = CLAMP(size + val, BAR_SIZE_INCREMENT * 2, BAR_SIZE_INCREMENT * 16); gtk_widget_set_size_request(bd->widget, size, -1); - options->layout.panels.info.width = bd->widget->allocation.width; } static void bar_larger(GtkWidget *widget, gpointer data) @@ -329,6 +341,12 @@ g_signal_connect(G_OBJECT(bd->widget), "destroy", G_CALLBACK(bar_destroy), bd); + g_signal_connect(G_OBJECT(bd->widget), "size_allocate", + G_CALLBACK(bar_sized), bd); + + bd->width = PANEL_DEFAULT_WIDTH; + gtk_widget_set_size_request(bd->widget, bd->width, -1); + box = gtk_hbox_new(FALSE, 0); sizer = sizer_new(bd->widget, bounding_widget, SIZER_POS_LEFT); @@ -388,5 +406,40 @@ return bd->widget; } +GtkWidget *bar_new_default(GtkWidget *bounding_widget) +{ + GtkWidget *bar = bar_new(bounding_widget); + + bar_populate_default(bar); + + gtk_widget_show(bar); + + return bar; +} + +GtkWidget *bar_new_from_config(GtkWidget *bounding_widget, const gchar **attribute_names, const gchar **attribute_values) +{ + GtkWidget *bar = bar_new(bounding_widget); + + gboolean enabled = TRUE; + gint width = PANEL_DEFAULT_WIDTH; + + while (*attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; + + if (READ_BOOL_FULL("enabled", enabled)) continue; + if (READ_INT_FULL("width", width)) continue; + + + DEBUG_1("unknown attribute %s = %s", option, value); + } + + gtk_widget_set_size_request(bar, width, -1); + if (enabled) gtk_widget_show(bar); + return bar; +} + /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/bar.h Tue Feb 24 18:00:45 2009 +0000 +++ b/src/bar.h Tue Feb 24 20:34:39 2009 +0000 @@ -31,8 +31,8 @@ GtkWidget *bar_new(GtkWidget *bounding_widget); - -void bar_populate_default(GtkWidget *bar); +GtkWidget *bar_new_default(GtkWidget *bounding_widget); +GtkWidget *bar_new_from_config(GtkWidget *bounding_widget, const gchar **attribute_names, const gchar **attribute_values); void bar_close(GtkWidget *bar);
--- a/src/layout.c Tue Feb 24 18:00:45 2009 +0000 +++ b/src/layout.c Tue Feb 24 20:34:39 2009 +0000 @@ -2023,7 +2023,6 @@ lw->options.main_window.hdivider_pos = MAIN_WINDOW_DIV_HPOS; lw->options.main_window.vdivider_pos = MAIN_WINDOW_DIV_VPOS; lw->options.float_window.vdivider_pos = MAIN_WINDOW_DIV_VPOS; - lw->options.panels.info.width = PANEL_DEFAULT_WIDTH; } /* window */ @@ -2159,10 +2158,6 @@ WRITE_BOOL(*layout, toolbar_hidden); - WRITE_BOOL(*layout, panels.exif.enabled); - WRITE_INT(*layout, panels.exif.width); - WRITE_BOOL(*layout, panels.info.enabled); - WRITE_INT(*layout, panels.info.width); WRITE_BOOL(*layout, panels.sort.enabled); WRITE_INT(*layout, panels.sort.action_state); WRITE_INT(*layout, panels.sort.mode_state); @@ -2230,10 +2225,6 @@ if (READ_BOOL(*layout, toolbar_hidden)) continue; /* panels */ - if (READ_BOOL(*layout, panels.exif.enabled)) continue; - if (READ_INT_CLAMP(*layout, panels.exif.width, PANEL_MIN_WIDTH, PANEL_MAX_WIDTH)) continue; - if (READ_BOOL(*layout, panels.info.enabled)) continue; - if (READ_INT_CLAMP(*layout, panels.info.width, PANEL_MIN_WIDTH, PANEL_MAX_WIDTH)) continue; 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;
--- a/src/layout_image.c Tue Feb 24 18:00:45 2009 +0000 +++ b/src/layout_image.c Tue Feb 24 20:34:39 2009 +0000 @@ -1759,7 +1759,6 @@ if (fd == layout_image_get_fd(lw)) { image_set_fd(lw->image, fd); - layout_bars_maint_renamed(lw); } }
--- a/src/layout_util.c Tue Feb 24 18:00:45 2009 +0000 +++ b/src/layout_util.c Tue Feb 24 20:34:39 2009 +0000 @@ -49,6 +49,7 @@ #define MENU_EDIT_ACTION_OFFSET 16 +static gboolean layout_bar_enabled(LayoutWindow *lw); /* *----------------------------------------------------------------------------- @@ -669,7 +670,7 @@ layout_exit_fullscreen(lw); - if (lw->options.panels.info.enabled == gtk_toggle_action_get_active(action)) return; + if (layout_bar_enabled(lw) == gtk_toggle_action_get_active(action)) return; layout_bar_toggle(lw); } @@ -1862,7 +1863,7 @@ gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.tools_float); action = gtk_action_group_get_action(lw->action_group, "SBar"); - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.panels.info.enabled); + 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); @@ -1941,18 +1942,22 @@ *----------------------------------------------------------------------------- */ +static gboolean layout_bar_enabled(LayoutWindow *lw) +{ + return lw->bar && GTK_WIDGET_VISIBLE(lw->bar); +} + static void layout_bar_destroyed(GtkWidget *widget, gpointer data) { LayoutWindow *lw = data; lw->bar = NULL; +/* + 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 - if (lw->utility_box) - { - /* destroyed from within itself */ - lw->options.panels.info.enabled = FALSE; - layout_util_sync_views(lw); - } +*/ } static GList *layout_bar_list_cb(gpointer data) @@ -1962,96 +1967,78 @@ return layout_selection_list(lw); } -static void layout_bar_sized(GtkWidget *widget, GtkAllocation *allocation, gpointer data) +static void layout_bar_set_default(LayoutWindow *lw) { - LayoutWindow *lw = data; - - if (!lw->bar) return; + GtkWidget *bar; - lw->options.panels.info.width = allocation->width; -} - -void layout_bar_new(LayoutWindow *lw, gboolean populate) -{ if (!lw->utility_box) return; - if (!lw->bar) - { - lw->bar = bar_new(lw->utility_box); - - if (populate) - { - bar_populate_default(lw->bar); - } - - bar_set_selection_func(lw->bar, layout_bar_list_cb, lw); - g_signal_connect(G_OBJECT(lw->bar), "destroy", - G_CALLBACK(layout_bar_destroyed), lw); - g_signal_connect(G_OBJECT(lw->bar), "size_allocate", - G_CALLBACK(layout_bar_sized), lw); - - - gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar, FALSE, FALSE, 0); - } - - lw->options.panels.info.enabled = TRUE; - gtk_widget_set_size_request(lw->bar, lw->options.panels.info.width, -1); - bar_set_fd(lw->bar, layout_image_get_fd(lw)); - gtk_widget_show(lw->bar); + bar = bar_new_default(lw->utility_box); + + layout_bar_set(lw, bar); } -void layout_bar_close(LayoutWindow *lw) +static void layout_bar_close(LayoutWindow *lw) { if (lw->bar) { bar_close(lw->bar); lw->bar = NULL; } - lw->options.panels.info.enabled = FALSE; } -static void layout_bar_hide(LayoutWindow *lw) + +void layout_bar_set(LayoutWindow *lw, GtkWidget *bar) { - if (lw->bar) + if (!lw->utility_box) return; + + layout_bar_close(lw); /* if any */ + + if (!bar) return; + lw->bar = bar; + + bar_set_selection_func(lw->bar, layout_bar_list_cb, lw); + g_signal_connect(G_OBJECT(lw->bar), "destroy", + G_CALLBACK(layout_bar_destroyed), lw); + + + gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar, FALSE, FALSE, 0); + + bar_set_fd(lw->bar, layout_image_get_fd(lw)); +} + + +void layout_bar_toggle(LayoutWindow *lw) +{ + if (layout_bar_enabled(lw)) { gtk_widget_hide(lw->bar); } - lw->options.panels.info.enabled = FALSE; -} - -void layout_bar_toggle(LayoutWindow *lw) -{ - if (lw->options.panels.info.enabled) - { - layout_bar_hide(lw); - } else { - layout_bar_new(lw, TRUE); + if (!lw->bar) + { + layout_bar_set_default(lw); + } + gtk_widget_show(lw->bar); } + layout_util_sync_views(lw); } static void layout_bar_new_image(LayoutWindow *lw) { - if (!lw->bar || !lw->options.panels.info.enabled) return; + if (!layout_bar_enabled(lw)) return; bar_set_fd(lw->bar, layout_image_get_fd(lw)); } static void layout_bar_new_selection(LayoutWindow *lw, gint count) { - if (!lw->bar || !lw->options.panels.info.enabled) return; + if (!layout_bar_enabled(lw)) return; // bar_info_selection(lw->bar_info, count - 1); } -static void layout_bar_maint_renamed(LayoutWindow *lw) -{ - if (!lw->bar || !lw->options.panels.info.enabled) return; - -// bar_maint_renamed(lw->bar_info, layout_image_get_fd(lw)); -} - static void layout_bar_sort_destroyed(GtkWidget *widget, gpointer data) { LayoutWindow *lw = data; @@ -2129,11 +2116,6 @@ layout_bar_sort_new(lw); } - if (lw->options.panels.info.enabled) - { - layout_bar_new(lw, TRUE); - } - return lw->utility_box; } @@ -2143,11 +2125,6 @@ layout_bar_close(lw); } -void layout_bars_maint_renamed(LayoutWindow *lw) -{ - layout_bar_maint_renamed(lw); -} - static void layout_exif_window_destroy(GtkWidget *widget, gpointer data) { LayoutWindow *lw = data;
--- a/src/layout_util.h Tue Feb 24 18:00:45 2009 +0000 +++ b/src/layout_util.h Tue Feb 24 20:34:39 2009 +0000 @@ -45,8 +45,7 @@ void layout_bar_toggle(LayoutWindow *lw); -void layout_bar_new(LayoutWindow *lw, gboolean populate); -void layout_bar_close(LayoutWindow *lw); +void layout_bar_set(LayoutWindow *lw, GtkWidget *bar); void layout_bar_exif_toggle(LayoutWindow *lw); void layout_bar_sort_toggle(LayoutWindow *lw); @@ -57,8 +56,6 @@ GtkWidget *layout_bars_prepare(LayoutWindow *lw, GtkWidget *image); void layout_bars_close(LayoutWindow *lw); -void layout_bars_maint_renamed(LayoutWindow *lw); - void layout_exif_window_new(LayoutWindow *lw); #endif
--- a/src/options.c Tue Feb 24 18:00:45 2009 +0000 +++ b/src/options.c Tue Feb 24 20:34:39 2009 +0000 @@ -120,10 +120,6 @@ options->open_recent_list_maxsize = 10; options->place_dialogs_under_mouse = FALSE; - options->layout.panels.exif.enabled = FALSE; - options->layout.panels.exif.width = PANEL_DEFAULT_WIDTH; - options->layout.panels.info.enabled = FALSE; - options->layout.panels.info.width = PANEL_DEFAULT_WIDTH; options->layout.panels.sort.action_state = 0; options->layout.panels.sort.enabled = FALSE; options->layout.panels.sort.mode_state = 0;
--- a/src/rcfile.c Tue Feb 24 18:00:45 2009 +0000 +++ b/src/rcfile.c Tue Feb 24 20:34:39 2009 +0000 @@ -877,9 +877,8 @@ LayoutWindow *lw = data; if (g_ascii_strcasecmp(element_name, "bar") == 0) { - if (lw->bar) - layout_bar_close(lw); - layout_bar_new(lw, FALSE); + GtkWidget *bar = bar_new_from_config(lw->utility_box, attribute_names, attribute_values); + layout_bar_set(lw, bar); options_parse_func_push(parser_data, options_parse_bar, NULL, lw->bar); } else @@ -889,6 +888,12 @@ } } +static void options_parse_layout_end(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, gpointer data, GError **error) +{ + LayoutWindow *lw = data; + layout_util_sync(lw); +} + static void options_parse_toplevel(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, "global") == 0) @@ -909,7 +914,7 @@ { LayoutWindow *lw; lw = layout_new_from_config(attribute_names, attribute_values, parser_data->startup); - options_parse_func_push(parser_data, options_parse_layout, NULL, lw); + options_parse_func_push(parser_data, options_parse_layout, options_parse_layout_end, lw); } else {
--- a/src/typedefs.h Tue Feb 24 18:00:45 2009 +0000 +++ b/src/typedefs.h Tue Feb 24 20:34:39 2009 +0000 @@ -518,16 +518,6 @@ struct { struct { gboolean enabled; - gint width; - } info; - - struct { - gboolean enabled; - gint width; - } exif; - - struct { - gboolean enabled; gint mode_state; gint action_state; gint selection_state;