[JEDI.NET-commits] main/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-24 20:06:42
|
Update of /cvsroot/jedidotnet/main/run In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2746/main/run Modified Files: Jedi.Collections.pas Jedi.System.pas Log Message: Removed AttributeUtils.OverrideAttributes and AttributeUtils.OverrideAttrList methods. replaced them with CombineAttributes methods that also allow specifying which operation to perform (Add, AddAndReplace, Delete or Replace). Index: Jedi.System.pas =================================================================== RCS file: /cvsroot/jedidotnet/main/run/Jedi.System.pas,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Jedi.System.pas 16 Jun 2004 14:29:53 -0000 1.1 --- Jedi.System.pas 24 Jun 2004 20:06:33 -0000 1.2 *************** *** 35,50 **** 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} --- 35,66 ---- type AttributeArray = array of Attribute; + AttributeCombineOperation = (Add, Replace, Delete, AddAndReplace); type AttributeUtils = class (System.Object) + strict private + {$HINTS OFF} + constructor Create; + {$HINTS ON} strict protected class function IndexOf(attrList: ArrayList; attr: System.Object): Integer; static; ! class function CombineAttributes(attributes1, attributes2: ArrayList; ! operation: AttributeCombineOperation): ArrayList; overload; static; public ! class function CombineAttributes(attributes1, attributes2: AttributeArray): AttributeArray; overload; static; ! class function CombineAttributes(attributes1, attributes2: AttributeArray; ! operation: AttributeCombineOperation): AttributeArray; overload; static; ! class function CombineAttributes(attributes1, attributes2: AttributeCollection): AttributeCollection; overload; static; + class function CombineAttributes(attributes1, attributes2: AttributeCollection; + operation: AttributeCombineOperation): AttributeCollection; overload; static; + class function CombineAttributes(attributes1: AttributeArray; + attributes2: AttributeCollection): AttributeArray; overload; static; + class function CombineAttributes(attributes1: AttributeArray; attributes2: AttributeCollection; + operation: AttributeCombineOperation): AttributeArray; overload; static; + class function CombineAttributes(attributes1: AttributeCollection; attributes2: + AttributeArray): AttributeCollection; overload; static; + class function CombineAttributes(attributes1: AttributeCollection; attributes2: AttributeArray; + operation: AttributeCombineOperation): AttributeCollection; overload; static; end; {$ENDREGION} *************** *** 53,56 **** --- 69,77 ---- {$REGION 'AttributeUtils'} + constructor AttributeUtils.Create; + begin + inherited Create; + end; + class function AttributeUtils.IndexOf(attrList: ArrayList; attr: System.Object): Integer; var *************** *** 66,123 **** 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} --- 87,164 ---- end; ! class function AttributeUtils.CombineAttributes(attributes1, attributes2: ArrayList; ! operation: AttributeCombineOperation): ArrayList; var ! index: Integer; attrIndex: Integer; begin ! Result := attributes1; ! for index := 0 to attributes2.Count - 1 do begin ! attrIndex := IndexOf(Result, attributes2[index]); if attrIndex > -1 then ! begin ! case operation of ! AddAndReplace, ! Replace: ! Result[attrIndex] := attributes2[index]; ! Delete: ! Result.RemoveAt(attrIndex); ! end; ! end else ! if (operation = Add) or (operation = AddAndReplace) then ! Result.Add(attributes2[index]); end; end; ! class function AttributeUtils.CombineAttributes(attributes1, attributes2: AttributeArray): AttributeArray; begin ! Result := CombineAttributes(attributes1, attributes2, AttributeCombineOperation.AddAndReplace); end; ! class function AttributeUtils.CombineAttributes(attributes1, attributes2: AttributeArray; ! operation: AttributeCombineOperation): AttributeArray; begin ! Result := AttributeArray(CombineAttributes(ArrayList.Create(&Array(attributes1)), ! ArrayList.Create(&Array(attributes2)), operation).ToArray(TypeOf(Attribute))); ! end; ! ! class function AttributeUtils.CombineAttributes(attributes1, attributes2: AttributeCollection): AttributeCollection; ! begin ! Result := CombineAttributes(attributes1, attributes2, AttributeCombineOperation.AddAndReplace); ! end; ! ! class function AttributeUtils.CombineAttributes(attributes1, attributes2: AttributeCollection; ! operation: AttributeCombineOperation): AttributeCollection; ! begin ! Result := AttributeCollection.Create(AttributeArray(CombineAttributes(ArrayList.Create(attributes1), ! ArrayList.Create(attributes2), operation).ToArray(TypeOf(Attribute)))); ! end; ! ! class function AttributeUtils.CombineAttributes(attributes1: AttributeArray; ! attributes2: AttributeCollection): AttributeArray; ! begin ! Result := CombineAttributes(attributes1, attributes2, AttributeCombineOperation.AddAndReplace); ! end; ! ! class function AttributeUtils.CombineAttributes(attributes1: AttributeArray; attributes2: AttributeCollection; ! operation: AttributeCombineOperation): AttributeArray; ! begin ! Result := AttributeArray(CombineAttributes(ArrayList.Create(&Array(attributes1)), ! ArrayList.Create(attributes2), operation).ToArray(TypeOf(Attribute))); ! end; ! ! class function AttributeUtils.CombineAttributes(attributes1: AttributeCollection; ! attributes2: AttributeArray): AttributeCollection; ! begin ! Result := CombineAttributes(attributes1, attributes2, AttributeCombineOperation.AddAndReplace); ! end; ! ! class function AttributeUtils.CombineAttributes(attributes1: AttributeCollection; ! attributes2: AttributeArray; operation: AttributeCombineOperation): AttributeCollection; ! begin ! Result := AttributeCollection.Create(AttributeArray(CombineAttributes(ArrayList.Create(attributes1), ! ArrayList.Create(&Array(attributes2)), operation).ToArray(TypeOf(Attribute)))); end; {$ENDREGION} Index: Jedi.Collections.pas =================================================================== RCS file: /cvsroot/jedidotnet/main/run/Jedi.Collections.pas,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Jedi.Collections.pas 16 Jun 2004 14:29:53 -0000 1.1 --- Jedi.Collections.pas 24 Jun 2004 20:06:33 -0000 1.2 *************** *** 169,174 **** attributes: AttributeArray); begin ! inherited Create(name, AttributeUtils.OverrideAttributes(attributes, ! Jedi.System.AttributeArray.Create(RefreshPropertiesAttribute.All), nil)); FComponentType := componentType; FPropertyType := propertyType; --- 169,174 ---- attributes: AttributeArray); begin ! inherited Create(name, AttributeUtils.CombineAttributes(attributes, ! Jedi.System.AttributeArray.Create(RefreshPropertiesAttribute.All))); FComponentType := componentType; FPropertyType := propertyType; *************** *** 267,272 **** attributes: AttributeArray; emptyValue: System.Object; index: System.Object); begin ! inherited Create(componentType, name, propertyType, AttributeUtils.OverrideAttributes(attributes, ! Jedi.System.AttributeArray.Create(RefreshPropertiesAttribute.All), nil)); FEmptyValue := emptyValue; FIndex := index; --- 267,272 ---- attributes: AttributeArray; emptyValue: System.Object; index: System.Object); begin ! inherited Create(componentType, name, propertyType, AttributeUtils.CombineAttributes(attributes, ! Jedi.System.AttributeArray.Create(RefreshPropertiesAttribute.All))); FEmptyValue := emptyValue; FIndex := index; *************** *** 277,282 **** Result := inherited get_Attributes; if Assigned(SavedInstance) then ! Result := AttributeUtils.OverrideAttributes(Result, ! Jedi.System.AttributeArray.Create(RefreshPropertiesAttribute.All), nil); end; --- 277,282 ---- Result := inherited get_Attributes; if Assigned(SavedInstance) then ! Result := AttributeUtils.CombineAttributes(Result, ! Jedi.System.AttributeArray.Create(RefreshPropertiesAttribute.All)); end; *************** *** 711,731 **** 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, --- 711,739 ---- raise ArgumentNullException.Create('property'); if description <> '' then ! attrs := AttributeUtils.CombineAttributes( ! AttributeUtils.CombineAttributes( ! &property.Attributes, ! Jedi.System.AttributeArray.Create( ! DescriptionAttribute.Create(description), ! TypeConverterAttribute.Create(TypeOf(SubPropertyTypeConverter)) ! ) ), Jedi.System.AttributeArray.Create( EditorAttribute.Create(TypeOf(SubPropertyUITypeEditor), TypeOf(UITypeEditor)) ! ), ! AttributeCombineOperation.AddAndReplace ) else ! attrs := AttributeUtils.CombineAttributes( ! AttributeUtils.CombineAttributes( ! &property.Attributes, ! Jedi.System.AttributeArray.Create( ! TypeConverterAttribute.Create(TypeOf(SubPropertyTypeConverter)) ! ) ), Jedi.System.AttributeArray.Create( EditorAttribute.Create(TypeOf(SubPropertyUITypeEditor), TypeOf(UITypeEditor)) ! ), ! AttributeCombineOperation.AddAndReplace ); inherited Create(componentType, name, itemType, *************** *** 913,918 **** 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; --- 921,926 ---- raise ArgumentNullException.Create('component'); if description <> '' then ! attributes := AttributeUtils.CombineAttributes(attributes, ! AttributeArray.Create(DescriptionAttribute.Create(description))); Result := ItemPropertyDescriptor.Create(component.GetType, name, propertyType, attributes, emptyValue, index); end; *************** *** 954,959 **** begin if description <> '' then ! attributes := AttributeUtils.OverrideAttributes(attributes, ! AttributeArray.Create(DescriptionAttribute.Create(description)), nil); Result := NewItemPropertyDescriptor.Create(componentType, name, propertyType, attributes, propertyId); end; --- 962,967 ---- begin if description <> '' then ! attributes := AttributeUtils.CombineAttributes(attributes, ! AttributeArray.Create(DescriptionAttribute.Create(description))); Result := NewItemPropertyDescriptor.Create(componentType, name, propertyType, attributes, propertyId); end; |