Skip to content

Commit 1657455

Browse files
committed
Add new "What's New" dialogue box and supporting code.
What's New uses an associated new frame class to host a new HTML document read from resources. The main CodeSnip project files and HTML resource compilation script were all updated as required.
1 parent 1b80b19 commit 1657455

8 files changed

+403
-2
lines changed

Src/CodeSnip.dpr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ uses
7878
Favourites.UFavourites in 'Favourites.UFavourites.pas',
7979
Favourites.UPersist in 'Favourites.UPersist.pas',
8080
FirstRun.FmV4ConfigDlg in 'FirstRun.FmV4ConfigDlg.pas' {V4ConfigDlg},
81+
FirstRun.FmWhatsNew in 'FirstRun.FmWhatsNew.pas' {WhatsNewDlg},
82+
FirstRun.FmWhatsNew.FrHTML in 'FirstRun.FmWhatsNew.FrHTML.pas' {WhatsNewHTMLFrame: TFrame},
8183
FirstRun.UConfigFile in 'FirstRun.UConfigFile.pas',
8284
FirstRun.UDatabase in 'FirstRun.UDatabase.pas',
8385
FirstRun.UIniFile in 'FirstRun.UIniFile.pas',

Src/CodeSnip.dproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@
8383
<DCCReference Include="FirstRun.FmV4ConfigDlg.pas">
8484
<Form>V4ConfigDlg</Form>
8585
</DCCReference>
86+
<DCCReference Include="FirstRun.FmWhatsNew.pas">
87+
<Form>WhatsNewDlg</Form>
88+
</DCCReference>
89+
<DCCReference Include="FirstRun.FmWhatsNew.FrHTML.pas">
90+
<Form>WhatsNewHTMLFrame</Form>
91+
<DesignClass>TFrame</DesignClass>
92+
</DCCReference>
8693
<DCCReference Include="FirstRun.UConfigFile.pas"/>
8794
<DCCReference Include="FirstRun.UDatabase.pas"/>
8895
<DCCReference Include="FirstRun.UIniFile.pas"/>
@@ -566,7 +573,6 @@
566573
<DCCReference Include="UXMLDocConsts.pas"/>
567574
<DCCReference Include="UXMLDocHelper.pas"/>
568575
<DCCReference Include="UXMLDocumentEx.pas"/>
569-
<DCCReference Include="SWAG.UVersion.pas"/>
570576
<None Include="CodeSnip.todo"/>
571577
<BuildConfiguration Include="Base">
572578
<Key>Base</Key>

Src/FirstRun.FmWhatsNew.FrHTML.dfm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
inherited WhatsNewHTMLFrame: TWhatsNewHTMLFrame
2+
inherited pnlBrowser: TPanel
3+
inherited wbBrowser: TWebBrowser
4+
ControlData = {
5+
4C000000A9200000641800000000000000000000000000000000000000000000
6+
000000004C000000000000000000000001000000E0D057007335CF11AE690800
7+
2B2E126208000000000000004C0000000114020000000000C000000000000046
8+
8000000000000000000000000000000000000000000000000000000000000000
9+
00000000000000000100000000000000000000000000000000000000}
10+
end
11+
end
12+
end

Src/FirstRun.FmWhatsNew.FrHTML.pas

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
unit FirstRun.FmWhatsNew.FrHTML;
2+
3+
interface
4+
5+
uses
6+
// VCL
7+
OleCtrls,
8+
SHDocVw,
9+
Classes,
10+
Controls,
11+
ExtCtrls,
12+
// Project
13+
FrBrowserBase,
14+
UCSSBuilder;
15+
16+
17+
type
18+
TWhatsNewHTMLFrame = class(TBrowserBaseFrame)
19+
strict protected
20+
procedure BuildCSS(const CSSBuilder: TCSSBuilder); override;
21+
{Generates CSS classes specific to this frame. This CSS is added
22+
to that provided by parent class.
23+
@param CSSBuilder [in] Object used to build the CSS code.
24+
}
25+
public
26+
constructor Create(AOwner: TComponent); override;
27+
{Object constructor. Sets up frame and initialises web browser.
28+
@param AOwner [in] Component that owns the frame (must be a form).
29+
}
30+
procedure Initialise(const HTML: string);
31+
end;
32+
33+
34+
implementation
35+
36+
37+
uses
38+
// VCL
39+
Graphics,
40+
// Project
41+
Browser.UUIMgr,
42+
UCSSUtils,
43+
UFontHelper;
44+
45+
{$R *.dfm}
46+
47+
48+
{ TWhatsNewHTMLFrame }
49+
50+
procedure TWhatsNewHTMLFrame.BuildCSS(const CSSBuilder: TCSSBuilder);
51+
var
52+
CSSFont: TFont; // font used to set CSS properties
53+
begin
54+
inherited;
55+
CSSFont := TFont.Create;
56+
try
57+
TFontHelper.SetContentFont(CSSFont);
58+
CSSFont.Size := CSSFont.Size + 2;
59+
with CSSBuilder.AddSelector('body') do
60+
begin
61+
AddProperty(TCSS.FontProps(CSSFont));
62+
AddProperty(TCSS.MarginProp(0, 8, 0, 8));
63+
end;
64+
with CSSBuilder.AddSelector('.lead') do
65+
begin
66+
AddProperty(TCSS.FontSizeProp(CSSFont.Size + 2));
67+
AddProperty(TCSS.FontWeightProp(cfwBold));
68+
AddProperty(TCSS.ColorProp($233bc2));
69+
end;
70+
// Sets paragraph margins and padding
71+
with CSSBuilder.AddSelector('p') do
72+
begin
73+
AddProperty(TCSS.MarginProp(cssTop, 6));
74+
AddProperty(TCSS.MarginProp(cssBottom, 0));
75+
AddProperty(TCSS.PaddingProp(0));
76+
end;
77+
with CSSBuilder.AddSelector('ul') do
78+
begin
79+
AddProperty(TCSS.MarginProp(cssTop, 6));
80+
AddProperty(TCSS.MarginProp(cssBottom, 0));
81+
AddProperty(TCSS.PaddingProp(0));
82+
end;
83+
with CSSBuilder.AddSelector('li') do
84+
begin
85+
AddProperty(TCSS.MarginProp(cssTop, 6));
86+
end;
87+
finally
88+
CSSFont.Free;
89+
end;
90+
end;
91+
92+
constructor TWhatsNewHTMLFrame.Create(AOwner: TComponent);
93+
begin
94+
inherited;
95+
WBController.UIMgr.ScrollbarStyle := sbsNormal;
96+
WBController.UIMgr.AllowTextSelection := False;
97+
end;
98+
99+
procedure TWhatsNewHTMLFrame.Initialise(const HTML: string);
100+
begin
101+
WBController.IOMgr.LoadFromString(HTML);
102+
end;
103+
104+
end.

Src/FirstRun.FmWhatsNew.dfm

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
inherited WhatsNewDlg: TWhatsNewDlg
2+
Caption = 'What'#39's New'
3+
ExplicitWidth = 474
4+
ExplicitHeight = 375
5+
PixelsPerInch = 96
6+
TextHeight = 13
7+
inherited pnlBody: TPanel
8+
inline frmHTML: TWhatsNewHTMLFrame
9+
Left = 0
10+
Top = 0
11+
Width = 377
12+
Height = 281
13+
Align = alClient
14+
TabOrder = 0
15+
TabStop = True
16+
ExplicitWidth = 377
17+
ExplicitHeight = 281
18+
inherited pnlBrowser: TPanel
19+
Width = 377
20+
Height = 281
21+
ExplicitWidth = 377
22+
ExplicitHeight = 281
23+
inherited wbBrowser: TWebBrowser
24+
Width = 377
25+
Height = 281
26+
ExplicitWidth = 377
27+
ExplicitHeight = 281
28+
ControlData = {
29+
4C000000F72600000B1D00000000000000000000000000000000000000000000
30+
000000004C000000000000000000000001000000E0D057007335CF11AE690800
31+
2B2E126208000000000000004C0000000114020000000000C000000000000046
32+
8000000000000000000000000000000000000000000000000000000000000000
33+
00000000000000000100000000000000000000000000000000000000}
34+
end
35+
end
36+
end
37+
end
38+
inherited btnHelp: TButton
39+
Visible = False
40+
end
41+
end

Src/FirstRun.FmWhatsNew.pas

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
{
2+
* This Source Code Form is subject to the terms of the Mozilla Public License,
3+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4+
* obtain one at http://mozilla.org/MPL/2.0/
5+
*
6+
* Copyright (C) 2020, Peter Johnson (gravatar.com/delphidabbler).
7+
*
8+
* Implements dialogue box that may be displayed the first time CodeSnip 4.x.x
9+
* is run after an update. The dialogue box displays a HTML page that draws
10+
* attention to key changes in the updated version of CodeSnip.
11+
}
12+
13+
14+
unit FirstRun.FmWhatsNew;
15+
16+
interface
17+
18+
19+
uses
20+
// VCL
21+
Controls,
22+
Forms,
23+
StdCtrls,
24+
ExtCtrls,
25+
Classes,
26+
// Project
27+
FirstRun.FmWhatsNew.FrHTML,
28+
FmGenericViewDlg,
29+
FrBrowserBase,
30+
IntfAligner,
31+
UBaseObjects;
32+
33+
34+
type
35+
/// <summary>Dialogue box that may be displayed the first time CodeSnip 4.x.x
36+
/// is run after an update. The dialogue box displays a HTML page that draws
37+
/// attention to key changes in the updated version of CodeSnip.</summary>
38+
TWhatsNewDlg = class(TGenericViewDlg, INoPublicConstruct)
39+
frmHTML: TWhatsNewHTMLFrame;
40+
strict private
41+
type
42+
/// <summary>Custom form aligner class for wizard.</summary>
43+
TAligner = class(TInterfacedObject, IFormAligner)
44+
public
45+
/// <summary>Aligns dialogue box at centre of primary monitor.
46+
/// </summary>
47+
procedure AlignForm(const AForm: TCustomForm);
48+
end;
49+
strict protected
50+
/// <summary>Returns instance of form aligner object.</summary>
51+
function GetAligner: IFormAligner; override;
52+
/// <summary>Sets form caption and loads HTML to be displayed from
53+
/// resources.</summary>
54+
procedure ConfigForm; override;
55+
/// <summary>Sets size of the HTML section of the display and aranges other
56+
/// controls around that.</summary>
57+
procedure ArrangeForm; override;
58+
/// <summary>Modifies window creation parameters to ensure the dialgue box
59+
/// displays a button in the task bar.</summary>
60+
/// <remarks>This is necessary because the dialogue box is displayed before
61+
/// CodeSnip's main window is shown, so there is no suitable button
62+
/// displayed yet.</remarks>
63+
procedure CreateParams(var Params: TCreateParams); override;
64+
public
65+
/// <summary>Displays dialogue box with given owner.</summary>
66+
class procedure Execute(AOwner: TComponent);
67+
end;
68+
69+
70+
implementation
71+
72+
73+
uses
74+
// VCL
75+
SysUtils,
76+
Math,
77+
Windows,
78+
// Project
79+
UAppInfo,
80+
UConsts,
81+
UEncodings,
82+
UResourceUtils,
83+
UStructs;
84+
85+
{$R *.dfm}
86+
87+
88+
{ TWhatsNewDlg }
89+
90+
procedure TWhatsNewDlg.ArrangeForm;
91+
const
92+
cBodyWidth = 500;
93+
cBodyHeight = 450;
94+
begin
95+
pnlBody.Width := cBodyWidth;
96+
pnlBody.Height := cBodyHeight;
97+
inherited;
98+
end;
99+
100+
procedure TWhatsNewDlg.ConfigForm;
101+
resourcestring
102+
sDlgTitle = 'Welcome to CodeSnip v%s';
103+
begin
104+
Caption := Format(sDlgTitle, [TAppInfo.ProgramReleaseVersion]);
105+
frmHTML.Initialise(
106+
LoadResourceAsString(HInstance, 'dlg-whatsnew.html', RT_HTML, etUTF8)
107+
);
108+
end;
109+
110+
procedure TWhatsNewDlg.CreateParams(var Params: TCreateParams);
111+
begin
112+
inherited;
113+
Params.ExStyle := Params.ExStyle OR WS_EX_APPWINDOW;
114+
end;
115+
116+
class procedure TWhatsNewDlg.Execute(AOwner: TComponent);
117+
begin
118+
with InternalCreate(AOwner) do
119+
try
120+
ShowModal;
121+
finally
122+
Free;
123+
end;
124+
end;
125+
126+
function TWhatsNewDlg.GetAligner: IFormAligner;
127+
begin
128+
Result := TAligner.Create;
129+
end;
130+
131+
{ TWhatsNewDlg.TAligner }
132+
133+
procedure TWhatsNewDlg.TAligner.AlignForm(const AForm: TCustomForm);
134+
var
135+
WorkArea: TRectEx;
136+
begin
137+
// This form is designed for display centred on desktop, so assume it fits
138+
WorkArea := Screen.WorkAreaRect;
139+
AForm.Left := WorkArea.Left + (WorkArea.Width - AForm.Width) div 2;
140+
AForm.Top := WorkArea.Top + (WorkArea.Height - AForm.Height) div 2;
141+
end;
142+
143+
end.
144+

Src/HTML.hrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Res\Scripts\3rdParty\jquery.cycle.lite.js
2525
# compiler error log
2626
Res\HTML\dlg-comperror-tplt.html
2727

28-
# active text preview dialogueue
28+
# active text preview dialogue
2929
Res\HTML\dlg-activetext-preview-tplt.html
3030

3131
# news dialogue
@@ -40,6 +40,11 @@ Res\HTML\dlg-dbupdate-intro-tplt.html
4040
Res\HTML\dlg-dbupdate-load.html
4141
Res\HTML\dlg-dbupdate-finish.html
4242

43+
# what's new dialogue
44+
# -------------------
45+
Res\HTML\dlg-whatsnew.html
46+
47+
4348

4449
# Detail pane pages, scripts and CSS
4550
# ==================================

0 commit comments

Comments
 (0)