Skip to content

Commit d20d9fd

Browse files
committed
Merge branch 'feature/issue#15-user-db-deletion' into develop
2 parents c1b073f + ed8becf commit d20d9fd

15 files changed

+403
-13
lines changed

Src/CodeSnip.dpr

Lines changed: 3 additions & 2 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 https://mozilla.org/MPL/2.0/
55
*
6-
* Copyright (C) 2005-2021, Peter Johnson (gravatar.com/delphidabbler).
6+
* Copyright (C) 2005-2022, Peter Johnson (gravatar.com/delphidabbler).
77
*
88
* CodeSnip application project file.
99
}
@@ -369,7 +369,8 @@ uses
369369
UWindowSettings in 'UWindowSettings.pas',
370370
UXMLDocConsts in 'UXMLDocConsts.pas',
371371
UXMLDocHelper in 'UXMLDocHelper.pas',
372-
UXMLDocumentEx in 'UXMLDocumentEx.pas';
372+
UXMLDocumentEx in 'UXMLDocumentEx.pas',
373+
FmDeleteUserDBDlg in 'FmDeleteUserDBDlg.pas' {DeleteUserDBDlg};
373374

374375
// Include resources
375376
{$Resource ExternalObj.tlb} // Type library file

Src/CodeSnip.dproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,9 @@
572572
<DCCReference Include="UXMLDocConsts.pas"/>
573573
<DCCReference Include="UXMLDocHelper.pas"/>
574574
<DCCReference Include="UXMLDocumentEx.pas"/>
575+
<DCCReference Include="FmDeleteUserDBDlg.pas">
576+
<Form>DeleteUserDBDlg</Form>
577+
</DCCReference>
575578
<None Include="CodeSnip.todo"/>
576579
<BuildConfiguration Include="Base">
577580
<Key>Base</Key>

Src/FmDeleteUserDBDlg.dfm

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
inherited DeleteUserDBDlg: TDeleteUserDBDlg
2+
Caption = 'Delete User Database'
3+
ExplicitWidth = 474
4+
ExplicitHeight = 375
5+
PixelsPerInch = 96
6+
TextHeight = 13
7+
inherited pnlBody: TPanel
8+
object edConfirm: TEdit
9+
Left = 0
10+
Top = 216
11+
Width = 201
12+
Height = 21
13+
TabOrder = 0
14+
end
15+
inline frmWarning: TFixedHTMLDlgFrame
16+
Left = 0
17+
Top = 0
18+
Width = 369
19+
Height = 210
20+
Align = alTop
21+
TabOrder = 1
22+
TabStop = True
23+
ExplicitWidth = 369
24+
ExplicitHeight = 210
25+
inherited pnlBrowser: TPanel
26+
Width = 369
27+
Height = 210
28+
ExplicitWidth = 369
29+
ExplicitHeight = 210
30+
inherited wbBrowser: TWebBrowser
31+
Width = 369
32+
Height = 210
33+
ExplicitWidth = 369
34+
ExplicitHeight = 210
35+
ControlData = {
36+
4C00000023260000B41500000000000000000000000000000000000000000000
37+
000000004C000000000000000000000001000000E0D057007335CF11AE690800
38+
2B2E126208000000000000004C0000000114020000000000C000000000000046
39+
8000000000000000000000000000000000000000000000000000000000000000
40+
00000000000000000100000000000000000000000000000000000000}
41+
end
42+
end
43+
end
44+
end
45+
inherited btnOK: TButton
46+
OnClick = btnOKClick
47+
end
48+
end

Src/FmDeleteUserDBDlg.pas

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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 https://mozilla.org/MPL/2.0/
5+
*
6+
* Copyright (C) 2022, Peter Johnson (gravatar.com/delphidabbler).
7+
*
8+
* Implements a dialogue box that asks user to confirm deletion of user-defined
9+
* snippets database.
10+
}
11+
12+
13+
unit FmDeleteUserDBDlg;
14+
15+
interface
16+
17+
uses
18+
// Delphi
19+
Forms, StdCtrls, Controls, ExtCtrls, Classes,
20+
// Project
21+
FmGenericOKDlg,
22+
FrBrowserBase, FrHTMLDlg, FrFixedHTMLDlg,
23+
UBaseObjects;
24+
25+
type
26+
TDeleteUserDBDlg = class(TGenericOKDlg, INoPublicConstruct)
27+
edConfirm: TEdit;
28+
frmWarning: TFixedHTMLDlgFrame;
29+
procedure btnOKClick(Sender: TObject);
30+
strict private
31+
const
32+
cConfirmText = 'DELETE MY SNIPPETS';
33+
var
34+
fPermissionGranted: Boolean;
35+
strict protected
36+
/// <summary>Protected constructor that sets up form.</summary>
37+
constructor InternalCreate(AOwner: TComponent); override;
38+
procedure ConfigForm; override;
39+
procedure ArrangeForm; override;
40+
function IsValidPassword: Boolean;
41+
public
42+
class function Execute(AOwner: TComponent): Boolean;
43+
end;
44+
45+
implementation
46+
47+
uses
48+
// Delphi
49+
SysUtils,
50+
// Project
51+
UCtrlArranger, UMessageBox;
52+
53+
{$R *.dfm}
54+
55+
procedure TDeleteUserDBDlg.ArrangeForm;
56+
begin
57+
frmWarning.Height := frmWarning.DocHeight;
58+
edConfirm.Left := 0;
59+
TCtrlArranger.MoveBelow(frmWarning, edConfirm, 12);
60+
TCtrlArranger.AlignHCentresTo([frmWarning], [edConfirm]);
61+
pnlBody.ClientHeight := TCtrlArranger.TotalControlHeight(pnlBody) + 8;
62+
inherited;
63+
end;
64+
65+
procedure TDeleteUserDBDlg.btnOKClick(Sender: TObject);
66+
resourcestring
67+
sBadPassword = 'Invalid confirmation text entered';
68+
begin
69+
inherited;
70+
fPermissionGranted := IsValidPassword;
71+
if not fPermissionGranted then
72+
begin
73+
TMessageBox.Error(Self, sBadPassword);
74+
edConfirm.Text := '';
75+
ModalResult := mrNone;
76+
end;
77+
end;
78+
79+
procedure TDeleteUserDBDlg.ConfigForm;
80+
begin
81+
inherited;
82+
// frmWarning.OnBuildCSS := BuildCSS;
83+
frmWarning.Initialise('dlg-dbdelete.html');
84+
end;
85+
86+
class function TDeleteUserDBDlg.Execute(AOwner: TComponent): Boolean;
87+
begin
88+
with InternalCreate(AOwner) do
89+
try
90+
ShowModal;
91+
Result := fPermissionGranted;
92+
finally
93+
Free;
94+
end;
95+
end;
96+
97+
constructor TDeleteUserDBDlg.InternalCreate(AOwner: TComponent);
98+
begin
99+
Assert(Supports(Self, INoPublicConstruct), ClassName + '.InternalCreate: '
100+
+ 'Form''s protected constructor can''t be called');
101+
inherited InternalCreate(AOwner);
102+
end;
103+
104+
function TDeleteUserDBDlg.IsValidPassword: Boolean;
105+
begin
106+
Result := edConfirm.Text = cConfirmText;
107+
end;
108+
109+
end.

Src/FmMain.dfm

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ inherited MainForm: TMainForm
88
Constraints.MinWidth = 480
99
Menu = mnuMain
1010
OnResize = FormResize
11-
ExplicitWidth = 613
12-
ExplicitHeight = 495
11+
ExplicitWidth = 621
12+
ExplicitHeight = 503
1313
PixelsPerInch = 96
1414
TextHeight = 13
1515
object sbStatusBar: TStatusBar
@@ -866,6 +866,14 @@ inherited MainForm: TMainForm
866866
' default web browser'
867867
ImageIndex = 6
868868
end
869+
object actDeleteUserDatabase: TAction
870+
Category = 'Database'
871+
Caption = 'Delete User Database...'
872+
Hint =
873+
'Delete User Database|Deletes the user'#39's snippets database - USE ' +
874+
'WITH CAUTION'
875+
OnExecute = actDeleteUserDatabaseExecute
876+
end
869877
end
870878
object mnuMain: TMainMenu
871879
Images = ilMain
@@ -1093,6 +1101,12 @@ inherited MainForm: TMainForm
10931101
object miMoveUserDatabase: TMenuItem
10941102
Action = actMoveUserDatabase
10951103
end
1104+
object miSpacer21: TMenuItem
1105+
Caption = '-'
1106+
end
1107+
object miDeleteUserDatabase: TMenuItem
1108+
Action = actDeleteUserDatabase
1109+
end
10961110
end
10971111
object miCompile: TMenuItem
10981112
Caption = 'Compile'

Src/FmMain.pas

Lines changed: 15 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 https://mozilla.org/MPL/2.0/
55
*
6-
* Copyright (C) 2005-2021, Peter Johnson (gravatar.com/delphidabbler).
6+
* Copyright (C) 2005-2022, Peter Johnson (gravatar.com/delphidabbler).
77
*
88
* Application's main form. Handles the program's main window display and user
99
* interaction.
@@ -56,6 +56,7 @@ TMainForm = class(THelpAwareForm)
5656
actAddFavourite: TAction;
5757
actAddSnippet: TAction;
5858
actBackupDatabase: TAction;
59+
actBlog: TBrowseURL;
5960
actBugReport: TAction;
6061
actCloseAllDetailsTabs: TAction;
6162
actCloseDetailsTab: TAction;
@@ -69,6 +70,7 @@ TMainForm = class(THelpAwareForm)
6970
actCopySource: TAction;
7071
actDeleteCategory: TAction;
7172
actDeleteSnippet: TAction;
73+
actDeleteUserDatabase: TAction;
7274
actDuplicateSnippet: TAction;
7375
actEditSnippet: TAction;
7476
actExit: TFileExit;
@@ -125,6 +127,7 @@ TMainForm = class(THelpAwareForm)
125127
miAddFavourite: TMenuItem;
126128
miAddSnippet: TMenuItem;
127129
miBackupDatabase: TMenuItem;
130+
miBlog: TMenuItem;
128131
miCategories: TMenuItem;
129132
miCloseAllDetailsTabs: TMenuItem;
130133
miCloseDetailsTab: TMenuItem;
@@ -138,6 +141,7 @@ TMainForm = class(THelpAwareForm)
138141
miDatabase: TMenuItem;
139142
miDeleteCategory: TMenuItem;
140143
miDeleteSnippet: TMenuItem;
144+
miDeleteUserDatabase: TMenuItem;
141145
miDuplicateSnippet: TMenuItem;
142146
miEdit: TMenuItem;
143147
miEditSnippet: TMenuItem;
@@ -195,6 +199,7 @@ TMainForm = class(THelpAwareForm)
195199
miSpacer17: TMenuItem;
196200
miSpacer18: TMenuItem;
197201
miSpacer20: TMenuItem;
202+
miSpacer21: TMenuItem;
198203
miSWAGImport: TMenuItem;
199204
miTestCompile: TMenuItem;
200205
miTools: TMenuItem;
@@ -236,8 +241,6 @@ TMainForm = class(THelpAwareForm)
236241
tbSpacer7: TToolButton;
237242
tbSpacer8: TToolButton;
238243
tbTestCompile: TToolButton;
239-
actBlog: TBrowseURL;
240-
miBlog: TMenuItem;
241244
/// <summary>Displays About Box.</summary>
242245
procedure actAboutExecute(Sender: TObject);
243246
/// <summary>Gets a new category from user and adds to database.</summary>
@@ -294,6 +297,9 @@ TMainForm = class(THelpAwareForm)
294297
/// <summary>Attempts to delete the current user defined snippet from the
295298
/// database.</summary>
296299
procedure actDeleteSnippetExecute(Sender: TObject);
300+
/// <summary>Requests permission then attempts to delete the user defined
301+
/// snippets database.</summary>
302+
procedure actDeleteUserDatabaseExecute(Sender: TObject);
297303
/// <summary>Displays a dialogue box that can be used to duplicate the
298304
/// selected snippet.</summary>
299305
procedure actDuplicateSnippetExecute(Sender: TObject);
@@ -713,6 +719,12 @@ procedure TMainForm.actDeleteSnippetExecute(Sender: TObject);
713719
// display update is handled by snippets change event handler
714720
end;
715721

722+
procedure TMainForm.actDeleteUserDatabaseExecute(Sender: TObject);
723+
begin
724+
if TUserDBMgr.DeleteDatabase then
725+
ReloadDatabase;
726+
end;
727+
716728
procedure TMainForm.actDuplicateSnippetExecute(Sender: TObject);
717729
begin
718730
TUserDBMgr.DuplicateSnippet(fMainDisplayMgr.CurrentView);

Src/HTML.hrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
33
# obtain one at https://mozilla.org/MPL/2.0/
44
#
5-
# Copyright (C) 2005-2021, Peter Johnson (gravatar.com/delphidabbler).
5+
# Copyright (C) 2005-2022, Peter Johnson (gravatar.com/delphidabbler).
66
#
77
# Manifest file used to generate HTML.res resource file.
88

@@ -38,9 +38,10 @@ Res\HTML\dlg-dbupdate-load.html
3838
Res\HTML\dlg-dbupdate-finish.html
3939

4040
# what's new dialogue
41-
# -------------------
4241
Res\HTML\dlg-whatsnew.html
4342

43+
# delete database dialogue
44+
Res\HTML\dlg-dbdelete.html
4445

4546

4647
# Detail pane pages, scripts and CSS

Src/Help/CodeSnip.hhp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ HTML\dlg_addcategory.htm
2525
HTML\dlg_backup.htm
2626
HTML\dlg_configcompilers.htm
2727
HTML\dlg_deletecategory.htm
28+
HTML\dlg_deleteuserdb.htm
2829
HTML\dlg_dependencies.htm
2930
HTML\dlg_dependencies_edit.htm
3031
HTML\dlg_duplicatesnippet.htm
@@ -96,6 +97,7 @@ HTML\task_addsnippets.htm
9697
HTML\task_backup.htm
9798
HTML\task_copysnippet.htm
9899
HTML\task_customise.htm
100+
HTML\task_deleteuserdb.htm
99101
HTML\task_export.htm
100102
HTML\task_generateunit.htm
101103
HTML\task_printroutine.htm

0 commit comments

Comments
 (0)