Menu

[r2802]: / trunk / Src / FmNewHiliterNameDlg.pas  Maximize  Restore  History

Download this file

132 lines (109 with data), 2.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
{
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2013, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Implements a dialogue box that enables the user to enter a new name for a
* named highlighter.
}
unit FmNewHiliterNameDlg;
interface
uses
// Delphi
Controls, StdCtrls, ExtCtrls, Classes,
// Project
FmGenericOKDlg, UBaseObjects, UIStringList;
type
TNewHiliterNameDlg = class(TGenericOKDlg, INoPublicConstruct)
lblNames: TLabel;
cbNames: TComboBox;
lblHelp: TLabel;
procedure cbNamesChange(Sender: TObject);
procedure btnOKClick(Sender: TObject);
strict private
var
fNewName: string;
fNames: IStringList;
procedure UpdateControls;
strict protected
procedure ArrangeForm; override;
procedure InitForm; override;
public
class function Execute(Owner: TComponent; const Names: array of string;
out NewName: string): Boolean;
end;
implementation
uses
// Delphi
SysUtils, Math,
// Project
UCtrlArranger, UMessageBox, UStrUtils;
{$R *.dfm}
{ TNewHiliterNameDlg }
procedure TNewHiliterNameDlg.ArrangeForm;
begin
lblNames.Top := 0;
TCtrlArranger.MoveBelow(lblNames, cbNames, 6);
TCtrlArranger.MoveBelow(cbNames, lblHelp, 4);
TCtrlArranger.AlignLefts([lblNames, cbNames], 0);
pnlBody.ClientWidth := Max(
TCtrlArranger.TotalControlWidth(pnlBody) + 8,
TCtrlArranger.RightOf(btnHelp) - btnOK.Left
);
cbNames.Width := pnlBody.ClientWidth;
pnlBody.ClientHeight := TCtrlArranger.TotalControlHeight(pnlBody) + 24;
inherited;
end;
procedure TNewHiliterNameDlg.btnOKClick(Sender: TObject);
resourcestring
sQuestion = '"%s" already exists. Overwrite it?';
var
ChosenName: string;
begin
ChosenName := StrTrim(cbNames.Text);
// check for errors
ModalResult := mrNone;
if ChosenName = '' then
Exit;
if fNames.Contains(ChosenName)
and not TMessageBox.Confirm(Self, Format(sQuestion, [ChosenName])) then
Exit;
// all OK
ModalResult := mrOK;
fNewName := ChosenName;
end;
procedure TNewHiliterNameDlg.cbNamesChange(Sender: TObject);
begin
UpdateControls;
end;
class function TNewHiliterNameDlg.Execute(Owner: TComponent;
const Names: array of string; out NewName: string): Boolean;
begin
with InternalCreate(Owner) do
try
fNames := TIStringList.Create(Names);
fNames.CaseSensitive := False;
Result := ShowModal = mrOK;
if Result then
NewName := fNewName;
finally
Free;
end;
end;
procedure TNewHiliterNameDlg.InitForm;
begin
inherited;
fNames.CopyTo(cbNames.Items, True);
cbNames.Text := '';
UpdateControls;
end;
procedure TNewHiliterNameDlg.UpdateControls;
begin
btnOK.Enabled := cbNames.Text <> '';
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.