Skip to content

Commit a09660b

Browse files
author
DelphiDabbler
committed
Merge branch 'feature/config-file-viewer' into develop
Added buttons to Path (now Path & Files) tab of About box that enable user to view the content of the program's config files.
2 parents 3339fdc + e1ac529 commit a09660b

File tree

6 files changed

+131
-33
lines changed

6 files changed

+131
-33
lines changed

Src/FirstRun.UInstallInfo.pas

Lines changed: 3 additions & 4 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) 2008-2013, Peter Johnson (www.delphidabbler.com).
6+
* Copyright (C) 2008-2016, Peter Johnson (www.delphidabbler.com).
77
*
88
* $Rev$
99
* $Date$
@@ -170,13 +170,12 @@ constructor TInstallInfo.Create;
170170

171171
function TInstallInfo.CurrentCommonConfigFileName: string;
172172
begin
173-
Result := IncludeTrailingPathDelimiter(TAppInfo.CommonAppDir)
174-
+ 'Common.config';
173+
Result := TAppInfo.AppConfigFileName;
175174
end;
176175

177176
class function TInstallInfo.CurrentUserConfigFileName: string;
178177
begin
179-
Result := MakeFullUserPath(UserConfigFileNames[CurrentVersionID]);
178+
Result := TAppInfo.UserConfigFileName;
180179
end;
181180

182181
class function TInstallInfo.CurrentUserDatabaseDir: string;

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);

Src/Help/HTML/dlg_about.htm

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
55
* obtain one at http://mozilla.org/MPL/2.0/
66
*
7-
* Copyright (C) 2005-2014, Peter Johnson (www.delphidabbler.com).
7+
* Copyright (C) 2005-2016, Peter Johnson (www.delphidabbler.com).
88
*
99
* $Rev$
1010
* $Date$
@@ -81,11 +81,17 @@ <h2>
8181
</li>
8282
</ul>
8383
<h2>
84-
Paths
84+
Paths &amp; Files
8585
</h2>
8686
<p>
8787
This tab gives information about various directories used by
88-
<em>CodeSnip</em>. They are:
88+
<em>CodeSnip</em> and enables the program's config files to be viewed.
89+
</p>
90+
<h3>
91+
Directories
92+
</h3>
93+
<p>
94+
The directories for which information is available are:
8995
</p>
9096
<ul class="unspaced">
9197
<li>
@@ -114,6 +120,22 @@ <h2>
114120
directory in Windows Explorer. If the directory does not exist then the
115121
button will be disabled.
116122
</p>
123+
<h3>
124+
Config Files
125+
</h3>
126+
<p>
127+
The content of the program's application wide and per-user config files
128+
can be displayed by clicking the <em>View Application Config File</em> and
129+
<em>View Per-User Config File</em> buttons respectively.
130+
</p>
131+
<p>
132+
You can find documentation of the meaning of the config file entries in
133+
<em>CodeSnip<em>'s <a
134+
href="https://github.com/delphidabbler/codesnip"
135+
class="weblink"
136+
target="_blank"
137+
>Git repository</a>.
138+
</p>
117139
</body>
118140
</html>
119141

Src/UAppInfo.pas

Lines changed: 17 additions & 1 deletion
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-2013, Peter Johnson (www.delphidabbler.com).
6+
* Copyright (C) 2005-2016, Peter Johnson (www.delphidabbler.com).
77
*
88
* $Rev$
99
* $Date$
@@ -97,6 +97,12 @@ TAppInfo = class(TNoConstructObject)
9797
{Returns fully specified name of CodeSnip's help file.
9898
@return Name of help file.
9999
}
100+
class function AppConfigFileName: string;
101+
{Returns fully specified name of application config file.
102+
}
103+
class function UserConfigFileName: string;
104+
{Returns fully specified name of per-user config file.
105+
}
100106
class function ProgramReleaseInfo: string;
101107
{Gets information about the current program release. Includes any special
102108
build information if present in version information.
@@ -146,6 +152,11 @@ implementation
146152

147153
{ TAppInfo }
148154

155+
class function TAppInfo.AppConfigFileName: string;
156+
begin
157+
Result := CommonAppDir + '\Common.config';
158+
end;
159+
149160
class function TAppInfo.AppDataDir: string;
150161
{Returns the directory where CodeSnip stores the "database" files.
151162
@return Full path to database sub directory.
@@ -347,6 +358,11 @@ class function TAppInfo.UserAppDir: string;
347358
{$ENDIF}
348359
end;
349360

361+
class function TAppInfo.UserConfigFileName: string;
362+
begin
363+
Result := UserAppDir + '\User.config';
364+
end;
365+
350366
class function TAppInfo.UserDataDir: string;
351367
{Returns the directory where CodeSnip stores the user's "database" files.
352368
@return Full path to database sub directory.

Src/USettings.pas

Lines changed: 3 additions & 3 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) 2006-2013, Peter Johnson (www.delphidabbler.com).
6+
* Copyright (C) 2006-2016, Peter Johnson (www.delphidabbler.com).
77
*
88
* $Rev$
99
* $Date$
@@ -595,9 +595,9 @@ function TIniSettingsBase.StorageName(
595595
begin
596596
case Storage of
597597
ssUser:
598-
Result := TAppInfo.UserAppDir + '\User.config';
598+
Result := TAppInfo.UserConfigFileName;
599599
ssCommon:
600-
Result := TAppInfo.CommonAppDir + '\Common.config';
600+
Result := TAppInfo.AppConfigFileName;
601601
else
602602
raise EBug.Create(ClassName + '.StorageName: unknown storage type');
603603
end;

0 commit comments

Comments
 (0)