Commit b6e9db8

mo khan <mo@mokhan.ca>
2009-05-13 19:00:32
split extension method in BindableTextBoxExtensions to allow you to chain in additional commands
1 parent 30f7bfd
Changed files (3)
product/Gorilla.Commons.Windows.Forms/Helpers/BindableTextBox.cs
@@ -9,6 +9,7 @@ namespace Gorilla.Commons.Windows.Forms.Helpers
         void bind_to(T item);
         T get_selected_value();
         string text();
+        void on_leave(Action<IBindableTextBox<T>> action);
     }
 
     public class BindableTextBox<T> : IBindableTextBox<T>
product/Gorilla.Commons.Windows.Forms/Helpers/BindableTextBoxExtensions.cs
@@ -6,17 +6,23 @@ namespace Gorilla.Commons.Windows.Forms.Helpers
 {
     static public class BindableTextBoxExtensions
     {
-        static public IBindableTextBox<ItemToBindTo> apply<ItemToBindTo>(this ITextControl<ItemToBindTo> text_control, params ITextBoxCommand<ItemToBindTo>[] commands)
-        {
-            var textbox = new BindableTextBox<ItemToBindTo>(text_control);
-            commands.each(x => textbox.on_leave(y => x.run(y)));
-            return textbox;
-        }
-
         static public IBindableTextBox<ItemToBindTo> rebind_with<ItemToBindTo>(
             this ITextControl<ItemToBindTo> text_control, Expression<Func<string, ItemToBindTo>> rebind)
         {
             return text_control.apply(new RebindTextBoxCommand<ItemToBindTo>(rebind));
         }
+
+        static public IBindableTextBox<ItemToBindTo> apply<ItemToBindTo>(this ITextControl<ItemToBindTo> text_control,
+                                                                         params ITextBoxCommand<ItemToBindTo>[] commands)
+        {
+            return new BindableTextBox<ItemToBindTo>(text_control).apply(commands);
+        }
+
+        static public IBindableTextBox<ItemToBindTo> apply<ItemToBindTo>(this IBindableTextBox<ItemToBindTo> textbox,
+                                                                         params ITextBoxCommand<ItemToBindTo>[] commands)
+        {
+            commands.each(x => textbox.on_leave(y => x.run(y)));
+            return textbox;
+        }
     }
 }
\ No newline at end of file
product/Gorilla.Commons.Windows.Forms/Helpers/BindableTextBoxSpecs.cs
@@ -45,7 +45,7 @@ namespace Gorilla.Commons.Windows.Forms.Helpers
 
         because b = () =>
                         {
-                            sut.downcast_to<BindableTextBox<string>>().on_leave(x => action.run());
+                            sut.on_leave(x => action.run());
                             control.when_text_is_changed();
                         };