Ejemplo n.º 1
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();

            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)
                    {
                        object member = property.GetValue(owner);

                        Type type = property.Attribute.GetEditorType(member);

                        Label label = propertyGrid.AddProperty(property.Attribute.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 (properties.Count > 0)
            {
                propertyGrid.UpdateSizes();
                propertyGrid.PropertiesVisible(true, true);
            }
        }
Ejemplo n.º 2
0
        public static bool IsPureConstDatum(object obj, object parent, string paramName)
        {
            Debug.Check(obj != null);

            if (obj != null)
            {
                Type type = obj.GetType();

                if (!Plugin.IsCustomClassType(type))
                {
                    return(false);
                }

                MethodDef method = parent as MethodDef;
                IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(type, null);

                foreach (DesignerPropertyInfo property in properties)
                {
                    if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                    {
                        object member = property.GetValue(obj);

                        if (property.Attribute is DesignerStruct)
                        {
                            if (!IsPureConstDatum(member, parent, paramName))
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            if (method != null)
                            {
                                MethodDef.Param param = method.GetParam(paramName, property);

                                if (param != null)
                                {
                                    if (!param.IsPureConstDatum)
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        private string getExportValue(object item, Type itemType)
        {
            string str = string.Empty;

            if (item != null)
            {
                IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(itemType);
                foreach (DesignerPropertyInfo property in properties)
                {
                    if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                    {
                        str += property.Property.Name + "=" + property.GetExportValue(item) + ";";
                    }
                }
            }

            return(str);
        }
Ejemplo n.º 4
0
        private static bool getPropertyInfo(Type type, string propertyName, out DesignerPropertyInfo p)
        {
            IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(type);

            foreach (DesignerPropertyInfo property in properties)
            {
                if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave) &&
                    property.Property.Name == propertyName)
                {
                    p = property;
                    return(true);
                }
            }

            p = new DesignerPropertyInfo();
            //throw new Exception(Resources.ExceptionDesignerAttributeInvalidType);
            return(false);
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
        public static string RetrieveExportValue(object obj, object parent, string paramName, bool bSave, int indexInArray = -1)
        {
            string str = "";

            Debug.Check(obj != null);

            Type type = obj.GetType();

            if (Plugin.IsRefType(type))
            {
                return("null");
            }

            bool bStructAsBasic = Plugin.IsRegisteredTypeName(type.Name);

            //struct as basic type, like Tag::Vector3, etc.
            //these types are exported as (W=0 X=0 Y=0 Z=0)
            if (!bSave && bStructAsBasic)
            {
                str = "(";
            }
            else
            {
                str = "{";
            }

            if (Plugin.IsCustomClassType(type))
            {
                MethodDef method = parent as MethodDef;

                bool bFirst = true;

                IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(type);
                foreach (DesignerPropertyInfo property in properties)
                {
                    if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave))
                    {
                        if (!bSave && bStructAsBasic && !bFirst)
                        {
                            str += " ";
                        }

                        bFirst = false;

                        if (!bSave)
                        {
                            if (bStructAsBasic)
                            {
                                str += property.Property.Name + "=";
                            }
                        }
                        else
                        {
                            str += property.Property.Name + "=";
                        }

                        object member = property.GetValue(obj);

                        Type memberType = null;

                        if (member != null)
                        {
                            memberType = member.GetType();
                        }
                        else
                        {
                            memberType = property.GetTypeFallback();
                        }

                        if (Plugin.IsArrayType(memberType))
                        {
                            str += DesignerArray.RetrieveExportValue(member);
                        }
                        else
                        {
                            if (property.Attribute is DesignerStruct)
                            {
                                str += RetrieveExportValue(member, parent, paramName, bSave);
                            }
                            else
                            {
                                bool bStructProperty = false;

                                if (method != null)
                                {
                                    MethodDef.Param param = method.GetParam(paramName, property, indexInArray);

                                    if (param != null)
                                    {
                                        bStructProperty = true;
                                        string s = param.GetExportValue(null);

                                        if (Plugin.IsStringType(param.Value.GetType()))
                                        {
                                            str += string.Format("\"{0}\"", s);
                                        }
                                        else
                                        {
                                            str += s;
                                        }
                                    }
                                }

                                if (!bStructProperty)
                                {
                                    string s = property.GetExportValue(obj);

                                    if (Plugin.IsStringType(property.Property.PropertyType))
                                    {
                                        str += string.Format("\"{0}\"", s);
                                    }
                                    else
                                    {
                                        str += s;
                                    }
                                }
                            }
                        }

                        if (!bSave && bStructAsBasic)
                        {
                        }
                        else
                        {
                            str += ";";
                        }
                    }
                }
            }
            else
            {
            }

            if (!bSave && bStructAsBasic)
            {
                str += ")";
            }
            else
            {
                str += "}";
            }

            return(str);
        }