Mercurial > geeqie
changeset 1335:588d96cda850
save and restore toolbar configuration
author | nadvornik |
---|---|
date | Sat, 28 Feb 2009 12:50:39 +0000 |
parents | f97450e632a1 |
children | 4179d41d1149 |
files | src/layout.c src/layout_util.c src/layout_util.h src/rcfile.c src/typedefs.h |
diffstat | 5 files changed, 109 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/layout.c Sat Feb 28 09:59:27 2009 +0000 +++ b/src/layout.c Sat Feb 28 12:50:39 2009 +0000 @@ -218,7 +218,7 @@ gtk_box_pack_start(GTK_BOX(box), menu_bar, FALSE, FALSE, 0); gtk_widget_show(menu_bar); - lw->toolbar = layout_button_bar(lw); + lw->toolbar = layout_actions_toolbar(lw); gtk_box_pack_start(GTK_BOX(box), lw->toolbar, FALSE, FALSE, 0); if (!lw->options.toolbar_hidden) gtk_widget_show(lw->toolbar); @@ -1971,6 +1971,7 @@ file_data_unref(lw->dir_fd); } + string_list_free(lw->toolbar_actions); free_layout_options_content(&lw->options); g_free(lw); } @@ -2177,6 +2178,8 @@ bar_sort_write_config(lw->bar_sort, outstr, indent + 1); bar_write_config(lw->bar, outstr, indent + 1); + layout_toolbar_write_config(lw, outstr, indent + 1); + WRITE_STRING("</layout>\n"); }
--- a/src/layout_util.c Sat Feb 28 09:59:27 2009 +0000 +++ b/src/layout_util.c Sat Feb 28 12:50:39 2009 +0000 @@ -43,6 +43,7 @@ #include "view_dir.h" #include "window.h" #include "metadata.h" +#include "rcfile.h" #include <gdk/gdkkeysyms.h> /* for keyboard values */ @@ -1444,17 +1445,6 @@ " </menu>" " </menubar>" " <toolbar name='ToolBar'>" -" <toolitem action='Thumbnails'/>" -" <toolitem action='Back'/>" -" <toolitem action='Home'/>" -" <toolitem action='Refresh'/>" -" <toolitem action='ZoomIn'/>" -" <toolitem action='ZoomOut'/>" -" <toolitem action='ZoomFit'/>" -" <toolitem action='ZoomFit'/>" -" <toolitem action='Zoom100'/>" -" <toolitem action='Preferences'/>" -" <toolitem action='FloatTools'/>" " </toolbar>" "<accelerator action='PrevImageAlt1'/>" "<accelerator action='PrevImageAlt2'/>" @@ -1478,7 +1468,6 @@ "<accelerator action='ConnectZoomFitAlt1'/>" "</ui>"; - static gchar *menu_translate(const gchar *path, gpointer data) { return (gchar *)(_(path)); @@ -1727,6 +1716,9 @@ exit(EXIT_FAILURE); } + layout_toolbar_clear(lw); + layout_toolbar_add_default(lw); + layout_actions_setup_marks(lw); layout_actions_setup_editors(lw); layout_copy_path_update(lw); @@ -1747,7 +1739,7 @@ return gtk_ui_manager_get_widget(lw->ui_manager, "/MainMenu"); } -GtkWidget *layout_button_bar(LayoutWindow *lw) +GtkWidget *layout_actions_toolbar(LayoutWindow *lw) { GtkWidget *bar = gtk_ui_manager_get_widget(lw->ui_manager, "/ToolBar"); gtk_toolbar_set_icon_size(GTK_TOOLBAR(bar), GTK_ICON_SIZE_SMALL_TOOLBAR); @@ -1755,6 +1747,77 @@ return bar; } +void layout_toolbar_clear(LayoutWindow *lw) +{ + if (lw->toolbar_merge_id) + { + gtk_ui_manager_remove_ui(lw->ui_manager, lw->toolbar_merge_id); + gtk_ui_manager_ensure_update(lw->ui_manager); + } + string_list_free(lw->toolbar_actions); + lw->toolbar_actions = NULL; + + lw->toolbar_merge_id = gtk_ui_manager_new_merge_id(lw->ui_manager); +} + + +void layout_toolbar_add(LayoutWindow *lw, const gchar *action) +{ + if (!action || !lw->ui_manager) return; + gtk_ui_manager_add_ui(lw->ui_manager, lw->toolbar_merge_id, "/ToolBar", action, action, GTK_UI_MANAGER_TOOLITEM, FALSE); + lw->toolbar_actions = g_list_append(lw->toolbar_actions, g_strdup(action)); +} + + +void layout_toolbar_add_default(LayoutWindow *lw) +{ + layout_toolbar_add(lw, "Thumbnails"); + layout_toolbar_add(lw, "Back"); + layout_toolbar_add(lw, "Home"); + layout_toolbar_add(lw, "Refresh"); + layout_toolbar_add(lw, "ZoomIn"); + layout_toolbar_add(lw, "ZoomOut"); + layout_toolbar_add(lw, "ZoomFit"); + layout_toolbar_add(lw, "Zoom100"); + layout_toolbar_add(lw, "Preferences"); + layout_toolbar_add(lw, "FloatTools"); +} + +void layout_toolbar_write_config(LayoutWindow *lw, GString *outstr, gint indent) +{ + GList *work = lw->toolbar_actions; + WRITE_STRING("<toolbar>\n"); + indent++; + while (work) + { + gchar *action = work->data; + work = work->next; + WRITE_STRING("<toolitem\n"); + write_char_option(outstr, indent + 1, "action", action); + WRITE_STRING("/>\n"); + } + indent--; + WRITE_STRING("</toolbar>\n"); +} + +void layout_toolbar_add_from_config(LayoutWindow *lw, const gchar **attribute_names, const gchar **attribute_values) +{ + gchar *action = NULL; + + while (*attribute_names) + { + const gchar *option = *attribute_names++; + const gchar *value = *attribute_values++; + + if (READ_CHAR_FULL("action", action)) continue; + + DEBUG_1("unknown attribute %s = %s", option, value); + } + + layout_toolbar_add(lw, action); + g_free(action); +} + /* *----------------------------------------------------------------------------- * misc
--- a/src/layout_util.h Sat Feb 28 09:59:27 2009 +0000 +++ b/src/layout_util.h Sat Feb 28 12:50:39 2009 +0000 @@ -33,9 +33,15 @@ void layout_actions_setup(LayoutWindow *lw); void layout_actions_add_window(LayoutWindow *lw, GtkWidget *window); GtkWidget *layout_actions_menu_bar(LayoutWindow *lw); +void layout_toolbar_add_from_config(LayoutWindow *lw, const gchar **attribute_names, const gchar **attribute_values); +GtkWidget *layout_actions_toolbar(LayoutWindow *lw); -GtkWidget *layout_button_bar(LayoutWindow *lw); +void layout_toolbar_clear(LayoutWindow *lw); +void layout_toolbar_add(LayoutWindow *lw, const gchar *action); +void layout_toolbar_add_default(LayoutWindow *lw); +void layout_toolbar_write_config(LayoutWindow *lw, GString *outstr, gint indent); + void layout_keyboard_init(LayoutWindow *lw, GtkWidget *window);
--- a/src/rcfile.c Sat Feb 28 09:59:27 2009 +0000 +++ b/src/rcfile.c Sat Feb 28 12:50:39 2009 +0000 @@ -887,6 +887,21 @@ } } +static void options_parse_toolbar(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) +{ + LayoutWindow *lw = data; + if (g_ascii_strcasecmp(element_name, "toolitem") == 0) + { + layout_toolbar_add_from_config(lw, attribute_names, attribute_values); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } + else + { + DEBUG_1("unexpected in <toolbar>: <%s>", element_name); + options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); + } +} + static void options_parse_layout(GQParserData *parser_data, GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer data, GError **error) { LayoutWindow *lw = data; @@ -902,6 +917,11 @@ layout_bar_sort_set(lw, bar); options_parse_func_push(parser_data, options_parse_leaf, NULL, NULL); } + else if (g_ascii_strcasecmp(element_name, "toolbar") == 0) + { + layout_toolbar_clear(lw); + options_parse_func_push(parser_data, options_parse_toolbar, NULL, lw); + } else { DEBUG_1("unexpected in <layout>: <%s>", element_name);