Skip to content

Commit

Permalink
Ensure selected item in Filelist Listview is visible in Directory Tr…
Browse files Browse the repository at this point in the history
…eeview

 #558
  • Loading branch information
FrankBijnen committed Sep 14, 2024
1 parent dc43e87 commit 97fbb87
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Source/Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ TFMain = class(TScaleForm)
procedure ShellListMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
procedure CounterETEvent(Counter: integer);
procedure ResetRootShowAll;
function SyncShellTree: TTreenode;
protected
function GetDefWindowSizes: TRect; override;
public
Expand Down Expand Up @@ -451,6 +452,45 @@ function TFMain.GetFormOffset(AddFileList: boolean = true): TPoint;
result.Y := result.Y + AdvPageFilelist.Top;
end;

// Make the path, from the selected file in the FileList, visible in the Directory Treeview
// Notes: Without selecting. That would refresh the ShellList
// Especially useful when subdirs are shown
function TFMain.SyncShellTree: TTreenode;
var
NewNode: TTreenode;
APath: string;
ASub: string;
ASubPath: string;
begin
result := ShellTree.Items[0];
if (ShellList.IncludeSubFolders = false) then
exit;
if (ShellList.SelectedFolder = nil) then
exit;

APath := ExtractFilePath(ShellList.SelectedFolder.PathName);
// Break-up Path in pieces, and find them in the treeview.
// Expand, if needed
// MakeVisible
ASubPath := '';
while (APath <> '') do
begin
ASub := NextField(APath, PathDelim);
ASubPath := ASubPath + ASub + PathDelim;
NewNode := ShellTree.NodeFromPath(result, ASubPath);
if (NewNode = nil) then
continue;

result := NewNode;
if (result <> nil) and
(result.Expanded = false) then
result.Expand(false);

end;

result.MakeVisible;
end;

procedure TFMain.ResetRootShowAll;
begin
ShellList.Enabled := false;
Expand Down Expand Up @@ -2781,6 +2821,8 @@ procedure TFMain.ShellListClick(Sender: TObject);
SpeedBtnQuickSave.Enabled := false;

EnableMenuItems;

SyncShellTree;
end;

procedure TFMain.ShellListColumnClick(Sender: TObject; Column: TListColumn);
Expand Down

0 comments on commit 97fbb87

Please sign in to comment.