public override object FromStringValue(List <Nodes.Node.ErrorCheck> result, DefaultObject node, object parentObject, Type type, string str) { if (type != typeof(RightValueDef)) { throw new Exception(Resources.ExceptionDesignerAttributeInvalidType); } if (str.Length == 0 || str.Length == 2 && str == "\"\"") { return(null); } if (!str.StartsWith("const")) { int pos = str.IndexOf('('); if (pos < 0) { VariableDef var = DesignerPropertyEnum.parsePropertyVar(result, node, str); return(new RightValueDef(var)); } else { Nodes.Behavior behavior = node.Behavior as Nodes.Behavior; AgentType agentType = (behavior != null) ? behavior.AgentType : null; string valueClass = VariableDef.kSelfMethod; MethodDef method = DesignerMethodEnum.parseMethodString(result, node, agentType, this.MethodType, str); if (method == null) { string className = Plugin.GetClassName(str); method = DesignerMethodEnum.parseMethodString(result, node, Plugin.GetInstanceAgentType(className, behavior, null), this.MethodType, str); valueClass = className + VariableDef.kMethod; } string instanceName = Plugin.GetInstanceName(str); if (!string.IsNullOrEmpty(instanceName)) { valueClass = instanceName + VariableDef.kMethod; } return(new RightValueDef(method, valueClass)); } } else { VariableDef var = this.parseConstVar(result, node, parentObject, str); if (var != null) { return(new RightValueDef(var)); } } return(null); }
protected void RereshProperty(bool byForce, DesignerPropertyInfo property) { if (!byForce) { DesignerPropertyEnum enumAtt = property.Attribute as DesignerPropertyEnum; if (enumAtt != null && enumAtt.DependingProperty != "") { byForce = true; } if (this._param != null && this._param.Type.FullName == "XMLPluginBehaviac.IList") { byForce = true; } } if (byForce && DesignerPropertyEditor.PropertyChanged != null) { try { //DesignerPropertyEditor.PropertyChanged(); this.BeginInvoke(new MethodInvoker(DesignerPropertyEditor.PropertyChanged)); } catch { } } }
private Type getPropertyType(DesignerPropertyInfo prop, object obj, string valueClass) { if (prop.Property != null && obj != null) { object propertyMember = prop.Property.GetValue(obj, null); if (propertyMember != null) { VariableDef variable = propertyMember as VariableDef; if (variable != null) { variable.ValueClass = valueClass; return(variable.GetValueType()); } RightValueDef varRV = propertyMember as RightValueDef; if (varRV != null) { return(varRV.ValueType); } } } if (prop.Attribute != null) { DesignerPropertyEnum enumAtt = prop.Attribute as DesignerPropertyEnum; if (enumAtt != null) { return(enumAtt.FilterType); } } return(null); }
private PropertyInfo getDependedProperty(DesignerPropertyInfo prop, object obj) { Debug.Check(obj != null); DesignerPropertyEnum propertyAttr = prop.Attribute as DesignerPropertyEnum; if (propertyAttr != null && !string.IsNullOrEmpty(propertyAttr.DependedProperty)) { return(obj.GetType().GetProperty(propertyAttr.DependedProperty)); } return(null); }
protected void RereshProperty(bool byForce, DesignerPropertyInfo property) { if (!byForce) { DesignerPropertyEnum enumAtt = property.Attribute as DesignerPropertyEnum; if (enumAtt != null && enumAtt.DependingProperty != "") { byForce = true; } } if (byForce && DesignerPropertyEditor.PropertyChanged != null) { this.BeginInvoke(new MethodInvoker(DesignerPropertyEditor.PropertyChanged)); } }
private static VariableDef createVariable(List <Nodes.Node.ErrorCheck> result, DefaultObject node, AgentType agentType, string instacneName, string propertyName) { List <string> tokens = DesignerPropertyEnum.SplitTokens(propertyName); Debug.Check(tokens.Count > 0); string arrayIndexStr = null; if (tokens.Count > 1) { propertyName = tokens[0] + "[]"; arrayIndexStr = tokens[1]; } Nodes.Behavior behavior = node.Behavior as Nodes.Behavior; agentType = Plugin.GetInstanceAgentType(instacneName, behavior, agentType); if (agentType != null) { IList <PropertyDef> properties = agentType.GetProperties(); foreach (PropertyDef p in properties) { if (p.Name == propertyName #if BEHAVIAC_NAMESPACE_FIX || p.Name.EndsWith(propertyName) #endif ) { VariableDef v = new VariableDef(p, instacneName); if (v != null && !string.IsNullOrEmpty(arrayIndexStr)) { v.ArrayIndexElement = new MethodDef.Param("ArrayIndex", typeof(int), "int", "ArrayIndex", "ArrayIndex"); v.ArrayIndexElement.IsArrayIndex = true; DesignerMethodEnum.parseParam(result, node, null, v.ArrayIndexElement, arrayIndexStr); } return(v); } } } return(null); }
public override object FromStringValue(List <Nodes.Node.ErrorCheck> result, DefaultObject node, object parentObject, Type type, string str) { if (type != typeof(VariableDef)) { throw new Exception(Resources.ExceptionDesignerAttributeInvalidType); } if (str.Length == 0 || str.Length == 2 && str == "\"\"") { return(null); } if (!str.StartsWith("const")) { return(DesignerPropertyEnum.parsePropertyVar(result, node, str)); } else { return(this.parseConstVar(result, node, parentObject, str)); } //return null; }
public override void SetProperty(DesignerPropertyInfo property, object obj) { base.SetProperty(property, obj); _isReady = false; DesignerPropertyEnum enumAtt = property.Attribute as DesignerPropertyEnum; DesignerRightValueEnum enumAttRV = property.Attribute as DesignerRightValueEnum; _methodOnly = true; _names.Clear(); _types.Clear(); int defaultSelect = 0; if (enumAtt.HasStyles(DesignerPropertyEnum.AllowStyles.Const)) { _methodOnly = false; _allowConst = true; _names.Add(VariableDef.kConst); _types.Add(VariableDef.kConst); } else { _allowConst = false; } if (enumAtt.HasStyles(DesignerPropertyEnum.AllowStyles.Self)) { _methodOnly = false; _names.Add(VariableDef.kSelf); _types.Add(VariableDef.kSelf); defaultSelect = _types.Count - 1; } List <Plugin.InstanceName_t> instanceNames = this.InstanceNames; if (enumAtt.HasStyles(DesignerPropertyEnum.AllowStyles.Instance)) { _methodOnly = false; foreach (Plugin.InstanceName_t instanceName in instanceNames) { _names.Add(instanceName.name_); _types.Add(instanceName.displayName_); } } if (enumAtt.HasStyles(DesignerPropertyEnum.AllowStyles.SelfMethod)) { _names.Add(VariableDef.kSelfMethod); _types.Add(VariableDef.kSelfMethod); if (enumAtt.HasStyles(DesignerPropertyEnum.AllowStyles.Instance)) { foreach (Plugin.InstanceName_t instanceName in instanceNames) { _names.Add(instanceName.name_ + VariableDef.kMethod); _types.Add(instanceName.displayName_ + VariableDef.kMethod); } } } typeComboBox.Enabled = (_types.Count > 1); if (property.Property.PropertyType == null) { throw new Exception(string.Format(Resources.ExceptionDesignerAttributeExpectedEnum, property.Property.Name)); } object propertyMember = property.Property.GetValue(obj, null); VariableDef variable = propertyMember as VariableDef; RightValueDef variableRV = propertyMember as RightValueDef; //right value's default should be const if (enumAtt != null && enumAtt.DependedProperty != null && enumAtt.HasStyles(DesignerPropertyEnum.AllowStyles.Const)) { defaultSelect = 0; } int typeIndex = -1; if (variableRV == null) { if (variable != null) { typeIndex = getComboIndex(variable.ValueClass); } else { typeIndex = defaultSelect; } } else { if (!string.IsNullOrEmpty(variableRV.ValueClass)) { typeIndex = getComboIndex(variableRV.ValueClass); } else { typeIndex = 0; } } if (_types.Count > 0 && typeIndex > -1) { // Keep only one type for efficiency. _currentNames.Clear(); _currentNames.Add(_names[typeIndex]); this.typeComboBox.Items.Clear(); this.typeComboBox.Items.Add(_types[typeIndex]); this.typeComboBox.SelectedIndex = 0; } _isReady = true; string selectedText = ((string)typeComboBox.SelectedItem); setPropertyEditor(CreateEditor(selectedText, _property, _object, _allowConst && selectedText == VariableDef.kConst, variableRV != null ? variableRV.IsMethod : false)); this.ValueWasAssigned(); }
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); } }
public override void SetProperty(DesignerPropertyInfo property, object obj) { base.SetProperty(property, obj); _resetProperties = false; Type enumtype = null; DesignerPropertyEnum enumAtt = property.Attribute as DesignerPropertyEnum; if (enumAtt != null) { enumtype = property.Property.PropertyType; } if (enumtype == null) { throw new Exception(string.Format(Resources.ExceptionDesignerAttributeExpectedEnum, property.Property.Name)); } Nodes.Behavior behavior = GetBehavior(); _agentType = (behavior != null) ? behavior.AgentType : null; object propertyMember = property.Property.GetValue(obj, null); VariableDef variable = propertyMember as VariableDef; RightValueDef variableRV = propertyMember as RightValueDef; if (variable != null && variable.ValueClass != VariableDef.kSelf) { _valueOwner = variable.ValueClass; _agentType = Plugin.GetInstanceAgentType(_valueOwner, behavior, _agentType); } if (variableRV != null && variableRV.ValueClassReal != VariableDef.kSelf) { _valueOwner = variableRV.ValueClassReal; _agentType = Plugin.GetInstanceAgentType(_valueOwner, behavior, _agentType); } string selectionName = string.Empty; if (variable != null && variable.Property != null) { selectionName = variable.Property.DisplayName; } else if (variableRV != null && variableRV.Var != null && variableRV.Var.Property != null) { selectionName = variableRV.Var.Property.DisplayName; } this.FilterType = null; if (enumAtt != null) { if (enumAtt.DependedProperty != "") { Type objType = _object.GetType(); PropertyInfo pi = objType.GetProperty(enumAtt.DependedProperty); object propMember = pi.GetValue(obj, null); VariableDef var = propMember as VariableDef; if (var != null) { this.FilterType = var.ValueType; } else { MethodDef method = propMember as MethodDef; if (method != null) { this.FilterType = method.ReturnType; } else { RightValueDef varRV = propMember as RightValueDef; if (varRV != null) { this.FilterType = varRV.ValueType; } } } } else { this.FilterType = enumAtt.FilterType; } } setComboBox(selectionName); //after the left is changed, the right might need to be invalidated if (this.comboBox.Text != selectionName) { property.Property.SetValue(_object, null, null); } }
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(); } }