Implements support for multiple masks separated by semi-comma in the shell controls. See bug #17222

git-svn-id: trunk@27576 -
This commit is contained in:
sekelsenmat 2010-10-04 15:09:03 +00:00
parent aac4168119
commit d291ed049d

View File

@ -383,7 +383,11 @@ end;
{ Helper routine. { Helper routine.
Finds all files/directories directly inside a directory. Finds all files/directories directly inside a directory.
Does not recurse inside subdirectories. } Does not recurse inside subdirectories.
AMask may contain multiple file masks separated by ;
Don't add a final ; after the last mask.
}
class procedure TCustomShellTreeView.GetFilesInDir(const ABaseDir: string; class procedure TCustomShellTreeView.GetFilesInDir(const ABaseDir: string;
AMask: string; AObjectTypes: TObjectTypes; AResult: TStrings; AFileSortType: TFileSortType); AMask: string; AObjectTypes: TObjectTypes; AResult: TStrings; AFileSortType: TFileSortType);
var var
@ -392,10 +396,11 @@ var
IsDirectory, IsValidDirectory, IsHidden, AddFile: Boolean; IsDirectory, IsValidDirectory, IsHidden, AddFile: Boolean;
ObjectData: TObject; ObjectData: TObject;
SearchStr: string; SearchStr: string;
MaskStr: string; CurMaskStr, MaskStr: string;
Files: TList; Files: TList;
FileItem: TFileItem; FileItem: TFileItem;
i: Integer; i: Integer;
MaskStrings: TStringList;
{$if defined(windows) and not defined(wince)} {$if defined(windows) and not defined(wince)}
ErrMode : LongWord; ErrMode : LongWord;
{$endif} {$endif}
@ -411,54 +416,67 @@ begin
if Trim(AMask) = '' then MaskStr := AllFilesMask if Trim(AMask) = '' then MaskStr := AllFilesMask
else MaskStr := AMask; else MaskStr := AMask;
if AFileSortType=fstNone then Files:=nil // The string list implements support for multiple masks separated
else Files:=TList.Create; // by semi-comma ";"
MaskStrings := TStringList.Create;
try
MaskStrings.Delimiter := ';';
MaskStrings.DelimitedText := MaskStr;
SearchStr := IncludeTrailingPathDelimiter(ABaseDir) + MaskStr; if AFileSortType=fstNone then Files:=nil
else Files:=TList.Create;
FindResult := FindFirstUTF8(SearchStr, faAnyFile, DirInfo); for i := 0 to MaskStrings.Count - 1 do
while FindResult = 0 do
begin
Application.ProcessMessages;
IsDirectory := (DirInfo.Attr and FaDirectory = FaDirectory);
IsValidDirectory := (DirInfo.Name <> '.') and (DirInfo.Name <> '..');
IsHidden := (DirInfo.Attr and faHidden = faHidden);
{$IFDEF Unix}
if (DirInfo.Name<>'') and (DirInfo.Name[1]='.') then
IsHidden:=true;
{$ENDIF}
// First check if we show hidden files
if IsHidden then AddFile := (otHidden in AObjectTypes)
else AddFile := True;
// If it is a directory, check if it is a valid one
if IsDirectory then
AddFile := AddFile and ((otFolders in AObjectTypes) and IsValidDirectory)
else
AddFile := AddFile and (otNonFolders in AObjectTypes);
// AddFile identifies if the file is valid or not
if AddFile then
begin begin
if not Assigned(Files) then begin SearchStr := IncludeTrailingPathDelimiter(ABaseDir) + MaskStrings.Strings[i];
// Mark if it is a directory (ObjectData <> nil)
if IsDirectory then ObjectData := AResult FindResult := FindFirstUTF8(SearchStr, faAnyFile, DirInfo);
else ObjectData := nil;
AResult.AddObject(DirInfo.Name, ObjectData) while FindResult = 0 do
end else begin
Files.Add ( TFileItem.Create(DirInfo)); Application.ProcessMessages;
IsDirectory := (DirInfo.Attr and FaDirectory = FaDirectory);
IsValidDirectory := (DirInfo.Name <> '.') and (DirInfo.Name <> '..');
IsHidden := (DirInfo.Attr and faHidden = faHidden);
{$IFDEF Unix}
if (DirInfo.Name<>'') and (DirInfo.Name[1]='.') then
IsHidden:=true;
{$ENDIF}
// First check if we show hidden files
if IsHidden then AddFile := (otHidden in AObjectTypes)
else AddFile := True;
// If it is a directory, check if it is a valid one
if IsDirectory then
AddFile := AddFile and ((otFolders in AObjectTypes) and IsValidDirectory)
else
AddFile := AddFile and (otNonFolders in AObjectTypes);
// AddFile identifies if the file is valid or not
if AddFile then
begin
if not Assigned(Files) then begin
// Mark if it is a directory (ObjectData <> nil)
if IsDirectory then ObjectData := AResult
else ObjectData := nil;
AResult.AddObject(DirInfo.Name, ObjectData)
end else
Files.Add ( TFileItem.Create(DirInfo));
end;
FindResult := FindNextUTF8(DirInfo);
end;
FindCloseUTF8(DirInfo);
end; end;
finally
FindResult := FindNextUTF8(DirInfo); MaskStrings.Free;
end; end;
FindCloseUTF8(DirInfo);
if Assigned(Files) then begin if Assigned(Files) then begin
Objectdata:=AResult; Objectdata:=AResult;