/// <include file='doc\PropertyBindingCollection.uex' path='docs/doc[@for="PropertyBindingCollection.CopyFrom"]/*' /> /// <devdoc> /// Creates a deep copy of the given collection, cloning each contained PropertyBinding. /// </devdoc> public void CopyFrom(PropertyBindingCollection coll) { Clear(); for (int i = 0; i < coll.Count; i++) { Add((PropertyBinding)coll[i].Clone()); } }
private void CreateBindings() { bindings = new PropertyBindingCollection(); ManagedPropertiesService svc = (ManagedPropertiesService)component.Site.GetService(typeof(ManagedPropertiesService)); if (svc != null) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(component, new Attribute[] { BrowsableAttribute.Yes }); for (int i = 0; i < properties.Count; i++) { PropertyDescriptor prop = properties[i]; if (prop.DesignTimeOnly) { continue; } if (prop.IsReadOnly) { continue; } if (prop.Attributes.Contains(DesignerSerializationVisibilityAttribute.Hidden)) { continue; } // don't show the ComponentSettings property - it can't be managed! if (prop.PropertyType == typeof(ComponentSettings)) { continue; } if (!ManagedPropertiesService.IsTypeSupported(prop.PropertyType)) { continue; } PropertyBinding binding = svc.Bindings[component, prop]; if (binding == null) { binding = new PropertyBinding(host); binding.Component = component; binding.Property = prop; binding.Reset(); } else { binding = (PropertyBinding)binding.Clone(); } bindings.Add(binding); } } }
/// <include file='doc\PropertyBindingCollection.uex' path='docs/doc[@for="PropertyBindingCollection.GetBindingsForComponent"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public PropertyBindingCollection GetBindingsForComponent(IComponent component) { PropertyBindingCollection collection = new PropertyBindingCollection(); foreach (PropertyBinding binding in contents) { if (binding.Component == component) { collection.Add(binding); } } return(collection); }
/// <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)); }
/// <include file='doc\AdvancedPropertyDialog.uex' path='docs/doc[@for="AdvancedPropertyDialog.SaveSelectedProperties"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void SaveSelectedProperties() { PropertyBindingCollection newBindings = Bindings; ManagedPropertiesService svc = (ManagedPropertiesService)component.Site.GetService(typeof(ManagedPropertiesService)); if (svc != null) { for (int i = 0; i < newBindings.Count; i++) { svc.EnsureKey(newBindings[i]); svc.Bindings[component, newBindings[i].Property] = newBindings[i]; } svc.MakeDirty(); } TypeDescriptor.Refresh(component); // now announce that it's changed IComponentChangeService changeService = (IComponentChangeService)component.Site.GetService(typeof(IComponentChangeService)); if (changeService != null) { changeService.OnComponentChanged(component, null, null, null); } }
/// <include file='doc\PropertyBindingCollection.uex' path='docs/doc[@for="PropertyBindingCollection.SetBindingsForComponent"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void SetBindingsForComponent(IComponent component, PropertyBindingCollection newBindings) { if (component == null) { throw new ArgumentNullException("component"); } if (newBindings == null) { throw new ArgumentNullException("newBindings"); } for (int i = Count - 1; i >= 0; i--) { if (this[i].Component == component) { RemoveAt(i); } } for (int i = 0; i < newBindings.Count; i++) { Add(newBindings[i]); } }
/// <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); }