/// <include file='doc\QueuePathEditor.uex' path='docs/doc[@for="PropertyBindingEditor.EditValue"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider != null) { IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc != null) { PropertyBinding binding = value as PropertyBinding; if (binding != null) { PropertyBinding bindingToEdit = new PropertyBinding(binding); SingleBindingDialog bindingUI = new SingleBindingDialog(bindingToEdit); if (edSvc.ShowDialog(bindingUI) == DialogResult.OK) { value = bindingToEdit; ManagedPropertiesService svc = (ManagedPropertiesService)context.GetService(typeof(ManagedPropertiesService)); if (svc != null) { svc.MakeDirty(); try { svc.WriteConfigFile(); } catch { } } } } } } return(value); }
public BindingData(PropertyBinding binding) { this.Name = binding.Property.Name; this.Key = binding.Key; this.Bound = binding.Bound; this.Value = binding; }
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\PropertyBinding.uex' path='docs/doc[@for="PropertyBinding.PropertyBinding1"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public PropertyBinding(PropertyBinding bindingToClone) { if (bindingToClone != null) { bound = bindingToClone.bound; enabled = bindingToClone.enabled; componentName = bindingToClone.componentName; property = bindingToClone.property; key = bindingToClone.key; host = bindingToClone.host; component = bindingToClone.component; isDefault = bindingToClone.isDefault; } }
/// <include file='doc\BindingPropertyDescriptor.uex' path='docs/doc[@for="BindingPropertyDescriptor.GetValue"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override object GetValue(object component) { PropertyBinding binding = compSettings.Bindings[compSettings.Component, property]; if (binding == null) { // this will only happen if the property was "recommended" but it had never // been bound. binding = new PropertyBinding(GetHost()); binding.Component = compSettings.Component; binding.Property = property; binding.Reset(); compSettings.Bindings[compSettings.Component, property] = binding; } return(binding); }
/// <include file='doc\PropertyBindingConverter.uex' path='docs/doc[@for="PropertyBindingConverter.ConvertTo"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string) && value is PropertyBinding) { if (value == null) { return(SR.GetString(SR.ConfigNone)); } PropertyBinding binding = (PropertyBinding)value; if (!binding.Bound) { return(SR.GetString(SR.ConfigNone)); } return(binding.Key); } else { return(base.ConvertTo(context, culture, value, destinationType)); } }
/// <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\SingleBindingDialog.uex' path='docs/doc[@for="SingleBindingDialog.SingleBindingDialog"]/*' /> /// <devdoc> /// Creates a new dialog to let the user edit dynamic property bindings. /// The bindings parameter must have all possible bindings in it for the /// components and their properties, even if none are bound. For unbound /// properties, the key property on the binding should be /// initialized to its suggested (default) values. /// </devdoc> public SingleBindingDialog(PropertyBinding binding) { this.binding = binding; this.InitializeComponent(); FillUI(); }
/// <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\PropertyBindingCollection.uex' path='docs/doc[@for="PropertyBindingCollection.Remove"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void Remove(PropertyBinding binding) { contents.Remove(binding); //hashedContents.Remove(new InstancedPropertyDescriptor(binding.ComponentName, binding.Property)); }
/// <include file='doc\PropertyBindingCollection.uex' path='docs/doc[@for="PropertyBindingCollection.Add"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void Add(PropertyBinding binding) { contents.Add(binding); //hashedContents[new InstancedPropertyDescriptor(binding.ComponentName, binding.Property)] = binding; }
/// <include file='doc\BindingPropertyDescriptor.uex' path='docs/doc[@for="BindingPropertyDescriptor.SetValue"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override void SetValue(object component, object newBinding) { // Debug.Assert(compSettings == component, "I don't get it - component is a " + component.GetType().FullName); Debug.Assert(newBinding is PropertyBinding || newBinding is string, "I still don't get it " + newBinding.GetType().FullName + " " + newBinding.ToString()); // make sure it's OK to change property. IComponentChangeService svc = null; if (compSettings.Component.Site != null) { svc = (IComponentChangeService)compSettings.Component.Site.GetService(typeof(IComponentChangeService)); } if (svc != null) { try { svc.OnComponentChanging(compSettings.Component, this); } catch (CheckoutException e) { if (e == CheckoutException.Canceled) { return; } throw e; } } PropertyBinding binding; if (newBinding is PropertyBinding) { binding = (PropertyBinding)newBinding; } else { binding = new PropertyBinding((PropertyBinding)GetValue(component)); binding.Host = GetHost(); if (newBinding == (object)PropertyBinding.None) { binding.Bound = false; } else { binding.Bound = true; binding.Enabled = false; // this will be set to true in EnsureKey if appropriate binding.Key = (string)newBinding; } } compSettings.Bindings[compSettings.Component, property] = binding; // if the key doesn't exist, use this property's value to set it. compSettings.Service.EnsureKey(binding); compSettings.Service.MakeDirty(); compSettings.Service.WriteConfigFile(); // now announce that it's changed TypeDescriptor.Refresh(compSettings.Component); if (svc != null) { svc.OnComponentChanged(compSettings.Component, null, null, null); } OnValueChanged(component, EventArgs.Empty); }
/// <include file='doc\BindingPropertyDescriptor.uex' path='docs/doc[@for="BindingPropertyDescriptor.ResetValue"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override void ResetValue(object component) { PropertyBinding binding = (PropertyBinding)GetValue(component); binding.Reset(); }