[gnome-clocks/wip/vala] Cleanup
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks/wip/vala] Cleanup
- Date: Tue, 12 Feb 2013 08:50:53 +0000 (UTC)
commit 9d25633f9d388543c7bc46034e52f87bf86a132e
Author: Paolo Borelli <pborelli gnome org>
Date: Tue Feb 12 09:50:23 2013 +0100
Cleanup
src/alarm.vala | 13 ++++++++-----
src/widgets.vala | 49 ++++++++++++++++++++++++++-----------------------
2 files changed, 34 insertions(+), 28 deletions(-)
---
diff --git a/src/alarm.vala b/src/alarm.vala
index 45084ca..d491771 100644
--- a/src/alarm.vala
+++ b/src/alarm.vala
@@ -207,24 +207,27 @@ private class SetupDialog : Gtk.Dialog {
Object (transient_for: parent, modal: true, title: _("New Alarm"));
add_buttons (Gtk.Stock.CANCEL, 0, Gtk.Stock.SAVE, 1);
+ set_default_response (1);
+
var builder = Utils.load_ui ("alarm.ui");
var grid = builder.get_object ("setup_dialog_content") as Gtk.Grid;
get_content_area ().add (grid);
h_spinbutton = builder.get_object ("h_spinbutton") as Gtk.SpinButton;
m_spinbutton = builder.get_object ("m_spinbutton") as Gtk.SpinButton;
- am_pm_button = new AmPmToggleButton();
+ am_pm_button = new AmPmToggleButton ();
var time_entry = builder.get_object ("time_entry") as Gtk.Box;
var wc = Utils.WallClock.get_default ();
if (wc.format == Utils.WallClock.Format.TWENTYFOUR)
- h_spinbutton.set_range (0,23);
+ h_spinbutton.set_range (0, 23);
else {
- h_spinbutton.set_range (1,12);
+ h_spinbutton.set_range (1, 12);
}
+
h_spinbutton.output.connect (show_leading_zeros);
m_spinbutton.output.connect (show_leading_zeros);
- time_entry.pack_end(am_pm_button);
+ time_entry.pack_end (am_pm_button);
}
// TODO: use the spin buttons
@@ -235,7 +238,7 @@ private class SetupDialog : Gtk.Dialog {
// }
private bool show_leading_zeros (Gtk.SpinButton spin_button) {
- spin_button.set_text ("%02i".printf(spin_button.get_value_as_int ()));
+ spin_button.set_text ("%02i".printf (spin_button.get_value_as_int ()));
return true;
}
}
diff --git a/src/widgets.vala b/src/widgets.vala
index 7a93c5c..be8e046 100644
--- a/src/widgets.vala
+++ b/src/widgets.vala
@@ -358,39 +358,42 @@ public class AmPmToggleButton : Gtk.Button {
PM
}
- public AmPm choice;
+ public AmPm choice {
+ get {
+ return _choice;
+ }
+ set {
+ if (_choice != value) {
+ _choice = value;
+ stack.visible_child = _choice == AmPm.AM ? am_label : pm_label;
+ }
+ }
+ }
- private Gtk.Notebook notebook;
+ private AmPm _choice;
+ private Gd.Stack stack;
private Gtk.Label am_label;
private Gtk.Label pm_label;
public AmPmToggleButton () {
- notebook = new Gtk.Notebook();
- notebook.set_show_tabs (false);
+ stack = new Gd.Stack ();
+
// TODO: get translated AM/PM strings from the system
- am_label = new Gtk.Label("AM");
- pm_label = new Gtk.Label("PM");
+ am_label = new Gtk.Label ("AM");
+ pm_label = new Gtk.Label ("PM");
- notebook.append_page(am_label);
- notebook.append_page(pm_label);
- add(notebook);
+ stack.add (am_label);
+ stack.add (pm_label);
+ add (stack);
- choice = AmPm.AM;
- notebook.set_current_page(0);
- clicked.connect(toggle);
- show_all();
- }
-
- public void set_choice(AmPm new_choice) {
- if (new_choice != choice)
- toggle();
- }
+ clicked.connect (() => {
+ choice = choice == AmPm.AM ? AmPm.PM : AmPm.AM;
+ });
- private void toggle () {
- choice = choice == AmPm.AM ? AmPm.PM : AmPm.AM;
- notebook.set_current_page(choice == AmPm.AM ? 0 : 1);
+ choice = AmPm.AM;
+ stack.visible_child = am_label;
+ show_all ();
}
}
-
} // namespace Clocks
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]