[gnome-clocks/zbrown/header-controls: 5/7] headerbar: unify the new/back buttons
- From: Zander <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks/zbrown/header-controls: 5/7] headerbar: unify the new/back buttons
- Date: Sat, 7 Dec 2019 19:11:13 +0000 (UTC)
commit 1f040cbbe57186d8cddf9a36ed2f909e2e9c9fcc
Author: Zander Brown <zbrown gnome org>
Date: Wed Dec 4 23:24:05 2019 +0000
headerbar: unify the new/back buttons
Intentionally takes up space even in the "none" state to prevent odd HdySwitcher behaviour when changing
pages
src/alarm.vala | 35 ++++++++---------
src/clock.vala | 9 +++++
src/headerbar.vala | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/meson.build | 1 +
src/stopwatch.vala | 5 +++
src/timer.vala | 1 +
src/widgets.vala | 38 ------------------
src/window.vala | 18 ++++++++-
src/world.vala | 36 +++++------------
9 files changed, 168 insertions(+), 86 deletions(-)
---
diff --git a/src/alarm.vala b/src/alarm.vala
index 557c605..f7e50ae 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -586,10 +586,11 @@ public class Face : Gtk.Stack, Clocks.Clock {
public string icon_name { get; construct set; }
public HeaderBar header_bar { get; construct set; }
public PanelId panel_id { get; construct set; }
+ public ButtonMode button_mode { get; private set; default = NEW; }
+
private ContentStore alarms;
private GLib.Settings settings;
- private Gtk.Button new_button;
[GtkChild]
private Gtk.Widget empty_view;
[GtkChild]
@@ -627,13 +628,6 @@ public class Face : Gtk.Stack, Clocks.Clock {
}
});
- // Translators: "New" refers to an alarm
- new_button = new Gtk.Button.with_label (C_("Alarm", "New"));
- new_button.valign = Gtk.Align.CENTER;
- new_button.no_show_all = true;
- new_button.action_name = "win.new";
- header_bar.pack_start (new_button);
-
content_view.bind_model (alarms, (item) => {
return new Tile ((Item)item);
});
@@ -758,18 +752,19 @@ public class Face : Gtk.Stack, Clocks.Clock {
public void update_header_bar () {
switch (header_bar.mode) {
- case HeaderBar.Mode.NORMAL:
- new_button.show ();
- content_view.update_header_bar ();
- break;
- case HeaderBar.Mode.SELECTION:
- content_view.update_header_bar ();
- break;
- case HeaderBar.Mode.STANDALONE:
- header_bar.title = ringing_panel.alarm.name;
- break;
- default:
- assert_not_reached ();
+ 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 ();
}
}
}
diff --git a/src/clock.vala b/src/clock.vala
index 50c6d1a..fd55e4b 100644
--- a/src/clock.vala
+++ b/src/clock.vala
@@ -42,6 +42,12 @@ public enum PanelId {
public const int N_PANELS = 4;
+public enum ButtonMode {
+ NEW,
+ BACK,
+ NONE
+}
+
public interface Clock : GLib.Object {
public abstract string label { get; protected construct set; }
public abstract string icon_name { get; protected construct set; }
@@ -51,6 +57,9 @@ public interface Clock : GLib.Object {
public virtual void activate_new () {
}
+ public virtual void activate_back () {
+ }
+
public virtual void activate_select_all () {
}
diff --git a/src/headerbar.vala b/src/headerbar.vala
new file mode 100644
index 0000000..d8e4690
--- /dev/null
+++ b/src/headerbar.vala
@@ -0,0 +1,111 @@
+/*
+ * © 2013 Paolo Borelli <pborelli gnome org>
+ * © 2019 Bilal Elmoussaoui <bilal elmoussaoui gnome org> &
+ * Zander Brown <zbrown gnome org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+public class Clocks.HeaderBar : Gtk.HeaderBar {
+ public enum Mode {
+ NORMAL,
+ SELECTION,
+ STANDALONE
+ }
+
+ [CCode (notify = false)]
+ public Mode mode {
+ get {
+ return _mode;
+ }
+
+ set {
+ if (_mode != value) {
+ _mode = value;
+
+ if (_mode == Mode.SELECTION) {
+ get_style_context ().add_class ("selection-mode");
+ button_stack.hide ();
+ } else {
+ get_style_context ().remove_class ("selection-mode");
+ button_stack.show ();
+ }
+
+ notify_property ("mode");
+ }
+ }
+ }
+
+ public ButtonMode button_mode {
+ get {
+ return _button_mode;
+ }
+
+ set {
+ switch (value) {
+ case NEW:
+ button_stack.visible_child_name = "new";
+ break;
+ case BACK:
+ button_stack.visible_child_name = "back";
+ break;
+ case NONE:
+ button_stack.visible_child_name = "none";
+ break;
+ }
+ }
+ }
+
+ private Mode _mode;
+ private ButtonMode _button_mode;
+ private Gtk.Stack button_stack;
+
+ construct {
+ button_stack = new Gtk.Stack ();
+ button_stack.homogeneous = true;
+ button_stack.transition_type = CROSSFADE;
+ button_stack.show ();
+
+ var new_button = new Gtk.Button.from_icon_name ("list-add-symbolic",
+ BUTTON);
+ new_button.tooltip_text = _("New");
+ new_button.action_name = "win.new";
+ new_button.show ();
+ button_stack.add_named (new_button, "new");
+
+ var back_button = new Gtk.Button.from_icon_name ("go-previous-symbolic",
+ BUTTON);
+ back_button.tooltip_text = _("Back");
+ back_button.action_name = "win.back";
+ back_button.show ();
+ button_stack.add_named (back_button, "back");
+
+ var empty = new Gtk.Box (VERTICAL, 0);
+ empty.show ();
+ button_stack.add_named (empty, "none");
+
+ pack_start (button_stack);
+ }
+
+ public void clear () {
+ custom_title = null;
+ foreach (Gtk.Widget w in get_children ()) {
+ if (w == button_stack) {
+ continue;
+ }
+ w.hide ();
+ }
+ }
+}
diff --git a/src/meson.build b/src/meson.build
index eec6ce9..2c80bed 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -7,6 +7,7 @@ clocks_vala_sources = [
'application.vala',
'clock.vala',
'geocoding.vala',
+ 'headerbar.vala',
'main.vala',
'search-provider.vala',
'stopwatch.vala',
diff --git a/src/stopwatch.vala b/src/stopwatch.vala
index fca93bb..d5b9c1c 100644
--- a/src/stopwatch.vala
+++ b/src/stopwatch.vala
@@ -116,6 +116,11 @@ public class Face : Gtk.Box, Clocks.Clock {
public string icon_name { get; construct set; }
public HeaderBar header_bar { get; construct set; }
public PanelId panel_id { get; construct set; }
+ public ButtonMode button_mode {
+ get {
+ return NONE;
+ }
+ }
public State state { get; private set; default = State.RESET; }
diff --git a/src/timer.vala b/src/timer.vala
index e80c3b3..7a0d7d4 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -75,6 +75,7 @@ public class Face : Gtk.Stack, Clocks.Clock {
public string icon_name { get; construct set; }
public HeaderBar header_bar { get; construct set; }
public PanelId panel_id { get; construct set; }
+ public ButtonMode button_mode { get; private set; default = NONE; }
public State state { get; private set; default = State.STOPPED; }
diff --git a/src/widgets.vala b/src/widgets.vala
index d98088c..a26ae91 100644
--- a/src/widgets.vala
+++ b/src/widgets.vala
@@ -18,44 +18,6 @@
namespace Clocks {
-public class HeaderBar : Gtk.HeaderBar {
- public enum Mode {
- NORMAL,
- SELECTION,
- STANDALONE
- }
-
- [CCode (notify = false)]
- public Mode mode {
- get {
- return _mode;
- }
-
- set {
- if (_mode != value) {
- _mode = value;
-
- if (_mode == Mode.SELECTION) {
- get_style_context ().add_class ("selection-mode");
- } else {
- get_style_context ().remove_class ("selection-mode");
- }
-
- notify_property ("mode");
- }
- }
- }
-
- private Mode _mode;
-
- public void clear () {
- custom_title = null;
- foreach (Gtk.Widget w in get_children ()) {
- w.hide ();
- }
- }
-}
-
public interface ContentItem : GLib.Object {
public abstract string name { get; set; }
public abstract bool selectable { get; set; default = true; }
diff --git a/src/window.vala b/src/window.vala
index a03396c..add06cd 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -24,6 +24,7 @@ public class Window : Gtk.ApplicationWindow {
// primary menu
{ "show-primary-menu", on_show_primary_menu_activate, null, "false", null },
{ "new", on_new_activate },
+ { "back", on_back_activate },
{ "help", on_help_activate },
{ "about", on_about_activate },
@@ -52,6 +53,8 @@ public class Window : Gtk.ApplicationWindow {
private GLib.Settings settings;
private Gtk.Widget[] panels;
+ private Binding bind_button_mode = null;
+
public Window (Application app) {
Object (application: app);
@@ -94,8 +97,17 @@ public class Window : Gtk.ApplicationWindow {
var stack_id = stack.notify["visible-child"].connect (() => {
var help_overlay = get_help_overlay ();
- help_overlay.view_name = Type.from_instance(stack.visible_child).name();
+ var page = stack.visible_child;
+ help_overlay.view_name = Type.from_instance (page).name();
update_header_bar ();
+
+ if (bind_button_mode != null) {
+ bind_button_mode.unbind ();
+ }
+ bind_button_mode = page.bind_property ("button-mode",
+ header_bar,
+ "button-mode",
+ SYNC_CREATE);
});
var header_bar_id = header_bar.notify["mode"].connect (() => {
@@ -183,6 +195,10 @@ public class Window : Gtk.ApplicationWindow {
((Clock) stack.visible_child).activate_new ();
}
+ private void on_back_activate () {
+ ((Clock) stack.visible_child).activate_back ();
+ }
+
private void on_select_all_activate () {
((Clock) stack.visible_child).activate_select_all ();
}
diff --git a/src/world.vala b/src/world.vala
index 1f76a74..81ebc64 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -342,11 +342,11 @@ public class Face : Gtk.Stack, Clocks.Clock {
public string icon_name { get; construct set; }
public HeaderBar header_bar { get; construct set; }
public PanelId panel_id { get; construct set; }
+ public ButtonMode button_mode { get; private set; default = NEW; }
+
private ContentStore locations;
private GLib.Settings settings;
- private Gtk.Button new_button;
- private Gtk.Button back_button;
private Item standalone_location;
[GtkChild]
private Gtk.Widget empty_view;
@@ -383,23 +383,6 @@ public class Face : Gtk.Stack, Clocks.Clock {
return 0;
});
- // Translators: "New" refers to a world clock
- new_button = new Gtk.Button.with_label (C_("World clock", "New"));
- new_button.valign = Gtk.Align.CENTER;
- new_button.no_show_all = true;
- new_button.action_name = "win.new";
- header_bar.pack_start (new_button);
-
- back_button = new Gtk.Button ();
- var back_button_image = new Gtk.Image.from_icon_name ("go-previous-symbolic", Gtk.IconSize.MENU);
- back_button.valign = Gtk.Align.CENTER;
- back_button.set_image (back_button_image);
- back_button.no_show_all = true;
- back_button.clicked.connect (() => {
- reset_view ();
- });
- header_bar.pack_start (back_button);
-
content_view.bind_model (locations, (item) => {
return new Tile ((Item)item);
});
@@ -528,6 +511,11 @@ public class Face : Gtk.Stack, Clocks.Clock {
dialog.show ();
}
+ public void activate_back () {
+ reset_view ();
+ button_mode = NEW;
+ }
+
public void activate_select_all () {
content_view.select_all ();
}
@@ -545,12 +533,6 @@ public class Face : Gtk.Stack, Clocks.Clock {
return content_view.escape_pressed ();
}
- public void back () {
- if (visible_child == standalone) {
- reset_view ();
- }
- }
-
public void reset_view () {
standalone_location = null;
visible_child = locations.get_n_items () == 0 ? empty_view : content_view;
@@ -562,8 +544,8 @@ public class Face : Gtk.Stack, Clocks.Clock {
case HeaderBar.Mode.NORMAL:
header_bar.title = _("Clocks");
header_bar.subtitle = null;
- new_button.show ();
content_view.update_header_bar ();
+ button_mode = NEW;
break;
case HeaderBar.Mode.SELECTION:
content_view.update_header_bar ();
@@ -575,7 +557,7 @@ public class Face : Gtk.Stack, Clocks.Clock {
header_bar.title = standalone_location.city_name;
}
header_bar.subtitle = standalone_location.country_name;
- back_button.show ();
+ button_mode = BACK;
break;
default:
assert_not_reached ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]