mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-05 09:58:06 +02:00
LCL/ShellTreeView: Fix error when clicking a non-default root node in sorted ShellTreeView. Issue #41373.
This commit is contained in:
parent
3cc1bc02fb
commit
d11d9793b2
@ -89,6 +89,7 @@ type
|
||||
FUseBuiltinIcons: Boolean;
|
||||
FOnAddItem: TAddItemEvent;
|
||||
FOnSortCompare: TFileItemCompareEvent;
|
||||
function CreateRootNode(const APath: String): TTreeNode;
|
||||
{ Setters and getters }
|
||||
function GetPath: string;
|
||||
procedure SetFileSortType(const AValue: TFileSortType);
|
||||
@ -600,6 +601,19 @@ begin
|
||||
Raise EShellCtrl.Create(sShellTreeViewIncorrectNodeType);
|
||||
end;
|
||||
|
||||
function TCustomShellTreeView.CreateRootNode(const APath: string): TTreeNode;
|
||||
var
|
||||
dirInfo: TSearchRec;
|
||||
begin
|
||||
Result := Items.AddChild(nil, APath);
|
||||
TShellTreeNode(Result).SetBasePath('');
|
||||
FindFirstUTF8(APath, faAnyFile, dirInfo);
|
||||
TShellTreeNode(Result).FFileInfo := dirInfo;
|
||||
FindCloseUTF8(dirInfo);
|
||||
Result.HasChildren := True;
|
||||
Result.Expand(False);
|
||||
end;
|
||||
|
||||
procedure TCustomShellTreeView.SetRoot(const AValue: string);
|
||||
var
|
||||
RootNode: TTreeNode;
|
||||
@ -630,12 +644,7 @@ begin
|
||||
//Make FRoot contain fully qualified pathname, we need it later in GetPathFromNode()
|
||||
FRoot := ExpandFileNameUtf8(FRoot);
|
||||
//Set RootNode.Text to AValue so user can choose if text is fully qualified path or not
|
||||
RootNode := Items.AddChild(nil, AValue);
|
||||
TShellTreeNode(RootNode).FFileInfo.Attr := FileGetAttr(FRoot);
|
||||
TShellTreeNode(RootNode).FFileInfo.Name := FRoot;
|
||||
TShellTreeNode(RootNode).SetBasePath('');
|
||||
RootNode.HasChildren := True;
|
||||
RootNode.Expand(False);
|
||||
RootNode := CreateRootNode(AValue);
|
||||
end;
|
||||
if Assigned(ShellListView) then
|
||||
ShellListView.Root := FRoot;
|
||||
@ -659,9 +668,7 @@ begin
|
||||
PopulateWithBaseFiles()
|
||||
else
|
||||
begin
|
||||
RootNode := Items.AddChild(nil, FRoot);
|
||||
RootNode.HasChildren := True;
|
||||
RootNode.Expand(False);
|
||||
RootNode := CreateRootNode(FRoot);
|
||||
if ExistsAndIsValid(CurrPath) then
|
||||
SetPath(CurrPath);
|
||||
end;
|
||||
@ -710,9 +717,7 @@ begin
|
||||
PopulateWithBaseFiles()
|
||||
else
|
||||
begin
|
||||
RootNode := Items.AddChild(nil, FRoot);
|
||||
RootNode.HasChildren := True;
|
||||
RootNode.Expand(False);
|
||||
RootNode := CreateRootNode(FRoot);
|
||||
if ExistsAndIsValid(Currpath) then
|
||||
SetPath(CurrPath);
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user