Exemplo n.º 1
0
        private void DoBindingPair()
        {
            List <BindingPair> ps = new List <BindingPair>();

            foreach (ComboBox cb in _comboxes.Keys)
            {
                BindingPair pair = null;
                //
                BindingDef def = _comboxes[cb];
                //与其它Action绑定
                if (cb.Tag is BindingScriptObject)
                {
                    pair = (cb.Tag as BindingScriptObject).ToBindingPair();
                }
                //直接绑定值
                else
                {
                    PropertyValueByValue pv = new PropertyValueByValue();
                    pv.ArgType = enumArgType.Var;
                    pv.Value   = GetDirectValue(def);
                    pair       = new BindingPair(def.PropertyInfo, pv);
                }
                ps.Add(pair);
            }
            _bindingEnvironment.UpdateBindingPair(_action, ps.ToArray());
        }
Exemplo n.º 2
0
 private object GetDirectValue(BindingDef def)
 {
     if (def.InputControl is ComboBox)
     {
         ComboBox cb    = def.InputControl as ComboBox;
         object   value = null;
         if (def.Editor.IsNeedInput && def.Editor.TryParse(cb.Text, out value))
         {
             return(value);
         }
         else
         {
             return(cb.Tag);
         }
     }
     else if (def.InputControl is ListBox)
     {
         ListBox lstBox = def.InputControl as ListBox;
         if (lstBox.Items.Count == 0)
         {
             return(null);
         }
         int   i        = 0;
         Array valArray = Array.CreateInstance(def.PropertyInfo.PropertyType.GetElementType(), lstBox.Items.Count);
         foreach (object v in lstBox.Items)
         {
             valArray.SetValue(v, i++);
         }
         return(valArray);
     }
     return(null);
 }
Exemplo n.º 3
0
        private void GetArgsAndInitComboBoxes()
        {
            BindingDef def = null;

            foreach (ComboBox cb in _comboxes.Keys)
            {
                def = _comboxes[cb];
                cb.Items.Clear();
                Dictionary <IAction, PropertyInfo[]> atts = _bindingEnvironment.QueryCompatibleProperty(_action, def.BindingAttribute, def.PropertyInfo);
                if (atts != null && atts.Count > 0)
                {
                    foreach (IAction act in atts.Keys)
                    {
                        PropertyInfo[] ps = atts[act];
                        if (ps == null || ps.Length == 0)
                        {
                            continue;
                        }
                        foreach (PropertyInfo p in ps)
                        {
                            BindingAttribute    ba     = ArgBindingHelper.GetBingdingAttribute(p.Name, act);
                            BindingScriptObject script = new BindingScriptObject(act, ba, p, def.PropertyInfo);
                            cb.Items.Add(script);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        void btnEditor_Click(object sender, EventArgs e)
        {
            BindingDef          def    = (sender as Button).Tag as BindingDef;
            ISemanticTypeEditor editor = def.Editor;
            object obj = editor.GetValue(_action);

            if (obj != null)
            {
                (def.InputControl as ComboBox).Text = editor.ToString(obj);
                (def.InputControl as ComboBox).Tag  = obj;
            }
        }
Exemplo n.º 5
0
        void cb_KeyPress(object sender, KeyPressEventArgs e)
        {
            BindingDef def = _comboxes[(sender as ComboBox)];

            e.Handled = !def.Editor.IsNeedInput;
        }
Exemplo n.º 6
0
        public void AddBinding(GLib.Object control, object dataSource, string propertyName)
        {
            // Get the type of control being bound.
            ObjectType widgetType = ObjectType.None;
            Type       ctrlType   = control.GetType();

            if (IsSameOrSubclass(ctrlType, typeof(Entry)))
            {
                widgetType = ObjectType.Entry;
            }
            else if (IsSameOrSubclass(ctrlType, typeof(TextView)))
            {
                widgetType = ObjectType.TextView;
            }
            else if (IsSameOrSubclass(ctrlType, typeof(ToggleButton)))
            {
                widgetType = ObjectType.ToggleButton;
            }
            else if (IsSameOrSubclass(ctrlType, typeof(ToggleAction)))
            {
                widgetType = ObjectType.ToggleAction;
            }

            // Get the datasource and ensure that the types are compatible.
            DataSource src         = new DataSource(dataSource, propertyName);
            bool       typeIsValid = false;

            switch (widgetType)
            {
            case ObjectType.Entry:
            case ObjectType.TextView:
                if (src.DataType == typeof(string))
                {
                    typeIsValid = true;
                }
                break;

            case ObjectType.ToggleButton:
            case ObjectType.ToggleAction:
                if (src.DataType == typeof(bool))
                {
                    typeIsValid = true;
                }
                break;
            }

            if (!typeIsValid)
            {
                string name = "unknown";
                if (IsSameOrSubclass(ctrlType, typeof(Gtk.Action)))
                {
                    name = ((Gtk.Action)control).Name;
                }
                else if (IsSameOrSubclass(ctrlType, typeof(Gtk.Widget)))
                {
                    name = ((Gtk.Widget)control).Name;
                }

                throw new Exception(string.Format("The binding for control '{0}' to '{1}' failed: incompatible data types.", name, propertyName));
            }

            // Add an event handler for the control.
            switch (widgetType)
            {
            case ObjectType.Entry:
                ((Entry)control).Changed += (object sender, EventArgs e) => {
                    if (!_updateInProgress)
                    {
                        BindingDef def = _bindings.Find(x => x.Control == sender);
                        if (def.DataSource.DataType == typeof(string))
                        {
                            def.DataSource.Value = ((Entry)sender).Text;
                        }

                        UpdateBindings(def.DataSource.Key, sender);
                    }
                };
                break;

            case ObjectType.ToggleButton:
                ((ToggleButton)control).Toggled += (object sender, EventArgs e) => {
                    if (!_updateInProgress)
                    {
                        BindingDef def = _bindings.Find(x => x.Control == sender);
                        def.DataSource.Value = ((ToggleButton)sender).Active;

                        UpdateBindings(def.DataSource.Key, sender);
                    }
                };
                break;

            case ObjectType.ToggleAction:
                ((ToggleAction)control).Toggled += (object sender, EventArgs e) => {
                    if (!_updateInProgress)
                    {
                        BindingDef def = _bindings.Find(x => x.Control == sender);
                        def.DataSource.Value = ((ToggleAction)sender).Active;

                        UpdateBindings(def.DataSource.Key, sender);
                    }
                };
                break;
            }

            _bindings.Add(new BindingDef(src, control, widgetType));
        }