public bool SetProperty(string valueName, string valueStr) { DesignerPropertyEditor propertyEditor = getPropertyEditor(valueName); if (propertyEditor == null) { return(false); } VariableDef var = propertyEditor.GetVariable(); if (var.Value.ToString().ToLower() != valueStr.ToLower()) { Plugin.InvokeTypeParser(null, var.GetValueType(), valueStr, (object value) => var.Value = value, null); propertyEditor.ValueWasnotAssigned(); propertyEditor.SetVariable(var, null); propertyEditor.ValueWasAssigned(); return(true); } return(false); }
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.GetValueType() != 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 DesignerPropertyEditor createValueEditor(int rowIndex, Type type) { Debug.Check(rowIndex > -1 && type != null); RowControl rowControl = _rowControls[rowIndex]; Type editorType = Plugin.InvokeEditorType(type); Debug.Check(editorType != null); DesignerPropertyEditor editor = (DesignerPropertyEditor)editorType.InvokeMember(string.Empty, BindingFlags.CreateInstance, null, null, new object[0]); editor.Dock = System.Windows.Forms.DockStyle.Fill; editor.Margin = new System.Windows.Forms.Padding(0); editor.ValueWasChanged += new DesignerPropertyEditor.ValueChanged(editor_ValueWasChanged); editor.SetPar(rowControl.Par, _rootNode); editor.ValueWasAssigned(); if (rowControl.DefaultValueEditor != null) { this.tableLayoutPanel.Controls.Remove(rowControl.DefaultValueEditor); } rowControl.DefaultValueEditor = editor; this.tableLayoutPanel.Controls.Add(rowControl.DefaultValueEditor, 3, rowIndex + 1); return(editor); }
void createParamEditor(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, _selectedObject, bReadonly); editor.ValueWasAssigned(); editor.MouseEnter += editor_MouseEnter; editor.DescriptionWasChanged += editor_DescriptionWasChanged; 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(" ", arrayIndexElement); } } }
void createArrayIndexEditor(string preBlank, MethodDef.Param arrayIndex) { Type editorType = typeof(DesignerParameterComboEnumEditor); string arugmentsName = preBlank + "Index"; bool bReadonly = false; Label label = propertyGrid.AddProperty(arugmentsName, editorType, bReadonly); label.MouseEnter += new EventHandler(label_MouseEnter); DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag; editor.Enabled = true; editor.SetParameter(arrayIndex, _selectedObject, bReadonly); editor.ValueWasAssigned(); editor.MouseEnter += editor_MouseEnter; editor.DescriptionWasChanged += editor_DescriptionWasChanged; editor.ValueWasChanged += editor_ValueWasChanged; }
void createParamEditor(MethodDef method, bool enable) { List <MethodDef.Param> parameters = method.Params; foreach (MethodDef.Param p in parameters) { Type editorType = typeof(DesignerParameterComboEnumEditor); string arugmentsName = " " + p.DisplayName; Label label = propertyGrid.AddProperty(arugmentsName, editorType, p.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnly)); label.MouseEnter += new EventHandler(label_MouseEnter); DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag; editor.Enabled = enable; editor.SetParameter(p, _selectedObject); editor.ValueWasAssigned(); editor.MouseEnter += editor_MouseEnter; editor.DescriptionWasChanged += editor_DescriptionWasChanged; editor.ValueWasChanged += editor_ValueWasChanged; } }
private DesignerPropertyEditor createValueEditor(Type type) { Debug.Check(type != null); Type editorType = Plugin.InvokeEditorType(type); Debug.Check(editorType != null); DesignerPropertyEditor editor = (DesignerPropertyEditor)Plugin.CreateInstance(editorType); editor.AutoSize = true; editor.Dock = System.Windows.Forms.DockStyle.Fill; editor.Margin = new System.Windows.Forms.Padding(0); editor.Name = "propertyEditor"; editor.TabIndex = 4; editor.ValueWasChanged += new DesignerPropertyEditor.ValueChanged(editor_ValueWasChanged); editor.SetPar(_parTemp, _rootNode); editor.ValueWasAssigned(); return(editor); }
public bool SetProperty(BehaviorNode behavior, string valueName, string valueStr) { DesignerPropertyEditor propertyEditor = getPropertyEditor(valueName); if (propertyEditor == null && behavior != null) { Node root = behavior as Node; foreach (PropertyDef p in root.LocalVars) { if (!p.IsArrayElement && p.BasicName == valueName) { propertyEditor = addRowControl(p); break; } } } if (propertyEditor == null) { return(false); } VariableDef var = propertyEditor.GetVariable(); if (var.Value.ToString().ToLower() != valueStr.ToLower()) { Plugin.InvokeTypeParser(null, var.ValueType, valueStr, (object value) => var.Value = value, null); propertyEditor.ValueWasnotAssigned(); propertyEditor.SetVariable(var, null); propertyEditor.ValueWasAssigned(); return(true); } return(false); }
private DesignerPropertyEditor createPropertyEditor(PropertyDef property) { Type type = property.Type; Type editorType = Plugin.InvokeEditorType(type); Debug.Check(editorType != null); DesignerPropertyEditor editor = (DesignerPropertyEditor)editorType.InvokeMember(string.Empty, BindingFlags.CreateInstance, null, null, new object[0]); editor.TabStop = false; editor.Dock = System.Windows.Forms.DockStyle.Fill; editor.Margin = new System.Windows.Forms.Padding(0); editor.ValueWasChanged += new DesignerPropertyEditor.ValueChanged(editor_ValueWasChanged); VariableDef var = new VariableDef(Plugin.DefaultValue(type)); editor.SetVariable(var, null); editor.ValueWasAssigned(); return(editor); }
//private void UpdateProperties(IList<DesignerPropertyInfo> properties, List<MethodDef.Param> parameters, string parametersCategory) private void UpdateProperties(IList <DesignerPropertyInfo> properties) { //Console.WriteLine("UpdateProperties"); //this.SuspendLayout(); List <string> categories = new List <string>(); foreach (DesignerPropertyInfo property in properties) { if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoDisplay) && (property.Attribute.CategoryResourceString != "CategoryVersion" || Settings.Default.ShowVersionInfo) && !categories.Contains(property.Attribute.CategoryResourceString)) { categories.Add(property.Attribute.CategoryResourceString); } } categories.Sort(); Nodes.Node node = SelectedObject as Nodes.Node; List <ParInfo> pars = new List <ParInfo>(); bool referrencedPar = false; NodeUIPolicy uiPolicy = null; if (node != null) { node.GetAllPars(ref pars); uiPolicy = NodeUIPolicy.CreateUIPolicy(node); uiPolicy.Initialize(SelectedObject); } else { Attachments.Attach attachment = SelectedObject as Behaviac.Design.Attachments.Attach; if (attachment != null) { node = attachment.Node; referrencedPar = true; attachment.GetAllPars(ref pars); uiPolicy = NodeUIPolicy.CreateUIPolicy(attachment); uiPolicy.Initialize(SelectedObject); } } if (pars.Count > 0 && !categories.Contains("CategoryPar")) { categories.Add("CategoryPar"); } foreach (string category in categories) { propertyGrid.AddCategory(Plugin.GetResourceString(category), true); foreach (DesignerPropertyInfo property in properties) { if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoDisplay) && property.Attribute.CategoryResourceString == category) { Type type = property.Attribute.GetEditorType(property.Property.GetValue(_selectedObject, null)); Label label = propertyGrid.AddProperty(property.Attribute.DisplayName, type, property.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnly)); // register description showing label.MouseEnter += new EventHandler(label_MouseEnter); // when we found an editor we connect it to the object if (type != null) { DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag; editor.SetRootNode((Nodes.Node) this._rootBehavior); editor.SetProperty(property, _selectedObject); editor.ValueWasAssigned(); editor.MouseEnter += editor_MouseEnter; editor.DescriptionWasChanged += editor_DescriptionWasChanged; editor.ValueWasChanged += editor_ValueWasChanged; if (uiPolicy != null) { uiPolicy.AddEditor(editor); } } MethodDef method = null; bool methodEditorEnable = true; DesignerMethodEnum propertyMethod = property.Attribute as DesignerMethodEnum; if (propertyMethod != null) { if (propertyMethod.MethodType != MethodType.Status) { method = property.Property.GetValue(_selectedObject, null) as MethodDef; methodEditorEnable = (propertyMethod.MethodType != MethodType.Event); } } else { DesignerRightValueEnum propertyRV = property.Attribute as DesignerRightValueEnum; if (propertyRV != null) { RightValueDef rv = property.Property.GetValue(_selectedObject, null) as RightValueDef; if (rv != null && rv.IsMethod) { method = rv.Method; } } } if (method != null) { createParamEditor(method, methodEditorEnable); } } } if (pars.Count > 0 && "CategoryPar" == category) { createParEditor(pars, referrencedPar ? typeof(DesignerParComboEnumEditor) : typeof(DesignerParEditor)); } } if (uiPolicy != null) { uiPolicy.Update(); } //this.ResumeLayout(false); }
//private void UpdateProperties(IList<DesignerPropertyInfo> properties, List<MethodDef.Param> parameters, string parametersCategory) private void UpdateProperties(IList <DesignerPropertyInfo> properties) { DefaultObject obj = SelectedObject as DefaultObject; if (obj != null) { uiPolicy = obj.CreateUIPolicy(); uiPolicy.Initialize(obj); } List <string> categories = new List <string>(); foreach (DesignerPropertyInfo property in properties) { if (uiPolicy.ShouldAddProperty(property) && !property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoDisplay) && (property.Attribute.CategoryResourceString != "CategoryVersion" || Settings.Default.ShowVersionInfo) && !categories.Contains(property.Attribute.CategoryResourceString)) { categories.Add(property.Attribute.CategoryResourceString); } } categories.Sort(new CategorySorter()); foreach (string category in categories) { propertyGrid.AddCategory(Plugin.GetResourceString(category), true); foreach (DesignerPropertyInfo property in properties) { if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoDisplay) && property.Attribute.CategoryResourceString == category) { if (uiPolicy != null && !uiPolicy.ShouldAddProperty(property)) { continue; } object value_ = property.Property.GetValue(_selectedObject, null); Type type = property.Attribute.GetEditorType(value_); 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)); // register description showing label.MouseEnter += new EventHandler(label_MouseEnter); // when we found an editor we connect it to the object if (type != null) { DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag; editor.SetRootNode((Nodes.Node) this._rootBehavior); editor.SetProperty(property, _selectedObject); editor.ValueWasAssigned(); editor.MouseEnter += editor_MouseEnter; editor.DescriptionWasChanged += editor_DescriptionWasChanged; editor.ValueWasChanged += editor_ValueWasChanged; if (uiPolicy != null) { uiPolicy.AddEditor(editor); } } MethodDef method = null; bool methodEditorEnable = true; if (propertyMethod != null) { if (propertyMethod.MethodType != MethodType.Status) { method = value_ as MethodDef; //methodEditorEnable = (propertyMethod.MethodType != MethodType.Event); } } else { DesignerRightValueEnum propertyRV = property.Attribute as DesignerRightValueEnum; if (propertyRV != null) { RightValueDef rv = value_ 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(method, methodEditorEnable, bReadonly); } } else { MethodDef.Param arrayIndexElement = null; if (value_ is VariableDef) { VariableDef var = value_ as VariableDef; arrayIndexElement = var.ArrayIndexElement; } else if (value_ is RightValueDef) { RightValueDef varRV = value_ as RightValueDef; if (varRV.Var != null) { arrayIndexElement = varRV.Var.ArrayIndexElement; } } if (arrayIndexElement != null) { createArrayIndexEditor(" ", arrayIndexElement); } } } } } } if (uiPolicy != null) { uiPolicy.Update(null, new DesignerPropertyInfo()); } }