|
| 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. |
0 commit comments