[california/wip/725783-time] Make up/down widgets sensitive according to their valid states
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/725783-time] Make up/down widgets sensitive according to their valid states
- Date: Tue, 5 Aug 2014 23:59:54 +0000 (UTC)
commit c94a14d979154f0cf43f8a223d1af67e70959da7
Author: Jim Nelson <jim yorba org>
Date: Tue Aug 5 16:59:33 2014 -0700
Make up/down widgets sensitive according to their valid states
src/host/host-date-time-widget.vala | 79 ++++++++++++++++++++++++++--------
1 files changed, 60 insertions(+), 19 deletions(-)
---
diff --git a/src/host/host-date-time-widget.vala b/src/host/host-date-time-widget.vala
index d715964..03f772f 100644
--- a/src/host/host-date-time-widget.vala
+++ b/src/host/host-date-time-widget.vala
@@ -32,7 +32,7 @@ public class DateTimeWidget : Gtk.Box {
* Indicates if the widgets are filled-in with invalid values or is valid but out of the range
* of { link floor} and/or { link ceiling}.
*/
- public bool out_of_range { get; private set; default = false; }
+ public bool out_of_range { get; protected set; default = false; }
[GtkChild]
private Gtk.Calendar calendar;
@@ -81,20 +81,43 @@ public class DateTimeWidget : Gtk.Box {
numeric_filter.connect_to(hour_entry);
numeric_filter.connect_to(minutes_entry);
- // use signal handlers to initialize widgets
- on_date_changed();
- on_wall_time_changed();
-
- connect_property_signals();
- connect_widget_signals();
-
// specifically-enabled sensitivities
bind_bool_to_time_controls(PROP_ENABLE_TIME, iterate<Gtk.Widget>(
hour_up, hour_down, minutes_up, minutes_down, meridiem_up, meridiem_down,
hour_entry, colon_label, minutes_entry, meridiem_label));
+ // set sensitivities for up/down widgets
+ foreach (Gtk.Widget widget in
+ iterate<Gtk.Widget>(hour_up, hour_down, minutes_up, minutes_down, meridiem_up, meridiem_down)) {
+ bind_property(PROP_DATE, widget, "sensitive", BindingFlags.SYNC_CREATE,
+ transform_adjustment_widget_to_sensitive);
+ bind_property(PROP_WALL_TIME, widget, "sensitive", BindingFlags.SYNC_CREATE,
+ transform_adjustment_widget_to_sensitive);
+ bind_property(PROP_FLOOR, widget, "sensitive", BindingFlags.SYNC_CREATE,
+ transform_adjustment_widget_to_sensitive);
+ bind_property(PROP_CEILING, widget, "sensitive", BindingFlags.SYNC_CREATE,
+ transform_adjustment_widget_to_sensitive);
+ }
+
+ // update out_of_range when its dependencies change
+ bind_property(PROP_DATE, this, PROP_OUT_OF_RANGE, BindingFlags.SYNC_CREATE,
+ transform_to_out_of_range);
+ bind_property(PROP_WALL_TIME, this, PROP_OUT_OF_RANGE, BindingFlags.SYNC_CREATE,
+ transform_to_out_of_range);
+ bind_property(PROP_FLOOR, this, PROP_OUT_OF_RANGE, BindingFlags.SYNC_CREATE,
+ transform_to_out_of_range);
+ bind_property(PROP_CEILING, this, PROP_OUT_OF_RANGE, BindingFlags.SYNC_CREATE,
+ transform_to_out_of_range);
+
bind_bool_to_time_controls(PROP_ENABLE_DATE, iterate<Gtk.Widget>(calendar));
+ // use signal handlers to initialize widgets
+ on_date_changed();
+ on_wall_time_changed();
+
+ connect_property_signals();
+ connect_widget_signals();
+
// honor 24-hour time
Calendar.System.instance.is_24hr_changed.connect(system_24hr_changed);
system_24hr_changed();
@@ -115,6 +138,25 @@ public class DateTimeWidget : Gtk.Box {
bind_property(property, time_widget, "sensitive", BindingFlags.SYNC_CREATE);
}
+ // Determine if the up/down adjustments should be sensitive (if they're next value is valid)
+ private bool transform_adjustment_widget_to_sensitive(Binding binding, Value source_value,
+ ref Value target_value) {
+ int amount;
+ Calendar.TimeUnit time_unit;
+ if (!adjust_time_controls((Gtk.Widget) binding.target, out amount, out time_unit))
+ return false;
+
+ target_value = is_valid_date_time(date, wall_time.adjust(amount, time_unit, null));
+
+ return true;
+ }
+
+ private bool transform_to_out_of_range(Binding binding, Value source_value, ref Value target_value) {
+ target_value = is_valid_date_time(date, wall_time);
+
+ return true;
+ }
+
private void connect_property_signals() {
notify[PROP_DATE].connect(on_date_changed);
notify[PROP_WALL_TIME].connect(on_wall_time_changed);
@@ -153,7 +195,7 @@ public class DateTimeWidget : Gtk.Box {
int amount;
Calendar.TimeUnit time_unit;
- if (!adjust_time_controls(details, out amount, out time_unit))
+ if (!adjust_time_controls(details.widget, out amount, out time_unit))
return Toolkit.PROPAGATE;
// use free_adjust() to adjust each unit individually without affecting others
@@ -167,23 +209,23 @@ public class DateTimeWidget : Gtk.Box {
return Toolkit.STOP;
}
- private bool adjust_time_controls(Toolkit.ButtonEvent details, out int amount, out Calendar.TimeUnit
time_unit) {
- if (details.widget == hour_up) {
+ private bool adjust_time_controls(Gtk.Widget widget, out int amount, out Calendar.TimeUnit time_unit) {
+ if (widget == hour_up) {
amount = 1;
time_unit = Calendar.TimeUnit.HOUR;
- } else if (details.widget == hour_down) {
+ } else if (widget == hour_down) {
amount = -1;
time_unit = Calendar.TimeUnit.HOUR;
- } else if (details.widget == minutes_up) {
+ } else if (widget == minutes_up) {
amount = 5;
time_unit = Calendar.TimeUnit.MINUTE;
- } else if (details.widget == minutes_down) {
+ } else if (widget == minutes_down) {
amount = -5;
time_unit = Calendar.TimeUnit.MINUTE;
- } else if (details.widget == meridiem_up) {
+ } else if (widget == meridiem_up) {
amount = 12;
time_unit = Calendar.TimeUnit.HOUR;
- } else if (details.widget == meridiem_down) {
+ } else if (widget == meridiem_down) {
amount = -12;
time_unit = Calendar.TimeUnit.HOUR;
} else {
@@ -276,10 +318,9 @@ public class DateTimeWidget : Gtk.Box {
disconnect_property_signals();
- freeze_notify();
out_of_range = !valid;
- wall_time = new_wall_time;
- thaw_notify();
+ if (valid)
+ wall_time = new_wall_time;
connect_property_signals();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]