main
 1using System;
 2using System.Collections.Generic;
 3using gorilla.commons.utility;
 4
 5namespace MoMoney.Presentation.Winforms.Helpers
 6{
 7    public interface IBindableTextBox<T>
 8    {
 9        void bind_to(T item);
10        T get_selected_value();
11        string text();
12        void on_leave(Action<IBindableTextBox<T>> action);
13    }
14
15    public class BindableTextBox<T> : IBindableTextBox<T>
16    {
17        readonly ITextControl<T> control;
18        readonly IList<Action<IBindableTextBox<T>>> actions = new List<Action<IBindableTextBox<T>>>();
19
20        public BindableTextBox(ITextControl<T> control)
21        {
22            this.control = control;
23            control.when_text_is_changed = () => actions.each(x => x(this));
24        }
25
26        public void bind_to(T item)
27        {
28            control.set_selected_item(item);
29        }
30
31        public T get_selected_value()
32        {
33            return control.get_selected_item();
34        }
35
36        public string text()
37        {
38            return control.text();
39        }
40
41        public void on_leave(Action<IBindableTextBox<T>> action)
42        {
43            actions.Add(action);
44        }
45    }
46}