Skip to content

Commit c79be6c

Browse files
committed
Add feature to delete user database.
New dialogue box unit to get permission to delete, with associated HTML frame contents. Update UUserDBMgr to add new method to perform deletion. Add new "Delete User Database" action and menu option to main form. Fixes #15
1 parent c1b073f commit c79be6c

File tree

9 files changed

+258
-10
lines changed

9 files changed

+258
-10
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 = 'DeleteUserDBDlg'
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: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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: not deleting';
68+
begin
69+
inherited;
70+
fPermissionGranted := IsValidPassword;
71+
if not fPermissionGranted then
72+
begin
73+
TMessageBox.Error(Self, sBadPassword);
74+
ModalResult := mrNone;
75+
end;
76+
end;
77+
78+
procedure TDeleteUserDBDlg.ConfigForm;
79+
begin
80+
inherited;
81+
// frmWarning.OnBuildCSS := BuildCSS;
82+
frmWarning.Initialise('dlg-dbdelete.html');
83+
end;
84+
85+
class function TDeleteUserDBDlg.Execute(AOwner: TComponent): Boolean;
86+
begin
87+
with InternalCreate(AOwner) do
88+
try
89+
ShowModal;
90+
Result := fPermissionGranted;
91+
finally
92+
Free;
93+
end;
94+
end;
95+
96+
constructor TDeleteUserDBDlg.InternalCreate(AOwner: TComponent);
97+
begin
98+
Assert(Supports(Self, INoPublicConstruct), ClassName + '.InternalCreate: '
99+
+ 'Form''s protected constructor can''t be called');
100+
inherited InternalCreate(AOwner);
101+
end;
102+
103+
function TDeleteUserDBDlg.IsValidPassword: Boolean;
104+
begin
105+
Result := edConfirm.Text = cConfirmText;
106+
end;
107+
108+
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: 13 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 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.
@@ -69,6 +69,7 @@ TMainForm = class(THelpAwareForm)
6969
actCopySource: TAction;
7070
actDeleteCategory: TAction;
7171
actDeleteSnippet: TAction;
72+
actDeleteUserDatabase: TAction;
7273
actDuplicateSnippet: TAction;
7374
actEditSnippet: TAction;
7475
actExit: TFileExit;
@@ -138,6 +139,7 @@ TMainForm = class(THelpAwareForm)
138139
miDatabase: TMenuItem;
139140
miDeleteCategory: TMenuItem;
140141
miDeleteSnippet: TMenuItem;
142+
miDeleteUserDatabase: TMenuItem;
141143
miDuplicateSnippet: TMenuItem;
142144
miEdit: TMenuItem;
143145
miEditSnippet: TMenuItem;
@@ -195,6 +197,7 @@ TMainForm = class(THelpAwareForm)
195197
miSpacer17: TMenuItem;
196198
miSpacer18: TMenuItem;
197199
miSpacer20: TMenuItem;
200+
miSpacer21: TMenuItem;
198201
miSWAGImport: TMenuItem;
199202
miTestCompile: TMenuItem;
200203
miTools: TMenuItem;
@@ -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/Res/HTML/dlg-dbdelete.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0"?>
2+
3+
<!DOCTYPE html
4+
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
5+
"https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
6+
7+
<!--
8+
* This Source Code Form is subject to the terms of the Mozilla Public License,
9+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
10+
* obtain one at https://mozilla.org/MPL/2.0/
11+
*
12+
* Copyright (C) 2022, Peter Johnson (gravatar.com/delphidabbler).
13+
*
14+
* Warning information displayed in dialogue box used to confirm deletion on the
15+
* user database.
16+
-->
17+
18+
<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
19+
20+
<head>
21+
<title>dlg-dbdelete.html</title>
22+
</head>
23+
24+
<body>
25+
26+
<h1>
27+
ARE YOU SURE?
28+
</h1>
29+
30+
<p>
31+
Before going any further you are <strong>strongly advised</strong> to take a backup of your snippets database. Use the <em>Database | Backup User Database</em> menu option to do this.
32+
</p>
33+
34+
<p>
35+
<strong class="warning">This action cannot be undone: you will loose all your user-defined snippets.</strong>
36+
</p>
37+
38+
<p>
39+
To confirm enter <code>DELETE MY SNIPPETS</code> (in capital letters) in the box below then click <em>OK</em>.
40+
</p>
41+
42+
<p>
43+
<strong>There will be no further chances to change your mind.</strong>
44+
</p>
45+
46+
</body>
47+
48+
</html>

0 commit comments

Comments
 (0)