Make AgWindow use the new AgHeaderBar

This commit is contained in:
Gergely Polonkai 2014-10-06 01:33:37 +02:00
parent 449775aa43
commit f3f24dd74e
2 changed files with 33 additions and 247 deletions

View File

@ -35,11 +35,10 @@
#include "ag-display-theme.h" #include "ag-display-theme.h"
#include "ag-icon-view.h" #include "ag-icon-view.h"
#include "ag-chart-edit.h" #include "ag-chart-edit.h"
#include "ag-header-bar.h"
struct _AgWindowPrivate { struct _AgWindowPrivate {
GtkWidget *header_bar; GtkWidget *header_bar;
GtkWidget *menubutton_stack;
GtkWidget *new_back_stack;
GtkWidget *selection_toolbar; GtkWidget *selection_toolbar;
GtkWidget *stack; GtkWidget *stack;
GtkWidget *house_system; 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) { if (strcmp("list", active_tab_name) == 0) {
gtk_stack_set_visible_child_name( ag_header_bar_set_mode(AG_HEADER_BAR(priv->header_bar), AG_HEADER_BAR_MODE_LIST);
GTK_STACK(priv->menubutton_stack),
"list"
);
gtk_stack_set_visible_child_name(
GTK_STACK(priv->new_back_stack),
"new"
);
} else { } else {
gtk_stack_set_visible_child_name( ag_header_bar_set_mode(AG_HEADER_BAR(priv->header_bar), AG_HEADER_BAR_MODE_CHART);
GTK_STACK(priv->menubutton_stack),
"chart"
);
gtk_stack_set_visible_child_name(
GTK_STACK(priv->new_back_stack),
"back"
);
// Note that priv->current_tab is actually the previously selected tab, // Note that priv->current_tab is actually the previously selected tab,
// not the real active one! // not the real active one!
@ -1516,44 +1501,46 @@ ag_window_refresh_action(GSimpleAction *action,
static void static void
ag_window_set_selection_mode(AgWindow *window, gboolean state) ag_window_set_selection_mode(AgWindow *window, gboolean state)
{ {
GtkStyleContext *style;
GET_PRIV(window); 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) { if (state) {
gtk_header_bar_set_show_close_button( ag_header_bar_set_mode(AG_HEADER_BAR(priv->header_bar), AG_HEADER_BAR_MODE_SELECTION);
GTK_HEADER_BAR(priv->header_bar),
FALSE
);
gtk_style_context_add_class(style, "selection-mode");
ag_icon_view_set_mode( ag_icon_view_set_mode(
AG_ICON_VIEW(priv->chart_list), AG_ICON_VIEW(priv->chart_list),
AG_ICON_VIEW_MODE_SELECTION 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 { } else {
gtk_header_bar_set_show_close_button( ag_header_bar_set_mode(AG_HEADER_BAR(priv->header_bar), AG_HEADER_BAR_MODE_LIST);
GTK_HEADER_BAR(priv->header_bar),
TRUE
);
gtk_style_context_remove_class(style, "selection-mode");
ag_icon_view_set_mode( ag_icon_view_set_mode(
AG_ICON_VIEW(priv->chart_list), AG_ICON_VIEW(priv->chart_list),
AG_ICON_VIEW_MODE_NORMAL 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 static void
ag_window_icon_view_mode_cb(AgIconView *icon_view, ag_window_icon_view_mode_cb(AgIconView *icon_view,
GParamSpec *pspec, 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_action_change_state(G_ACTION(action), g_variant_new_boolean(new_state));
g_variant_unref(state); g_variant_unref(state);
g_debug("Set selection mode: %d", new_state);
ag_window_set_selection_mode(window, new_state); ag_window_set_selection_mode(window, new_state);
} }
@ -2134,16 +2119,6 @@ ag_window_class_init(AgWindowClass *klass)
AgWindow, AgWindow,
header_bar 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( gtk_widget_class_bind_template_child_private(
widget_class, widget_class,
AgWindow, AgWindow,
@ -2242,6 +2217,10 @@ ag_window_class_init(AgWindowClass *klass)
widget_class, widget_class,
ag_window_house_system_changed_cb ag_window_house_system_changed_cb
); );
gtk_widget_class_bind_template_callback(
widget_class,
ag_window_header_bar_mode_change_cb
);
} }
static gboolean static gboolean

View File

@ -80,201 +80,8 @@
<property name="icon_name">astrognome</property> <property name="icon_name">astrognome</property>
<signal name="delete-event" handler="ag_window_delete_event_callback" swapped="no"/> <signal name="delete-event" handler="ag_window_delete_event_callback" swapped="no"/>
<child type="titlebar"> <child type="titlebar">
<object class="GtkHeaderBar" id="header_bar"> <object class="AgHeaderBar" id="header_bar">
<property name="visible">True</property> <signal name="notify::mode" handler="ag_window_header_bar_mode_change_cb" swapped="no"/>
<property name="can_focus">False</property>
<property name="vexpand">False</property>
<property name="show_close_button">True</property>
<property name="title" translatable="yes">Astrognome</property>
<child>
<object class="GtkStack" id="new_back_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton" id="new_button">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="action_name">win.new-chart</property>
<style>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage" id="new_image">
<property name="visible">True</property>
<property name="icon_size">1</property>
<property name="icon_name">document-new-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="refresh_button">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="action_name">win.refresh</property>
<style>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage" id="refresh_image">
<property name="visible">True</property>
<property name="icon_size">1</property>
<property name="icon_name">view-refresh-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="name">new</property>
</packing>
</child>
<child>
<object class="GtkButton" id="back_button">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="action_name">win.back</property>
<style>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage" id="back_image">
<property name="visible">True</property>
<property name="icon_size">1</property>
<property name="icon_name">go-previous-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="name">back</property>
</packing>
</child>
</object>
</child>
<child>
<object class="GtkBox" id="box">
<property name="visible">True</property>
<property name="valign">center</property>
<property name="can_focus">False</property>
<style>
<class name="linked"/>
</style>
</object>
</child>
<child>
<object class="GtkStack" id="menubutton_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">False</property>
<child>
<object class="GtkToggleButton">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="action_name">win.selection</property>
<style>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon_size">1</property>
<property name="icon_name">object-select-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="name">list</property>
</packing>
</child>
<child>
<object class="GtkBox" id="menubutton_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuButton">
<property name="visible">True</property>
<property name="valign">center</property>
<property name="can_focus">False</property>
<property name="action_name">win.view-menu</property>
<property name="menu_model">view_menu</property>
<property name="use_popover">False</property>
<style>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage" id="view_image">
<property name="visible">True</property>
<property name="icon_size">1</property>
<property name="icon_name">document-properties-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkMenuButton">
<property name="visible">True</property>
<property name="valign">center</property>
<property name="can_focus">False</property>
<property name="action_name">win.gear-menu</property>
<property name="menu_model">gear_menu</property>
<property name="use_popover">False</property>
<style>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage" id="gear_image">
<property name="visible">True</property>
<property name="icon_size">1</property>
<property name="icon_name">open-menu-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="name">chart</property>
</packing>
</child>
<child>
<object class="GtkBox" id="selection_mode_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Cancel</property>
<signal name="clicked" handler="ag_window_selection_mode_cancel_cb" object="AgWindow" swapped="no"/>
</object>
</child>
</object>
<packing>
<property name="name">selection</property>
</packing>
</child>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</object> </object>
</child> </child>
<child> <child>