Skip to content

Commit 300936f

Browse files
committed
Replace tabs with list box in Preferences dlg
All page control tabs hidden. A new list box added on left of dialogue box that displays tab names. Clicking a name selects the required tab. Fixes #24
1 parent c88b6da commit 300936f

File tree

2 files changed

+58
-49
lines changed

2 files changed

+58
-49
lines changed

Src/FmPreferencesDlg.dfm

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,37 @@ inherited PreferencesDlg: TPreferencesDlg
33
Top = 138
44
Caption = 'Preferences'
55
ClientHeight = 421
6-
ClientWidth = 462
7-
ExplicitWidth = 468
8-
ExplicitHeight = 447
6+
ClientWidth = 722
7+
ExplicitWidth = 728
8+
ExplicitHeight = 450
99
PixelsPerInch = 96
1010
TextHeight = 13
1111
inherited pnlBody: TPanel
12-
Width = 446
13-
Height = 377
14-
ExplicitWidth = 446
15-
ExplicitHeight = 377
12+
Width = 609
13+
Height = 329
14+
ExplicitWidth = 609
15+
ExplicitHeight = 329
1616
object pcMain: TPageControl
17-
Left = 0
17+
Left = 163
1818
Top = 0
1919
Width = 446
20-
Height = 377
21-
Align = alClient
20+
Height = 329
21+
Align = alRight
2222
MultiLine = True
23+
TabOrder = 1
24+
ExplicitLeft = 159
25+
ExplicitHeight = 377
26+
end
27+
object lbPages: TListBox
28+
Left = 0
29+
Top = 0
30+
Width = 153
31+
Height = 329
32+
Align = alLeft
33+
ItemHeight = 13
2334
TabOrder = 0
24-
OnChange = pcMainChange
25-
OnChanging = pcMainChanging
26-
OnMouseDown = pcMainMouseDown
35+
OnClick = lbPagesClick
36+
ExplicitHeight = 377
2737
end
2838
end
2939
inherited btnOK: TButton

Src/FmPreferencesDlg.pas

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,13 @@ interface
3232
/// </remarks>
3333
TPreferencesDlg = class(TGenericOKDlg, INoPublicConstruct)
3434
pcMain: TPageControl;
35+
lbPages: TListBox;
3536
/// <summary>OK button click event handler. Writes preference data to
3637
/// persistent storage.</summary>
3738
procedure btnOKClick(Sender: TObject);
38-
/// <param>Called when current tab sheet has changed. Gets newly selected
39-
/// page to re-initialise its controls from local preferences.</param>
40-
/// <remarks>This enables any pages that depend on preferences that may
41-
/// have been changed in other pages to update appropriately.</remarks>
42-
procedure pcMainChange(Sender: TObject);
43-
/// <summary>Called just before active tab sheet is changed. Causes page
44-
/// about to be deselected to update local preferences with any changes.
45-
/// </summary>
46-
/// <remarks>We do this in case another page needs to update due to changes
47-
/// made on current page.</remarks>
48-
procedure pcMainChanging(Sender: TObject; var AllowChange: Boolean);
49-
/// <summary>Handles event triggered when user clicks on one of page
50-
/// control tabs. Ensures page control has focus.</summary>
51-
/// <remarks>Without this fix, page control does not always get focus when
52-
/// a tab is clicked.</remarks>
53-
procedure pcMainMouseDown(Sender: TObject; Button: TMouseButton;
54-
Shift: TShiftState; X, Y: Integer);
39+
/// <summary>Handles event triggered when list box is clicked or changed
40+
/// via keyboard.</summary>
41+
procedure lbPagesClick(Sender: TObject);
5542
strict private
5643
class var
5744
/// <summary>List of registered page frames</summary>
@@ -62,6 +49,8 @@ TPreferencesDlg = class(TGenericOKDlg, INoPublicConstruct)
6249
/// <summary>Records if main UI needs to be updated to reflect changed
6350
/// preferences.</summary>
6451
fUpdateUI: Boolean;
52+
/// <summary>Records index of currently select tab/list item.</summary>
53+
fCurrentPageIdx: Integer;
6554
/// <summary>Creates the required frames and displays each in a tab sheet
6655
/// within the page control.</summary>
6756
/// <param name="FrameClasses">array of TPrefsFrameClass [in] Class
@@ -83,6 +72,10 @@ TPreferencesDlg = class(TGenericOKDlg, INoPublicConstruct)
8372
/// <summary>Gets reference to preferences frame on currently selected tab.
8473
/// </summary>
8574
function GetSelectedPage: TPrefsBaseFrame;
75+
/// <summary>Selects given tab.</summary>
76+
/// <remarks>Stores state of tab being closed and restores state of tab
77+
/// being opened.</remarks>
78+
procedure SelectTab(TS: TTabSheet);
8679
strict protected
8780
/// <summary>Gets the help A-link keyword to be used when help button
8881
/// clicked.</summary>
@@ -241,6 +234,10 @@ procedure TPreferencesDlg.CreatePages(
241234
Frame.Top := 4;
242235
// set tab sheet caption to frame's display name
243236
TS.Caption := Frame.DisplayName;
237+
TS.TabVisible := False;
238+
239+
// Create list box item for page
240+
lbPages.Items.AddObject(Frame.DisplayName, TS);
244241
end;
245242
end;
246243

@@ -313,7 +310,18 @@ procedure TPreferencesDlg.InitForm;
313310
for TabIdx := 0 to Pred(pcMain.PageCount) do
314311
MapTabSheetToPage(TabIdx).LoadPrefs(fLocalPrefs);
315312
// Select first TabSheet
316-
pcMain.ActivePageIndex := 0;
313+
fCurrentPageIdx := 0;
314+
pcMain.ActivePageIndex := fCurrentPageIdx;
315+
lbPages.ItemIndex := fCurrentPageIdx;
316+
end;
317+
318+
procedure TPreferencesDlg.lbPagesClick(Sender: TObject);
319+
begin
320+
if lbPages.ItemIndex < 0 then
321+
Exit;
322+
if lbPages.ItemIndex = fCurrentPageIdx then
323+
Exit;
324+
SelectTab(lbPages.Items.Objects[lbPages.ItemIndex] as TTabSheet)
317325
end;
318326

319327
class function TPreferencesDlg.MapClassNameToPageClass(const ClsName: string):
@@ -351,24 +359,6 @@ function TPreferencesDlg.MapTabSheetToPage(
351359
Assert(Assigned(Result), ClassName + '.MapTabSheetToPage: Frame not found');
352360
end;
353361

354-
procedure TPreferencesDlg.pcMainChange(Sender: TObject);
355-
begin
356-
GetSelectedPage.Activate(fLocalPrefs);
357-
end;
358-
359-
procedure TPreferencesDlg.pcMainChanging(Sender: TObject;
360-
var AllowChange: Boolean);
361-
begin
362-
GetSelectedPage.Deactivate(fLocalPrefs);
363-
end;
364-
365-
procedure TPreferencesDlg.pcMainMouseDown(Sender: TObject; Button: TMouseButton;
366-
Shift: TShiftState; X, Y: Integer);
367-
begin
368-
if htOnItem in pcMain.GetHitTestInfoAt(X, Y) then
369-
pcMain.SetFocus;
370-
end;
371-
372362
class procedure TPreferencesDlg.RegisterPage(const FrameCls: TPrefsFrameClass);
373363
var
374364
PageIdx: Integer; // loops through all registered frames
@@ -389,5 +379,14 @@ class procedure TPreferencesDlg.RegisterPage(const FrameCls: TPrefsFrameClass);
389379
fPages.Insert(InsIdx, FrameCls);
390380
end;
391381

382+
procedure TPreferencesDlg.SelectTab(TS: TTabSheet);
383+
begin
384+
Assert(Assigned(TS), ClassName + '.SelectTab: TS is nil');
385+
GetSelectedPage.Deactivate(fLocalPrefs);
386+
pcMain.ActivePage := TS;
387+
GetSelectedPage.Activate(fLocalPrefs);
388+
fCurrentPageIdx := pcMain.ActivePageIndex;
389+
end;
390+
392391
end.
393392

0 commit comments

Comments
 (0)