[gnome-clocks] Port to GdHeaderBar
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] Port to GdHeaderBar
- Date: Fri, 8 Mar 2013 22:08:44 +0000 (UTC)
commit 357c8b8c7a6c0df3d051e30338f6aaee78486133
Author: Stefano Facchini <stefano facchini gmail com>
Date: Fri Mar 8 11:29:50 2013 +0100
Port to GdHeaderBar
configure.ac | 2 +-
src/alarm.vala | 31 ++++++++++----------
src/clock.vala | 4 +-
src/stopwatch.vala | 6 ++--
src/timer.vala | 6 ++--
src/widgets.vala | 78 +++++++++++++++++++++++++++++----------------------
src/window.ui | 3 +-
src/window.vala | 47 +++++++++++++------------------
src/world.vala | 35 +++++++++++------------
9 files changed, 106 insertions(+), 106 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index db6bf44..6adc966 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,7 +54,7 @@ PKG_CHECK_MODULES(CLOCKS, [
LIBGD_INIT([
static
- main-toolbar
+ header-bar
stack
vapi
])
diff --git a/src/alarm.vala b/src/alarm.vala
index 86010f3..db4472a 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -464,22 +464,22 @@ private class RingingPanel : Gtk.EventBox {
public class MainPanel : Gd.Stack, Clocks.Clock {
public string label { get; construct set; }
- public Toolbar toolbar { get; construct set; }
+ public HeaderBar header_bar { get; construct set; }
private List<Item> alarms;
private GLib.Settings settings;
private ContentView content_view;
private RingingPanel ringing_panel;
- public MainPanel (Toolbar toolbar) {
- Object (label: _("Alarm"), toolbar: toolbar);
+ public MainPanel (HeaderBar header_bar) {
+ Object (label: _("Alarm"), header_bar: header_bar);
alarms = new List<Item> ();
settings = new GLib.Settings ("org.gnome.clocks");
var builder = Utils.load_ui ("alarm.ui");
var empty_view = builder.get_object ("empty_panel") as Gtk.Widget;
- content_view = new ContentView (empty_view, toolbar);
+ content_view = new ContentView (empty_view, header_bar);
add (content_view);
content_view.item_activated.connect ((item) => {
@@ -509,9 +509,9 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
notify["visible-child"].connect (() => {
if (visible_child == content_view) {
- toolbar.mode = Toolbar.Mode.NORMAL;
+ header_bar.mode = HeaderBar.Mode.NORMAL;
} else if (visible_child == ringing_panel) {
- toolbar.mode = Toolbar.Mode.STANDALONE;
+ header_bar.mode = HeaderBar.Mode.STANDALONE;
}
});
@@ -609,23 +609,22 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
return content_view.escape_pressed ();
}
- public void update_toolbar () {
- switch (toolbar.mode) {
- case Toolbar.Mode.NORMAL:
+ public void update_header_bar () {
+ switch (header_bar.mode) {
+ case HeaderBar.Mode.NORMAL:
// Translators: "New" refers to an alarm
- var new_button = toolbar.add_button (null, _("New"), true);
+ var new_button = header_bar.add_button (null, _("New"), true);
new_button.clicked.connect (() => {
activate_new ();
});
new_button.show ();
- content_view.update_toolbar ();
+ content_view.update_header_bar ();
break;
- case Toolbar.Mode.SELECTION:
- content_view.update_toolbar ();
+ case HeaderBar.Mode.SELECTION:
+ content_view.update_header_bar ();
break;
- case Toolbar.Mode.STANDALONE:
- toolbar.set_labels_menu (null);
- toolbar.set_labels (GLib.Markup.escape_text (ringing_panel.alarm.name), null);
+ case HeaderBar.Mode.STANDALONE:
+ header_bar.title = GLib.Markup.escape_text (ringing_panel.alarm.name);
break;
default:
assert_not_reached ();
diff --git a/src/clock.vala b/src/clock.vala
index ad629f6..daa039c 100644
--- a/src/clock.vala
+++ b/src/clock.vala
@@ -20,7 +20,7 @@ namespace Clocks {
public interface Clock : GLib.Object {
public abstract string label { get; protected construct set; }
- public abstract Toolbar toolbar { get; protected construct set; }
+ public abstract HeaderBar header_bar { get; protected construct set; }
public virtual void activate_new () {
}
@@ -35,7 +35,7 @@ public interface Clock : GLib.Object {
return false;
}
- public virtual void update_toolbar () {
+ public virtual void update_header_bar () {
}
}
diff --git a/src/stopwatch.vala b/src/stopwatch.vala
index f742be5..ff74748 100644
--- a/src/stopwatch.vala
+++ b/src/stopwatch.vala
@@ -33,7 +33,7 @@ public class MainPanel : Gtk.Box, Clocks.Clock {
}
public string label { get; construct set; }
- public Toolbar toolbar { get; construct set; }
+ public HeaderBar header_bar { get; construct set; }
private State state;
private GLib.Timer timer;
@@ -46,8 +46,8 @@ public class MainPanel : Gtk.Box, Clocks.Clock {
private Gtk.ListStore laps_model;
private Gtk.TreeView laps_view;
- public MainPanel (Toolbar toolbar) {
- Object (label: _("Stopwatch"), toolbar: toolbar);
+ public MainPanel (HeaderBar header_bar) {
+ Object (label: _("Stopwatch"), header_bar: header_bar);
timer = new GLib.Timer ();
timeout_id = 0;
diff --git a/src/timer.vala b/src/timer.vala
index 887582d..3f742bf 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -27,7 +27,7 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
}
public string label { get; construct set; }
- public Toolbar toolbar { get; construct set; }
+ public HeaderBar header_bar { get; construct set; }
private State state;
private GLib.Settings settings;
@@ -45,8 +45,8 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
private double span;
private GLib.Timer timer;
- public MainPanel (Toolbar toolbar) {
- Object (label: _("Timer"), toolbar: toolbar, transition_type: Gd.StackTransitionType.CROSSFADE);
+ public MainPanel (HeaderBar header_bar) {
+ Object (label: _("Timer"), header_bar: header_bar, transition_type:
Gd.StackTransitionType.CROSSFADE);
settings = new GLib.Settings ("org.gnome.clocks");
diff --git a/src/widgets.vala b/src/widgets.vala
index bdf7fec..be15020 100644
--- a/src/widgets.vala
+++ b/src/widgets.vala
@@ -18,7 +18,7 @@
namespace Clocks {
-public class Toolbar : Gd.MainToolbar {
+public class HeaderBar : Gd.HeaderBar {
public enum Mode {
NORMAL,
SELECTION,
@@ -26,7 +26,7 @@ public class Toolbar : Gd.MainToolbar {
}
private List<Gtk.Widget> buttons;
- private List<Clock> clocks;
+ private Gd.StackSwitcher stack_switcher;
[CCode (notify = false)]
public Mode mode {
@@ -35,10 +35,10 @@ public class Toolbar : Gd.MainToolbar {
}
set {
- if (_mode != value) {
+ if (_mode != value && get_realized ()) {
_mode = value;
- show_modes = (_mode == Mode.NORMAL);
+ custom_title = (_mode == Mode.NORMAL) ? stack_switcher : null;
if (_mode == Mode.SELECTION) {
get_style_context ().add_class ("selection-mode");
@@ -53,27 +53,33 @@ public class Toolbar : Gd.MainToolbar {
private Mode _mode;
- public signal void clock_changed (Clock clock);
+ construct {
+ stack_switcher = new Gd.StackSwitcher ();
+ realize.connect (() => {
+ custom_title = stack_switcher;
+ });
+ }
- public void add_clock (Clock clock) {
- var button = add_mode (clock.label) as Gtk.ToggleButton;
- clocks.prepend (clock);
- button.toggled.connect(() => {
- if (button.active) {
- clock_changed (clock);
- }
- });
+ public void set_stack (Gd.Stack stack) {
+ stack_switcher.set_stack (stack);
}
- // we wrap add_button so that we can keep track of which
- // buttons to remove in clear() without removing the radio buttons
- public new Gtk.Button add_button (string? icon_name, string? label, bool pack_start) {
- var button = base.add_button (icon_name, label, pack_start);
+ public Gtk.Button add_button (string? icon_name, string? label, bool should_pack_start) {
+ var button = new Gd.HeaderSimpleButton ();
+ button.label = label;
+ button.symbolic_icon_name = icon_name;
+
+ if (should_pack_start) {
+ pack_start (button);
+ } else {
+ pack_end (button);
+ }
+
buttons.prepend (button);
return (Gtk.Button) button;
}
- public new void clear () {
+ public void clear () {
foreach (Gtk.Widget button in buttons) {
button.destroy ();
}
@@ -369,14 +375,15 @@ public class ContentView : Gtk.Bin {
private Gtk.Widget empty_page;
private IconView icon_view;
- private Toolbar main_toolbar;
+ private HeaderBar header_bar;
+ private Gd.HeaderMenuButton selection_button;
private GLib.MenuModel selection_menu;
private Gtk.Toolbar selection_toolbar;
private Gtk.Overlay overlay;
- public ContentView (Gtk.Widget e, Toolbar t) {
+ public ContentView (Gtk.Widget e, HeaderBar b) {
empty_page = e;
- main_toolbar = t;
+ header_bar = b;
icon_view = new IconView ();
@@ -402,9 +409,10 @@ public class ContentView : Gtk.Bin {
icon_view.notify["mode"].connect (() => {
if (icon_view.mode == IconView.Mode.SELECTION) {
- main_toolbar.mode = Toolbar.Mode.SELECTION;
+ header_bar.mode = HeaderBar.Mode.SELECTION;
} else if (icon_view.mode == IconView.Mode.NORMAL) {
- main_toolbar.mode = Toolbar.Mode.NORMAL;
+ header_bar.mode = HeaderBar.Mode.NORMAL;
+ selection_button = null;
}
});
@@ -418,7 +426,7 @@ public class ContentView : Gtk.Bin {
} else {
label = ngettext ("%d selected", "%d selected", n_items).printf (n_items);
}
- main_toolbar.set_labels (label, null);
+ selection_button.label = label;
if (n_items != 0) {
fade_in (selection_toolbar);
@@ -561,22 +569,24 @@ public class ContentView : Gtk.Bin {
return false;
}
- public void update_toolbar () {
- switch (main_toolbar.mode) {
- case Toolbar.Mode.SELECTION:
- var done_button = main_toolbar.add_button (null, _("Done"), false);
- main_toolbar.set_labels (_("Click on items to select them"), null);
- main_toolbar.set_labels_menu (selection_menu);
+ public void update_header_bar () {
+ switch (header_bar.mode) {
+ case HeaderBar.Mode.SELECTION:
+ selection_button = new Gd.HeaderMenuButton ();
+ selection_button.label = _("Click on items to select them");
+ selection_button.menu_model = selection_menu;
+ selection_button.get_style_context ().add_class ("selection-menu");
+ header_bar.custom_title = selection_button;
+
+ var done_button = header_bar.add_button (null, _("Done"), false);
done_button.get_style_context ().add_class ("suggested-action");
done_button.clicked.connect (() => {
icon_view.mode = IconView.Mode.NORMAL;
});
done_button.show ();
break;
- case Toolbar.Mode.NORMAL:
- main_toolbar.set_labels (null, null);
- main_toolbar.set_labels_menu (null);
- var select_button = main_toolbar.add_button ("object-select-symbolic", null, false);
+ case HeaderBar.Mode.NORMAL:
+ var select_button = header_bar.add_button ("object-select-symbolic", null, false);
select_button.clicked.connect (() => {
icon_view.mode = IconView.Mode.SELECTION;
});
diff --git a/src/window.ui b/src/window.ui
index bd293c4..fda72fc 100644
--- a/src/window.ui
+++ b/src/window.ui
@@ -5,10 +5,9 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
- <object class="ClocksToolbar" id="toolbar">
+ <object class="ClocksHeaderBar" id="header_bar">
<property name="visible">True</property>
<property name="vexpand">False</property>
- <property name="show-modes">True</property>
<style>
<class name="menubar"/>
</style>
diff --git a/src/window.vala b/src/window.vala
index 8de8ced..eca549c 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -33,7 +33,7 @@ public class Window : Gtk.ApplicationWindow {
{ "select-none", on_select_none_activate }
};
- private Toolbar toolbar;
+ private HeaderBar header_bar;
private Gd.Stack stack;
private World.MainPanel world;
private Alarm.MainPanel alarm;
@@ -51,39 +51,32 @@ public class Window : Gtk.ApplicationWindow {
var builder = Utils.load_ui ("window.ui");
var main_panel = builder.get_object ("main_panel") as Gtk.Widget;
- toolbar = builder.get_object ("toolbar") as Toolbar;
+ header_bar = builder.get_object ("header_bar") as HeaderBar;
stack = builder.get_object ("stack") as Gd.Stack;
- world = new World.MainPanel (toolbar);
- alarm = new Alarm.MainPanel (toolbar);
- stopwatch = new Stopwatch.MainPanel (toolbar);
- timer = new Timer.MainPanel (toolbar);
+ world = new World.MainPanel (header_bar);
+ alarm = new Alarm.MainPanel (header_bar);
+ stopwatch = new Stopwatch.MainPanel (header_bar);
+ timer = new Timer.MainPanel (header_bar);
- toolbar.add_clock (world);
- toolbar.add_clock (alarm);
- toolbar.add_clock (stopwatch);
- toolbar.add_clock (timer);
+ stack.add_titled (world, world.label, world.label);
+ stack.add_titled (alarm, alarm.label, alarm.label);
+ stack.add_titled (stopwatch, stopwatch.label, stopwatch.label);
+ stack.add_titled (timer, timer.label, timer.label);
- stack.add (world);
- stack.add (alarm);
- stack.add (stopwatch);
- stack.add (timer);
-
- toolbar.clock_changed.connect ((c) => {
- stack.visible_child = (Gtk.Widget) c;
- });
+ header_bar.set_stack (stack);
var stack_id = stack.notify["visible-child"].connect (() => {
- update_toolbar ();
+ update_header_bar ();
});
- var toolbar_id = toolbar.notify["mode"].connect (() => {
- update_toolbar ();
+ var header_bar_id = header_bar.notify["mode"].connect (() => {
+ update_header_bar ();
});
stack.destroy.connect(() => {
- toolbar.disconnect (toolbar_id);
- toolbar_id = 0;
+ header_bar.disconnect (header_bar_id);
+ header_bar_id = 0;
stack.disconnect (stack_id);
stack_id = 0;
});
@@ -97,7 +90,7 @@ public class Window : Gtk.ApplicationWindow {
});
stack.visible_child = world;
- world.update_toolbar ();
+ update_header_bar ();
add (main_panel);
show_all ();
@@ -158,11 +151,11 @@ public class Window : Gtk.ApplicationWindow {
null);
}
- private void update_toolbar () {
- toolbar.clear ();
+ private void update_header_bar () {
+ header_bar.clear ();
var clock = (Clock) stack.visible_child;
if (clock != null) {
- clock.update_toolbar ();
+ clock.update_header_bar ();
}
}
}
diff --git a/src/world.vala b/src/world.vala
index f0ea607..881eb9b 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -243,7 +243,7 @@ private class StandalonePanel : Gtk.EventBox {
public class MainPanel : Gd.Stack, Clocks.Clock {
public string label { get; construct set; }
- public Toolbar toolbar { get; construct set; }
+ public HeaderBar header_bar { get; construct set; }
private List<Item> locations;
private GLib.Settings settings;
@@ -252,8 +252,8 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
private ContentView content_view;
private StandalonePanel standalone;
- public MainPanel (Toolbar toolbar) {
- Object (label: _("World"), toolbar: toolbar, transition_type: Gd.StackTransitionType.CROSSFADE);
+ public MainPanel (HeaderBar header_bar) {
+ Object (label: _("World"), header_bar: header_bar, transition_type:
Gd.StackTransitionType.CROSSFADE);
locations = new List<Item> ();
settings = new GLib.Settings ("org.gnome.clocks");
@@ -263,7 +263,7 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
var builder = Utils.load_ui ("world.ui");
var empty_view = builder.get_object ("empty_panel") as Gtk.Widget;
- content_view = new ContentView (empty_view, toolbar);
+ content_view = new ContentView (empty_view, header_bar);
add (content_view);
content_view.item_activated.connect ((item) => {
@@ -287,9 +287,9 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
notify["visible-child"].connect (() => {
if (visible_child == content_view) {
- toolbar.mode = Toolbar.Mode.NORMAL;
+ header_bar.mode = HeaderBar.Mode.NORMAL;
} else if (visible_child == standalone) {
- toolbar.mode = Toolbar.Mode.STANDALONE;
+ header_bar.mode = HeaderBar.Mode.STANDALONE;
}
});
@@ -352,25 +352,24 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
return content_view.escape_pressed ();
}
- public void update_toolbar () {
- toolbar.clear ();
- switch (toolbar.mode) {
- case Toolbar.Mode.NORMAL:
+ public void update_header_bar () {
+ header_bar.clear ();
+ switch (header_bar.mode) {
+ case HeaderBar.Mode.NORMAL:
// Translators: "New" refers to a world clock
- var new_button = toolbar.add_button (null, _("New"), true);
+ var new_button = header_bar.add_button (null, _("New"), true);
new_button.clicked.connect (() => {
activate_new ();
});
new_button.show ();
- content_view.update_toolbar ();
+ content_view.update_header_bar ();
break;
- case Toolbar.Mode.SELECTION:
- content_view.update_toolbar ();
+ case HeaderBar.Mode.SELECTION:
+ content_view.update_header_bar ();
break;
- case Toolbar.Mode.STANDALONE:
- toolbar.set_labels_menu (null);
- toolbar.set_labels (GLib.Markup.escape_text (standalone.location.name), null);
- var back_button = toolbar.add_button ("go-previous-symbolic", null, true);
+ case HeaderBar.Mode.STANDALONE:
+ header_bar.title = GLib.Markup.escape_text (standalone.location.name);
+ var back_button = header_bar.add_button ("go-previous-symbolic", null, true);
back_button.clicked.connect (() => {
visible_child = content_view;
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]