| @@ -93,7 +93,16 @@ type | |||
| destructor Destroy; override; | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| IutlFilterBuilder = interface['{BC5039C7-42E7-428F-A3E7-DDF7757B1907}'] | |||
| function Add(aDescr, aMask: string; const aAppendFilterToDesc: boolean = true): IutlFilterBuilder; | |||
| function AddFilter(aFilter: string): IutlFilterBuilder; | |||
| function Compose(const aIncludeAllSupported: String = ''; const aIncludeAllFiles: String = ''): string; | |||
| end; | |||
| function utlEventEqual(const aEvent1, aEvent2): Boolean; | |||
| function utlFilterBuilder: IutlFilterBuilder; | |||
| implementation | |||
| @@ -390,5 +399,106 @@ begin | |||
| inherited Destroy; | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| //IutlFilterBuilder/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| type | |||
| TFilterBuilderImpl = class(TInterfacedObject, IutlFilterBuilder) | |||
| private type | |||
| TFilterEntry = class | |||
| Descr, | |||
| Filter: String; | |||
| end; | |||
| TFilterList = specialize TutlList<TFilterEntry>; | |||
| private | |||
| fFilters: TFilterList; | |||
| public | |||
| constructor Create; | |||
| destructor Destroy; override; | |||
| function Add(aDescr, aMask: string; const aAppendFilterToDesc: boolean): IutlFilterBuilder; | |||
| function AddFilter(aFilter: string): IutlFilterBuilder; | |||
| function Compose(const aIncludeAllSupported: String = ''; const aIncludeAllFiles: String = ''): string; | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| constructor TFilterBuilderImpl.Create; | |||
| begin | |||
| inherited Create; | |||
| fFilters:= TFilterList.Create(true); | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| destructor TFilterBuilderImpl.Destroy; | |||
| begin | |||
| FreeAndNil(fFilters); | |||
| inherited Destroy; | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| function TFilterBuilderImpl.Compose(const aIncludeAllSupported: String; | |||
| const aIncludeAllFiles: String): string; | |||
| var | |||
| s: String; | |||
| e: TFilterEntry; | |||
| begin | |||
| Result:= ''; | |||
| if (aIncludeAllSupported>'') and (fFilters.Count > 0) then begin | |||
| s:= ''; | |||
| for e in fFilters do begin | |||
| if s>'' then | |||
| s += ';'; | |||
| s += e.Filter; | |||
| end; | |||
| Result+= Format('%s|%s', [aIncludeAllSupported, s, s]); | |||
| end; | |||
| for e in fFilters do begin | |||
| if Result>'' then | |||
| Result += '|'; | |||
| Result+= Format('%s|%s', [e.Descr, e.Filter]); | |||
| end; | |||
| if aIncludeAllFiles > '' then begin | |||
| if Result>'' then | |||
| Result += '|'; | |||
| Result+= Format('%s|%s', [aIncludeAllFiles, '*.*']); | |||
| end; | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| function TFilterBuilderImpl.Add(aDescr, aMask: string; | |||
| const aAppendFilterToDesc: boolean): IutlFilterBuilder; | |||
| var | |||
| e: TFilterEntry; | |||
| begin | |||
| Result:= Self; | |||
| e:= TFilterEntry.Create; | |||
| if aAppendFilterToDesc then | |||
| e.Descr:= Format('%s (%s)', [aDescr, aMask]) | |||
| else | |||
| e.Descr:= aDescr; | |||
| e.Filter:= aMask; | |||
| fFilters.Add(e); | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| function TFilterBuilderImpl.AddFilter(aFilter: string): IutlFilterBuilder; | |||
| var | |||
| c: integer; | |||
| begin | |||
| c:= Pos('|', aFilter); | |||
| if c > 0 then | |||
| Result:= (Self as IutlFilterBuilder).Add(Copy(aFilter, 1, c-1), Copy(aFilter, c+1, Maxint)) | |||
| else | |||
| Result:= (Self as IutlFilterBuilder).Add(aFilter, aFilter, false); | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| function utlFilterBuilder: IutlFilterBuilder; | |||
| begin | |||
| Result:= TFilterBuilderImpl.Create; | |||
| end; | |||
| end. | |||