Esempio n. 1
0
        private void setEditor(string valueType, DesignerPropertyEditor editor, DesignerPropertyInfo prop, object obj, bool isConst, bool isFunction)
        {
            if (editor != null)
            {
                editor.SetRootNode(this._root);

                object        propertyMember = prop.Property.GetValue(obj, null);
                VariableDef   var            = propertyMember as VariableDef;
                RightValueDef varRV          = propertyMember as RightValueDef;

                DesignerPropertyEnum   enumAtt   = prop.Attribute as DesignerPropertyEnum;
                DesignerRightValueEnum enumAttRV = prop.Attribute as DesignerRightValueEnum;

                if (isConst)
                {
                    bool bHasDepend    = false;
                    Type dependVarType = getDependedPropertyType(prop, obj);

                    if (dependVarType == null)
                    {
                        dependVarType = getPropertyType(prop, obj, VariableDef.kConst);
                    }
                    else
                    {
                        bHasDepend = true;
                    }

                    Debug.Check(dependVarType != null);

                    object defaultValue = Plugin.DefaultValue(dependVarType);
                    Debug.Check(defaultValue != null);

                    //for a const bool, to use true as the default when it is the right operand
                    if (bHasDepend && (defaultValue is bool))
                    {
                        defaultValue = true;
                    }

                    if (var == null)
                    {
                        var = new VariableDef(defaultValue);
                    }

                    if (var.Value == null || var.Value.GetType() != defaultValue.GetType())
                    {
                        var.Value = defaultValue;
                    }

                    var.ValueClass = VariableDef.kConst;

                    if (enumAttRV == null)
                    {
                        prop.Property.SetValue(obj, var, null);
                        editor.SetVariable(var, obj);

                        if (enumAtt != null)
                        {
                            editor.SetRange(enumAtt.MinValue, enumAtt.MaxValue);
                        }
                    }
                    else
                    {
                        if (varRV == null || varRV.Var == null || varRV.ValueClass != var.ValueClass || varRV.ValueType != var.ValueType)
                        {
                            varRV = new RightValueDef(var);
                        }

                        prop.Property.SetValue(obj, varRV, null);
                        editor.SetVariable(varRV.Var, obj);
                    }
                }
                else
                {
                    // VariableDef
                    if (enumAttRV == null)
                    {
                        if (var == null)
                        {
                            var = new VariableDef(null);
                            prop.Property.SetValue(obj, var, null);
                        }

                        var.ValueClass = valueType;
                    }

                    // RightValueDef
                    else
                    {
                        if (varRV == null)
                        {
                            varRV = new RightValueDef(var);
                            prop.Property.SetValue(obj, varRV, null);
                        }

                        varRV.ValueClass = valueType;
                    }

                    editor.ValueType = prop.Attribute.ValueType;
                    editor.SetProperty(prop, obj);
                }

                editor.ValueWasAssigned();
                OnValueChanged(_property);
            }
        }
        private void setEditor(DesignerPropertyEditor editor, DesignerPropertyInfo prop, object obj, bool isConst, bool isPar, bool isFunction)
        {
            if (editor != null)
            {
                editor.SetRootNode(this._root);

                object propertyMember = prop.Property.GetValue(obj, null);
                VariableDef var = propertyMember as VariableDef;
                RightValueDef varRV = propertyMember as RightValueDef;

                DesignerPropertyEnum enumAtt = prop.Attribute as DesignerPropertyEnum;
                DesignerRightValueEnum enumAttRV = prop.Attribute as DesignerRightValueEnum;

                if (isConst)
                {
                    Type dependVarType = getDependedPropertyType(prop, obj);
                    if (dependVarType == null)
                    {
                        dependVarType = getPropertyType(prop, obj, VariableDef.kConst);
                    }
                    Debug.Check(dependVarType != null);

                    object defaultValue = Plugin.DefaultValue(dependVarType);
                    Debug.Check(defaultValue != null);

                    if (var == null)
                    {
                        var = new VariableDef(defaultValue);
                    }

                    if (var.Value == null || var.Value.GetType() != defaultValue.GetType())
                        var.Value = defaultValue;

                    var.ValueClass = VariableDef.kConst;

                    if (enumAttRV == null)
                    {
                        prop.Property.SetValue(obj, var, null);
                        editor.SetVariable(var, obj);
                        if (enumAtt != null)
                            editor.SetRange(enumAtt.MinValue, enumAtt.MaxValue);
                    }
                    else
                    {
                        if (varRV == null || varRV.Var == null || varRV.ValueClass != var.ValueClass || varRV.ValueType != var.GetValueType())
                        {
                            varRV = new RightValueDef(var);
                        }

                        prop.Property.SetValue(obj, varRV, null);
                        editor.SetVariable(varRV.Var, obj);
                    }
                }
                else if (isPar)
                {
                    Type dependVarType = getDependedPropertyType(prop, obj);
                    //if (dependVarType == null)
                    //    dependVarType = getPropertyType(prop, obj, VariableDef.kPar);
                    if (dependVarType == null)
                        dependVarType = prop.Attribute.FilterType;

                    object defaultValue = Plugin.DefaultValue((var != null) ? var.GetValueType() : dependVarType);

                    if (varRV == null || varRV.ValueClass != VariableDef.kPar)
                    {
                        if (var == null)
                        {
                            ParInfo par = new ParInfo(obj as Nodes.Node);
                            par.Variable = new VariableDef(defaultValue);

                            var = new VariableDef(par);
                        }

                        if (var.Value == null)
                        {
                            ParInfo par = new ParInfo(obj as Nodes.Node);
                            par.Variable = new VariableDef(defaultValue);

                            var.Value = par;
                        }

                        var.ValueClass = VariableDef.kPar;
                    }

                    editor.FilterType = dependVarType;

                    if (enumAttRV == null)
                    {
                        prop.Property.SetValue(obj, var, null);
                        editor.SetVariable(var, obj);
                    }
                    else
                    {
                        if (var != null &&
                            (varRV == null || varRV.Var == null ||
                                (varRV.ValueClass != var.ValueClass || (var.GetValueType() != null && varRV.ValueType != var.GetValueType())
                                )
                            )
                           )
                        {
                            varRV = new RightValueDef(var);
                        }

                        prop.Property.SetValue(obj, varRV, null);
                        editor.SetVariable(varRV.Var, obj);
                    }
                }
                else
                {
                    // VariableDef
                    if (enumAttRV == null)
                    {
                        if (var == null)
                        {
                            var = new VariableDef(null);
                            prop.Property.SetValue(obj, var, null);
                        }

                        if (var != null && typeComboBox.SelectedIndex > -1)
                            var.ValueClass = _currentNames[typeComboBox.SelectedIndex];
                    }
                    // RightValueDef
                    else
                    {
                        if (varRV == null)
                        {
                            varRV = new RightValueDef(var);
                            prop.Property.SetValue(obj, varRV, null);
                        }

                        if (typeComboBox.SelectedIndex > -1)
                            varRV.ValueClass = _currentNames[typeComboBox.SelectedIndex];
                    }

                    editor.ValueType = prop.Attribute.ValueType;
                    editor.SetProperty(prop, obj);
                }

                editor.ValueWasAssigned();
            }
        }
Esempio n. 3
0
        private void createValueEditor(Type type)
        {
            Type editorType = Plugin.InvokeEditorType(type);
            Debug.Check(editorType != null);

            ParInfo par = this._property as ParInfo;

            if (_property.Variable == null || _property.Variable.ValueType != type)
            {
                _property.Variable = new VariableDef(Plugin.DefaultValue(type));
            }

            _valueEditor = (DesignerPropertyEditor)editorType.InvokeMember(string.Empty, System.Reflection.BindingFlags.CreateInstance, null, null, new object[0]);
            _valueEditor.Margin = new System.Windows.Forms.Padding(0);
            _valueEditor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            _valueEditor.Width = this.dispTextBox.Width;
            _valueEditor.Location = this.dispTextBox.Location;
            _valueEditor.Location = new Point(_valueEditor.Location.X, _valueEditor.Location.Y - _valueEditor.Height - 6);
            _valueEditor.ValueWasChanged += new DesignerPropertyEditor.ValueChanged(editor_ValueWasChanged);

            if (par != null)
            {
                _valueEditor.SetPar(par, null);
            }
            else
            {
                _valueEditor.SetVariable(this._property.Variable, null);
            }

            _valueEditor.ValueWasAssigned();

            this.Controls.Add(_valueEditor);
            _valueEditor.BringToFront();
        }
        private void setEditor(string valueType, DesignerPropertyEditor editor, DesignerPropertyInfo prop, object obj, bool isConst, bool isFunction)
        {
            if (editor != null) {
                editor.SetRootNode(this._root);

                object propertyMember = prop.Property.GetValue(obj, null);
                VariableDef var = propertyMember as VariableDef;
                RightValueDef varRV = propertyMember as RightValueDef;

                DesignerPropertyEnum enumAtt = prop.Attribute as DesignerPropertyEnum;
                DesignerRightValueEnum enumAttRV = prop.Attribute as DesignerRightValueEnum;

                if (isConst) {
                    bool bHasDepend = false;
                    Type dependVarType = getDependedPropertyType(prop, obj);

                    if (dependVarType == null) {
                        dependVarType = getPropertyType(prop, obj, VariableDef.kConst);

                    } else {
                        bHasDepend = true;
                    }

                    Debug.Check(dependVarType != null);

                    object defaultValue = Plugin.DefaultValue(dependVarType);
                    Debug.Check(defaultValue != null);

                    //for a const bool, to use true as the default when it is the right operand
                    if (bHasDepend && (defaultValue is bool)) {
                        defaultValue = true;
                    }

                    if (var == null) {
                        var = new VariableDef(defaultValue);
                    }

                    if (var.Value == null || var.Value.GetType() != defaultValue.GetType())
                    { var.Value = defaultValue; }

                    var.ValueClass = VariableDef.kConst;

                    if (enumAttRV == null) {
                        prop.Property.SetValue(obj, var, null);
                        editor.SetVariable(var, obj);

                        if (enumAtt != null)
                        { editor.SetRange(enumAtt.MinValue, enumAtt.MaxValue); }

                    } else {
                        if (varRV == null || varRV.Var == null || varRV.ValueClass != var.ValueClass || varRV.ValueType != var.GetValueType()) {
                            varRV = new RightValueDef(var);
                        }

                        prop.Property.SetValue(obj, varRV, null);
                        editor.SetVariable(varRV.Var, obj);
                    }

                } else {
                    // VariableDef
                    if (enumAttRV == null) {
                        if (var == null) {
                            var = new VariableDef(null);
                            prop.Property.SetValue(obj, var, null);
                        }

                        var.ValueClass = valueType;
                    }

                    // RightValueDef
                    else {
                        if (varRV == null) {
                            varRV = new RightValueDef(var);
                            prop.Property.SetValue(obj, varRV, null);
                        }

                        varRV.ValueClass = valueType;
                    }

                    editor.ValueType = prop.Attribute.ValueType;
                    editor.SetProperty(prop, obj);
                }

                editor.ValueWasAssigned();
                OnValueChanged(_property);
                this.ValueWasAssigned();
            }
        }
        private void setEditor(DesignerPropertyEditor editor, DesignerPropertyInfo prop, object obj, bool isConst, bool isPar, bool isFunction)
        {
            if (editor != null)
            {
                editor.SetRootNode(this._root);

                object        propertyMember = prop.Property.GetValue(obj, null);
                VariableDef   var            = propertyMember as VariableDef;
                RightValueDef varRV          = propertyMember as RightValueDef;

                DesignerPropertyEnum   enumAtt   = prop.Attribute as DesignerPropertyEnum;
                DesignerRightValueEnum enumAttRV = prop.Attribute as DesignerRightValueEnum;

                if (isConst)
                {
                    Type dependVarType = getDependedPropertyType(prop, obj);
                    if (dependVarType == null)
                    {
                        dependVarType = getPropertyType(prop, obj, VariableDef.kConst);
                    }
                    Debug.Check(dependVarType != null);

                    object defaultValue = Plugin.DefaultValue(dependVarType);
                    Debug.Check(defaultValue != null);

                    if (var == null)
                    {
                        var = new VariableDef(defaultValue);
                    }

                    if (var.Value == null || var.Value.GetType() != defaultValue.GetType())
                    {
                        var.Value = defaultValue;
                    }

                    var.ValueClass = VariableDef.kConst;

                    if (enumAttRV == null)
                    {
                        prop.Property.SetValue(obj, var, null);
                        editor.SetVariable(var, obj);
                        if (enumAtt != null)
                        {
                            editor.SetRange(enumAtt.MinValue, enumAtt.MaxValue);
                        }
                    }
                    else
                    {
                        if (varRV == null || varRV.Var == null || varRV.ValueClass != var.ValueClass || varRV.ValueType != var.GetValueType())
                        {
                            varRV = new RightValueDef(var);
                        }

                        prop.Property.SetValue(obj, varRV, null);
                        editor.SetVariable(varRV.Var, obj);
                    }
                }
                else if (isPar)
                {
                    Type dependVarType = getDependedPropertyType(prop, obj);
                    //if (dependVarType == null)
                    //    dependVarType = getPropertyType(prop, obj, VariableDef.kPar);
                    if (dependVarType == null)
                    {
                        dependVarType = prop.Attribute.FilterType;
                    }

                    object defaultValue = Plugin.DefaultValue((var != null) ? var.GetValueType() : dependVarType);

                    if (varRV == null || varRV.ValueClass != VariableDef.kPar)
                    {
                        if (var == null)
                        {
                            ParInfo par = new ParInfo(obj as Nodes.Node);
                            par.Variable = new VariableDef(defaultValue);

                            var = new VariableDef(par);
                        }

                        if (var.Value == null)
                        {
                            ParInfo par = new ParInfo(obj as Nodes.Node);
                            par.Variable = new VariableDef(defaultValue);

                            var.Value = par;
                        }

                        var.ValueClass = VariableDef.kPar;
                    }

                    editor.FilterType = dependVarType;

                    if (enumAttRV == null)
                    {
                        prop.Property.SetValue(obj, var, null);
                        editor.SetVariable(var, obj);
                    }
                    else
                    {
                        if (var != null &&
                            (varRV == null || varRV.Var == null ||
                             (varRV.ValueClass != var.ValueClass || (var.GetValueType() != null && varRV.ValueType != var.GetValueType())
                             )
                            )
                            )
                        {
                            varRV = new RightValueDef(var);
                        }

                        prop.Property.SetValue(obj, varRV, null);
                        editor.SetVariable(varRV.Var, obj);
                    }
                }
                else
                {
                    // VariableDef
                    if (enumAttRV == null)
                    {
                        if (var == null)
                        {
                            var = new VariableDef(null);
                            prop.Property.SetValue(obj, var, null);
                        }

                        if (var != null && typeComboBox.SelectedIndex > -1)
                        {
                            var.ValueClass = _currentNames[typeComboBox.SelectedIndex];
                        }
                    }
                    // RightValueDef
                    else
                    {
                        if (varRV == null)
                        {
                            varRV = new RightValueDef(var);
                            prop.Property.SetValue(obj, varRV, null);
                        }

                        if (typeComboBox.SelectedIndex > -1)
                        {
                            varRV.ValueClass = _currentNames[typeComboBox.SelectedIndex];
                        }
                    }

                    editor.ValueType = prop.Attribute.ValueType;
                    editor.SetProperty(prop, obj);
                }

                editor.ValueWasAssigned();
            }
        }