Add New/Back buttons to the header bar

New opens the Edit tab immediately, back goes back to the chart list
This commit is contained in:
Gergely Polonkai 2014-08-01 23:24:18 +02:00
parent d30b31ce7e
commit c2241e622a
2 changed files with 134 additions and 34 deletions

View File

@ -17,6 +17,8 @@
struct _AgWindowPrivate {
GtkWidget *header_bar;
GtkWidget *menubutton_revealer;
GtkWidget *new_back_stack;
GtkWidget *stack;
GtkWidget *name;
GtkWidget *north_lat;
@ -860,6 +862,14 @@ ag_window_tab_changed_cb(GtkStack *stack, GParamSpec *pspec, AgWindow *window)
gtk_widget_set_size_request(active_tab, 600, 600);
}
if (strcmp("list", active_tab_name) == 0) {
gtk_revealer_set_reveal_child(GTK_REVEALER(priv->menubutton_revealer), FALSE);
gtk_stack_set_visible_child_name(GTK_STACK(priv->new_back_stack), "new");
} else {
gtk_revealer_set_reveal_child(GTK_REVEALER(priv->menubutton_revealer), TRUE);
gtk_stack_set_visible_child_name(GTK_STACK(priv->new_back_stack), "back");
}
// If we are coming from the Edit tab, lets assume the chart data has
// changed. This is a bad idea, though, it should be checked instead!
// (TODO)
@ -886,6 +896,30 @@ ag_window_change_tab_action(GSimpleAction *action,
g_action_change_state(G_ACTION(action), parameter);
}
static void
ag_window_new_chart_action(GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
AgWindow *window = AG_WINDOW(user_data);
AgWindowPrivate *priv = ag_window_get_instance_private(window);
gtk_stack_set_visible_child_name(GTK_STACK(priv->stack), "edit");
}
static void
ag_window_back_action(GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
AgWindow *window = AG_WINDOW(user_data);
AgWindowPrivate *priv = ag_window_get_instance_private(window);
/* TODO: Check for saving! */
ag_window_load_chart_list(window);
gtk_stack_set_visible_child_name(GTK_STACK(priv->stack), "list");
}
static GActionEntry win_entries[] = {
{ "close", ag_window_close_action, NULL, NULL, NULL },
{ "save", ag_window_save_action, NULL, NULL, NULL },
@ -894,6 +928,8 @@ static GActionEntry win_entries[] = {
{ "view-menu", ag_window_view_menu_action, NULL, "false", NULL },
{ "gear-menu", ag_window_gear_menu_action, NULL, "false", NULL },
{ "change-tab", ag_window_change_tab_action, "s", "'edit'", NULL },
{ "new-chart", ag_window_new_chart_action, NULL, NULL, NULL },
{ "back", ag_window_back_action, NULL, NULL, NULL },
};
static void
@ -1130,6 +1166,16 @@ 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_revealer
);
gtk_widget_class_bind_template_child_private(
widget_class,
AgWindow,

View File

@ -148,6 +148,44 @@
<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="GtkButton" id="new_button">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">New</property>
<property name="action_name">win.new-chart</property>
</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>
@ -159,44 +197,60 @@
</object>
</child>
<child>
<object class="GtkMenuButton">
<object class="GtkRevealer" id="menubutton_revealer">
<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>
<property name="reveal_child">False</property>
<child>
<object class="GtkImage" id="gear_image">
<object class="GtkBox" id="menubutton_box">
<property name="visible">True</property>
<property name="icon_size">1</property>
<property name="icon_name">emblem-system-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="pack_type">end</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.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>
<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">emblem-system-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>