[JEDI.NET-commits] dev/jedi_mbe/run Jedi.Collections.pas,1.1,1.2 Jedi.System.pas,1.1,1.2
Status: Pre-Alpha
Brought to you by:
jedi_mbe
From: Marcel B. <jed...@us...> - 2004-06-15 19:32:54
|
Update of /cvsroot/jedidotnet/dev/jedi_mbe/run In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19231/dev/jedi_mbe/run Modified Files: Jedi.Collections.pas Jedi.System.pas Log Message: Inline collection editing is now working: Add, modify or delete collection items from within the Object Inspector Index: Jedi.System.pas =================================================================== RCS file: /cvsroot/jedidotnet/dev/jedi_mbe/run/Jedi.System.pas,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Jedi.System.pas 12 Jun 2004 18:31:38 -0000 1.1 --- Jedi.System.pas 15 Jun 2004 19:32:44 -0000 1.2 *************** *** 8,12 **** limitations under the License. ! The Original Code is: Jedi.System.pas, released on 2004-05-20. The Initial Developer of the Original Code is Marcel Bestebroer --- 8,12 ---- limitations under the License. ! The Original Code is: Jedi.System.pas, released on 2004-06-13. The Initial Developer of the Original Code is Marcel Bestebroer *************** *** 16,26 **** Contributor(s): ! Last Modified: 2004-05-20 ! ! You may retrieve the latest version of this file at the Project JEDI's JWFL home page, located at ! http://jwfl.sourceforge.net Known Issues: ---------------------------------------------------------------------------------------------------} unit Jedi.System; --- 16,25 ---- Contributor(s): ! You may retrieve the latest version of this file at the JEDI.NET home page, located at ! http://sf.net/projects/jedidotnet Known Issues: ---------------------------------------------------------------------------------------------------} + // $Id$ unit Jedi.System; *************** *** 28,76 **** {$REGION 'interface uses'} {$ENDREGION} ! {$REGION 'Inline collection editing attributes'} type ! { Provides info for collections that can be edited inline in a property grid. Requires the InlineCollectionEditor ! and InlineCollectionConverter (both located in Jedi.Windows.Forms.Design) to work. } ! [AttributeUsage(AttributeTargets.Class)] ! InlineCollectionAttribute = class abstract (Attribute) ! strict private ! _canAddItems: Boolean; ! _displayValue: string; ! _newItemName: string; ! public ! constructor Create; ! { Flag to indicate if items can be added. Defaults to True, but will be ignored for collection types that do ! not allow adding/deleting of items. } ! property CanAddItems: Boolean read _canAddItems write _canAddItems; ! { Name to display as the collection's value. If not specified, defaults to standard value for CollectionBase. } ! property DisplayValue: string read _displayValue write _displayValue; ! { Name to use for the 'new' item. When not specified, defaults to 'New'. Ignored if CanAddItems is False or the ! collection type does not allow items to be added. } ! property NewItemName: string read _newItemName write _newItemName; ! end; ! { Provides info for collections that can be edited inline in a property grid. Requires the InlineCollectionEditor ! and InlineCollectionConverter (both located in Jedi.Windows.Forms.Design) to work. } ! InlineListAttribute = class (InlineCollectionAttribute) ! strict private ! _itemType: System.Type; ! _nameMember: string; ! _scanForDefaultProperty: Boolean; ! _valueProperty: string; public ! constructor Create; ! { Item type to use for the 'new' item in the editor. If not specified, the collection type is scanned for an Item ! or Items property and use it's type instead. } ! property ItemType: System.Type read _itemType write _itemType; ! (* Name of the member that will provide the item's display name. If not specified, item names will be formatted as ! 'Item {0}'. *) ! property NameMember: string read _nameMember write _nameMember; ! { When set to True, specifies that each item type is scanned for the DefaultProperty attribute. } ! property ScanForDefaultProperty: Boolean read _scanForDefaultProperty write _scanForDefaultProperty; ! { Name of the primary property of an item. If ScanForDefaultProperty is set to True this property can be an empty ! string. } ! property ValueProperty: string read _valueProperty write _valueProperty; end; {$ENDREGION} --- 27,50 ---- {$REGION 'interface uses'} + uses + System.Collections, + System.ComponentModel; {$ENDREGION} ! {$REGION 'Attributes'} type ! AttributeArray = array of Attribute; ! type ! AttributeUtils = class (System.Object) ! strict protected ! class function IndexOf(attrList: ArrayList; attr: System.Object): Integer; static; ! class function OverrideAttrList(attrList, overrideList: ArrayList; mustExist: Boolean): ArrayList; static; public ! class function OverrideAttributes(attributes, overrides, replacements: AttributeArray): AttributeArray; ! overload; static; ! class function OverrideAttributes(attributes: AttributeCollection; overrides, ! replacements: AttributeArray): AttributeCollection; ! overload; static; end; {$ENDREGION} *************** *** 78,111 **** implementation ! {$REGION 'implementation uses'} ! uses ! System.Resources; ! {$ENDREGION} ! {$REGION 'InlineCollectionAttribute'} ! constructor InlineCollectionAttribute.Create; var ! rm: ResourceManager; begin ! inherited Create; ! rm := ResourceManager.Create('System', TypeOf(Uri).Module.Assembly); ! try ! _displayValue := rm.GetString('CollectionConverterText'); ! finally ! rm.Free; end; - _canAddItems := True; - _newItemName := '(new)'; end; - {$ENDREGION} ! {$REGION 'InlineListAttribute'} ! constructor InlineListAttribute.Create; begin ! inherited Create; ! _itemType := nil; ! _nameMember := ''; ! _scanForDefaultProperty := True; ! _valueProperty := ''; end; {$ENDREGION} --- 52,123 ---- implementation ! {$REGION 'AttributeUtils'} ! class function AttributeUtils.IndexOf(attrList: ArrayList; attr: System.Object): Integer; ! var ! attrType: System.Type; ! begin ! if attr is System.Type then ! attrType := System.Type(attr) ! else ! attrType := attr.GetType; ! Result := attrList.Count - 1; ! while (Result >= 0) and not attrType.IsAssignableFrom(attrList[Result].GetType) do ! Dec(Result); ! end; ! class function AttributeUtils.OverrideAttrList(attrList, overrideList: ArrayList; mustExist: Boolean): ArrayList; var ! i: Integer; ! attrIndex: Integer; begin ! Result := attrList; ! for i := 0 to overrideList.Count - 1 do ! begin ! attrIndex := AttributeUtils.IndexOf(Result, overrideList[i]); ! if attrIndex > -1 then ! Result[attrIndex] := overrideList[i] ! else ! if not mustExist then ! Result.Add(overrideList[i]); end; end; ! class function AttributeUtils.OverrideAttributes(attributes, overrides, replacements: AttributeArray): AttributeArray; ! var ! attrList: ArrayList; ! overrideList: ArrayList; ! replaceList: ArrayList; begin ! attrList := ArrayList.Create(System.Array(attributes)); ! if Assigned(overrides) then ! overrideList := ArrayList.Create(System.Array(overrides)) ! else ! overrideList := ArrayList.Create; ! if Assigned(replacements) then ! replaceList := ArrayList.Create(System.Array(replacements)) ! else ! replaceList := ArrayList.Create; ! Result := AttributeArray(OverrideAttrList(OverrideAttrList(attrList, replaceList, True), overrideList, ! False).ToArray(TypeOf(Attribute))); ! end; ! ! class function AttributeUtils.OverrideAttributes(attributes: AttributeCollection; overrides, ! replacements: AttributeArray): AttributeCollection; ! var ! attrList: ArrayList; ! overrideList: ArrayList; ! replaceList: ArrayList; ! begin ! attrList := ArrayList.Create(attributes); ! if Assigned(overrides) then ! overrideList := ArrayList.Create(System.Array(overrides)) ! else ! overrideList := ArrayList.Create; ! if Assigned(replacements) then ! replaceList := ArrayList.Create(System.Array(replacements)) ! else ! replaceList := ArrayList.Create; ! Result := AttributeCollection.Create(AttributeArray(OverrideAttrList(OverrideAttrList(attrList, replaceList, True), ! overrideList, False).ToArray(TypeOf(Attribute)))); end; {$ENDREGION} Index: Jedi.Collections.pas =================================================================== RCS file: /cvsroot/jedidotnet/dev/jedi_mbe/run/Jedi.Collections.pas,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Jedi.Collections.pas 12 Jun 2004 18:31:38 -0000 1.1 --- Jedi.Collections.pas 15 Jun 2004 19:32:44 -0000 1.2 *************** *** 8,12 **** limitations under the License. ! The Original Code is: Jedi.Collections.pas, released on 2004-06-12. The Initial Developer of the Original Code is Marcel Bestebroer --- 8,12 ---- limitations under the License. ! The Original Code is: Jedi.Collections.pas, released on 2004-06-13. The Initial Developer of the Original Code is Marcel Bestebroer *************** *** 16,21 **** Contributor(s): ! You may retrieve the latest version of this file at the Project JEDI's JWFL home page, located at ! http://jwfl.sourceforge.net Known Issues: --- 16,21 ---- Contributor(s): ! You may retrieve the latest version of this file at the JEDI.NET home page, located at ! http://sf.net/projects/jedidotnet Known Issues: *************** *** 28,31 **** --- 28,32 ---- {$REGION 'interface uses'} uses + Jedi.System, System.Collections, System.Collections.Specialized, *************** *** 36,42 **** {$ENDREGION} - type - AttributeArray = array of Attribute; - {$REGION 'Inline collection editing'} type --- 37,40 ---- *************** *** 71,74 **** --- 69,74 ---- IInlineCollection = interface + { determine if the specified key can be removed } + function GetAllowRemove(key: System.Object): Boolean; { string to show in the property grid for the collection itself. } function GetCollectionValue: string; *************** *** 113,116 **** --- 113,117 ---- {$REGION 'IInlineCollection methods'} procedure AddItem(value: System.Object; addPropertyId: System.Object); virtual; + function GetAllowRemove(key: System.Object): Boolean; virtual; function GetCollectionValue: string; virtual; function GetNewItemProperties: PropertyDescriptorCollection; virtual; *************** *** 132,135 **** --- 133,137 ---- {$REGION 'IInlineCollection methods'} procedure AddItem(value: System.Object; addPropertyId: System.Object); virtual; + function GetAllowRemove(key: System.Object): Boolean; virtual; function GetCollectionValue: string; virtual; function GetNewItemProperties: PropertyDescriptorCollection; virtual; *************** *** 170,187 **** constructor SimplePropertyDescriptor.Create(componentType: System.Type; name: string; propertyType: System.Type; attributes: AttributeArray); - var - i: Integer; begin ! i := High(attributes); ! while (i >= 0) and not TypeOf(RefreshPropertiesAttribute).IsAssignableFrom(attributes[i].GetType) do ! Dec(i); ! if i >= 0 then ! attributes[i] := RefreshPropertiesAttribute.All ! else ! begin ! SetLength(attributes, Length(attributes) + 1); ! attributes[High(attributes)] := RefreshPropertiesAttribute.All; ! end; ! inherited Create(name, attributes); _componentType := componentType; _propertyType := propertyType; --- 172,178 ---- constructor SimplePropertyDescriptor.Create(componentType: System.Type; name: string; propertyType: System.Type; attributes: AttributeArray); begin ! inherited Create(name, AttributeUtils.OverrideAttributes(attributes, ! Jedi.System.AttributeArray.Create(RefreshPropertiesAttribute.All), nil)); _componentType := componentType; _propertyType := propertyType; *************** *** 263,269 **** _emptyValue: System.Object; _index: System.Object; strict protected property EmptyValue: System.Object read _emptyValue; ! property Index: System.Object read _index; public constructor Create(componentType: System.Type; name: string; propertyType: System.Type; attributes: AttributeArray; --- 254,262 ---- _emptyValue: System.Object; _index: System.Object; + _savedInstance: System.Object; strict protected property EmptyValue: System.Object read _emptyValue; ! property Index: System.Object read _index write _index; ! property SavedInstance: System.Object read _savedInstance write _savedInstance; public constructor Create(componentType: System.Type; name: string; propertyType: System.Type; attributes: AttributeArray; *************** *** 272,292 **** procedure SetValue(component, value: System.Object); override; function ItemInstance(component: System.Object): System.Object; end; - function ItemPropertyDescriptor.ItemInstance(component: System.Object): System.Object; - begin - if component is IList then - Result := IList(component).Item[Integer(_index)] - else - if component is IDictionary then - Result := IDictionary(component).Item[_index] - else - Result := nil; - end; - constructor ItemPropertyDescriptor.Create(componentType: System.Type; name: string; propertyType: System.Type; attributes: AttributeArray; emptyValue: System.Object; index: System.Object); begin ! inherited Create(componentType, name, propertyType, attributes); _emptyValue := emptyValue; _index := index; --- 265,276 ---- procedure SetValue(component, value: System.Object); override; function ItemInstance(component: System.Object): System.Object; + function get_Attributes: AttributeCollection; override; end; constructor ItemPropertyDescriptor.Create(componentType: System.Type; name: string; propertyType: System.Type; attributes: AttributeArray; emptyValue: System.Object; index: System.Object); begin ! inherited Create(componentType, name, propertyType, AttributeUtils.OverrideAttributes(attributes, ! Jedi.System.AttributeArray.Create(RefreshPropertiesAttribute.All), nil)); _emptyValue := emptyValue; _index := index; *************** *** 306,315 **** if value = _emptyValue then begin ! ccs := IComponentChangeService(IInlineCollection(component).GetService(TypeOf(IComponentChangeService))); ! if Assigned(ccs) then ! ccs.OnComponentChanging(component, nil); ! IList(component).RemoveAt(Integer(_index)); ! if Assigned(ccs) then ! ccs.OnComponentChanged(component, nil, nil, nil); end else --- 290,304 ---- if value = _emptyValue then begin ! if IInlineCollection(component).GetAllowRemove(_index) then ! begin ! ccs := IComponentChangeService(IInlineCollection(component).GetService(TypeOf(IComponentChangeService))); ! if Assigned(ccs) then ! ccs.OnComponentChanging(component, nil); ! _savedInstance := ItemInstance(component); ! IList(component).RemoveAt(Integer(_index)); ! _index := -1; ! if Assigned(ccs) then ! ccs.OnComponentChanged(component, nil, nil, nil); ! end; end else *************** *** 321,330 **** if value = _emptyValue then begin ! ccs := IComponentChangeService(IInlineCollection(component).GetService(TypeOf(IComponentChangeService))); ! if Assigned(ccs) then ! ccs.OnComponentChanging(component, nil); ! IDictionary(component).Remove(_index); ! if Assigned(ccs) then ! ccs.OnComponentChanged(component, nil, nil, nil); end else --- 310,324 ---- if value = _emptyValue then begin ! if IInlineCollection(component).GetAllowRemove(_index) then ! begin ! ccs := IComponentChangeService(IInlineCollection(component).GetService(TypeOf(IComponentChangeService))); ! if Assigned(ccs) then ! ccs.OnComponentChanging(component, nil); ! _savedInstance := ItemInstance(component); ! IDictionary(component).Remove(_index); ! _index := nil; ! if Assigned(ccs) then ! ccs.OnComponentChanged(component, nil, nil, nil); ! end; end else *************** *** 332,335 **** --- 326,358 ---- end; end; + + function ItemPropertyDescriptor.ItemInstance(component: System.Object): System.Object; + begin + if (component is IList) then + begin + if not Assigned(SavedInstance) then + Result := IList(component).Item[Integer(_index)] + else + Result := SavedInstance; + end + else + if (component is IDictionary) then + begin + if Assigned(_index) then + Result := IDictionary(component).Item[_index] + else + Result := SavedInstance; + end + else + Result := SavedInstance; + end; + + function ItemPropertyDescriptor.get_Attributes: AttributeCollection; + begin + Result := inherited get_Attributes; + if Assigned(SavedInstance) then + Result := AttributeUtils.OverrideAttributes(Result, + Jedi.System.AttributeArray.Create(RefreshPropertiesAttribute.All), nil); + end; {$ENDREGION} *************** *** 352,357 **** end; {$REGION 'SubPropertyTypeConverter'} ! (*type SubPropertyTypeConverter = class (TypeConverter) strict private --- 375,480 ---- end; + {$REGION 'SubPropertyContext'} + type + SubPropertyContext = class (System.Object, ITypeDescriptorContext) + strict private + _container: IContainer; + _instance: System.Object; + _propertyDescriptor: PropertyDescriptor; + _serviceProvider: IServiceProvider; + public + constructor Create(container: IContainer; instance: System.Object; propertyDescriptor: PropertyDescriptor; + serviceProvider: IServiceProvider); overload; + constructor Create(context: ITypeDescriptorContext); overload; + constructor Create(context: ITypeDescriptorContext; provider: IServiceProvider); overload; + procedure OnComponentChanged; + function OnComponentChanging: Boolean; + function get_Container: IContainer; + function get_Instance: System.Object; + function get_PropertyDescriptor: PropertyDescriptor; + function GetService(serviceType: System.Type): System.Object; + end; + + constructor SubPropertyContext.Create(container: IContainer; instance: System.Object; + propertyDescriptor: PropertyDescriptor; serviceProvider: IServiceProvider); + begin + inherited Create; + _container := container; + _instance := instance; + _propertyDescriptor := propertyDescriptor; + _serviceProvider := serviceProvider; + end; + + constructor SubPropertyContext.Create(context: ITypeDescriptorContext); + begin + if Assigned(context) and Assigned(ItemSubPropertyDescriptor(context.PropertyDescriptor)) then + Create( + context.Container, + ItemSubPropertyDescriptor(context.PropertyDescriptor).ItemInstance(context.Instance), + ItemSubPropertyDescriptor(context.PropertyDescriptor).RealDescriptor, + IServiceProvider(context) + ) + else + Create(nil, nil, nil, nil); + end; + + constructor SubPropertyContext.Create(context: ITypeDescriptorContext; provider: IServiceProvider); + begin + if Assigned(context) and Assigned(ItemSubPropertyDescriptor(context.PropertyDescriptor)) then + Create( + context.Container, + ItemSubPropertyDescriptor(context.PropertyDescriptor).ItemInstance(context.Instance), + ItemSubPropertyDescriptor(context.PropertyDescriptor).RealDescriptor, + provider + ) + else + Create(nil, nil, nil, nil); + end; + + procedure SubPropertyContext.OnComponentChanged; + var + ccs: IComponentChangeService; + begin + ccs := GetService(TypeOf(IComponentChangeService)); + if Assigned(ccs) then + ccs.OnComponentChanged(_instance, nil, nil, nil); + end; + + function SubPropertyContext.OnComponentChanging: Boolean; + var + ccs: IComponentChangeService; + begin + Result := True; + ccs := GetService(TypeOf(IComponentChangeService)); + if Assigned(ccs) then + ccs.OnComponentChanging(_instance, nil); + end; + + function SubPropertyContext.get_Container: IContainer; + begin + Result := _container; + end; + + function SubPropertyContext.get_Instance: System.Object; + begin + Result := _instance; + end; + + function SubPropertyContext.get_PropertyDescriptor: PropertyDescriptor; + begin + Result := _propertyDescriptor; + end; + + function SubPropertyContext.GetService(serviceType: System.Type): System.Object; + begin + if Assigned(_serviceProvider) then + Result := _serviceProvider.GetService(serviceType) + else + Result := nil; + end; + {$ENDREGION} + {$REGION 'SubPropertyTypeConverter'} ! type SubPropertyTypeConverter = class (TypeConverter) strict private *************** *** 378,382 **** function SubPropertyTypeConverter.PropertyConverter(context: ITypeDescriptorContext): TypeConverter; begin ! if not Assigned(_propertyConverter) and Assigned(context) and Assigned(context.PropertyDescriptor) then _propertyConverter := ItemSubPropertyDescriptor(context.PropertyDescriptor).RealDescriptor.Converter; Result := _propertyConverter; --- 501,506 ---- function SubPropertyTypeConverter.PropertyConverter(context: ITypeDescriptorContext): TypeConverter; begin ! if not Assigned(_propertyConverter) and Assigned(context) and ! Assigned(ItemSubPropertyDescriptor(context.PropertyDescriptor)) then _propertyConverter := ItemSubPropertyDescriptor(context.PropertyDescriptor).RealDescriptor.Converter; Result := _propertyConverter; *************** *** 385,389 **** function SubPropertyTypeConverter.InstanceConverter(context: ITypeDescriptorContext): TypeConverter; begin ! if not Assigned(_instanceConverter) and Assigned(context) and Assigned(context.PropertyDescriptor) then _instanceConverter := TypeDescriptor.GetConverter(ItemSubPropertyDescriptor( context.PropertyDescriptor).ItemInstance(context.Instance)); --- 509,514 ---- function SubPropertyTypeConverter.InstanceConverter(context: ITypeDescriptorContext): TypeConverter; begin ! if not Assigned(_instanceConverter) and Assigned(context) and ! Assigned(ItemSubPropertyDescriptor(context.PropertyDescriptor)) then _instanceConverter := TypeDescriptor.GetConverter(ItemSubPropertyDescriptor( context.PropertyDescriptor).ItemInstance(context.Instance)); *************** *** 394,398 **** begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.CanConvertFrom(context, sourceType) else Result := inherited CanConvertFrom(context, sourceType); --- 519,523 ---- begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.CanConvertFrom(SubPropertyContext.Create(context), sourceType) else Result := inherited CanConvertFrom(context, sourceType); *************** *** 402,406 **** begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.CanConvertTo(context, destinationType) else Result := inherited CanConvertTo(context, destinationType); --- 527,531 ---- begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.CanConvertTo(SubPropertyContext.Create(context), destinationType) else Result := inherited CanConvertTo(context, destinationType); *************** *** 411,415 **** begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.ConvertFrom(context, culture, value) else Result := inherited ConvertFrom(context, culture, value); --- 536,543 ---- begin if Assigned(PropertyConverter(context)) then ! begin ! Result := ItemSubPropertyDescriptor(context.PropertyDescriptor).ItemInstance(context.Instance); ! Result := _propertyConverter.ConvertFrom(SubPropertyContext.Create(context), culture, value); ! end else Result := inherited ConvertFrom(context, culture, value); *************** *** 418,424 **** function SubPropertyTypeConverter.ConvertTo(context: ITypeDescriptorContext; culture: CultureInfo; value: System.Object; destinationType: System.Type): System.Object; begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.ConvertTo(context, culture, value, destinationType) else Result := inherited ConvertTo(context, culture, value, destinationType); --- 546,559 ---- function SubPropertyTypeConverter.ConvertTo(context: ITypeDescriptorContext; culture: CultureInfo; value: System.Object; destinationType: System.Type): System.Object; + var + pd: PropertyDescriptor; + propValue: System.Object; begin if Assigned(PropertyConverter(context)) then ! begin ! pd := ItemSubPropertyDescriptor(context.PropertyDescriptor).RealDescriptor; ! propValue := pd.GetValue(ItemSubPropertyDescriptor(context.PropertyDescriptor).ItemInstance(context.Instance)); ! Result := _propertyConverter.ConvertTo(SubPropertyContext.Create(context), culture, propValue, destinationType); ! end else Result := inherited ConvertTo(context, culture, value, destinationType); *************** *** 429,433 **** begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.CreateInstance(context, propertyValues) else Result := inherited CreateInstance(context, propertyValues); --- 564,568 ---- begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.CreateInstance(SubPropertyContext.Create(context), propertyValues) else Result := inherited CreateInstance(context, propertyValues); *************** *** 437,441 **** begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.GetCreateInstanceSupported(context) else Result := inherited GetCreateInstanceSupported(context); --- 572,576 ---- begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.GetCreateInstanceSupported(SubPropertyContext.Create(context)) else Result := inherited GetCreateInstanceSupported(context); *************** *** 445,482 **** attributes: AttributeArray): PropertyDescriptorCollection; var - propPropColl: PropertyDescriptorCollection; itemInst: System.Object; - instPropColl: PropertyDescriptorCollection; begin - if Assigned(value) then - propPropColl := TypeDescriptor.GetProperties(value, attributes) - else - if Assigned(context) and Assigned(context.PropertyDescriptor) then - propPropColl := TypeDescriptor.GetProperties(context.PropertyDescriptor.PropertyType, attributes) - else - propPropColl := PropertyDescriptorCollection.Empty; - if Assigned(context) and Assigned(context.PropertyDescriptor) and Assigned(context.Instance) then begin itemInst := ItemPropertyDescriptor(context.PropertyDescriptor).ItemInstance(context.Instance); if Assigned(itemInst) then ! instPropColl := TypeDescriptor.GetProperties(itemInst, attributes) else ! instPropColl := PropertyDescriptorCollection.Empty; end else begin itemInst := nil; ! instPropColl := PropertyDescriptorCollection.Empty; end; - - if Assigned(context) and Assigned(ItemSubPropertyDescriptor(context.PropertyDescriptor)) then - instPropColl.Remove(ItemSubPropertyDescriptor(context.PropertyDescriptor).RealDescriptor); end; function SubPropertyTypeConverter.GetPropertiesSupported(context: ITypeDescriptorContext): Boolean; begin ! Result := (Assigned(PropertyConverter(context)) and _propertyConverter.GetPropertiesSupported(context)) or ! ((Assigned(InstanceConverter(context)) and _instanceConverter.GetPropertiesSupported(context))); end; --- 580,603 ---- attributes: AttributeArray): PropertyDescriptorCollection; var itemInst: System.Object; begin if Assigned(context) and Assigned(context.PropertyDescriptor) and Assigned(context.Instance) then begin itemInst := ItemPropertyDescriptor(context.PropertyDescriptor).ItemInstance(context.Instance); if Assigned(itemInst) then ! Result := TypeDescriptor.GetProperties(itemInst, attributes) else ! Result := PropertyDescriptorCollection.Empty; end else begin itemInst := nil; ! Result := PropertyDescriptorCollection.Empty; end; end; function SubPropertyTypeConverter.GetPropertiesSupported(context: ITypeDescriptorContext): Boolean; begin ! Result := Assigned(InstanceConverter(context)) and _instanceConverter.GetPropertiesSupported(context); end; *************** *** 485,489 **** begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.GetStandardValues(context) else Result := inherited GetStandardValues(context); --- 606,610 ---- begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.GetStandardValues(SubPropertyContext.Create(context)) else Result := inherited GetStandardValues(context); *************** *** 493,499 **** begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.GetStandardValuesExclusive(context) else ! Result := inherited GetStandardValuesExclusive(context); end; --- 614,620 ---- begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.GetStandardValuesExclusive(SubPropertyContext.Create(context)) else ! Result := inherited GetStandardValuesExclusive(SubPropertyContext(context)); end; *************** *** 501,505 **** begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.GetStandardValuesSupported(context) else Result := inherited GetStandardValuesSupported(context); --- 622,626 ---- begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.GetStandardValuesSupported(SubPropertyContext.Create(context)) else Result := inherited GetStandardValuesSupported(context); *************** *** 509,516 **** begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.IsValid(context, value) else Result := inherited IsValid(context, value); ! end;*) {$ENDREGION} --- 630,708 ---- begin if Assigned(PropertyConverter(context)) then ! Result := _propertyConverter.IsValid(SubPropertyContext.Create(context), value) else Result := inherited IsValid(context, value); ! end; ! {$ENDREGION} ! ! {$REGION 'SubPropertyUITypeEditor'} ! type ! SubPropertyUITypeEditor = class (UITypeEditor) ! strict protected ! function GetEditor(context: ITypeDescriptorContext): UITypeEditor; ! public ! function EditValue(context: ITypeDescriptorContext; provider: IServiceProvider; value: System.Object): System.Object; override; ! function GetEditStyle(context: ITypeDescriptorContext): UITypeEditorEditStyle; override; ! function GetPaintValueSupported(context: ITypeDescriptorContext): Boolean; override; ! procedure PaintValue(e: PaintValueEventArgs); override; ! end; ! ! function SubPropertyUITypeEditor.GetEditor(context: ITypeDescriptorContext): UITypeEditor; ! begin ! if Assigned(context) and Assigned(context.PropertyDescriptor) then ! Result := UITypeEditor(context.PropertyDescriptor.GetEditor(TypeOf(UITypeEditor))) ! else ! Result := nil; ! end; ! ! function SubPropertyUITypeEditor.EditValue(context: ITypeDescriptorContext; provider: IServiceProvider; ! value: System.Object): System.Object; ! var ! realContext: ITypeDescriptorContext; ! begin ! realContext := SubPropertyContext.Create(context, provider); ! if Assigned(realContext.Instance) and Assigned(GetEditor(realContext)) then ! begin ! GetEditor(realContext).EditValue(realContext, provider, ! realContext.PropertyDescriptor.GetValue(realContext.instance)); ! Result := value; ! end ! else ! Result := inherited EditValue(context, provider, value); ! end; ! ! function SubPropertyUITypeEditor.GetEditStyle(context: ITypeDescriptorContext): UITypeEditorEditStyle; ! var ! realContext: ITypeDescriptorContext; ! begin ! realContext := SubPropertyContext.Create(context); ! if Assigned(realContext.Instance) and Assigned(GetEditor(realContext)) then ! Result := GetEditor(realContext).GetEditStyle(realContext) ! else ! Result := inherited GetEditStyle(context); ! end; ! ! function SubPropertyUITypeEditor.GetPaintValueSupported(context: ITypeDescriptorContext): Boolean; ! var ! realContext: ITypeDescriptorContext; ! begin ! realContext := SubPropertyContext.Create(context); ! if Assigned(realContext.Instance) and Assigned(GetEditor(realContext)) then ! Result := GetEditor(realContext).GetPaintValueSupported(realContext) ! else ! Result := inherited GetPaintValueSupported(context); ! end; ! ! procedure SubPropertyUITypeEditor.PaintValue(e: PaintValueEventArgs); ! var ! realContext: ITypeDescriptorContext; ! begin ! realContext := SubPropertyContext.Create(e.Context); ! if Assigned(realContext.Instance) and Assigned(GetEditor(realContext)) then ! GetEditor(realContext).PaintValue(PaintValueEventArgs.Create(realContext, ! realContext.PropertyDescriptor.GetValue(realContext.instance), e.Graphics, e.Bounds)) ! else ! inherited PaintValue(e); ! end; {$ENDREGION} *************** *** 518,538 **** &property: PropertyDescriptor; itemType: System.Type; emptyValue, index: System.Object); var ! attrs: ArrayList; ! i: Integer; begin if not Assigned(&property) then raise ArgumentNullException.Create('property'); - attrs := ArrayList.Create(&property.Attributes); if description <> '' then ! begin ! i := attrs.Count - 1; ! while (i >= 0) and (attrs.Item[i].GetType <> TypeOf(DescriptionAttribute)) do ! Dec(i); ! if i >= 0 then ! attrs.RemoveAt(i); ! attrs.Add(DescriptionAttribute.Create(description)); ! end; inherited Create(componentType, name, itemType, ! Jedi.Collections.AttributeArray(attrs.ToArray(TypeOf(Attribute))), emptyValue, index); _realDescriptor := &property; end; --- 710,738 ---- &property: PropertyDescriptor; itemType: System.Type; emptyValue, index: System.Object); var ! attrs: AttributeCollection; begin if not Assigned(&property) then raise ArgumentNullException.Create('property'); if description <> '' then ! attrs := AttributeUtils.OverrideAttributes(&property.Attributes, ! Jedi.System.AttributeArray.Create( ! DescriptionAttribute.Create(description), ! TypeConverterAttribute.Create(TypeOf(SubPropertyTypeConverter)) ! ), ! Jedi.System.AttributeArray.Create( ! EditorAttribute.Create(TypeOf(SubPropertyUITypeEditor), TypeOf(UITypeEditor)) ! ) ! ) ! else ! attrs := AttributeUtils.OverrideAttributes(&property.Attributes, ! Jedi.System.AttributeArray.Create( ! TypeConverterAttribute.Create(TypeOf(SubPropertyTypeConverter)) ! ), ! Jedi.System.AttributeArray.Create( ! EditorAttribute.Create(TypeOf(SubPropertyUITypeEditor), TypeOf(UITypeEditor)) ! ) ! ); inherited Create(componentType, name, itemType, ! Jedi.System.AttributeArray(ArrayList.Create(attrs).ToArray(TypeOf(Attribute))), emptyValue, index); _realDescriptor := &property; end; *************** *** 550,561 **** function ItemSubPropertyDescriptor.GetValue(component: System.Object): System.Object; - (*var - item: System.Object;*) begin Result := ItemInstance(component); - (*if Assigned(item) then - Result := RealDescriptor.GetValue(item) - else - Result := nil;*) end; --- 750,755 ---- *************** *** 580,604 **** var ccs: IComponentChangeService; - item: System.Object; begin ! ccs := IComponentChangeService(IInlineCollection(component).GetService(TypeOf(IComponentChangeService))); ! if Assigned(ccs) then ! ccs.OnComponentChanging(component, nil); ! if RealDescriptor.GetValue(Value) = EmptyValue then begin if component is IList then ! IList(component).RemoveAt(Integer(Index)) else if component is IDictionary then IDictionary(component).Remove(Index); ! end; ! (* else begin ! item := ItemInstance(component); ! if Assigned(item) then ! RealDescriptor.SetValue(item, value); ! end;*) ! if Assigned(ccs) then ! ccs.OnComponentChanged(component, nil, nil, nil); end; --- 774,814 ---- var ccs: IComponentChangeService; begin ! if (value = EmptyValue) and IInlineCollection(component).GetAllowRemove(Index) then begin if component is IList then ! begin ! ccs := IComponentChangeService(IInlineCollection(component).GetService(TypeOf(IComponentChangeService))); ! if Assigned(ccs) then ! ccs.OnComponentChanging(component, nil); ! SavedInstance := ItemInstance(component); ! IList(component).RemoveAt(Integer(Index)); ! Index := -1; ! if Assigned(ccs) then ! ccs.OnComponentChanged(component, nil, nil, nil); ! end else if component is IDictionary then + begin + ccs := IComponentChangeService(IInlineCollection(component).GetService(TypeOf(IComponentChangeService))); + if Assigned(ccs) then + ccs.OnComponentChanging(component, nil); + SavedInstance := ItemInstance(component); IDictionary(component).Remove(Index); ! Index := nil; ! if Assigned(ccs) then ! ccs.OnComponentChanged(component, nil, nil, nil); ! end; ! end ! else ! if (value <> EmptyValue) and (RealDescriptor.GetValue(ItemInstance(component)) <> value) then begin ! ccs := IComponentChangeService(IInlineCollection(component).GetService(TypeOf(IComponentChangeService))); ! if Assigned(ccs) then ! ccs.OnComponentChanging(component, nil); ! RealDescriptor.SetValue(ItemInstance(component), value); ! if Assigned(ccs) then ! ccs.OnComponentChanged(component, nil, nil, nil); ! end; end; *************** *** 676,693 **** class function InlineCollectionUtils.CreateNewItemProperty(componentType, propertyType: System.Type; attributes: AttributeArray; name, description: string; propertyId: System.Object): PropertyDescriptor; - var - attrs: ArrayList; - i: Integer; begin - attrs := ArrayList.Create; - for i := 0 to High(attributes) do - begin - if (description = '') or (attributes[i].GetType <> TypeOf(DescriptionAttribute)) then - attrs.Add(attributes[i]); - end; if description <> '' then ! attrs.Add(DescriptionAttribute.Create(description)); ! Result := NewItemPropertyDescriptor.Create(componentType, name, propertyType, ! AttributeArray(attrs.ToArray(TypeOf(Attribute))), propertyId); end; --- 886,894 ---- class function InlineCollectionUtils.CreateNewItemProperty(componentType, propertyType: System.Type; attributes: AttributeArray; name, description: string; propertyId: System.Object): PropertyDescriptor; begin if description <> '' then ! attributes := AttributeUtils.OverrideAttributes(attributes, ! AttributeArray.Create(DescriptionAttribute.Create(description)), nil); ! Result := NewItemPropertyDescriptor.Create(componentType, name, propertyType, attributes, propertyId); end; *************** *** 720,723 **** --- 921,931 ---- defaultProperty := TypeDescriptor.GetDefaultProperty(info.PropertyType); end + end + else + begin + if Assigned(itemInstance) then + itemType := itemInstance.GetType + else + itemType := info.PropertyType; end; *************** *** 731,738 **** for i := 0 to High(mattrs) do begin ! if mattrs[i].GetType <> TypeOf(DescriptionAttribute) then attrs.Add(mattrs[i]); end; ! attrs.Add(DescriptionAttribute.Create(description)); Result := ItemPropertyDescriptor.Create(info.DeclaringType, name, itemInstance.GetType, --- 939,947 ---- for i := 0 to High(mattrs) do begin ! if (description = '') or (mattrs[i].GetType <> TypeOf(DescriptionAttribute)) then attrs.Add(mattrs[i]); end; ! if description <> '' then ! attrs.Add(DescriptionAttribute.Create(description)); Result := ItemPropertyDescriptor.Create(info.DeclaringType, name, itemInstance.GetType, *************** *** 743,749 **** class function InlineCollectionUtils.CreateItemProperty(propertyType: System.Type; attributes: AttributeArray; component: System.Object; name, description: string; index, emptyValue: System.Object): PropertyDescriptor; - var - attrs: ArrayList; - i: Integer; begin if not Assigned(propertyType) then --- 952,955 ---- *************** *** 751,764 **** if not Assigned(component) then raise ArgumentNullException.Create('component'); - attrs := ArrayList.Create; - for i := 0 to High(attributes) do - begin - if (description = '') or (attributes[i].GetType <> TypeOf(DescriptionAttribute)) then - attrs.Add(attributes[i]); - end; if description <> '' then ! attrs.Add(DescriptionAttribute.Create(description)); ! Result := ItemPropertyDescriptor.Create(component.GetType, name, propertyType, ! AttributeArray(attrs.ToArray(TypeOf(Attribute))), emptyValue, index); end; {$ENDREGION} --- 957,964 ---- if not Assigned(component) then raise ArgumentNullException.Create('component'); if description <> '' then ! attributes := AttributeUtils.OverrideAttributes(attributes, ! AttributeArray.Create(DescriptionAttribute.Create(description)), nil); ! Result := ItemPropertyDescriptor.Create(component.GetType, name, propertyType, attributes, emptyValue, index); end; {$ENDREGION} *************** *** 876,879 **** --- 1076,1084 ---- end; + function InlineCollectionBase.GetAllowRemove(key: System.Object): Boolean; + begin + Result := True; + end; + function InlineCollectionBase.GetCollectionValue: string; begin *************** *** 924,927 **** --- 1129,1137 ---- end; + function InlineDictionaryBase.GetAllowRemove(key: System.Object): Boolean; + begin + Result := True; + end; + function InlineDictionaryBase.GetCollectionValue: string; begin |