/// <include file='doc\ComponentSettingsConverter.uex' path='docs/doc[@for="ComponentSettingsConverter.GetProperties"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            ComponentSettings         compSettings = (ComponentSettings)value;
            PropertyBindingCollection bindings     = compSettings.Bindings.GetBindingsForComponent(compSettings.Component);

            ArrayList props = new ArrayList();

            // go through all the properties on the component and see if they have the "show me" attribute.
            // also check to see if the propert has already been bound.
            IComponent    component = compSettings.Component;
            IDesignerHost host      = (IDesignerHost)component.Site.GetService(typeof(IDesignerHost));
            PropertyDescriptorCollection componentProps = TypeDescriptor.GetProperties(component);

            for (int i = 0; i < componentProps.Count; i++)
            {
                PropertyDescriptor prop = componentProps[i];
                if (!prop.IsReadOnly && ManagedPropertiesService.IsTypeSupported(prop.PropertyType))
                {
                    bool            recommended = ((RecommendedAsConfigurableAttribute)prop.Attributes[typeof(RecommendedAsConfigurableAttribute)]).RecommendedAsConfigurable;
                    PropertyBinding binding     = bindings[component, prop];
                    if (recommended || (binding != null && binding.Bound))
                    {
                        props.Add(new BindingPropertyDescriptor(compSettings, prop));
                    }
                }
            }

            // add the (Advanced...) property
            props.Add(new AdvancedPropertyDescriptor(compSettings));

            PropertyDescriptor[] propsArray = new PropertyDescriptor[props.Count];
            for (int i = 0; i < props.Count; i++)
            {
                propsArray[i] = (PropertyDescriptor)props[i];
            }
            return(new PropertyDescriptorCollection(propsArray));
        }
예제 #2
0
 /// <include file='doc\AdvancedPropertyDescriptor.uex' path='docs/doc[@for="AdvancedPropertyDescriptor.AdvancedPropertyDescriptor"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public AdvancedPropertyDescriptor(ComponentSettings settings) : base(SR.GetString(SR.ConfigAdvanced),
                                                                      new Attribute[] { RefreshPropertiesAttribute.All,
                                                                                        new SRDescriptionAttribute(SR.ConfigAdvancedDesc) })
 {
     this.compSettings = settings;
 }
예제 #3
0
        /// <include file='doc\AdvancedPropertyEditor.uex' path='docs/doc[@for="AdvancedPropertyEditor.EditValue"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            ComponentSettings compSettings = ((AdvancedPropertyDescriptor)value).ComponentSettings;
            IComponent        component    = compSettings.Component;

            // make sure it's OK to change
            IComponentChangeService changeService = null;

            if (component.Site != null)
            {
                changeService = (IComponentChangeService)component.Site.GetService(typeof(IComponentChangeService));
            }
            if (changeService != null)
            {
                try {
                    changeService.OnComponentChanging(component, (PropertyDescriptor)value);
                }
                catch (CheckoutException e) {
                    if (e == CheckoutException.Canceled)
                    {
                        return(value);
                    }
                    throw e;
                }
            }

            IWindowsFormsEditorService editorSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            Debug.Assert(editorSvc != null, "Couldn't get IWindowsFormsEditorService");
            if (editorSvc != null)
            {
                try {
                    using (AdvancedPropertyDialog dlg = new AdvancedPropertyDialog(component)) {
                        DialogResult result = editorSvc.ShowDialog(dlg);
                        if (result == DialogResult.OK)
                        {
                            bool changeMade = false;
                            PropertyBindingCollection newBindings = dlg.Bindings;
                            ManagedPropertiesService  svc         = (ManagedPropertiesService)context.GetService(typeof(ManagedPropertiesService));
                            Debug.Assert(svc != null, "Couldn't get ManagedPropertiesService");
                            if (svc != null)
                            {
                                for (int i = 0; i < newBindings.Count; i++)
                                {
                                    svc.EnsureKey(newBindings[i]);
                                    PropertyBinding oldBinding = svc.Bindings[component, newBindings[i].Property];
                                    if (oldBinding == null)
                                    {
                                        if (newBindings[i].Bound)
                                        {
                                            changeMade = true;
                                        }
                                    }
                                    else if ((oldBinding.Bound != newBindings[i].Bound) || (oldBinding.Key != newBindings[i].Key))
                                    {
                                        changeMade = true;
                                    }
                                    svc.Bindings[component, newBindings[i].Property] = newBindings[i];
                                }
                                svc.MakeDirty();

                                if (changeMade)
                                {
                                    TypeDescriptor.Refresh(compSettings.Component);
                                    if (changeService != null)
                                    {
                                        changeService.OnComponentChanged(compSettings.Component, null, null, null);
                                    }
                                    try {
                                        svc.WriteConfigFile();
                                    }
                                    catch {
                                    }
                                }

                                // this fools the properties window into thinking we changed the value, so it refreshes
                                // the owner object.
                                object retval = new AdvancedPropertyDescriptor(compSettings);
                                return(retval);
                            }
                        }
                    }
                }
                catch (Exception e) {
                    System.Windows.Forms.MessageBox.Show(e.Message, SR.GetString(SR.ConfigConfiguredProperties));
                }
            }

            return(value);
        }
 /// <include file='doc\BindingPropertyDescriptor.uex' path='docs/doc[@for="BindingPropertyDescriptor.BindingPropertyDescriptor"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public BindingPropertyDescriptor(ComponentSettings settings, PropertyDescriptor prop) : base(prop.Name, new Attribute[] { RefreshPropertiesAttribute.All })
 {
     this.compSettings = settings;
     this.property     = prop;
 }