Exemplo n.º 1
0
        private UITypeEditor lookUpEditor(ITypeDescriptorContext context)
        {
            if (context != null && context.Instance != null && typeof(WhiskeyPropertyContainer).IsAssignableFrom(context.Instance.GetType()))
            {
                WhiskeyPropertyContainer wpc = (WhiskeyPropertyContainer)context.Instance;
                return(WhiskeyTypeEditors.lookUp(wpc.TypeName));
            }

            return(null);
        }
        public override void PaintValue(PaintValueEventArgs e)
        {
            UITypeEditor editor = lookUpEditor(e.Context);

            if (editor != null)
            {
                if (typeof(WhiskeyPropertyContainer).IsAssignableFrom(e.Value.GetType()))
                {
                    WhiskeyPropertyContainer wpc = (WhiskeyPropertyContainer)e.Value;
                    PaintValueEventArgs      e2  = new PaintValueEventArgs(e.Context, wpc.Value, e.Graphics, e.Bounds);
                    editor.PaintValue(e2);
                    return;
                }
            }

            base.PaintValue(e);
        }
        private UITypeEditor lookUpEditor(ITypeDescriptorContext context)
        {
            if (context != null && context.PropertyDescriptor is GeneralPropertyDescriptor)
            {
                GeneralPropertyDescriptor gpd = (GeneralPropertyDescriptor)context.PropertyDescriptor;

                if (gpd.PropValue != null && typeof(WhiskeyPropertyContainer).IsAssignableFrom(gpd.PropValue.GetType()))
                {
                    WhiskeyPropertyContainer wpc = (WhiskeyPropertyContainer)gpd.PropValue;
                    //if (editors.ContainsKey(wpc.TypeName))
                    //{
                    //    return editors[wpc.TypeName];
                    //}
                    return(WhiskeyTypeEditors.lookUp(wpc.TypeName));
                }
            }
            return(null);
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            UITypeEditor editor = lookUpEditor(context);

            if (editor != null)
            {
                if (typeof(WhiskeyPropertyContainer).IsAssignableFrom(value.GetType()))
                {
                    WhiskeyPropertyContainer wpc = (WhiskeyPropertyContainer)value;

                    object newValue = editor.EditValue(context, provider, wpc.Value);

                    wpc.Value = newValue;

                    return(value);
                }
            }


            return(base.EditValue(context, provider, value));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Getting a set of properties to give to the propertygrid
        /// </summary>
        /// <param name="attributes">?</param>
        /// <returns>a set of properties for the propertygrid</returns>
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            //clear previous property model set
            LastModelSet.Clear();
            List <PropertyDescriptor> properties = new List <PropertyDescriptor>();

            //for every property in our set...
            foreach (WhiskeyProperty prop in WhiskeyPropertys)
            {
                if (prop.Visible)
                {
                    //create a new property descriptor (for the property grid) for it....
                    GeneralPropertyDescriptor gpd = new GeneralPropertyDescriptor(prop.Name);

                    //create a model, that is either secure or unsecure depending on if the WhiskeyProp.Secure is true/false
                    WhiskeyPropertyContainer model;
                    if (prop.Secure)
                    {
                        model = new WhiskeyPropertyContainerSecured(prop);

                        gpd.PropCategory = "Base Properties";
                    }
                    else
                    {
                        model = new WhiskeyPropertyContainer(prop);

                        gpd.PropCategory = "Properties";
                    }

                    //set the value of the propertygrid property descriptor, to our model
                    gpd.PropValue    = model;
                    gpd.PropCategory = prop.Category;

                    //add a listener that will update the propertygrid when the model changes
                    model.Changed += (s, a) =>
                    {
                        gpd.PropDisplayName = a.WhiskeyProperty.Name;

                        if (PropertyGrid.IsHandleCreated)
                        {
                            //PropertyGrid.BeginInvoke(new NoArgFunction(() => {
                            PropertyGrid.Refresh();
                            //}));
                            PropertyValueChanged(this, new EventArgs());
                        }
                    };

                    //add the model to our set
                    LastModelSet.Add(model);
                    //add the propertygrid descriptor to the set to be returned
                    properties.Add(gpd);
                }
            }

            //converting the set of propertygrid descriptors to a returnable array
            //properties.Sort();

            //other
            foreach (GeneralPropertyDescriptor prop in OtherProperties)
            {
                //properties.Add(new WhiskeyPropertyContainer(new WhiskeyProperty(prop.DisplayName, new WhiskeyEditor.Backend.RealType(prop.ComponentType, prop.PropValue)));
                properties.Add(prop);
            }

            PropertyDescriptor[] props = (PropertyDescriptor[])properties.ToArray();

            return(new PropertyDescriptorCollection(props));
        }