Menu

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

Download this file

156 lines (132 with data), 4.2 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
{
* 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 syntax highlighter
* name.
}
unit FmNewHiliterNameDlg;
interface
uses
// Delphi
Controls, StdCtrls, ExtCtrls, Classes,
// Project
FmGenericOKDlg, UBaseObjects, UIStringList;
type
/// <summary>Class that implements a dialogue box that enables the user to
/// enter a syntax highlighter name.</summary>
TNewHiliterNameDlg = class(TGenericOKDlg, INoPublicConstruct)
cbNames: TComboBox;
lblHelp: TLabel;
lblNames: TLabel;
/// <summary>Checks validity of chosen name and, if valid, records it and
/// closes dialogue box.</summary>
procedure btnOKClick(Sender: TObject);
/// <summary>Updates dialogue box controls when selection in names combo
/// box changes.</summary>
procedure cbNamesChange(Sender: TObject);
strict private
var
/// <summary>Records chosen highlighter name.</summary>
fNewName: string;
/// <summary>List of existing highlighter names.</summary>
fNames: IStringList;
/// <summary>Updates control state based on current entries in dialogue
/// box.</summary>
procedure UpdateControls;
strict protected
/// <summary>Arranges controls on form and size dialogue box window to fit.
/// </summary>
procedure ArrangeForm; override;
/// <summary>Initialises form's controls.</summary>
procedure InitForm; override;
public
/// <summary>Displays dialogue box and passes any entered highlighter name
/// back to caller.</summary>
/// <param name="Owner">TComponent [in] Owning control. Dialogue box is
/// aligned over it.</param>
/// <param name="Names">array of string [in] Existing highlighter names.
/// </param>
/// <param name="NewName">string [out] Set to name entered by user if OK
/// pressed or undefined if dialogue box is cancelled.</param>
/// <returns>Boolean. True if OK button pressed or False if dialogue box
/// cancelled.</returns>
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.