Skip to content

Commit adca139

Browse files
author
DelphiDabbler
committed
Renamed About box Paths tab to Paths & Files and added buttons to view config files
1 parent 134b148 commit adca139

File tree

2 files changed

+83
-22
lines changed

2 files changed

+83
-22
lines changed

Src/FmAboutDlg.dfm

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ inherited AboutDlg: TAboutDlg
55
ClientHeight = 384
66
ClientWidth = 485
77
ExplicitWidth = 491
8-
ExplicitHeight = 410
8+
ExplicitHeight = 413
99
PixelsPerInch = 96
1010
TextHeight = 13
1111
inherited pnlBody: TPanel
@@ -33,10 +33,6 @@ inherited AboutDlg: TAboutDlg
3333
OnMouseDown = pcDetailMouseDown
3434
object tsProgram: TTabSheet
3535
Caption = 'About The Program'
36-
ExplicitLeft = 0
37-
ExplicitTop = 0
38-
ExplicitWidth = 0
39-
ExplicitHeight = 0
4036
inline frmProgram: THTMLTpltDlgFrame
4137
Left = 0
4238
Top = 0
@@ -70,10 +66,6 @@ inherited AboutDlg: TAboutDlg
7066
object tsDatabase: TTabSheet
7167
Caption = 'About The Database'
7268
ImageIndex = 1
73-
ExplicitLeft = 0
74-
ExplicitTop = 0
75-
ExplicitWidth = 0
76-
ExplicitHeight = 0
7769
inline frmDatabase: THTMLTpltDlgFrame
7870
Left = 0
7971
Top = 0
@@ -107,10 +99,24 @@ inherited AboutDlg: TAboutDlg
10799
object tsPaths: TTabSheet
108100
Caption = 'Paths'
109101
ImageIndex = 2
110-
ExplicitLeft = 0
111-
ExplicitTop = 0
112-
ExplicitWidth = 0
113-
ExplicitHeight = 0
102+
object btnViewAppConfig: TButton
103+
Left = 3
104+
Top = 144
105+
Width = 170
106+
Height = 25
107+
Caption = 'View Application Config File...'
108+
TabOrder = 1
109+
OnClick = btnViewAppConfigClick
110+
end
111+
object btnViewUserConfig: TButton
112+
Left = 192
113+
Top = 144
114+
Width = 170
115+
Height = 25
116+
Caption = 'View Per-User Config File...'
117+
TabOrder = 0
118+
OnClick = btnViewUserConfigClick
119+
end
114120
end
115121
end
116122
object pnlTitle: TPanel

Src/FmAboutDlg.pas

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
44
* obtain one at http://mozilla.org/MPL/2.0/
55
*
6-
* Copyright (C) 2005-2014, Peter Johnson (www.delphidabbler.com).
6+
* Copyright (C) 2005-2016, Peter Johnson (www.delphidabbler.com).
77
*
88
* $Rev$
99
* $Date$
@@ -89,6 +89,8 @@ TAboutDlg = class(TGenericViewDlg)
8989
pnlTitle: TPanel;
9090
frmTitle: THTMLTpltDlgFrame;
9191
tsPaths: TTabSheet;
92+
btnViewAppConfig: TButton;
93+
btnViewUserConfig: TButton;
9294
procedure btnRegisterClick(Sender: TObject);
9395
procedure FormCreate(Sender: TObject);
9496
procedure FormDestroy(Sender: TObject);
@@ -98,6 +100,8 @@ TAboutDlg = class(TGenericViewDlg)
98100
/// a tab is clicked.</remarks>
99101
procedure pcDetailMouseDown(Sender: TObject; Button: TMouseButton;
100102
Shift: TShiftState; X, Y: Integer);
103+
procedure btnViewAppConfigClick(Sender: TObject);
104+
procedure btnViewUserConfigClick(Sender: TObject);
101105
strict private
102106
fMainDBPathGp: TPathInfoBox; // control that displays main database folder
103107
fUserDBPathGp: TPathInfoBox; // control that displays user database folder
@@ -120,6 +124,12 @@ TAboutDlg = class(TGenericViewDlg)
120124
determines names that are displayed.
121125
@return Required HTML.
122126
}
127+
procedure ViewConfigFile(const FileName, DlgTitle: string);
128+
{Displays content of a config file in a preview dialogue box. If file
129+
does not exist an error message is displayed.
130+
@param FileName [in] Name of config file.
131+
@param DlgTitle [in] Title of preview dialogue box.
132+
}
123133
strict protected
124134
procedure ConfigForm; override;
125135
{Configures form by creating custom controls and initialising HTML frames.
@@ -162,9 +172,9 @@ implementation
162172
// Delphi
163173
SysUtils, Graphics, Math, Windows, ShellAPI, IOUtils,
164174
// Project
165-
FmEasterEgg, FmRegistrationDlg, UAppInfo, UColours, UConsts, UCSSUtils,
166-
UCtrlArranger, UFontHelper, UGraphicUtils, UHTMLUtils, UHTMLTemplate,
167-
UResourceUtils, UThemesEx;
175+
FmEasterEgg, FmPreviewDlg, FmRegistrationDlg, UAppInfo, UColours, UConsts,
176+
UCSSUtils, UCtrlArranger, UEncodings, UFontHelper, UGraphicUtils, UHTMLUtils,
177+
UHTMLTemplate, UIOUtils, UMessageBox, UResourceUtils, UThemesEx;
168178

169179

170180
{
@@ -215,7 +225,15 @@ procedure TAboutDlg.ArrangeForm;
215225
begin
216226
fMainDBPathGp.Top := TCtrlArranger.BottomOf(fInstallPathGp, 8);
217227
fUserDBPathGp.Top := TCtrlArranger.BottomOf(fMainDBPathGp, 8);
218-
PathTabHeight := TCtrlArranger.BottomOf(fUserDBPathGp);
228+
TCtrlArranger.AlignTops(
229+
[btnViewAppConfig, btnViewUserConfig],
230+
TCtrlArranger.BottomOf(fUserDBPathGp, 8)
231+
);
232+
PathTabHeight := TCtrlArranger.BottomOf(
233+
[btnViewUserConfig, btnViewAppConfig]
234+
);
235+
TCtrlArranger.AlignLefts([fUserDBPathGp, btnViewAppConfig]);
236+
TCtrlArranger.AlignRights([fUserDBPathGp, btnViewUserConfig]);
219237
// Set height of title frame and page control
220238
pnlTitle.Height := frmTitle.DocHeight;
221239
pcDetail.ClientHeight :=
@@ -240,15 +258,31 @@ procedure TAboutDlg.btnRegisterClick(Sender: TObject);
240258
btnRegister.Hide; // hide registration button now that program registered OK
241259
end;
242260

261+
procedure TAboutDlg.btnViewAppConfigClick(Sender: TObject);
262+
resourcestring
263+
sTitle = 'Application Config File';
264+
begin
265+
ViewConfigFile(TAppInfo.AppConfigFileName, sTitle);
266+
end;
267+
268+
procedure TAboutDlg.btnViewUserConfigClick(Sender: TObject);
269+
resourcestring
270+
sTitle = 'Per-User Config File';
271+
begin
272+
ViewConfigFile(TAppInfo.UserConfigFileName, sTitle);
273+
end;
274+
243275
procedure TAboutDlg.ConfigForm;
244276
{Configures form by creating custom controls and initialising HTML frames.
245277
Called from ancestor class.
246278
}
247279

248-
function CreatePathInfoBox(const Caption, Path: string): TPathInfoBox;
280+
function CreatePathInfoBox(const Caption, Path: string;
281+
const TabOrder: Integer): TPathInfoBox;
249282
{Creates and initialises a custom path information control.
250283
@param Caption [in] Group box caption.
251284
@param Path [in] Path to be displayed.
285+
@param TabOrder [in] Tab order of info box.
252286
@return New control.
253287
}
254288
begin
@@ -257,6 +291,7 @@ procedure TAboutDlg.ConfigForm;
257291
Result.SetBounds(8, 8, tsPaths.ClientWidth - 16, 0);
258292
Result.Caption := Caption;
259293
Result.Path := Path;
294+
Result.TabOrder := TabOrder;
260295
end;
261296

262297
resourcestring
@@ -268,14 +303,16 @@ procedure TAboutDlg.ConfigForm;
268303
inherited;
269304
// Creates required custom controls
270305
fInstallPathGp := CreatePathInfoBox(
271-
sInstallPathGpCaption, TAppInfo.AppExeDir
306+
sInstallPathGpCaption, TAppInfo.AppExeDir, 0
272307
);
273308
fMainDBPathGp := CreatePathInfoBox(
274-
sMainDBPathGpCaption, TAppInfo.AppDataDir
309+
sMainDBPathGpCaption, TAppInfo.AppDataDir, 1
275310
);
276311
fUserDBPathGp := CreatePathInfoBox(
277-
sUserDBPathGpCaption, TAppInfo.UserDataDir
312+
sUserDBPathGpCaption, TAppInfo.UserDataDir, 2
278313
);
314+
btnViewAppConfig.TabOrder := fUserDBPathGp.TabOrder + 1;
315+
btnViewUserConfig.TabOrder := btnViewAppConfig.TabOrder + 1;
279316
// Load content into HTML frames
280317
InitHTMLFrames;
281318
end;
@@ -551,6 +588,24 @@ procedure TAboutDlg.UpdateTitleCSS(Sender: TObject;
551588
end;
552589
end;
553590

591+
procedure TAboutDlg.ViewConfigFile(const FileName, DlgTitle: string);
592+
var
593+
Data: TEncodedData;
594+
resourcestring
595+
sErrorMsg = 'Sorry, this config file does not (yet) exist.';
596+
begin
597+
if not TFile.Exists(FileName) then
598+
begin
599+
TMessageBox.Error(Self, sErrorMsg);
600+
Exit;
601+
end;
602+
Data := TEncodedData.Create(
603+
TFileIO.ReadAllText(FileName, TEncoding.Unicode, True),
604+
etUTF16LE
605+
);
606+
TPreviewDlg.Execute(Self, Data, dtPlainText, DlgTitle);
607+
end;
608+
554609
{ TPathInfoBox }
555610

556611
procedure TPathInfoBox.BtnClick(Sender: TObject);

0 commit comments

Comments
 (0)