public static void Ctor_Refresh(RefreshProperties refresh, bool expectedIsDefaultAttribute) { var attribute = new RefreshPropertiesAttribute(refresh); Assert.Equal(refresh, attribute.RefreshProperties); Assert.Equal(expectedIsDefaultAttribute, attribute.IsDefaultAttribute()); }
public void Equals_Object_ReturnsExpected(RefreshPropertiesAttribute attribute, object other, bool expected) { Assert.Equal(expected, attribute.Equals(other)); if (other is RefreshPropertiesAttribute) { Assert.Equal(expected, attribute.GetHashCode().Equals(other.GetHashCode())); } }
/// <summary> /// <para> /// Overrides object's Equals method. /// </para> /// </summary> public override bool Equals(object obj) { if (obj == this) { return(true); } RefreshPropertiesAttribute other = obj as RefreshPropertiesAttribute; return((other != null) && other.RefreshProperties == RefreshProperties); }
internal override void EditPropertyValue(PropertyGridView iva) { base.EditPropertyValue(iva); if (!this.IsValueEditable) { RefreshPropertiesAttribute attribute = (RefreshPropertiesAttribute)this.propertyInfo.Attributes[typeof(RefreshPropertiesAttribute)]; if ((attribute != null) && !attribute.RefreshProperties.Equals(RefreshProperties.None)) { this.GridEntryHost.Refresh((attribute != null) && attribute.Equals(RefreshPropertiesAttribute.All)); } } }
/// <summary> /// Invokes the type editor for editing this item. /// </summary> internal override void EditPropertyValue(PropertyGridView iva) { base.EditPropertyValue(iva); if (!IsValueEditable) { RefreshPropertiesAttribute refreshAttr = (RefreshPropertiesAttribute)propertyInfo.Attributes[typeof(RefreshPropertiesAttribute)]; if ((refreshAttr != null && !refreshAttr.RefreshProperties.Equals(RefreshProperties.None))) { this.GridEntryHost.Refresh(refreshAttr != null && refreshAttr.Equals(RefreshPropertiesAttribute.All)); } } }
// Determine if two attribute values are equal. public override bool Equals(Object obj) { RefreshPropertiesAttribute other = (obj as RefreshPropertiesAttribute); if (other != null) { return(refresh == other.refresh); } else { return(false); } }
public override PropertyDescriptorCollection GetWrappedProperties(int id, Attribute[] attributes) { int n = 0; Attribute[] attrs = new Attribute[n + 1]; Attribute[] attrs2 = new Attribute[n + 2]; attrs[n] = new EditorAttribute(typeof(UITypeEditorMathExpression2), typeof(UITypeEditor)); attrs2[n] = new EditorAttribute(typeof(TypeEditorSelectAction), typeof(UITypeEditor)); attrs2[n + 1] = new RefreshPropertiesAttribute(RefreshProperties.All); return(new PropertyDescriptorCollection(new PropertyDescriptor[] { new DataValuePropertyDescriptor(this, attrs), new PropertyDescriptorInlineAction(this, attrs2, "InitAction"), new PropertyDescriptorInlineAction(this, attrs2, "IncrementAction") } )); }
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { List <PropertyDescriptor> pdl = new List <PropertyDescriptor>(); int n = 0; if (attributes != null) { n = attributes.Length; } foreach (ExceptionHandler eh in this) { Attribute[] attrs; if (eh.IsDefaultExceptionType) { attrs = new Attribute[n + 4]; } else { attrs = new Attribute[n + 3]; } if (n > 0) { attributes.CopyTo(attrs, 0); } if (eh.IsDefaultExceptionType) { attrs[n] = new DescriptionAttribute("Select a type of exceptions to be handled. Choose type Exception under System namespace for generic exceptions"); attrs[n + 1] = new EditorAttribute(typeof(PropEditorDataType), typeof(UITypeEditor)); attrs[n + 2] = new TypeScopeAttribute(typeof(Exception)); attrs[n + 3] = new RefreshPropertiesAttribute(RefreshProperties.All); } else { attrs[n] = new DescriptionAttribute(string.Format(CultureInfo.InvariantCulture, "Specify actions for handling exceptions of type {0}", eh.ExceptionType.DisplayName)); attrs[n + 1] = new EditorAttribute(typeof(TypeEditorExceptionHandler), typeof(UITypeEditor)); attrs[n + 2] = new RefreshPropertiesAttribute(RefreshProperties.All); } pdl.Add(new PropertyDescriptorExceptionHandler(eh, attrs)); } return(new PropertyDescriptorCollection(pdl.ToArray())); }
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { int n = 1; Attribute[] attrs = new Attribute[4]; if (_scope == null) { attrs[0] = new ComponentReferenceSelectorTypeAttribute(typeof(IComponent)); } else { attrs[0] = new ComponentReferenceSelectorTypeAttribute(_scope); } attrs[1] = new EditorAttribute(typeof(ComponentReferenceSelector), typeof(UITypeEditor)); attrs[2] = new RefreshPropertiesAttribute(RefreshProperties.All); attrs[3] = new DescriptionAttribute("Component name"); List <PropertyDescriptor> ps = new List <PropertyDescriptor>(); foreach (string ic in this) { Attribute[] attrs0 = new Attribute[4]; if (_scope == null) { attrs0[0] = new ComponentReferenceSelectorTypeAttribute(typeof(IComponent)); } else { attrs0[0] = new ComponentReferenceSelectorTypeAttribute(_scope); } attrs0[1] = new EditorAttribute(typeof(ComponentReferenceSelector), typeof(UITypeEditor)); attrs0[2] = new RefreshPropertiesAttribute(RefreshProperties.All); attrs0[3] = new XmlIgnoreAttribute(); PropertyDescriptorComponent p = new PropertyDescriptorComponent( string.Format(CultureInfo.InvariantCulture, "Item{0}", n), ic, this, attrs0); ps.Add(p); n++; } ps.Add(new PropertyDescriptorComponent(string.Format(CultureInfo.InvariantCulture, "Item{0}", n), null, this, attrs)); return(new PropertyDescriptorCollection(ps.ToArray())); }
private object SetPropertyValue(object obj, object objVal, bool reset, string undoText) { DesignerTransaction trans = null; try { object oldValue = GetPropertyValueCore(obj); if (objVal != null && objVal.Equals(oldValue)) { return(objVal); } ClearCachedValues(); IDesignerHost host = DesignerHost; if (host != null) { string text = (undoText == null ? string.Format(SR.PropertyGridSetValue, propertyInfo.Name) : undoText); trans = host.CreateTransaction(text); } // Usually IComponent things are sited and this notification will be // fired automatically by the PropertyDescriptor. However, for non-IComponent sub objects // or sub objects that are non-sited sub components, we need to manuall fire // the notification. // bool needChangeNotify = !(obj is IComponent) || ((IComponent)obj).Site == null; if (needChangeNotify) { try { if (ComponentChangeService != null) { ComponentChangeService.OnComponentChanging(obj, propertyInfo); } } catch (CheckoutException coEx) { if (coEx == CheckoutException.Canceled) { return(oldValue); } throw coEx; } } bool wasExpanded = this.InternalExpanded; int childCount = -1; if (wasExpanded) { childCount = this.ChildCount; } RefreshPropertiesAttribute refreshAttr = (RefreshPropertiesAttribute)propertyInfo.Attributes[typeof(RefreshPropertiesAttribute)]; bool needsRefresh = wasExpanded || (refreshAttr != null && !refreshAttr.RefreshProperties.Equals(RefreshProperties.None)); if (needsRefresh) { DisposeChildren(); } // Determine if this is an event being created, and if so, navigate to the event code // EventDescriptor eventDesc = null; // This is possibly an event. Check it out. // if (obj != null && objVal is string) { if (eventBindings == null) { eventBindings = (IEventBindingService)GetService(typeof(IEventBindingService)); } if (eventBindings != null) { eventDesc = eventBindings.GetEvent(propertyInfo); } // For a merged set of properties, the event binding service won't // find an event. So, we ask type descriptor directly. // if (eventDesc == null) { // If we have a merged property descriptor, pull out one of // the elements. // object eventObj = obj; if (propertyInfo is MergePropertyDescriptor && obj is Array) { Array objArray = obj as Array; if (objArray.Length > 0) { eventObj = objArray.GetValue(0); } } eventDesc = TypeDescriptor.GetEvents(eventObj)[propertyInfo.Name]; } } bool setSuccessful = false; try { if (reset) { propertyInfo.ResetValue(obj); } else if (eventDesc != null) { ViewEvent(obj, (string)objVal, eventDesc, false); } else { // Not an event SetPropertyValueCore(obj, objVal, true); } setSuccessful = true; // Now notify the change service that the change was successful. // if (needChangeNotify && ComponentChangeService != null) { ComponentChangeService.OnComponentChanged(obj, propertyInfo, null, objVal); } NotifyParentChange(this); } finally { // see if we need to refresh the property browser // 1) if this property has the refreshpropertiesattribute, or // 2) it's got expanded sub properties // if (needsRefresh && this.GridEntryHost != null) { RecreateChildren(childCount); if (setSuccessful) { this.GridEntryHost.Refresh(refreshAttr != null && refreshAttr.Equals(RefreshPropertiesAttribute.All)); } } } } catch (CheckoutException checkoutEx) { if (trans != null) { trans.Cancel(); trans = null; } if (checkoutEx == CheckoutException.Canceled) { return(null); } throw; } catch { if (trans != null) { trans.Cancel(); trans = null; } throw; } finally { if (trans != null) { trans.Commit(); } } return(obj); }
public void GetRefreshProperties(RefreshProperties value) { var attribute = new RefreshPropertiesAttribute(value); Assert.Equal(value, attribute.RefreshProperties); }
public void NameTests(RefreshPropertiesAttribute attribute, RefreshProperties refreshProperties) { Assert.Equal(refreshProperties, attribute.RefreshProperties); }
internal override bool NotifyValueGivenParent(object obj, int type) { if (obj is ICustomTypeDescriptor) { obj = ((ICustomTypeDescriptor)obj).GetPropertyOwner(propertyInfo); } switch (type) { case NOTIFY_RESET: propertyInfo.ResetValue(obj); if (pvUIItems != null) { for (int i = 0; i < pvUIItems.Length; i++) { pvUIItems[i].Reset(); } } pvUIItems = null; RefreshPropertiesAttribute refreshAttr = (RefreshPropertiesAttribute)propertyInfo.Attributes[typeof(RefreshPropertiesAttribute)]; if ((refreshAttr != null && !refreshAttr.RefreshProperties.Equals(RefreshProperties.None))) { this.GridEntryHost.Refresh(refreshAttr != null && refreshAttr.Equals(RefreshPropertiesAttribute.All)); } return(false); case NOTIFY_CAN_RESET: try { return(propertyInfo.CanResetValue(obj) || (pvUIItems != null && pvUIItems.Length > 0)); } catch { if (this.exceptionConverter == null) { // clear the flags this.Flags = 0; this.exceptionConverter = new ExceptionConverter(); this.exceptionEditor = new ExceptionEditor(); } return(false); } case NOTIFY_SHOULD_PERSIST: try{ return(propertyInfo.ShouldSerializeValue(obj)); } catch { if (this.exceptionConverter == null) { // clear the flags this.Flags = 0; this.exceptionConverter = new ExceptionConverter(); this.exceptionEditor = new ExceptionEditor(); } return(false); } case NOTIFY_DBL_CLICK: case NOTIFY_RETURN: if (eventBindings == null) { eventBindings = (IEventBindingService)GetService(typeof(IEventBindingService)); } if (eventBindings != null) { EventDescriptor descriptor = eventBindings.GetEvent(propertyInfo); if (descriptor != null) { return(ViewEvent(obj, null, null, true)); } } break; } return(false); }
public void DefaultProperties_GetRefreshProperties_ReturnsExpected(RefreshPropertiesAttribute attribute, RefreshProperties expectedRefreshProperties, bool expectedIsDefaultAttribute) { Assert.Equal(expectedRefreshProperties, attribute.RefreshProperties); Assert.Equal(expectedIsDefaultAttribute, attribute.IsDefaultAttribute()); }
/// <summary> /// Function to retrieve any attributes from this property. /// </summary> private void GetAttributes() { DefaultValueAttribute defaultValue = null; ReadOnlyAttribute readOnly = null; RefreshPropertiesAttribute refresh = null; DescriptionAttribute description = null; CategoryAttribute category = null; EditorAttribute editor = null; TypeConverterAttribute typeConverter = null; DisplayNameAttribute displayName = null; foreach (Attribute attribute in _descriptor.Attributes.Cast <Attribute>()) { if (defaultValue == null) { defaultValue = attribute as DefaultValueAttribute; } if (readOnly == null) { readOnly = attribute as ReadOnlyAttribute; } if (refresh == null) { refresh = attribute as RefreshPropertiesAttribute; } if (description == null) { description = attribute as DescriptionAttribute; } if (category == null) { category = attribute as CategoryAttribute; } if (editor == null) { editor = attribute as EditorAttribute; } if (typeConverter == null) { typeConverter = attribute as TypeConverterAttribute; } if (displayName == null) { displayName = attribute as DisplayNameAttribute; } } if (defaultValue != null) { DefaultValue = defaultValue.Value; } if (readOnly != null) { IsReadOnly = readOnly.IsReadOnly; } if (refresh != null) { RefreshProperties = refresh.RefreshProperties; } if (description != null) { Description = description.Description; } if (category != null) { Category = category.Category; } if (editor != null) { _editorBase = editor.EditorBaseTypeName; Editor = editor.EditorTypeName; } if (displayName != null) { DisplayName = displayName.DisplayName; } if (typeConverter != null) { Converter = typeConverter.ConverterTypeName; } }
private object SetPropertyValue(object obj, object objVal, bool reset, string undoText) { DesignerTransaction transaction = null; try { object propertyValueCore = this.GetPropertyValueCore(obj); if ((objVal != null) && objVal.Equals(propertyValueCore)) { return(objVal); } base.ClearCachedValues(); IDesignerHost designerHost = this.DesignerHost; if (designerHost != null) { string description = (undoText == null) ? System.Windows.Forms.SR.GetString("PropertyGridSetValue", new object[] { this.propertyInfo.Name }) : undoText; transaction = designerHost.CreateTransaction(description); } bool flag = !(obj is IComponent) || (((IComponent)obj).Site == null); if (flag) { try { if (this.ComponentChangeService != null) { this.ComponentChangeService.OnComponentChanging(obj, this.propertyInfo); } } catch (CheckoutException exception) { if (exception != CheckoutException.Canceled) { throw exception; } return(propertyValueCore); } } bool internalExpanded = this.InternalExpanded; int oldCount = -1; if (internalExpanded) { oldCount = base.ChildCount; } RefreshPropertiesAttribute attribute = (RefreshPropertiesAttribute)this.propertyInfo.Attributes[typeof(RefreshPropertiesAttribute)]; bool flag3 = internalExpanded || ((attribute != null) && !attribute.RefreshProperties.Equals(RefreshProperties.None)); if (flag3) { this.DisposeChildren(); } EventDescriptor eventdesc = null; if ((obj != null) && (objVal is string)) { if (this.eventBindings == null) { this.eventBindings = (IEventBindingService)this.GetService(typeof(IEventBindingService)); } if (this.eventBindings != null) { eventdesc = this.eventBindings.GetEvent(this.propertyInfo); } if (eventdesc == null) { object component = obj; if ((this.propertyInfo is MergePropertyDescriptor) && (obj is Array)) { Array array = obj as Array; if (array.Length > 0) { component = array.GetValue(0); } } eventdesc = TypeDescriptor.GetEvents(component)[this.propertyInfo.Name]; } } bool flag4 = false; try { if (reset) { this.propertyInfo.ResetValue(obj); } else if (eventdesc != null) { this.ViewEvent(obj, (string)objVal, eventdesc, false); } else { this.SetPropertyValueCore(obj, objVal, true); } flag4 = true; if (flag && (this.ComponentChangeService != null)) { this.ComponentChangeService.OnComponentChanged(obj, this.propertyInfo, null, objVal); } this.NotifyParentChange(this); } finally { if (flag3 && (this.GridEntryHost != null)) { base.RecreateChildren(oldCount); if (flag4) { this.GridEntryHost.Refresh((attribute != null) && attribute.Equals(RefreshPropertiesAttribute.All)); } } } return(obj); } catch (CheckoutException exception2) { if (transaction != null) { transaction.Cancel(); transaction = null; } if (exception2 != CheckoutException.Canceled) { throw; } return(null); } catch { if (transaction != null) { transaction.Cancel(); transaction = null; } throw; } finally { if (transaction != null) { transaction.Commit(); } } return(obj); }