Ejemplo n.º 1
0
        private BaseControl CreateCustomControl(ConfigCustomAttribute configCustom)
        {
            //Get type from local project if possible, if not use other loader
            Type objectType = System.Type.GetType(configCustom.CustomControlName) ?? _plugin.Runtime.Loader.GetObjectType(configCustom.CustomControlName);

            BaseControl createdUserControl = Activator.CreateInstance(objectType, _plugin) as BaseControl;

            return(createdUserControl);
        }
Ejemplo n.º 2
0
        private void AutoGenPluginUserControlLoad(object sender, EventArgs e)
        {
            this.Controls.Clear();

            Type t = _plugin.GetType();

            List <BaseControl> controls = new List <BaseControl>();

            foreach (PropertyInfo prop in t.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (Attribute.IsDefined(prop, typeof(ConfigAttribute)) &&
                    !(Attribute.GetCustomAttribute(prop, typeof(ConfigAttribute)) as ConfigAttribute).IsHidden)
                {
                    if (Attribute.IsDefined(prop, typeof(ConfigLookupAttribute)))
                    {
                        controls.Add(new LookupControl(prop, _plugin));
                    }
                    else if (Attribute.IsDefined(prop, typeof(ConfigNumberAttribute)))
                    {
                        controls.Add(new NumberControl(prop, _plugin));
                    }
                    else if (Attribute.IsDefined(prop, typeof(ConfigStringAttribute)))
                    {
                        controls.Add(new StringControl(prop, _plugin));
                    }
                    else if (Attribute.IsDefined(prop, typeof(ConfigReadOnlyAttribute)))
                    {
                        controls.Add(new ReadOnlyControl(prop, _plugin));
                    }
                }
            }
            ConfigCustomAttribute configCustom = (ConfigCustomAttribute)Attribute.GetCustomAttribute(t, typeof(ConfigCustomAttribute));

            if (configCustom != null)
            {
                BaseControl control = CreateCustomControl(configCustom);

                control.Parent = this;
                control.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;

                controls.Add(control);
            }

            //Add Sort to not set values
            foreach (var item in controls.Where(s => s.SortIndex == 0))
            {
                item.SortIndex = (from c in controls
                                  orderby c.SortIndex descending
                                  select c.SortIndex).FirstOrDefault() + 100;
            }

            //Sort controls
            controls = (from c in controls
                        orderby c.SortIndex
                        select c).ToList();

            //Add Controls
            controls.ForEach(c => AddControl(c));

            //TODO add scroll bar control may not need it
        }