From f3f24dd74e01f5b7a0a4f99e0e122e02174c2dd0 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 6 Oct 2014 01:33:37 +0200 Subject: [PATCH] Make AgWindow use the new AgHeaderBar --- src/ag-window.c | 83 ++++++-------- src/resources/ui/ag-window.ui | 197 +--------------------------------- 2 files changed, 33 insertions(+), 247 deletions(-) diff --git a/src/ag-window.c b/src/ag-window.c index bb66833..55d4118 100644 --- a/src/ag-window.c +++ b/src/ag-window.c @@ -35,11 +35,10 @@ #include "ag-display-theme.h" #include "ag-icon-view.h" #include "ag-chart-edit.h" +#include "ag-header-bar.h" struct _AgWindowPrivate { GtkWidget *header_bar; - GtkWidget *menubutton_stack; - GtkWidget *new_back_stack; GtkWidget *selection_toolbar; GtkWidget *stack; GtkWidget *house_system; @@ -1341,23 +1340,9 @@ ag_window_tab_changed_cb(GtkStack *stack, GParamSpec *pspec, AgWindow *window) } if (strcmp("list", active_tab_name) == 0) { - gtk_stack_set_visible_child_name( - GTK_STACK(priv->menubutton_stack), - "list" - ); - gtk_stack_set_visible_child_name( - GTK_STACK(priv->new_back_stack), - "new" - ); + ag_header_bar_set_mode(AG_HEADER_BAR(priv->header_bar), AG_HEADER_BAR_MODE_LIST); } else { - gtk_stack_set_visible_child_name( - GTK_STACK(priv->menubutton_stack), - "chart" - ); - gtk_stack_set_visible_child_name( - GTK_STACK(priv->new_back_stack), - "back" - ); + ag_header_bar_set_mode(AG_HEADER_BAR(priv->header_bar), AG_HEADER_BAR_MODE_CHART); // Note that priv->current_tab is actually the previously selected tab, // not the real active one! @@ -1516,44 +1501,46 @@ ag_window_refresh_action(GSimpleAction *action, static void ag_window_set_selection_mode(AgWindow *window, gboolean state) { - GtkStyleContext *style; GET_PRIV(window); - style = gtk_widget_get_style_context(priv->header_bar); + if (priv->current_tab != priv->tab_list) { + g_warning("You can activate selection mode only in the list view!"); + + return; + } + + g_debug("Set selection mode: %d", state); if (state) { - gtk_header_bar_set_show_close_button( - GTK_HEADER_BAR(priv->header_bar), - FALSE - ); - gtk_style_context_add_class(style, "selection-mode"); + ag_header_bar_set_mode(AG_HEADER_BAR(priv->header_bar), AG_HEADER_BAR_MODE_SELECTION); ag_icon_view_set_mode( AG_ICON_VIEW(priv->chart_list), AG_ICON_VIEW_MODE_SELECTION ); - gtk_widget_hide(priv->new_back_stack); - gtk_stack_set_visible_child_name( - GTK_STACK(priv->menubutton_stack), - "selection" - ); } else { - gtk_header_bar_set_show_close_button( - GTK_HEADER_BAR(priv->header_bar), - TRUE - ); - gtk_style_context_remove_class(style, "selection-mode"); + ag_header_bar_set_mode(AG_HEADER_BAR(priv->header_bar), AG_HEADER_BAR_MODE_LIST); ag_icon_view_set_mode( AG_ICON_VIEW(priv->chart_list), AG_ICON_VIEW_MODE_NORMAL ); - gtk_widget_show_all(priv->new_back_stack); - gtk_stack_set_visible_child_name( - GTK_STACK(priv->menubutton_stack), - "list" - ); } } +static void +ag_window_header_bar_mode_change_cb(AgHeaderBar *header_bar, + GParamSpec *pspec, + AgWindow *window) +{ + AgHeaderBarMode mode; + + mode = ag_header_bar_get_mode(header_bar); + + ag_window_set_selection_mode( + window, + (mode == AG_HEADER_BAR_MODE_SELECTION) + ); +} + static void ag_window_icon_view_mode_cb(AgIconView *icon_view, GParamSpec *pspec, @@ -1585,8 +1572,6 @@ ag_window_selection_mode_action(GSimpleAction *action, g_action_change_state(G_ACTION(action), g_variant_new_boolean(new_state)); g_variant_unref(state); - g_debug("Set selection mode: %d", new_state); - ag_window_set_selection_mode(window, new_state); } @@ -2134,16 +2119,6 @@ ag_window_class_init(AgWindowClass *klass) AgWindow, header_bar ); - gtk_widget_class_bind_template_child_private( - widget_class, - AgWindow, - new_back_stack - ); - gtk_widget_class_bind_template_child_private( - widget_class, - AgWindow, - menubutton_stack - ); gtk_widget_class_bind_template_child_private( widget_class, AgWindow, @@ -2242,6 +2217,10 @@ ag_window_class_init(AgWindowClass *klass) widget_class, ag_window_house_system_changed_cb ); + gtk_widget_class_bind_template_callback( + widget_class, + ag_window_header_bar_mode_change_cb + ); } static gboolean diff --git a/src/resources/ui/ag-window.ui b/src/resources/ui/ag-window.ui index 1231d95..d519370 100644 --- a/src/resources/ui/ag-window.ui +++ b/src/resources/ui/ag-window.ui @@ -80,201 +80,8 @@ astrognome - - True - False - False - True - Astrognome - - - True - False - False - - - True - False - - - True - False - win.new-chart - - - - True - 1 - document-new-symbolic - - - - - 0 - - - - - True - False - win.refresh - - - - True - 1 - view-refresh-symbolic - - - - - 1 - - - - - new - - - - - True - False - win.back - - - - True - 1 - go-previous-symbolic - - - - - back - - - - - - - True - center - False - - - - - - True - False - False - - - True - False - center - win.selection - - - - True - 1 - object-select-symbolic - - - - - list - - - - - True - False - - - True - center - False - win.view-menu - view_menu - False - - - - True - 1 - document-properties-symbolic - - - - - 0 - - - - - True - center - False - win.gear-menu - gear_menu - False - - - - True - 1 - open-menu-symbolic - - - - - 1 - - - - - chart - - - - - True - False - - - True - False - Cancel - - - - - - selection - - - - - end - - + +