Skip to content

Commit 60fd26d

Browse files
committed
feat: view style toggle toolbar in file dialog, persisted in settings
1 parent d573caa commit 60fd26d

5 files changed

Lines changed: 101 additions & 5 deletions

File tree

‎extra/locale/heidisql.en.mo‎

134 Bytes
Binary file not shown.

‎extra/locale/heidisql.po‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7101,3 +7101,11 @@ msgstr "The bug report was sent to %s. Thank you!"
71017101
#: crashdialog.pas:74
71027102
msgid "Sending the report failed"
71037103
msgstr "Sending the report failed"
7104+
7105+
#: extfiledialog.pas
7106+
msgid "Switch to details view"
7107+
msgstr "Switch to details view"
7108+
7109+
#: extfiledialog.pas
7110+
msgid "Switch to icon view"
7111+
msgstr "Switch to icon view"

‎source/apphelpers.pas‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ TCustomComboBoxHelper = class helper for TCustomComboBox
249249
asIncrementalSearch, asQueryHistoryEnabled, asQueryHistoryKeepDays,
250250
asColumnSelectorWidth, asColumnSelectorHeight, asDonatedEmail, asFavoriteObjects, asFavoriteObjectsOnly, asFullTableStatus, asLineBreakStyle,
251251
asPreferencesWindowWidth, asPreferencesWindowHeight,
252-
asFileDialogEncoding, asFileDialogPreviousDir,
252+
asFileDialogEncoding, asFileDialogPreviousDir, asFileDialogViewStyle,
253253
asThemePreviewWidth, asThemePreviewHeight, asThemePreviewTop, asThemePreviewLeft,
254254
asCreateDbCollation, asRealTrailingZeros,
255255
asSequalSuggestWindowWidth, asSequalSuggestWindowHeight, asSequalSuggestPrompt, asSequalSuggestRecentPrompts,
@@ -4106,6 +4106,7 @@ constructor TAppSettings.Create;
41064106
InitSetting(asPreferencesWindowHeight, 'PreferencesWindowHeight', 500);
41074107
InitSetting(asFileDialogEncoding, 'FileDialogEncoding_%s', 0);
41084108
InitSetting(asFileDialogPreviousDir, 'FileDialogPreviousDir', 0, False, '');
4109+
InitSetting(asFileDialogViewStyle, 'FileDialogViewStyle', 0, False, 'report');
41094110
InitSetting(asThemePreviewWidth, 'ThemePreviewWidth', 300);
41104111
InitSetting(asThemePreviewHeight, 'ThemePreviewHeight', 200);
41114112
InitSetting(asThemePreviewTop, 'ThemePreviewTop', 300);

‎source/extfiledialog.lfm‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ object frmExtFileDialog: TfrmExtFileDialog
88
ClientHeight = 435
99
ClientWidth = 698
1010
Position = poOwnerFormCenter
11+
ShowHint = True
1112
LCLVersion = '4.8.0.0'
1213
OnCloseQuery = FormCloseQuery
1314
OnCreate = FormCreate
@@ -225,6 +226,37 @@ object frmExtFileDialog: TfrmExtFileDialog
225226
OnMouseDown = lblPathMouseDown
226227
OnMouseMove = lblPathMouseMove
227228
end
229+
object tbViewStyle: TToolBar
230+
AnchorSideTop.Control = lblPath
231+
AnchorSideTop.Side = asrCenter
232+
AnchorSideRight.Control = Owner
233+
AnchorSideRight.Side = asrBottom
234+
Left = 643
235+
Height = 22
236+
Top = 1
237+
Width = 47
238+
Align = alNone
239+
Anchors = [akRight]
240+
AutoSize = True
241+
BorderSpacing.Around = 8
242+
EdgeBorders = []
243+
Images = MainForm.ImageListMain
244+
TabOrder = 4
245+
object tbtnViewIcons: TToolButton
246+
Left = 1
247+
Top = 0
248+
Grouped = True
249+
ImageIndex = 41
250+
OnClick = btnViewIconsClick
251+
end
252+
object tbtnViewDetails: TToolButton
253+
Left = 24
254+
Top = 0
255+
Grouped = True
256+
ImageIndex = 56
257+
OnClick = btnViewDetailsClick
258+
end
259+
end
228260
object IdleTimerTreeNodeScrolltoview: TIdleTimer
229261
AutoEnabled = True
230262
Interval = 200

‎source/extfiledialog.pas‎

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface
66

77
uses
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

1212
type
@@ -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];
483495
end;
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+
485510
procedure TfrmExtFileDialog.ShellListViewResize(Sender: TObject);
486511
var
487512
i, W: Integer;
@@ -495,6 +520,36 @@ procedure TfrmExtFileDialog.ShellListViewResize(Sender: TObject);
495520
end;
496521
end;
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+
498553
procedure TfrmExtFileDialog.ShellListViewContextPopup(Sender: TObject;
499554
MousePos: TPoint; var Handled: Boolean);
500555
var

0 commit comments

Comments
 (0)