Skip to content

Commit 98b796b

Browse files
committed
feat: support click on path parts on top label of file dialog
Refs #2268
1 parent fe65231 commit 98b796b

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

source/extfiledialog.lfm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,18 @@ object frmExtFileDialog: TfrmExtFileDialog
206206
OnSelectItem = ShellListViewSelectItem
207207
end
208208
object lblPath: TLabel
209+
Cursor = crHandPoint
209210
Left = 10
210211
Height = 20
211212
Top = 10
212213
Width = 852
213214
Align = alTop
214215
BorderSpacing.Around = 10
215216
Caption = 'lblPath'
217+
ParentShowHint = False
218+
ShowHint = True
219+
OnClick = lblPathClick
220+
OnMouseDown = lblPathMouseDown
221+
OnMouseMove = lblPathMouseMove
216222
end
217223
end

source/extfiledialog.pas

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ TfrmExtFileDialog = class(TExtForm)
3434
procedure FormCreate(Sender: TObject);
3535
procedure FormDestroy(Sender: TObject);
3636
procedure FormShow(Sender: TObject);
37+
procedure lblPathClick(Sender: TObject);
38+
procedure lblPathMouseDown(Sender: TObject; Button: TMouseButton;
39+
Shift: TShiftState; X, Y: Integer);
40+
procedure lblPathMouseMove(Sender: TObject; Shift: TShiftState; X,
41+
Y: Integer);
3742
procedure ShellListViewClick(Sender: TObject);
3843
procedure ShellListViewDblClick(Sender: TObject);
3944
procedure ShellListViewSelectItem(Sender: TObject; Item: TListItem;
@@ -53,11 +58,13 @@ TfrmExtFileDialog = class(TExtForm)
5358
FOptions: TOpenOptions;
5459
FFiles: TStringList;
5560
FOnTypeChange: TNotifyEvent;
61+
FClickedPathPart: String;
5662
procedure SetTitle(AValue: String);
5763
function GetFileName: String;
5864
procedure SetFileName(const AValue: String);
5965
procedure SetInitialDir(const AValue: String);
6066
procedure SetFilterIndex(AValue: Integer);
67+
function GetPathPartAt(X: Integer): String;
6168
public
6269
property OnTypeChange: TNotifyEvent read FOnTypeChange write FOnTypeChange;
6370
property Title: String write SetTitle;
@@ -156,6 +163,57 @@ procedure TfrmExtFileDialog.FormShow(Sender: TObject);
156163
comboLineBreaks.ItemIndex := LineBreakIndexInt;
157164
end;
158165

166+
procedure TfrmExtFileDialog.lblPathClick(Sender: TObject);
167+
begin
168+
if (not FClickedPathPart.IsEmpty) and DirectoryExists(FClickedPathPart) then begin
169+
if ofNoChangeDir in FOptions then
170+
ErrorDialog('You cannot change the directory in this context.')
171+
else
172+
ShellTreeView.Path := FClickedPathPart;
173+
end;
174+
end;
175+
176+
procedure TfrmExtFileDialog.lblPathMouseDown(Sender: TObject;
177+
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
178+
begin
179+
FClickedPathPart := GetPathPartAt(X);
180+
end;
181+
182+
function TfrmExtFileDialog.GetPathPartAt(X: Integer): String;
183+
var
184+
i, CharIndex, CurrentWidth: Integer;
185+
TextWidth: Integer;
186+
begin
187+
CharIndex := -1;
188+
CurrentWidth := 0;
189+
Result := '';
190+
191+
lblPath.Canvas.Font := lblPath.Font;
192+
for i := 1 to Length(lblPath.Caption) do
193+
begin
194+
TextWidth := lblPath.Canvas.TextWidth(Copy(lblPath.Caption, i, 1));
195+
if (X >= CurrentWidth) and (X < CurrentWidth + TextWidth) then
196+
begin
197+
CharIndex := i; // 1-based character index clicked
198+
Break;
199+
end;
200+
Inc(CurrentWidth, TextWidth);
201+
end;
202+
if CharIndex > 0 then begin
203+
for i:=CharIndex to Length(lblPath.Caption) do begin
204+
if Copy(lblPath.Caption, i, 1) = PathDelim then
205+
break;
206+
end;
207+
Result := Copy(lblPath.Caption, 1, i);
208+
end;
209+
end;
210+
211+
procedure TfrmExtFileDialog.lblPathMouseMove(Sender: TObject;
212+
Shift: TShiftState; X, Y: Integer);
213+
begin
214+
lblPath.Hint := GetPathPartAt(X);
215+
end;
216+
159217
procedure TfrmExtFileDialog.comboFileTypeChange(Sender: TObject);
160218
var
161219
FileMask: String;

0 commit comments

Comments
 (0)