[gnome-clocks/wip/vala] Port to Gd.Stack
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks/wip/vala] Port to Gd.Stack
- Date: Mon, 11 Feb 2013 20:32:27 +0000 (UTC)
commit 2c9b7ec0c9b82a296b4a2d695e9197b19eb14b26
Author: Paolo Borelli <pborelli gnome org>
Date: Mon Feb 11 21:07:24 2013 +0100
Port to Gd.Stack
configure.ac | 1 +
libgd | 2 +-
src/alarm.vala | 41 +++++++++++++++--------------------------
src/timer.vala | 27 ++++++++++++---------------
src/widgets.vala | 12 +++---------
src/window.vala | 48 ++++++++++++++++++++----------------------------
src/world.vala | 39 +++++++++++++--------------------------
7 files changed, 65 insertions(+), 105 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 20c6724..603a27f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,6 +44,7 @@ PKG_CHECK_MODULES(CLOCKS, [
LIBGD_INIT([
static
main-toolbar
+ stack
vapi
])
diff --git a/libgd b/libgd
index 41dfd2a..25911b0 160000
--- a/libgd
+++ b/libgd
@@ -1 +1 @@
-Subproject commit 41dfd2acbb5a84950b1956169051b9c362a50b49
+Subproject commit 25911b0068b78cd425f0f405eae9b5654699dd2f
diff --git a/src/alarm.vala b/src/alarm.vala
index 1ff1b14..5135972 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -235,12 +235,7 @@ private class StandalonePanel : Gtk.EventBox {
}
}
-public class MainPanel : Gtk.Notebook, Clocks.Clock {
- private enum Page {
- OVERVIEW,
- STANDALONE
- }
-
+public class MainPanel : Gd.Stack, Clocks.Clock {
private enum Column {
SELECTED,
NAME,
@@ -259,7 +254,7 @@ public class MainPanel : Gtk.Notebook, Clocks.Clock {
private StandalonePanel standalone;
public MainPanel (Toolbar toolbar) {
- Object (label: _("Alarms"), toolbar: toolbar, show_tabs: false);
+ Object (label: _("Alarms"), toolbar: toolbar);
alarms = new List<Item> ();
settings = new GLib.Settings("org.gnome.clocks");
@@ -275,19 +270,23 @@ public class MainPanel : Gtk.Notebook, Clocks.Clock {
});
content_view = new ContentView (icon_view, "alarm-symbolic", _("Select <b>New</b> to add an alarm"));
- append_page (content_view);
+ add (content_view);
standalone = new StandalonePanel ();
- append_page (standalone);
+ add (standalone);
load ();
- set_current_page (Page.OVERVIEW);
+ notify["visible-child"].connect (() => {
+ update_toolbar ();
+ });
+
+ visible_child = content_view;
show_all ();
}
- public virtual signal void ring() {
- set_current_page (Page.STANDALONE);
+ public virtual signal void ring () {
+ visible_child = standalone;
}
private void tick () {
@@ -333,17 +332,9 @@ public class MainPanel : Gtk.Notebook, Clocks.Clock {
dialog.show ();
}
- public override void switch_page (Gtk.Widget widget, uint page) {
- base.switch_page (widget, page);
-
- // Update the toolbar *after* the current page changes
- update_toolbar ();
- }
-
public void update_toolbar () {
toolbar.clear ();
- switch (get_current_page ()) {
- case Page.OVERVIEW:
+ if (visible_child == content_view) {
if (icon_view.mode == IconView.Mode.SELECTION) {
toolbar.mode = Toolbar.Mode.SELECTION;
var done_button = toolbar.add_button (null, _("Done"), false);
@@ -365,17 +356,15 @@ public class MainPanel : Gtk.Notebook, Clocks.Clock {
update_toolbar ();
});
}
- break;
- case Page.STANDALONE:
+ } else if (visible_child == standalone) {
toolbar.mode = Toolbar.Mode.STANDALONE;
var back_button = toolbar.add_button ("go-previous-symbolic", null, true);
back_button.clicked.connect (() => {
- set_current_page (Page.OVERVIEW);
+ visible_child = content_view;
});
toolbar.add_button (null, _("Edit"), false);
toolbar.set_labels (GLib.Markup.escape_text (standalone.alarm.name), null);
- break;
- default:
+ } else {
assert_not_reached ();
}
}
diff --git a/src/timer.vala b/src/timer.vala
index d9557fc..f71854b 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -19,28 +19,25 @@
namespace Clocks {
namespace Timer {
-public class MainPanel : Gtk.Notebook, Clocks.Clock {
+public class MainPanel : Gd.Stack, Clocks.Clock {
enum State {
STOPPED,
RUNNING,
PAUSED
}
- enum Page {
- SETUP,
- COUNTDOWN
- }
-
public string label { get; construct set; }
public Toolbar toolbar { get; construct set; }
private State state;
private uint timeout_id;
private Utils.Bell bell;
+ private Gtk.Widget setup_panel;
private Gtk.SpinButton h_spinbutton;
private Gtk.SpinButton m_spinbutton;
private Gtk.SpinButton s_spinbutton;
private Gtk.Button start_button;
+ private Gtk.Widget countdown_panel;
private Gtk.Label time_label;
private Gtk.Button left_button;
private Gtk.Button right_button;
@@ -48,7 +45,7 @@ public class MainPanel : Gtk.Notebook, Clocks.Clock {
private GLib.Timer timer;
public MainPanel (Toolbar toolbar) {
- Object (label: _("Timer"), toolbar: toolbar, show_tabs: false);
+ Object (label: _("Timer"), toolbar: toolbar);
bell = new Utils.Bell ("complete", _("Time is up!"), _("Timer countdown finished"));
@@ -58,7 +55,7 @@ public class MainPanel : Gtk.Notebook, Clocks.Clock {
var builder = Utils.load_ui ("timer.ui");
- var setup_panel = builder.get_object ("setup_panel") as Gtk.Widget;
+ setup_panel = builder.get_object ("setup_panel") as Gtk.Widget;
h_spinbutton = builder.get_object ("spinbutton_hours") as Gtk.SpinButton;
m_spinbutton = builder.get_object ("spinbutton_minutes") as Gtk.SpinButton;
s_spinbutton = builder.get_object ("spinbutton_seconds") as Gtk.SpinButton;
@@ -76,7 +73,7 @@ public class MainPanel : Gtk.Notebook, Clocks.Clock {
start ();
});
- var countdown_panel = builder.get_object ("countdown_panel") as Gtk.Widget;
+ countdown_panel = builder.get_object ("countdown_panel") as Gtk.Widget;
time_label = builder.get_object ("time_label") as Gtk.Label;
left_button = builder.get_object ("left_button") as Gtk.Button;
right_button = builder.get_object ("right_button") as Gtk.Button;
@@ -103,12 +100,12 @@ public class MainPanel : Gtk.Notebook, Clocks.Clock {
left_button.set_label (_("Pause"));
});
- insert_page (setup_panel, null, Page.SETUP);
- insert_page (countdown_panel, null, Page.COUNTDOWN);
+ add (setup_panel);
+ add (countdown_panel);
reset ();
- set_current_page (Page.SETUP);
+ visible_child = setup_panel;
show_all ();
}
@@ -138,7 +135,7 @@ public class MainPanel : Gtk.Notebook, Clocks.Clock {
m_spinbutton.value = 0;
s_spinbutton.value = 0;
start_button.set_sensitive (false);
- set_current_page (Page.SETUP);
+ visible_child = setup_panel;
}
private void start () {
@@ -151,7 +148,7 @@ public class MainPanel : Gtk.Notebook, Clocks.Clock {
duration = h * 3600 + m * 60 + s;
timer.start ();
- set_current_page (Page.COUNTDOWN);
+ visible_child = countdown_panel;
update_countdown_label (h, m, s);
add_timeout ();
@@ -191,7 +188,7 @@ public class MainPanel : Gtk.Notebook, Clocks.Clock {
state = State.STOPPED;
remove_timeout ();
update_countdown_label (0, 0, 0);
- set_current_page (Page.SETUP);
+ visible_child = setup_panel;
return false;
}
diff --git a/src/widgets.vala b/src/widgets.vala
index 15190bd..a646a47 100644
--- a/src/widgets.vala
+++ b/src/widgets.vala
@@ -25,7 +25,6 @@ public class Toolbar : Gd.MainToolbar {
STANDALONE
}
- private int n_clocks;
private List<Gtk.Widget> buttons;
public Mode mode {
@@ -52,22 +51,17 @@ public class Toolbar : Gd.MainToolbar {
public Toolbar () {
Object (show_modes: true, vexpand: false);
- n_clocks = 0;
}
- public signal void clock_changed (int clock);
+ public signal void clock_changed (Clock clock);
- public int add_clock (Clock clock) {
- int n = n_clocks;
- n_clocks++;
+ public void add_clock (Clock clock) {
var button = add_mode (clock.label) as Gtk.ToggleButton;
button.toggled.connect(() => {
if (button.active) {
- clock_changed (n);
+ clock_changed (clock);
}
});
-
- return n;
}
// we wrap add_button so that we can keep track of which
diff --git a/src/window.vala b/src/window.vala
index 4eb4fdf..a9a812c 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -28,15 +28,8 @@ public class Window : Gtk.ApplicationWindow {
{ "about", on_about_activate }
};
- private enum Page {
- WORLD,
- ALARM,
- STOPWATCH,
- TIMER
- }
-
private Toolbar toolbar;
- private Gtk.Notebook notebook;
+ private Gd.Stack stack;
private World.MainPanel world;
private Alarm.MainPanel alarm;
private Stopwatch.MainPanel stopwatch;
@@ -62,48 +55,47 @@ public class Window : Gtk.ApplicationWindow {
toolbar.add_clock (stopwatch);
toolbar.add_clock (timer);
- notebook = new Gtk.Notebook ();
- notebook.set_show_tabs (false);
- notebook.set_show_border (true);
- notebook.get_style_context ().add_class ("clocks-content-view");
- notebook.get_style_context ().add_class ("view");
- notebook.get_style_context ().add_class ("content-view");
-
- notebook.append_page (world, null);
- notebook.append_page (alarm, null);
- notebook.append_page (stopwatch, null);
- notebook.append_page (timer, null);
+ stack = new Gd.Stack ();
+ stack.add (world);
+ stack.add (alarm);
+ stack.add (stopwatch);
+ stack.add (timer);
toolbar.clock_changed.connect ((c) => {
- notebook.set_current_page (c);
+ stack.visible_child = (Gtk.Widget) c;
});
- notebook.switch_page.connect ((w, i) => {
- ((Clock) w).update_toolbar ();
+ stack.notify["visible-child"].connect (() => {
+ ((Clock) stack.visible_child).update_toolbar ();
});
alarm.ring.connect ((w) => {
- notebook.set_current_page (Page.ALARM);
+ stack.visible_child = w;
});
timer.ring.connect ((w) => {
- notebook.set_current_page (Page.TIMER);
+ stack.visible_child = w;
});
- notebook.set_current_page (0);
+ stack.visible_child = world;
world.update_toolbar ();
+ var frame = new Gtk.Frame (null);
+ frame.get_style_context ().add_class ("clocks-content-view");
+ frame.get_style_context ().add_class ("view");
+ frame.get_style_context ().add_class ("content-view");
+ frame.add (stack);
+
var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
vbox.pack_start (toolbar, false, false, 0);
- vbox.pack_end (notebook, true, true, 0);
+ vbox.pack_end (frame, true, true, 0);
add (vbox);
show_all ();
}
private void on_new_activate () {
- var clock = notebook.get_nth_page (notebook.get_current_page ()) as Clock;
- clock.activate_new ();
+ ((Clock) stack.visible_child).activate_new ();
}
private void on_about_activate () {
diff --git a/src/world.vala b/src/world.vala
index ad6ba30..ca9bc67 100644
--- a/src/world.vala
+++ b/src/world.vala
@@ -215,12 +215,7 @@ private class StandalonePanel : Gtk.EventBox {
}
}
-public class MainPanel : Gtk.Notebook, Clocks.Clock {
- private enum Page {
- OVERVIEW,
- STANDALONE
- }
-
+public class MainPanel : Gd.Stack, Clocks.Clock {
private enum Column {
SELECTED,
NAME,
@@ -240,7 +235,7 @@ public class MainPanel : Gtk.Notebook, Clocks.Clock {
private StandalonePanel standalone;
public MainPanel (Toolbar toolbar) {
- Object (label: _("World"), toolbar: toolbar, show_tabs: false);
+ Object (label: _("World"), toolbar: toolbar);
settings = new GLib.Settings("org.gnome.clocks");
@@ -270,19 +265,21 @@ public class MainPanel : Gtk.Notebook, Clocks.Clock {
list_store.get (i, Column.ITEM, out location);
standalone.location = location;
standalone.update ();
- set_current_page (Page.STANDALONE);
+ visible_child = standalone;
}
});
content_view = new ContentView (icon_view, "document-open-recent-symbolic", _("Select <b>New</b> to add a world clock"));
- append_page (content_view);
+ add (content_view);
standalone = new StandalonePanel ();
- append_page (standalone);
+ add (standalone);
- load ();
+ notify["visible-child"].connect (() => {
+ update_toolbar ();
+ });
- set_current_page (Page.OVERVIEW);
+ visible_child = content_view;
show_all ();
}
@@ -314,17 +311,9 @@ public class MainPanel : Gtk.Notebook, Clocks.Clock {
dialog.show ();
}
- public override void switch_page (Gtk.Widget widget, uint page) {
- base.switch_page (widget, page);
-
- // Update the toolbar *after* the current page changes
- update_toolbar ();
- }
-
public void update_toolbar () {
toolbar.clear ();
- switch (get_current_page ()) {
- case Page.OVERVIEW:
+ if (visible_child == content_view) {
if (icon_view.mode == IconView.Mode.SELECTION) {
toolbar.mode = Toolbar.Mode.SELECTION;
var done_button = toolbar.add_button (null, _("Done"), false);
@@ -346,16 +335,14 @@ public class MainPanel : Gtk.Notebook, Clocks.Clock {
update_toolbar ();
});
}
- break;
- case Page.STANDALONE:
+ } else if (visible_child == standalone) {
toolbar.mode = Toolbar.Mode.STANDALONE;
var back_button = toolbar.add_button ("go-previous-symbolic", null, true);
back_button.clicked.connect (() => {
- set_current_page (Page.OVERVIEW);
+ visible_child = content_view;
});
toolbar.set_labels (GLib.Markup.escape_text (standalone.location.name), null);
- break;
- default:
+ } else {
assert_not_reached ();
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]