Verified Commit cea01d06 authored by Zander Brown's avatar Zander Brown 🔲
Browse files

headerbar: move headerbar logic to the headerbar itself

each panel stores it's own state that is them bound to the headerbar at the active panel changes

this helps ensure the state is consistent as an inactive panel cannot change the headerbar
parent 1f040cbb
build
_build
*~
.vscode
......@@ -8,6 +8,7 @@
<file preprocess="xml-stripblanks">gtk/menus.ui</file>
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
<file preprocess="xml-stripblanks">ui/window.ui</file>
<file preprocess="xml-stripblanks">ui/headerbar.ui</file>
<file preprocess="xml-stripblanks">ui/worldlocationdialog.ui</file>
<file preprocess="xml-stripblanks">ui/world.ui</file>
<file preprocess="xml-stripblanks">ui/worldtile.ui</file>
......
......@@ -5,6 +5,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">False</property>
<property name="n-selected" bind-source="content_view" bind-property="n-selected" bind-flags="sync-create" />
<signal name="notify::visible-child" handler="visible_child_changed" swapped="no"/>
<child>
<object class="GtkGrid" id="empty_view">
......@@ -46,6 +47,7 @@
<child>
<object class="ClocksContentView" id="content_view">
<property name="visible">True</property>
<property name="mode" bind-source="ClocksAlarmFace" bind-property="view-mode" bind-flags="sync-create|bidirectional" />
<signal name="item-activated" handler="item_activated" swapped="no"/>
</object>
</child>
......
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.20"/>
<requires lib="libhandy" version="0.0"/>
<menu id="primary-menu">
<section>
<item>
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
<attribute name="action">win.show-help-overlay</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Help</attribute>
<attribute name="action">win.help</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_About Clocks</attribute>
<attribute name="action">win.about</attribute>
</item>
</section>
</menu>
<template class="ClocksHeaderBar" parent="HdyHeaderBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title">Clocks</property>
<property name="centering_policy">strict</property>
<property name="show_close_button">True</property>
<signal name="notify::subtitle" handler="subtitle_changed" swapped="no"/>
<child type="title">
<object class="GtkStack" id="title_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">False</property>
<property name="transition_type">none</property>
<child>
<object class="HdySqueezer" id="squeezer">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="transition_type">crossfade</property>
<child>
<object class="HdyViewSwitcher" id="title_wide_switcher">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="policy">wide</property>
<property name="stack" bind-source="ClocksHeaderBar" bind-property="stack" bind-flags="sync-create">ignore-me</property>
</object>
</child>
<child>
<object class="HdyViewSwitcher" id="title_narrow_switcher">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="policy">narrow</property>
<property name="stack" bind-source="ClocksHeaderBar" bind-property="stack" bind-flags="sync-create">ignore-me</property>
</object>
</child>
<child>
<object class="GtkBox" id="title_text">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="title_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" bind-source="ClocksHeaderBar" bind-property="title" bind-flags="sync-create" />
<style>
<class name="title"/>
</style>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="name">switcher</property>
</packing>
</child>
<child>
<object class="ClocksSelectionMenuButton">
<property name="visible">True</property>
<property name="n-items" bind-source="ClocksHeaderBar" bind-property="n-selected" bind-flags="sync-create" />
</object>
<packing>
<property name="name">selection</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="valign">center</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label" bind-source="ClocksHeaderBar" bind-property="title" bind-flags="sync-create" />
<property name="ellipsize">end</property>
<style>
<class name="title"/>
</style>
</object>
</child>
<child>
<object class="GtkRevealer" id="reveal_subtitle">
<property name="visible">True</property>
<property name="reveal-child">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label" bind-source="ClocksHeaderBar" bind-property="subtitle" bind-flags="sync-create" />
<property name="ellipsize">end</property>
<style>
<class name="subtitle"/>
</style>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="name">title</property>
</packing>
</child>
</object>
</child>
<child>
<object class="GtkStack" id="start_button_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="transition_type">crossfade</property>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">win.new</property>
<property name="tooltip-text" translatable="yes">New</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">list-add-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="name">new</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">win.back</property>
<property name="tooltip-text" translatable="yes">Back</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">go-previous-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="name">back</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
</object>
<packing>
<property name="name">empty</property>
</packing>
</child>
</object>
</child>
<child>
<object class="GtkStack" id="end_button_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hhomogeneous">False</property>
<property name="transition_type">crossfade</property>
<child>
<object class="GtkMenuButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">win.show-primary-menu</property>
<property name="tooltip-text" translatable="yes">Menu</property>
<property name="menu_model">primary-menu</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">open-menu-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="name">menu</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">_Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">win.select-cancel</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="name">cancel</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
</object>
<packing>
<property name="name">empty</property>
</packing>
</child>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
<child>
<object class="GtkStack" id="select_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="transition_type">crossfade</property>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">win.select</property>
<property name="tooltip-text" translatable="yes">Select</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">object-select-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="name">select</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="name">empty</property>
</packing>
</child>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</template>
<object class="GtkStack" id="ignore-me"></object>
</interface>
......@@ -4,94 +4,17 @@
<requires lib="gtk+" version="3.20"/>
<requires lib="libhandy" version="0.0"/>
<template class="ClocksWindow" parent="GtkApplicationWindow">
<property name="title" translatable="yes">Clocks</property>
<menu id="primary-menu">
<section>
<item>
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
<attribute name="action">win.show-help-overlay</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Help</attribute>
<attribute name="action">win.help</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_About Clocks</attribute>
<attribute name="action">win.about</attribute>
</item>
</section>
</menu>
<property name="title" bind-source="header_bar" bind-property="title" bind-flags="sync-create" />
<child type="titlebar">
<object class="ClocksHeaderBar" id="header_bar">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="vexpand">False</property>
<property name="stack">stack</property>
<property name="switcher_bar">switcher_bar</property>
<style>
<class name="titlebar"/>
</style>
<child type="title">
<object class="HdySqueezer" id="squeezer">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="transition_type">crossfade</property>
<child>
<object class="HdyViewSwitcher" id="title_wide_switcher">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="policy">wide</property>
<property name="stack">stack</property>
</object>
</child>
<child>
<object class="HdyViewSwitcher" id="title_narrow_switcher">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="policy">narrow</property>
<property name="stack">stack</property>
</object>
</child>
<child>
<object class="GtkBox" id="title_text">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="title_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Clock</property>
<style>
<class name="title"/>
</style>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuButton" id="menu_button">
<property name="valign">center</property>
<property name="menu_model">primary-menu</property>
<property name="action_name">win.show-primary-menu</property>
<property name="direction">none</property>
<style>
<class name="image-button"/>
</style>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</object>
</child>
<child>
......@@ -106,8 +29,46 @@
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="homogeneous">False</property>
<signal name="notify::visible-child" handler="pane_changed" swapped="no"/>
<child>
<placeholder/>
<object class="ClocksWorldFace" id="world">
<property name="visible">True</property>
</object>
<packing>
<property name="name">world</property>
<property name="title">World</property>
<property name="icon-name">globe-symbolic</property>
</packing>
</child>
<child>
<object class="ClocksAlarmFace" id="alarm">
<property name="visible">True</property>
</object>
<packing>
<property name="name">alarm</property>
<property name="title">Alarms</property>
<property name="icon-name">alarm-symbolic</property>
</packing>
</child>
<child>
<object class="ClocksStopwatchFace" id="stopwatch">
<property name="visible">True</property>
</object>
<packing>
<property name="name">stopwatch</property>
<property name="title">Stopwatch</property>
<property name="icon-name">stopwatch-symbolic</property>
</packing>
</child>
<child>
<object class="ClocksTimerFace" id="timer">
<property name="visible">True</property>
</object>
<packing>
<property name="name">timer</property>
<property name="title">Timer</property>
<property name="icon-name">timer-symbolic</property>
</packing>
</child>
</object>
<packing>
......
......@@ -5,6 +5,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">False</property>
<property name="n-selected" bind-source="content_view" bind-property="n-selected" bind-flags="sync-create" />
<signal name="notify::visible-child" handler="visible_child_changed" swapped="no"/>
<child>
<object class="GtkGrid" id="empty_view">
......@@ -46,6 +47,7 @@
<child>
<object class="ClocksContentView" id="content_view">
<property name="visible">True</property>
<property name="mode" bind-source="ClocksWorldFace" bind-property="view-mode" bind-flags="sync-create|bidirectional" />
<signal name="item-activated" handler="item_activated" swapped="no"/>
</object>
</child>
......
......@@ -582,12 +582,13 @@ private class RingingPanel : Gtk.Grid {
[GtkTemplate (ui = "/org/gnome/clocks/ui/alarm.ui")]
public class Face : Gtk.Stack, Clocks.Clock {
public string label { get; construct set; }
public string icon_name { get; construct set; }
public HeaderBar header_bar { get; construct set; }
public ViewMode view_mode { get; set; default = NORMAL; }
public PanelId panel_id { get; construct set; }
public ButtonMode button_mode { get; private set; default = NEW; }
public ButtonMode button_mode { get; set; default = NEW; }
public bool can_select { get; set; default = true; }
public bool n_selected { get; set; }
public string title { get; set; default = _("Clocks"); }
public string subtitle { get; set; }
private ContentStore alarms;
private GLib.Settings settings;
......@@ -598,11 +599,8 @@ public class Face : Gtk.Stack, Clocks.Clock {
[GtkChild]
private RingingPanel ringing_panel;
public Face (HeaderBar header_bar) {
Object (label: _("Alarm"),
icon_name: "alarm-symbolic",
header_bar: header_bar,
panel_id: PanelId.ALARM);
construct {
panel_id = ALARM;
alarms = new ContentStore ();
settings = new GLib.Settings ("org.gnome.clocks");
......@@ -632,8 +630,6 @@ public class Face : Gtk.Stack, Clocks.Clock {
return new Tile ((Item)item);
});
content_view.set_header_bar (header_bar);
load ();
show_all ();
......@@ -675,14 +671,16 @@ public class Face : Gtk.Stack, Clocks.Clock {
[GtkCallback]
private void dismiss_ringing_panel () {
reset_view ();
button_mode = NEW;
title = _("Clocks");
}
[GtkCallback]
private void visible_child_changed () {
if (visible_child == empty_view || visible_child == content_view) {
header_bar.mode = HeaderBar.Mode.NORMAL;
view_mode = NORMAL;
} else if (visible_child == ringing_panel) {
header_bar.mode = HeaderBar.Mode.STANDALONE;
view_mode = STANDALONE;
}
}
......@@ -717,11 +715,13 @@ public class Face : Gtk.Stack, Clocks.Clock {
ringing_panel.alarm = alarm;
ringing_panel.update ();
visible_child = ringing_panel;
title = ringing_panel.alarm.name;
view_mode = STANDALONE;
button_mode = NONE;
}
private void reset_view () {
visible_child = alarms.get_n_items () == 0 ? empty_view : content_view;
request_header_bar_update ();
}
public void activate_new () {
......@@ -738,6 +738,14 @@ public class Face : Gtk.Stack, Clocks.Clock {
dialog.show_all ();
}
public void activate_select () {
view_mode = SELECTION;
}
public void activate_select_cancel () {
view_mode = NORMAL;
}
public void activate_select_all () {
content_view.select_all ();
}
......@@ -749,24 +757,6 @@ public class Face : Gtk.Stack, Clocks.Clock {
public bool escape_pressed () {
return content_view.escape_pressed ();
}
public void update_header_bar () {
switch (header_bar.mode) {
case HeaderBar.Mode.NORMAL:
button_mode = NEW;
content_view.update_header_bar ();
break;
case HeaderBar.Mode.SELECTION:
content_view.update_header_bar ();
break;
case HeaderBar.Mode.STANDALONE:
button_mode = NONE;
header_bar.title = ringing_panel.alarm.name;
break;
default:
assert_not_reached ();
}
}
}
} // namespace Alarm
......
......@@ -16,43 +16,22 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
namespace Clocks {
public enum PanelId {
public enum Clocks.PanelId {
WORLD,
ALARM,
STOPWATCH,
TIMER;
public string to_string() {
switch (this) {
case WORLD:
return "world";
case ALARM:
return "alarm";
case STOPWATCH:
return "stopwatch";
case TIMER:
return "timer";
default:
assert_not_reached();
}
}
TIMER,
}
public const int N_PANELS = 4;
public enum ButtonMode {