private void comboBox_SelectedIndexChanged(object sender, EventArgs e) { if (!_valueWasAssigned || comboBox.SelectedIndex < 0 || comboBox.SelectedIndex >= _methods.Count) { return; } DesignerRightValueEnum propertRV = _property.Attribute as DesignerRightValueEnum; MethodDef m_ = _methods[comboBox.SelectedIndex] as MethodDef; MethodDef m = new MethodDef(m_); m.Owner = VariableDef.kSelf; if (propertRV == null) { _property.Property.SetValue(_object, m, null); } else { object propertyMember = _property.Property.GetValue(_object, null); if (propertyMember != null) { RightValueDef oldvarRV = propertyMember as RightValueDef; RightValueDef varRV = new RightValueDef(m, oldvarRV.ValueClass); _property.Property.SetValue(_object, varRV, null); } } this.RereshProperty(true, _property); OnValueChanged(_property); }
public override void Update(object sender, DesignerPropertyInfo property) { if (_obj != null) { DesignerPropertyEditor oplEditor = GetEditor(_obj, "Opl"); Debug.Check(oplEditor != null); if (oplEditor == sender) { VariableDef opl = (VariableDef)GetProperty(_obj, "Opl"); if (opl != null) { RightValueDef opr = (RightValueDef)GetProperty(_obj, "Opr"); if (opr != null && opl.ValueType != opr.ValueType) { DesignerPropertyEditor oprEditor = GetEditor(_obj, "Opr"); Debug.Check(oprEditor != null); oprEditor.Clear(); } } } } }
public override void SetParameter(MethodDef.Param param, object obj, bool bReadonly) { base.SetParameter(param, obj, bReadonly); _resetProperties = false; string selectionName = string.Empty; VariableDef variable = param.Value as VariableDef; if (variable != null) { _valueOwner = variable.ValueClass; selectionName = (variable.Property != null) ? variable.Property.DisplayName : variable.DisplayName; } else { RightValueDef variableRV = param.Value as RightValueDef; if (variableRV != null) { _valueOwner = variableRV.ValueClassReal; selectionName = variableRV.DisplayName; } } Nodes.Behavior behavior = GetBehavior(); _agentType = (behavior != null) ? behavior.AgentType : null; if (_valueOwner != VariableDef.kSelf) { _agentType = Plugin.GetInstanceAgentType(_valueOwner, behavior, _agentType); } setComboBox(selectionName); }
public override void SetParameter(MethodDef.Param param, object obj) { base.SetParameter(param, obj); _resetProperties = false; Behaviac.Design.Attachments.Attach evt = obj as Behaviac.Design.Attachments.Attach; Behaviac.Design.Nodes.BaseNode baseNode = (evt != null) ? evt.Node : obj as Behaviac.Design.Nodes.BaseNode; Behaviac.Design.Nodes.Behavior behavior = (baseNode != null) ? baseNode.Behavior as Behaviac.Design.Nodes.Behavior : null; _agentType = (behavior != null) ? behavior.AgentType : null; if (!string.IsNullOrEmpty(_globalType)) { _agentType = Plugin.GetInstanceAgentType(_globalType); } string selectionName = string.Empty; VariableDef variable = param.Value as VariableDef; if (variable != null) { selectionName = (variable.Property != null) ? variable.Property.DisplayName : variable.DisplayName; } else { RightValueDef variableRV = param.Value as RightValueDef; if (variableRV != null) { selectionName = variableRV.DisplayName; } } setComboBox(selectionName); }
private Type getDependedPropertyType(DesignerPropertyInfo prop, object obj) { Debug.Check(obj != null); PropertyInfo pi = getDependedProperty(prop, obj); if (pi != null) { object propertyMember = pi.GetValue(obj, null); VariableDef variable = propertyMember as VariableDef; if (variable != null) { return(variable.ValueType); } RightValueDef varRV = propertyMember as RightValueDef; if (varRV != null) { return(varRV.ValueType); } MethodDef method = propertyMember as MethodDef; if (method != null) { return(method.ReturnType); } } return(null); }
/// <summary> /// Creates a new referenced behaviour. The behaviour which will be referenced is read from the Reference attribute. /// </summary> public ReferencedBehavior() : base(Resources.ReferencedBehavior, Resources.ReferencedBehaviorDesc) { _genericChildren = new ConnectorMultiple(_children, string.Empty, Connector.kGeneric, 1, int.MaxValue); _referencedBehavior = null; }
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 void setComboBox() { object action = _property.Property.GetValue(_object, null); MethodDef actionObj = action as MethodDef; RightValueDef varRV = action as RightValueDef; string selectionName = string.Empty; if (actionObj != null) { selectionName = actionObj.DisplayName; } else if (varRV != null && varRV.Method != null) { selectionName = varRV.Method.DisplayName; } _methods = getMethods(); comboBox.Items.Clear(); foreach (MethodDef md in _methods) { if (md.DisplayName == selectionName) { _methods.Clear(); _methods.Add(md); comboBox.Items.Add(md.DisplayName); break; } } comboBox.Text = selectionName; }
private void editor_ValueWasChanged(object sender, DesignerPropertyInfo property) { // Set the owner for the method. if (_property.Property != null) { object propertyMember = _property.Property.GetValue(_object, null); RightValueDef varRV = propertyMember as RightValueDef; if (varRV != null && varRV.IsMethod) { int methodIndex = -1; int offset = 0; for (int i = 0; i < typeComboBox.Items.Count; ++i) { string item = typeComboBox.Items[i].ToString(); int pos = item.IndexOf(VariableDef.kMethod); if (pos != -1) { methodIndex = i; if (item == VariableDef.kSelfMethod) { offset = 1; } break; } } if (methodIndex != -1) { Debug.Check(varRV.Method != null); if (typeComboBox.SelectedIndex - methodIndex - offset >= 0) { string owner = _currentNames[typeComboBox.SelectedIndex - methodIndex - offset]; int pos = owner.IndexOf(VariableDef.kMethod); if (pos >= 0) { owner = owner.Substring(0, pos); } varRV.Method.Owner = owner; } else { varRV.Method.Owner = VariableDef.kSelf; } } } } OnValueChanged(_property); }
private List <MethodDef> getMethods() { List <MethodDef> methods = new List <MethodDef>(); Behaviac.Design.Attachments.Attach evt = _object as Behaviac.Design.Attachments.Attach; Behaviac.Design.Nodes.BaseNode baseNode = (evt != null) ? evt.Node : _object as Behaviac.Design.Nodes.BaseNode; if (baseNode == null) { baseNode = this._root; } Behaviac.Design.Nodes.Behavior behavior = null; if (baseNode != null) { behavior = baseNode.Behavior as Behaviac.Design.Nodes.Behavior; } AgentType agentType = null; if (behavior != null && behavior.AgentType != null) { agentType = behavior.AgentType; } object action = _property.Property.GetValue(_object, null); RightValueDef varRV = action as RightValueDef; if (varRV != null && Plugin.IsInstanceName(varRV.ValueClassReal)) { agentType = Plugin.GetInstanceAgentType(varRV.ValueClassReal); } if (agentType != null) { DesignerRightValueEnum enumAttRV = _property.Attribute as DesignerRightValueEnum; DesignerMethodEnum attrMethod = _property.Attribute as DesignerMethodEnum; MethodType methodType = attrMethod != null ? attrMethod.MethodType : MethodType.Getter; if (enumAttRV != null) { methodType = enumAttRV.MethodType; } IList <MethodDef> actions = agentType.GetMethods(methodType); foreach (MethodDef actionType in actions) { if (Plugin.IsCompatibleType(this.FilterType, actionType.ReturnType, false)) { methods.Add(actionType); } } } return(methods); }
void createParamEditor(object owner, MethodDef method, bool enable, bool bReadonlyParent) { List <MethodDef.Param> parameters = method.Params; foreach (MethodDef.Param p in parameters) { Type editorType = typeof(DesignerParameterComboEnumEditor); string arugmentsName = " " + p.DisplayName; bool bReadonly = bReadonlyParent | p.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnly); Label label = propertyGrid.AddProperty(arugmentsName, editorType, bReadonly); label.MouseEnter += new EventHandler(label_MouseEnter); DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag; if (p.Type.Name == "IList") { lastListParam = p; } if (p.Type.Name == "System_Object" && lastListParam != null) { p.ListParam = lastListParam; } editor.Enabled = enable; editor.SetParameter(p, owner, bReadonly); editor.ValueWasAssigned(); editor.MouseEnter += editor_MouseEnter; editor.ValueWasChanged += editor_ValueWasChanged; //editor.ValueType = p.Attribute.ValueType; MethodDef.Param arrayIndexElement = null; if (p.Value is VariableDef) { VariableDef var = p.Value as VariableDef; arrayIndexElement = var.ArrayIndexElement; } else if (p.Value is RightValueDef) { RightValueDef varRV = p.Value as RightValueDef; if (varRV.Var != null) { arrayIndexElement = varRV.Var.ArrayIndexElement; } } if (arrayIndexElement != null) { createArrayIndexEditor(owner, " ", arrayIndexElement); } } }
private void initTime() { if (Workspace.Current.UseIntValue) { _time = new RightValueDef(new VariableDef(1000)); } else { _time = new RightValueDef(new VariableDef(1000.0f)); } }
public static void GenerateClassConstructor(DefaultObject defaultObj, RightValueDef rightValue, StringWriter stream, string indent, string var) { if (rightValue.IsMethod) { MethodCsExporter.GenerateClassConstructor(defaultObj, rightValue.Method, stream, indent, var); } else { VariableCsExporter.GenerateClassConstructor(defaultObj, rightValue.Var, stream, indent, var); } }
private void valueComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (!_valueWasAssigned || typeComboBox.SelectedIndex < 0 || typeComboBox.SelectedIndex >= _currentNames.Count || valueComboBox.SelectedIndex < 0 || valueComboBox.SelectedIndex >= _methods.Count) { return; } MethodDef m_ = _methods[valueComboBox.SelectedIndex] as MethodDef; MethodDef m = new MethodDef(m_); m.Owner = _currentNames[typeComboBox.SelectedIndex]; DesignerMethodEnum attrMethod = _property.Attribute as DesignerMethodEnum; if (attrMethod != null) { if ((attrMethod.MethodType & MethodType.AllowNullMethod) == MethodType.AllowNullMethod && attrMethod.HasFlags(DesignerProperty.DesignerFlags.BeValid) && attrMethod.Display == DesignerProperty.DisplayMode.List) { object oldValue = _property.Property.GetValue(_object, null); if (oldValue == null) { Nodes.Node n = this._object as Nodes.Node; if (n != null) { //n.AddSubItem(new NodeViewData.SubItemProperty(n, _property, attrMethod)); n.DoSubItemAdded(_property); } } } _property.Property.SetValue(_object, m, null); } else { object propertyMember = _property.Property.GetValue(_object, null); RightValueDef oldvarRV = propertyMember as RightValueDef; RightValueDef v = new RightValueDef(m, oldvarRV.ValueClass); _property.Property.SetValue(_object, m, null); } OnValueChanged(_property); this.RereshProperty(true, _property); }
public Wait() : base(Resources.Wait, Resources.WaitDesc) { _exportName = "Wait"; if (Workspace.Current.UseIntValue) { _time = new RightValueDef(new VariableDef(1000)); } else { _time = new RightValueDef(new VariableDef(1000.0f)); } }
public override bool ShouldAddProperty(DesignerPropertyInfo property) { if (_obj != null) { DesignerPropertyInfo oplProp = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opl"); DesignerPropertyInfo opr1Prop = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opr1"); DesignerPropertyInfo operatorProp = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Operator"); DesignerPropertyInfo opr2Prop = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opr2"); if (oplProp.Property != null) { RightValueDef rv = oplProp.GetValue(_obj) as RightValueDef; if (rv != null && rv.IsMethod && rv.Method != null) { return(property.Property != opr1Prop.Property && property.Property != operatorProp.Property && property.Property != opr2Prop.Property); } } OperatorTypes operatorType = (OperatorTypes)GetProperty(_obj, "Operator"); // action if (this.isAction()) { return(property.Property != opr1Prop.Property && property.Property != operatorProp.Property && property.Property != opr2Prop.Property); } // assign else if (operatorType == OperatorTypes.Assign) { return(property.Property != opr1Prop.Property); } // compute else if (operatorType >= OperatorTypes.Add && operatorType <= OperatorTypes.Div) { } // compare else if (operatorType >= OperatorTypes.Equal && operatorType <= OperatorTypes.LessEqual) { return(property.Property != opr1Prop.Property); } } return(base.ShouldAddProperty(property)); }
public override void SetProperty(DesignerPropertyInfo property, object obj) { base.SetProperty(property, obj); _resetMethods = false; DesignerRightValueEnum enumAttRV = _property.Attribute as DesignerRightValueEnum; this.FilterType = null; if (enumAttRV != null && enumAttRV.DependedProperty != "") { Type objType = _object.GetType(); PropertyInfo pi = objType.GetProperty(enumAttRV.DependedProperty); object propMember = pi.GetValue(_object, 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 varRVp = propMember as RightValueDef; if (varRVp != null) { this.FilterType = varRVp.ValueType; } } } } else { this.FilterType = _property.Attribute.FilterType; } SetupCastSettings(obj); setComboBox(); }
public static string GenerateCode(DefaultObject defaultObj, RightValueDef rightValue, StringWriter stream, string indent, string typename, string var, string caller) { string retStr = string.Empty; if (rightValue.IsMethod) { retStr = MethodCsExporter.GenerateCode(defaultObj, rightValue.Method, stream, indent, rightValue.Method.NativeReturnType, var, caller); } else { retStr = VariableCsExporter.GenerateCode(defaultObj, rightValue.Var, false, stream, indent, typename, var, caller); } return(retStr); }
public override void ResetMembers(AgentType agentType, bool resetPar) { if (this.Opl != null && this.Opl.ShouldBeReset(agentType, resetPar)) { this.Opl = null; } if (this.Opr1 != null && this.Opr1.ShouldBeReset(agentType, resetPar)) { this.Opr1 = null; } if (this.Opr2 != null && this.Opr2.ShouldBeReset(agentType, resetPar)) { this.Opr2 = null; } base.ResetMembers(agentType, resetPar); }
private List <MethodDef> getMethods() { List <MethodDef> methods = new List <MethodDef>(); Nodes.Behavior behavior = GetBehavior(); AgentType agentType = (behavior != null) ? behavior.AgentType : null; object action = _property.Property.GetValue(_object, null); VariableDef var = action as VariableDef; Debug.Check(var == null); RightValueDef varRV = action as RightValueDef; if (varRV != null && Plugin.IsInstanceName(varRV.ValueClassReal, behavior)) { agentType = Plugin.GetInstanceAgentType(varRV.ValueClassReal, behavior, agentType); } if (agentType != null) { DesignerRightValueEnum enumAttRV = _property.Attribute as DesignerRightValueEnum; DesignerMethodEnum attrMethod = _property.Attribute as DesignerMethodEnum; MethodType methodType = attrMethod != null ? attrMethod.MethodType : MethodType.Getter; if (enumAttRV != null) { methodType = enumAttRV.MethodType; } IList <MethodDef> actions = agentType.GetMethods(true, methodType); foreach (MethodDef actionType in actions) { if (Plugin.IsCompatibleType(this.ValueType, this.FilterType, actionType.ReturnType, false)) { methods.Add(actionType); } } } return(methods); }
public static void GenerateOperand(StreamWriter stream, string indent, RightValueDef operand, string operandName, string nodeName) { if (operand != null) { string typeName = DataCsExporter.GetGeneratedNativeType(operand.ValueType); typeName = typeName.Replace("::", "."); if (operand.IsMethod) // method { RightValueCsExporter.GenerateCode(operand, stream, indent, typeName, operandName, string.Empty); RightValueCsExporter.PostGenerateCode(operand, stream, indent, typeName, operandName, string.Empty); } else { VariableDef var = operand.Var; if (var != null) { if (var.IsProperty) // property { PropertyDef prop = var.Property; if (prop != null) { string property = PropertyCsExporter.GetProperty(prop, var.ArrayIndexElement, stream, indent, operandName, nodeName); string propName = prop.BasicName.Replace("[]", ""); if (prop.IsArrayElement && var.ArrayIndexElement != null) { ParameterCsExporter.GenerateCode(var.ArrayIndexElement, stream, indent, "int", operandName + "_index", nodeName + "_opl"); property = string.Format("({0})[{1}_index]", property, operandName); } stream.WriteLine("{0}{1} {2} = {3};", indent, typeName, operandName, property); } } else if (var.IsConst) // const { RightValueCsExporter.GenerateCode(operand, stream, indent, typeName, operandName, string.Empty); } } } } }
public override void Update(object sender, DesignerPropertyInfo property) { if (_obj != null) { RightValueDef opl = (RightValueDef)GetProperty(_obj, "Opl"); bool bEnable = (opl != null && (opl.Var != null || opl.Method != null)); DesignerPropertyEditor opEditor = GetEditor(_obj, "Operator"); if (opEditor != null) { opEditor.Enabled = bEnable; } DesignerPropertyEditor oprEditor = GetEditor(_obj, "Opr"); if (oprEditor != null) { oprEditor.Enabled = bEnable; } } }
public override bool ShouldAddProperty(DesignerPropertyInfo property) { if (_obj != null) { DesignerPropertyInfo oplProp = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opl"); DesignerPropertyInfo opr1Prop = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opr1"); DesignerPropertyInfo operatorProp = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Operator"); DesignerPropertyInfo opr2Prop = DesignerProperty.GetDesignerProperty(_obj.GetType(), "Opr2"); if (oplProp.Property != null) { RightValueDef rv = oplProp.GetValue(_obj) as RightValueDef; if (rv != null && rv.IsMethod && rv.Method != null) { return(property.Property != opr1Prop.Property && property.Property != operatorProp.Property && property.Property != opr2Prop.Property); } } } return(base.ShouldAddProperty(property)); }
public override void SetParameter(MethodDef.Param param, object obj, bool bReadonly) { base.SetParameter(param, obj, bReadonly); _resetProperties = false; Behaviac.Design.Attachments.Attach evt = obj as Behaviac.Design.Attachments.Attach; Behaviac.Design.Nodes.BaseNode baseNode = (evt != null) ? evt.Node : obj as Behaviac.Design.Nodes.BaseNode; Behaviac.Design.Nodes.Behavior behavior = (baseNode != null) ? baseNode.Behavior as Behaviac.Design.Nodes.Behavior : null; string selectionName = string.Empty; VariableDef variable = param.Value as VariableDef; if (variable != null) { _valueOwner = variable.ValueClass; selectionName = (variable.Property != null) ? variable.Property.DisplayName : variable.DisplayName; } else { RightValueDef variableRV = param.Value as RightValueDef; if (variableRV != null) { _valueOwner = variableRV.ValueClassReal; selectionName = variableRV.DisplayName; } } _agentType = (behavior != null) ? behavior.AgentType : null; if (_valueOwner != VariableDef.kSelf) { _agentType = Plugin.GetInstanceAgentType(_valueOwner); } setComboBox(selectionName); }
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(); } }
public void SetReferenceBehavior(string referencedBehaviorFileName) { this._referencedBehavior = new RightValueDef(new VariableDef(referencedBehaviorFileName)); SetTask(referencedBehaviorFileName); }
private void comboBox_SelectedIndexChanged(object sender, EventArgs e) { if (!_valueWasAssigned || comboBox.SelectedIndex < 0 || comboBox.SelectedIndex >= _properties.Count) return; PropertyDef selectedProperty = _properties[comboBox.SelectedIndex]; selectedProperty = new PropertyDef(selectedProperty); selectedProperty.Owner = !string.IsNullOrEmpty(_globalType) ? _globalType : VariableDef.kSelf; if (_property.Property != null) { object propertyMember = _property.Property.GetValue(_object, null); VariableDef var = propertyMember as VariableDef; DesignerRightValueEnum rvPropertyEnum = _property.Attribute as DesignerRightValueEnum; if (rvPropertyEnum == null) { if (var == null) var = new VariableDef(selectedProperty, VariableDef.kSelf); else var.SetProperty(selectedProperty, var.ValueClass); _property.Property.SetValue(_object, var, null); } else if (propertyMember != null) { RightValueDef varRV = propertyMember as RightValueDef; if (varRV == null) { Debug.Check(false); //varRV = new RightValueDef(selectedProperty, VariableDef.kSelf); } else { if (varRV.IsMethod) { Debug.Check(false); } else { if (varRV.Var != null) { varRV.Var.SetProperty(selectedProperty, varRV.ValueClassReal); } else { var = new VariableDef(selectedProperty, varRV.ValueClassReal); varRV = new RightValueDef(var); } } } _property.Property.SetValue(_object, varRV, null); } } else if (_param != null) { string valueType = !string.IsNullOrEmpty(_globalType) ? _globalType : VariableDef.kSelf; _param.Value = new VariableDef(selectedProperty, valueType); } OnValueChanged(_property); this.RereshProperty(false, _property); }
private void comboBox_SelectedIndexChanged(object sender, EventArgs e) { if (!_valueWasAssigned || comboBox.SelectedIndex < 0 || comboBox.SelectedIndex >= _properties.Count) { return; } PropertyDef selectedProperty = _properties[comboBox.SelectedIndex]; selectedProperty = selectedProperty.Clone(); selectedProperty.Owner = _valueOwner; bool isArrayElement = selectedProperty.IsArrayElement; bool bForceFresh = false; if (_property.Property != null) { object propertyMember = _property.Property.GetValue(_object, null); VariableDef var = propertyMember as VariableDef; DesignerRightValueEnum rvPropertyEnum = _property.Attribute as DesignerRightValueEnum; if (rvPropertyEnum == null) { if (var == null) { var = new VariableDef(selectedProperty, VariableDef.kSelf); } else { var.SetProperty(selectedProperty, var.ValueClass); } if (isArrayElement && var.ArrayIndexElement == null) { var.ArrayIndexElement = new MethodDef.Param("ArrayIndex", typeof(int), "int", "ArrayIndex", "ArrayIndex"); var.ArrayIndexElement.IsArrayIndex = true; bForceFresh = true; } else if (!isArrayElement && var.ArrayIndexElement != null) { var.ArrayIndexElement = null; bForceFresh = true; } _property.Property.SetValue(_object, var, null); } else if (propertyMember != null) { RightValueDef varRV = propertyMember as RightValueDef; if (varRV == null) { Debug.Check(false); //varRV = new RightValueDef(selectedProperty, VariableDef.kSelf); } else { if (varRV.IsMethod) { Debug.Check(false); } else { if (varRV.Var != null) { varRV.Var.SetProperty(selectedProperty, varRV.ValueClassReal); } else { var = new VariableDef(selectedProperty, varRV.ValueClassReal); varRV = new RightValueDef(var); } } } if (varRV != null && varRV.Var != null) { if (isArrayElement && varRV.Var.ArrayIndexElement == null) { varRV.Var.ArrayIndexElement = new MethodDef.Param("ArrayIndex", typeof(int), "int", "ArrayIndex", "ArrayIndex"); varRV.Var.ArrayIndexElement.IsArrayIndex = true; bForceFresh = true; } else if (!isArrayElement && varRV.Var.ArrayIndexElement != null) { varRV.Var.ArrayIndexElement = null; bForceFresh = true; } } _property.Property.SetValue(_object, varRV, null); } } else if (_param != null) { string valueType = _valueOwner; bool bOldArrayElment = false; if (_param.Value != null && _param.Value is VariableDef) { VariableDef paramV = _param.Value as VariableDef; if (paramV.ArrayIndexElement != null) { bOldArrayElment = true; } } VariableDef paramValue = new VariableDef(selectedProperty, valueType); _param.Value = paramValue; if (isArrayElement && paramValue.ArrayIndexElement == null) { paramValue.ArrayIndexElement = new MethodDef.Param("ArrayIndex", typeof(int), "int", "ArrayIndex", "ArrayIndex"); paramValue.ArrayIndexElement.IsArrayIndex = true; bForceFresh = true; } else if (!isArrayElement && bOldArrayElment) { paramValue.ArrayIndexElement = null; bForceFresh = true; } } this.RereshProperty(bForceFresh, _property); OnValueChanged(_property); }
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); } }
private void comboBox_SelectedIndexChanged(object sender, EventArgs e) { if (!_valueWasAssigned || comboBox.SelectedIndex < 0 || comboBox.SelectedIndex >= _methods.Count) { return; } DesignerRightValueEnum propertRV = _property.Attribute as DesignerRightValueEnum; MethodDef m_ = _methods[comboBox.SelectedIndex] as MethodDef; MethodDef m = new MethodDef(m_); m.Owner = VariableDef.kSelf; if (propertRV == null) { _property.Property.SetValue(_object, m, null); } else { object propertyMember = _property.Property.GetValue(_object, null); RightValueDef oldvarRV = propertyMember as RightValueDef; RightValueDef varRV = new RightValueDef(m, oldvarRV.ValueClass); _property.Property.SetValue(_object, varRV, null); } this.RereshProperty(true, _property); OnValueChanged(_property); }
private void updateStructProperties(object owner) { IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(_structProperty.Type, DesignerProperty.SortByDisplayOrder); List <string> categories = new List <string>(); foreach (DesignerPropertyInfo property in properties) { if (!categories.Contains(property.Attribute.CategoryResourceString)) { categories.Add(property.Attribute.CategoryResourceString); } } categories.Sort(); UIObject uiObj = owner as UIObject; if (uiObj != null) { uiPolicy = uiObj.CreateUIPolicy(); uiPolicy.Initialize(uiObj); } foreach (string category in categories) { if (categories.Count > 1) { propertyGrid.AddCategory(Plugin.GetResourceString(category), true); } foreach (DesignerPropertyInfo property in properties) { if (property.Attribute.CategoryResourceString == category) { if (uiPolicy != null && !uiPolicy.ShouldAddProperty(property)) { continue; } object member = property.GetValue(owner); Type type = property.Attribute.GetEditorType(member); DesignerMethodEnum propertyMethod = property.Attribute as DesignerMethodEnum; if (propertyMethod != null) { if ((propertyMethod.MethodType & MethodType.Task) == MethodType.Task) { type = typeof(DesignerMethodEnumEditor); } } string displayName = property.Attribute.DisplayName; if (uiPolicy != null) { displayName = uiPolicy.GetLabel(property); } Label label = propertyGrid.AddProperty(displayName, type, property.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnly)); label.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))); label.MouseEnter += new EventHandler(label_MouseEnter); if (type != null) { DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag; editor.SetRootNode(this._node); editor.SetProperty(property, owner); editor.ValueWasAssigned(); editor.MouseEnter += editor_MouseEnter; editor.ValueWasChanged += editor_ValueWasChanged; if (uiPolicy != null) { uiPolicy.AddEditor(editor); } } MethodDef method = null; if (propertyMethod != null) { if (propertyMethod.MethodType != MethodType.Status) { method = member as MethodDef; } } else { DesignerRightValueEnum propertyRV = property.Attribute as DesignerRightValueEnum; if (propertyRV != null) { RightValueDef rv = member as RightValueDef; if (rv != null && rv.IsMethod) { method = rv.Method; } } } if (property.Attribute != null) { if (method != null) { if (property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoDisplayOnProperty)) { //don't dipslay on the property panel } else { bool bReadonly = property.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnlyParams); createParamEditor(owner, method, true, bReadonly); } } else { MethodDef.Param arrayIndexElement = null; if (member is VariableDef) { VariableDef var = member as VariableDef; arrayIndexElement = var.ArrayIndexElement; } else if (member is RightValueDef) { RightValueDef varRV = member as RightValueDef; if (varRV.Var != null) { arrayIndexElement = varRV.Var.ArrayIndexElement; } } if (arrayIndexElement != null) { createArrayIndexEditor(owner, " ", arrayIndexElement); } } } } } } if (uiPolicy != null) { uiPolicy.Update(null, new DesignerPropertyInfo()); } if (properties.Count > 0) { propertyGrid.UpdateSizes(); propertyGrid.PropertiesVisible(true, true); } }
private void valueComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (!_valueWasAssigned || typeComboBox.SelectedIndex < 0 || typeComboBox.SelectedIndex >= _currentNames.Count || valueComboBox.SelectedIndex < 0 || valueComboBox.SelectedIndex >= _methods.Count) { return; } MethodDef m_ = _methods[valueComboBox.SelectedIndex] as MethodDef; MethodDef m = new MethodDef(m_); m.Owner = _currentNames[typeComboBox.SelectedIndex]; DesignerMethodEnum attrMethod = _property.Attribute as DesignerMethodEnum; if (attrMethod != null) { if ((attrMethod.MethodType & MethodType.AllowNullMethod) == MethodType.AllowNullMethod && attrMethod.Display == DesignerProperty.DisplayMode.List) { object oldValue = _property.Property.GetValue(_object, null); if (oldValue == null) { Nodes.Node n = this._object as Nodes.Node; if (n != null) { //n.AddSubItem(new NodeViewData.SubItemProperty(n, _property, attrMethod)); n.DoSubItemAdded(_property); } } } _property.Property.SetValue(_object, m, null); } else { object propertyMember = _property.Property.GetValue(_object, null); RightValueDef oldvarRV = propertyMember as RightValueDef; RightValueDef v = new RightValueDef(m, oldvarRV.ValueClass); _property.Property.SetValue(_object, m, null); } this.RereshProperty(true, _property); OnValueChanged(_property); }
static private void WritePropertyValue(BsonSerializer file, DesignerPropertyInfo property, object o) { string str = property.GetExportValue(o); string[] tokens = str.Split(' '); string valueString = null; if (tokens.Length == 3 && tokens[0] == "const") { valueString = tokens[2]; } else if (tokens.Length == 1) { valueString = str; } bool bW = false; if (valueString != null) { object obj = property.Property.GetValue(o, null); object v = null; Type valueType = null; VariableDef varType = obj as VariableDef; if (varType != null) { valueType = varType.GetValueType(); } else { RightValueDef rvarType = obj as RightValueDef; if (rvarType != null) { if (rvarType.Method == null) { valueType = rvarType.ValueType; } } else { MethodDef mType = obj as MethodDef; if (mType != null) { Debug.Check(true); } else { valueType = obj.GetType(); } } } if (valueType != null && Plugin.InvokeTypeParser(null, valueType, valueString, (object value) => v = value, null)) { file.WriteAttribute(property.Property.Name, v); bW = true; } } if (!bW) { file.WriteAttributeString(property.Property.Name, str); } }
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(); } }
public override void Update(object sender, DesignerPropertyInfo property) { if (_obj != null) { DesignerPropertyEditor oplEditor = GetEditor(_obj, "Opl"); Debug.Check(oplEditor != null); if (oplEditor == sender) { VariableDef opl = (VariableDef)GetProperty(_obj, "Opl"); if (opl != null) { RightValueDef opr = (RightValueDef)GetProperty(_obj, "Opr"); if (opr != null) { if (opl.ValueType != opr.ValueType) { DesignerPropertyEditor oprEditor = GetEditor(_obj, "Opr"); Debug.Check(oprEditor != null); if (oprEditor != null) { oprEditor.Clear(); } } } } } else { DesignerPropertyEditor oplEditorCast = GetEditor(_obj, "CastRight"); Debug.Check(oplEditorCast != null); if (oplEditorCast == sender) { PluginBehaviac.Nodes.Assignment assignNode = _obj as PluginBehaviac.Nodes.Assignment; if (assignNode != null) { RightValueDef opr = (RightValueDef)GetProperty(_obj, "Opr"); if (opr != null) { DesignerPropertyEditor oprEditor = GetEditor(_obj, "Opr"); Debug.Check(oprEditor != null); // oprEditor.ValueType might be overwritten in SetupCastSettings if casting // so that here to backup it first so that it can be restored later if not casting if (assignNode.IsCasting) { _valueTypesBackup = oprEditor.ValueType; } else { oprEditor.ValueType = _valueTypesBackup; } oprEditor.Clear(); oprEditor.FilterType = null; } } } } } }