Skip to content

Commit 74b4ec6

Browse files
committed
Add support for passing flags to preferences frames
Code that displays the preferences dialogue box can now pass optional flags to each frame. Each flag is a UInt64 that has the frame's unique index number in its high 32 bits and a frame specific flag or bitmask in the lower 32 bits. FrPrefsBase provides utility class methods for manipulating these flags.
1 parent 4fcb12e commit 74b4ec6

9 files changed

+83
-31
lines changed

Src/FmPreferencesDlg.pas

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ TPreferencesDlg = class(TGenericOKDlg, INoPublicConstruct)
5050
/// <summary>Records if main UI needs to be updated to reflect changed
5151
/// preferences.</summary>
5252
fUpdateUI: Boolean;
53+
/// <summary>Records flags to be passed to frames.</summary>
54+
fFrameFlags: UInt64;
5355
/// <summary>Records index of currently select tab/list item.</summary>
5456
fCurrentPageIdx: Integer;
5557
/// <summary>Creates the required frames and displays each in a tab sheet
@@ -108,7 +110,8 @@ TPreferencesDlg = class(TGenericOKDlg, INoPublicConstruct)
108110
/// <returns>Boolean. True if user clicks OK to accept changes or False if
109111
/// user cancels and no changes made.</returns>
110112
class function Execute(AOwner: TComponent;
111-
const Pages: array of TPrefsFrameClass; out UpdateUI: Boolean): Boolean;
113+
const Pages: array of TPrefsFrameClass; out UpdateUI: Boolean;
114+
const Flags: UInt64 = 0): Boolean;
112115
overload;
113116
/// <summary>Displays dialog with pages for each specified preferences
114117
/// frame.</summary>
@@ -119,7 +122,8 @@ TPreferencesDlg = class(TGenericOKDlg, INoPublicConstruct)
119122
/// <returns>Boolean. True if user clicks OK to accept changes or False if
120123
/// user cancels and no changes made.</returns>
121124
class function Execute(AOwner: TComponent;
122-
const Pages: array of TPrefsFrameClass): Boolean; overload;
125+
const Pages: array of TPrefsFrameClass; const Flags: UInt64 = 0):
126+
Boolean; overload;
123127
/// <summary>Displays preferences dialog with all registered preference
124128
/// frames.</summary>
125129
/// <param name="AOwner">TComponent [in] Component that owns dialog.
@@ -128,8 +132,8 @@ TPreferencesDlg = class(TGenericOKDlg, INoPublicConstruct)
128132
/// be updated as a result of preference changes.</param>
129133
/// <returns>Boolean. True if user clicks OK to accept changes or False if
130134
/// user cancels and no changes made.</returns>
131-
class function Execute(AOwner: TComponent; out UpdateUI: Boolean): Boolean;
132-
overload;
135+
class function Execute(AOwner: TComponent; out UpdateUI: Boolean;
136+
const Flags: UInt64 = 0): Boolean; overload;
133137
/// <summary>Displays dialogue with showing a single frame, specified by
134138
/// its class name.</summary>
135139
/// <param name="AOwner">TComponent [in] Component that owns dialog.
@@ -141,7 +145,7 @@ TPreferencesDlg = class(TGenericOKDlg, INoPublicConstruct)
141145
/// <returns>Boolean. True if user clicks OK to accept changes or False if
142146
/// user cancels and no changes made.</returns>
143147
class function Execute(AOwner: TComponent; const PageClsName: string;
144-
out UpdateUI: Boolean): Boolean; overload;
148+
out UpdateUI: Boolean; const Flags: UInt64 = 0): Boolean; overload;
145149
/// <summary>Registers given preferences frame class for inclusion in the
146150
/// preferences dialog box.</summary>
147151
/// <remarks>Registered frames are created when the dialog box is displayed
@@ -258,10 +262,12 @@ function TPreferencesDlg.CustomHelpKeyword: string;
258262
end;
259263

260264
class function TPreferencesDlg.Execute(AOwner: TComponent;
261-
const Pages: array of TPrefsFrameClass; out UpdateUI: Boolean): Boolean;
265+
const Pages: array of TPrefsFrameClass; out UpdateUI: Boolean;
266+
const Flags: UInt64): Boolean;
262267
begin
263268
with InternalCreate(AOwner) do
264269
try
270+
fFrameFlags := Flags;
265271
CreatePages(Pages);
266272
Result := ShowModal = mrOK;
267273
if Result then
@@ -274,21 +280,22 @@ class function TPreferencesDlg.Execute(AOwner: TComponent;
274280
end;
275281

276282
class function TPreferencesDlg.Execute(AOwner: TComponent;
277-
out UpdateUI: Boolean): Boolean;
283+
out UpdateUI: Boolean; const Flags: UInt64): Boolean;
278284
begin
279-
Result := Execute(AOwner, fPages.ToArray, UpdateUI);
285+
Result := Execute(AOwner, fPages.ToArray, UpdateUI, Flags);
280286
end;
281287

282288
class function TPreferencesDlg.Execute(AOwner: TComponent;
283-
const Pages: array of TPrefsFrameClass): Boolean;
289+
const Pages: array of TPrefsFrameClass; const Flags: UInt64): Boolean;
284290
var
285291
Dummy: Boolean; // unused UpdateUI parameters
286292
begin
287-
Result := Execute(AOwner, Pages, Dummy);
293+
Result := Execute(AOwner, Pages, Dummy, Flags);
288294
end;
289295

290296
class function TPreferencesDlg.Execute(AOwner: TComponent;
291-
const PageClsName: string; out UpdateUI: Boolean): Boolean;
297+
const PageClsName: string; out UpdateUI: Boolean; const Flags: UInt64):
298+
Boolean;
292299
var
293300
FrameClass: TPrefsFrameClass;
294301
begin
@@ -335,7 +342,7 @@ procedure TPreferencesDlg.InitForm;
335342
fLocalPrefs := (Preferences as IClonable).Clone as IPreferences;
336343
// Display and initialise required pages
337344
for TabIdx := 0 to Pred(pcMain.PageCount) do
338-
MapTabSheetToPage(TabIdx).LoadPrefs(fLocalPrefs);
345+
MapTabSheetToPage(TabIdx).LoadPrefs(fLocalPrefs, fFrameFlags);
339346
// Select last use tab sheet (or 1st if last not known)
340347
fCurrentPageIdx := GetLastTabIdx;
341348
if fCurrentPageIdx < 0 then
@@ -413,7 +420,7 @@ procedure TPreferencesDlg.SelectTab(TS: TTabSheet);
413420
Assert(Assigned(TS), ClassName + '.SelectTab: TS is nil');
414421
GetSelectedPage.Deactivate(fLocalPrefs);
415422
pcMain.ActivePage := TS;
416-
GetSelectedPage.Activate(fLocalPrefs);
423+
GetSelectedPage.Activate(fLocalPrefs, fFrameFlags);
417424
fCurrentPageIdx := pcMain.ActivePageIndex;
418425
end;
419426

Src/FrCodeGenPrefs.pas

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ TCodeGenPrefsFrame = class(TPrefsBaseFrame)
176176
/// <summary>Records details of warnings from given preferences object and
177177
/// updates controls accordingly.</summary>
178178
/// <remarks>Called when page is activated.</remarks>
179-
procedure Activate(const Prefs: IPreferences); override;
179+
procedure Activate(const Prefs: IPreferences; const Flags: UInt64);
180+
override;
180181
/// <summary>Updates given preferences object with details of warnings as
181182
/// modified by user.</summary>
182183
/// <remarks>Called when page is deactivated.</remarks>
@@ -322,7 +323,8 @@ procedure TCodeGenPrefsFrame.actDeleteUpdate(Sender: TObject);
322323
actDelete.Enabled := Assigned(fLVWarnings.Selected);
323324
end;
324325

325-
procedure TCodeGenPrefsFrame.Activate(const Prefs: IPreferences);
326+
procedure TCodeGenPrefsFrame.Activate(const Prefs: IPreferences;
327+
const Flags: UInt64);
326328
begin
327329
(fWarnings as IAssignable).Assign(Prefs.Warnings);
328330
chkWARNEnabled.Checked := fWarnings.Enabled;

Src/FrDisplayPrefs.pas

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ TDisplayPrefsFrame = class(TPrefsBaseFrame)
6363
{Class constructor. Sets up frame and populates controls.
6464
@param AOwner [in] Component that owns frame.
6565
}
66-
procedure Activate(const Prefs: IPreferences); override;
66+
procedure Activate(const Prefs: IPreferences; const Flags: UInt64);
67+
override;
6768
{Called when page activated. Updates controls.
6869
@param Prefs [in] Object that provides info used to update controls.
6970
}
@@ -106,7 +107,8 @@ implementation
106107

107108
{ TDisplayPrefsFrame }
108109

109-
procedure TDisplayPrefsFrame.Activate(const Prefs: IPreferences);
110+
procedure TDisplayPrefsFrame.Activate(const Prefs: IPreferences;
111+
const Flags: UInt64);
110112
{Called when page activated. Updates controls.
111113
@param Prefs [in] Object that provides info used to update controls.
112114
}

Src/FrGeneralPrefs.pas

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ TGeneralPrefsFrame = class(TPrefsBaseFrame)
4545
{Class constructor. Sets up frame and populates controls.
4646
@param AOwner [in] Component that owns frame.
4747
}
48-
procedure Activate(const Prefs: IPreferences); override;
48+
procedure Activate(const Prefs: IPreferences; const Flags: UInt64);
49+
override;
4950
{Called when page activated. Updates controls.
5051
@param Prefs [in] Object that provides info used to update controls.
5152
}
@@ -88,7 +89,8 @@ implementation
8889

8990
{ TGeneralPrefsFrame }
9091

91-
procedure TGeneralPrefsFrame.Activate(const Prefs: IPreferences);
92+
procedure TGeneralPrefsFrame.Activate(const Prefs: IPreferences;
93+
const Flags: UInt64);
9294
{Called when page activated. Updates controls.
9395
@param Prefs [in] Object that provides info used to update controls.
9496
}

Src/FrHiliterPrefs.pas

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ THiliterPrefsFrame = class(TPrefsBaseFrame)
143143
/// <summary>Updates controls from given preferences object.</summary>
144144
/// <remarks>Called when the dialogue page containing the frame is
145145
/// activated.</remarks>
146-
procedure Activate(const Prefs: IPreferences); override;
146+
procedure Activate(const Prefs: IPreferences; const Flags: UInt64);
147+
override;
147148
/// <summary>Updates given preferences object with data entered in controls.
148149
/// </summary>
149150
/// <remarks>Called when the dialogue page containing the frame is
@@ -254,7 +255,8 @@ implementation
254255

255256
{ THiliterPrefsFrame }
256257

257-
procedure THiliterPrefsFrame.Activate(const Prefs: IPreferences);
258+
procedure THiliterPrefsFrame.Activate(const Prefs: IPreferences;
259+
const Flags: UInt64);
258260
begin
259261
(fAttrs as IAssignable).Assign(Prefs.HiliteAttrs);
260262
(fNamedAttrs as IAssignable).Assign(Prefs.NamedHiliteAttrs);

Src/FrPrefsBase.pas

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,24 @@ TPrefsFrameClass = class of TPrefsBaseFrame;
3838
preferences dialog box.
3939
}
4040
TPrefsBaseFrame = class(TFrame)
41+
strict protected
42+
class function IsFlagSupported(const Flag: UInt64): Boolean; inline;
43+
class function ExtractFrameFlag(const Flag: UInt64): UInt32; inline;
4144
public
4245
procedure SavePrefs(const Prefs: IPreferences); virtual;
4346
{Saves information user entered in frame. By default the method simply
4447
calls Deactivate. May be overridden to save any custom data that doesn't
4548
use Prefs object.
4649
@param Prefs [in] Object used to store information.
4750
}
48-
procedure LoadPrefs(const Prefs: IPreferences); virtual;
51+
procedure LoadPrefs(const Prefs: IPreferences; const Flags: UInt64);
52+
virtual;
4953
{Initialises controls. By default the method simply calls Activate. May be
5054
overridden to load any custom data that doesn't use Prefs object.
5155
@param Prefs [in] Object that provides info used to update controls.
5256
}
53-
procedure Activate(const Prefs: IPreferences); virtual; abstract;
57+
procedure Activate(const Prefs: IPreferences; const Flags: UInt64);
58+
virtual; abstract;
5459
{Called when page activated. Must update controls from preferences.
5560
@param Prefs [in] Object that provides info used to update controls.
5661
}
@@ -77,23 +82,49 @@ TPrefsBaseFrame = class(TFrame)
7782
new entries at a later date.
7883
@return Required index number.
7984
}
85+
class function MakeFrameFlag(const Flag: UInt32): UInt64; inline;
8086
end;
8187

8288

8389
implementation
8490

91+
uses
92+
// Delphi
93+
SysUtils;
94+
8595

8696
{$R *.dfm}
8797

8898
{ TPrefsBaseFrame }
8999

90-
procedure TPrefsBaseFrame.LoadPrefs(const Prefs: IPreferences);
100+
class function TPrefsBaseFrame.ExtractFrameFlag(const Flag: UInt64): UInt32;
101+
begin
102+
if not IsFlagSupported(Flag) then
103+
Exit(0);
104+
Result := Int64Rec(Flag).Lo;
105+
end;
106+
107+
class function TPrefsBaseFrame.IsFlagSupported(const Flag: UInt64): Boolean;
108+
begin
109+
Result := Int64Rec(Flag).Hi = UInt32(Index);
110+
end;
111+
112+
procedure TPrefsBaseFrame.LoadPrefs(const Prefs: IPreferences;
113+
const Flags: UInt64);
91114
{Initialises controls. By default the method simply calls Activate. May be
92115
overridden to load any custom data that doesn't use Prefs object.
93116
@param Prefs [in] Object that provides info used to update controls.
94117
}
95118
begin
96-
Activate(Prefs);
119+
Activate(Prefs, Flags);
120+
end;
121+
122+
class function TPrefsBaseFrame.MakeFrameFlag(const Flag: UInt32): UInt64;
123+
begin
124+
// Frame flag is in form $IIIIIIIIFFFFFFFF where $IIIIIIII is the frame's
125+
// index number and $FFFFFFFF is the 32 bit flag or bitmask of flags
126+
Int64Rec(Result).Hi := UInt32(Index);
127+
Int64Rec(Result).Lo := Flag;
97128
end;
98129

99130
procedure TPrefsBaseFrame.SavePrefs(const Prefs: IPreferences);

Src/FrPrintingPrefs.pas

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ TPrintingPrefsFrame = class(TPrefsBaseFrame)
6060
constructor Create(AOwner: TComponent); override;
6161
{Class constructor. Sets up frame object.
6262
}
63-
procedure Activate(const Prefs: IPreferences); override;
63+
procedure Activate(const Prefs: IPreferences; const Flags: UInt64);
64+
override;
6465
{Called when page activated. Updates controls.
6566
@param Prefs [in] Object that provides info used to update controls.
6667
}
@@ -141,7 +142,8 @@ TPrintingPrefsPreview = class(TObject)
141142

142143
{ TPrintingPrefsFrame }
143144

144-
procedure TPrintingPrefsFrame.Activate(const Prefs: IPreferences);
145+
procedure TPrintingPrefsFrame.Activate(const Prefs: IPreferences;
146+
const Flags: UInt64);
145147
{Called when page activated. Updates controls.
146148
@param Prefs [in] Object that provides info used to update controls.
147149
}

Src/FrSnippetLayoutPrefs.pas

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ TSnippetLayoutPrefsFrame = class(TPrefsBaseFrame)
6464
public
6565
constructor Create(AOwner: TComponent); override;
6666
destructor Destroy; override;
67-
procedure Activate(const Prefs: IPreferences); override;
67+
procedure Activate(const Prefs: IPreferences; const Flags: UInt64);
68+
override;
6869
procedure Deactivate(const Prefs: IPreferences); override;
6970
/// <summary>Checks if preference changes require that main window UI is
7071
/// updated.</summary>
@@ -146,7 +147,8 @@ procedure TSnippetLayoutPrefsFrame.actIncludeFragmentUpdate(Sender: TObject);
146147
and (lbAvailableFragments.ItemIndex >= 0);
147148
end;
148149

149-
procedure TSnippetLayoutPrefsFrame.Activate(const Prefs: IPreferences);
150+
procedure TSnippetLayoutPrefsFrame.Activate(const Prefs: IPreferences;
151+
const Flags: UInt64);
150152
begin
151153
fPageStructs.Assign(Prefs.PageStructures);
152154
UpdateFragmentInfo;

Src/FrSourcePrefs.pas

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ TSourcePrefsFrame = class(TPrefsBaseFrame)
7474
constructor Create(AOwner: TComponent); override;
7575
{Class constructor. Initialises controls.
7676
}
77-
procedure Activate(const Prefs: IPreferences); override;
77+
procedure Activate(const Prefs: IPreferences; const Flags: UInt64);
78+
override;
7879
{Called when page activated. Updates controls.
7980
@param Prefs [in] Object that provides info used to update controls.
8081
}
@@ -165,7 +166,8 @@ TSourcePrefsPreview = class(TObject)
165166

166167
{ TSourcePrefsFrame }
167168

168-
procedure TSourcePrefsFrame.Activate(const Prefs: IPreferences);
169+
procedure TSourcePrefsFrame.Activate(const Prefs: IPreferences;
170+
const Flags: UInt64);
169171
{Called when page activated. Updates controls.
170172
@param Prefs [in] Object that provides info used to update controls.
171173
}

0 commit comments

Comments
 (0)