[california/wip/725786-edit-recurring] OK sensitivity in new dialog



commit 0000921db90db58f7169728215b126ac863b3224
Author: Jim Nelson <jim yorba org>
Date:   Wed Jul 16 14:04:35 2014 -0700

    OK sensitivity in new dialog

 src/host/host-create-update-recurring.vala |   65 ++++++++++++++++++++++++++--
 1 files changed, 61 insertions(+), 4 deletions(-)
---
diff --git a/src/host/host-create-update-recurring.vala b/src/host/host-create-update-recurring.vala
index 5e0589e..30dc901 100644
--- a/src/host/host-create-update-recurring.vala
+++ b/src/host/host-create-update-recurring.vala
@@ -138,10 +138,27 @@ public class CreateUpdateRecurring : Gtk.Grid, Toolkit.Card {
         on_day_checkbuttons[Calendar.DayOfWeek.FRI] = friday_checkbutton;
         on_day_checkbuttons[Calendar.DayOfWeek.SAT] = saturday_checkbutton;
         
-        /*
-        foreach (Gtk.CheckButton check_button in on_day_checkbuttons.keys)
-            check_button.notify["active"].connect(on_checkbox_active_changed);
-        */
+        // Ok button's sensitivity is tied to a whole-lotta controls here
+        make_recurring_checkbutton.bind_property("active", ok_button, "sensitive",
+            BindingFlags.SYNC_CREATE, transform_to_ok_button_sensitive);
+        every_entry.bind_property("text", ok_button, "sensitive",
+            BindingFlags.SYNC_CREATE, transform_to_ok_button_sensitive);
+        repeats_combobox.bind_property("active", ok_button, "sensitive",
+            BindingFlags.SYNC_CREATE, transform_to_ok_button_sensitive);
+        foreach (Gtk.CheckButton checkbutton in on_day_checkbuttons.values) {
+            checkbutton.bind_property("active", ok_button, "sensitive",
+                BindingFlags.SYNC_CREATE, transform_to_ok_button_sensitive);
+        }
+        bind_property(PROP_START_DATE, ok_button, "sensitive",
+            BindingFlags.SYNC_CREATE, transform_to_ok_button_sensitive);
+        ends_on_radiobutton.bind_property("active", ok_button, "sensitive",
+            BindingFlags.SYNC_CREATE, transform_to_ok_button_sensitive);
+        bind_property(PROP_END_DATE, ok_button, "sensitive",
+            BindingFlags.SYNC_CREATE, transform_to_ok_button_sensitive);
+        after_radiobutton.bind_property("active", ok_button, "sensitive",
+            BindingFlags.SYNC_CREATE, transform_to_ok_button_sensitive);
+        after_entry.bind_property("text", ok_button, "sensitive",
+            BindingFlags.SYNC_CREATE, transform_to_ok_button_sensitive);
     }
     
     private bool transform_repeats_active_to_on_days_visible(Binding binding, Value source_value,
@@ -158,6 +175,46 @@ public class CreateUpdateRecurring : Gtk.Grid, Toolkit.Card {
         return true;
     }
     
+    private bool transform_to_ok_button_sensitive(Binding binding, Value source_value, ref Value 
target_value) {
+        target_value = is_ok_ready();
+        
+        return true;
+    }
+    
+    // if controls are added or removed here, that needs to be reflected in the ctor by binding/
+    // unbinding to its properties
+    private bool is_ok_ready() {
+        // if not recurring, ok
+        if (!make_recurring_checkbutton.active)
+            return true;
+        
+        // every entry must be positive value
+        if (String.is_empty(every_entry.text) || int.parse(every_entry.text) <= 0)
+            return false;
+        
+        // if weekly, at least one checkbox must be active
+        if (repeats_combobox.active == Repeats.WEEKLY) {
+            if (!traverse<Gtk.CheckButton>(on_day_checkbuttons.values).any(checkbutton => 
checkbutton.active))
+                return false;
+        }
+        
+        // need a start date
+        if (start_date == null)
+            return false;
+        
+        // end date required if specified
+        if (ends_on_radiobutton.active && end_date == null)
+            return false;
+        
+        // count required if specified
+        if (after_radiobutton.active) {
+            if (String.is_empty(after_entry.text) || int.parse(after_entry.text) <= 0)
+                return false;
+        }
+        
+        return true;
+    }
+    
     public void jumped_to(Toolkit.Card? from, Toolkit.Card.Jump reason, Value? message) {
         assert(message != null);
         


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]