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);

                        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);
                            }
                        }
                    }
                }
            }

            if (uiPolicy != null)
            {
                uiPolicy.Update();
            }

            if (properties.Count > 0)
            {
                propertyGrid.UpdateSizes();
                propertyGrid.PropertiesVisible(true, true);
            }
        }
예제 #2
0
        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);
            }
        }