ShellCtrls: Speed up population of TShellListView by adding BeginUpdate/EndUpdate calls.

git-svn-id: trunk@64553 -
This commit is contained in:
wp 2021-02-12 15:04:54 +00:00
parent ad98b8ef31
commit b729025142

View File

@ -862,6 +862,7 @@ begin
if (csDesigning in ComponentState) then Exit; if (csDesigning in ComponentState) then Exit;
Files := TStringList.Create; Files := TStringList.Create;
Items.BeginUpdate;
try try
Files.OwnsObjects := True; Files.OwnsObjects := True;
GetFilesInDir(ANodePath, AllFilesMask, FObjectTypes, Files, FFileSortType); GetFilesInDir(ANodePath, AllFilesMask, FObjectTypes, Files, FFileSortType);
@ -886,6 +887,7 @@ begin
end; end;
finally finally
Files.Free; Files.Free;
Items.EndUpdate;
end; end;
end; end;
@ -899,22 +901,27 @@ var
begin begin
// avoids crashes in the IDE by not populating during design // avoids crashes in the IDE by not populating during design
if (csDesigning in ComponentState) then Exit; if (csDesigning in ComponentState) then Exit;
Items.Clear; Items.BeginUpdate;
r := GetLogicalDriveStrings(SizeOf(Drives), Drives); try
if r = 0 then Exit; Items.Clear;
if r > SizeOf(Drives) then Exit; r := GetLogicalDriveStrings(SizeOf(Drives), Drives);
// raise Exception.Create(SysErrorMessage(ERROR_OUTOFMEMORY)); if r = 0 then Exit;
pDrive := Drives; if r > SizeOf(Drives) then Exit;
while pDrive^ <> #0 do // raise Exception.Create(SysErrorMessage(ERROR_OUTOFMEMORY));
begin pDrive := Drives;
NewNode := Items.AddChildObject(nil, ExcludeTrailingBackslash(pDrive), pDrive); while pDrive^ <> #0 do
//Yes, we want to remove the backslash,so don't use ChompPathDelim here begin
TShellTreeNode(NewNode).FFileInfo.Name := ExcludeTrailingBackslash(pDrive); NewNode := Items.AddChildObject(nil, ExcludeTrailingBackslash(pDrive), pDrive);
//On NT platforms drive-roots really have these attributes //Yes, we want to remove the backslash,so don't use ChompPathDelim here
TShellTreeNode(NewNode).FFileInfo.Attr := faDirectory + faSysFile{%H-} + faHidden{%H-}; TShellTreeNode(NewNode).FFileInfo.Name := ExcludeTrailingBackslash(pDrive);
TShellTreeNode(NewNode).SetBasePath(''); //On NT platforms drive-roots really have these attributes
NewNode.HasChildren := True; TShellTreeNode(NewNode).FFileInfo.Attr := faDirectory + faSysFile{%H-} + faHidden{%H-};
Inc(pDrive, 4); TShellTreeNode(NewNode).SetBasePath('');
NewNode.HasChildren := True;
Inc(pDrive, 4);
end;
finally
Items.EndUpdate;
end; end;
end; end;
{$else} {$else}
@ -1409,9 +1416,14 @@ begin
and not DirectoryExistsUtf8(ExpandFilenameUtf8(Value)) then and not DirectoryExistsUtf8(ExpandFilenameUtf8(Value)) then
Raise EInvalidPath.CreateFmt(sShellCtrlsInvalidRoot,[Value]); Raise EInvalidPath.CreateFmt(sShellCtrlsInvalidRoot,[Value]);
FRoot := Value; FRoot := Value;
Clear; BeginUpdate;
Items.Clear; try
PopulateWithRoot(); Clear;
Items.Clear;
PopulateWithRoot();
finally
EndUpdate;
end;
end; end;
end; end;
@ -1455,6 +1467,7 @@ begin
// Check inputs // Check inputs
if Trim(FRoot) = '' then Exit; if Trim(FRoot) = '' then Exit;
Items.BeginUpdate;
Files := TStringList.Create; Files := TStringList.Create;
try try
Files.OwnsObjects := True; Files.OwnsObjects := True;
@ -1489,6 +1502,7 @@ begin
Sort; Sort;
finally finally
Files.Free; Files.Free;
Items.EndUpdate;
end; end;
end; end;