@@ -6,7 +6,7 @@ interface
66
77uses
88 Classes, SysUtils, LCLType, Forms, Controls, Graphics, Dialogs,
9- ExtCtrls, StdCtrls, ShellCtrls, ComCtrls, apphelpers, extra_controls, Math, generic_types
9+ ExtCtrls, StdCtrls, Buttons, ShellCtrls, ComCtrls, apphelpers, extra_controls, Math, generic_types
1010 { $IFDEF WINDOWS} , Windows, WinDirs, ActiveX, ShlObj, LazUTF8 { $ENDIF} ;
1111
1212type
@@ -16,6 +16,9 @@ interface
1616 TfrmExtFileDialog = class (TExtForm)
1717 btnCancel: TButton;
1818 btnOk: TButton;
19+ tbViewStyle: TToolBar;
20+ tbtnViewIcons: TToolButton;
21+ tbtnViewDetails: TToolButton;
1922 comboLineBreaks: TComboBox;
2023 comboEncoding: TComboBox;
2124 comboFileType: TComboBox;
@@ -54,6 +57,8 @@ TfrmExtFileDialog = class(TExtForm)
5457 Data: Integer; var Compare: Integer);
5558 procedure ShellListViewColumnClick (Sender: TObject; Column: TListColumn);
5659 procedure ShellListViewResize (Sender: TObject);
60+ procedure btnViewIconsClick (Sender: TObject);
61+ procedure btnViewDetailsClick (Sender: TObject);
5762 procedure ShellTreeViewChange (Sender: TObject; Node: TTreeNode);
5863 procedure ShellTreeViewChanging (Sender: TObject; Node: TTreeNode;
5964 var AllowChange: Boolean);
@@ -74,6 +79,8 @@ TfrmExtFileDialog = class(TExtForm)
7479 FClickedPathPart: String;
7580 FSortDirection: TSortDirection; // SortDirection is not published by TShellListView
7681 function CompareFileNames (const Name1, Name2: String): Integer;
82+ procedure UpdateViewStyleButton ;
83+ procedure SetupListViewColumns ;
7784 { $IFDEF WINDOWS}
7885 function ShowShellContextMenu (FileName: String; ScreenPos: TPoint): Boolean;
7986 { $ENDIF}
@@ -145,6 +152,7 @@ procedure TfrmExtFileDialog.FormCreate(Sender: TObject);
145152 ShellTreeView.OnGetImageIndex := ShellTreeViewGetImageIndex;
146153 ShellTreeView.OnGetSelectedIndex := ShellTreeViewGetSelectedIndex;
147154 ShellListView.SmallImages := MainForm.ImageListMain;
155+ ShellListView.LargeImages := MainForm.ImageListMain;
148156 { $ENDIF}
149157 ShellListView.OnCompare := ShellListViewCompare;
150158 ShellListView.OnColumnClick := ShellListViewColumnClick;
@@ -158,10 +166,13 @@ procedure TfrmExtFileDialog.FormCreate(Sender: TObject);
158166 Caption := _(' Modified' );
159167 Width := 140 ;
160168 end ;
161- ShellListView.Columns[1 ].Width := 80 ; // Size
162- ShellListView.Columns[2 ].Width := 80 ; // Type
163169 ShellListView.OnResize := ShellListViewResize;
164- ShellListViewResize(ShellListView);
170+ SetupListViewColumns;
171+ if AppSettings.ReadString(asFileDialogViewStyle) = ' icon' then
172+ ShellListView.ViewStyle := vsIcon
173+ else
174+ ShellListView.ViewStyle := vsReport;
175+ UpdateViewStyleButton;
165176 FSortDirection := sdAscending;
166177 { $IFDEF WINDOWS}
167178 ShellListView.OnContextPopup := ShellListViewContextPopup;
@@ -202,6 +213,7 @@ procedure TfrmExtFileDialog.FormShow(Sender: TObject);
202213 SetInitialDir(GetUserDir);
203214
204215 SetFilterIndex(FFilterIndex);
216+ SetupListViewColumns;
205217
206218 comboEncoding.Items.AddStrings(FEncodings, True);
207219 comboEncoding.AutoSizeItemWidth;
@@ -482,6 +494,19 @@ procedure TfrmExtFileDialog.ShellListViewColumnClick(Sender: TObject;
482494 Column.SortIndicator := DirToIndicator[NewDirection];
483495end ;
484496
497+ procedure TfrmExtFileDialog.SetupListViewColumns ;
498+ begin
499+ // Fixed widths for the secondary columns; the name column gets the remaining
500+ // space (see ShellListViewResize). Re-applied on every show and view change,
501+ // because switching the view style resets the native column widths.
502+ if ShellListView.Columns.Count > 3 then begin
503+ ShellListView.Columns[1 ].Width := 80 ; // Size
504+ ShellListView.Columns[2 ].Width := 80 ; // Type
505+ ShellListView.Columns[3 ].Width := 140 ; // Modified
506+ end ;
507+ ShellListViewResize(ShellListView);
508+ end ;
509+
485510procedure TfrmExtFileDialog.ShellListViewResize (Sender: TObject);
486511var
487512 i, W: Integer;
@@ -495,6 +520,36 @@ procedure TfrmExtFileDialog.ShellListViewResize(Sender: TObject);
495520 end ;
496521end ;
497522
523+ procedure TfrmExtFileDialog.btnViewIconsClick (Sender: TObject);
524+ begin
525+ ShellListView.ViewStyle := vsIcon;
526+ AppSettings.WriteString(asFileDialogViewStyle, ' icon' );
527+ // Repopulate so item icons match the new view style (large vs. small icons).
528+ // Keeps the current sort order, see ShellTreeViewChange.
529+ ShellListView.UpdateView;
530+ SetupListViewColumns;
531+ UpdateViewStyleButton;
532+ end ;
533+
534+ procedure TfrmExtFileDialog.btnViewDetailsClick (Sender: TObject);
535+ begin
536+ ShellListView.ViewStyle := vsReport;
537+ AppSettings.WriteString(asFileDialogViewStyle, ' report' );
538+ ShellListView.UpdateView;
539+ SetupListViewColumns;
540+ UpdateViewStyleButton;
541+ end ;
542+
543+ procedure TfrmExtFileDialog.UpdateViewStyleButton ;
544+ begin
545+ // The button matching the current view style stays pressed (Down), the other
546+ // one is up. Both share GroupIndex 1, so they behave like radio buttons.
547+ tbtnViewIcons.Down := ShellListView.ViewStyle = vsIcon;
548+ tbtnViewDetails.Down := ShellListView.ViewStyle = vsReport;
549+ tbtnViewIcons.Hint := _(' Switch to icon view' );
550+ tbtnViewDetails.Hint := _(' Switch to details view' );
551+ end ;
552+
498553procedure TfrmExtFileDialog.ShellListViewContextPopup (Sender: TObject;
499554 MousePos: TPoint; var Handled: Boolean);
500555var
0 commit comments