1 {
2 ***************************************************************************
3 * *
4 * This source is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This code is distributed in the hope that it will be useful, but *
10 * WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * General Public License for more details. *
13 * *
14 * A copy of the GNU General Public License is available on the World *
15 * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
16 * obtain it by writing to the Free Software Foundation, *
17 * Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. *
18 * *
19 ***************************************************************************
20
21 Author: Mattias Gaertner
22
23 Abstract:
24 A simple dialog for the $PROMPT() tranfer macro function,
25 and a MessageDlg for the $CONFIRM() macro.
26
27 }
28 unit MacroPromptDlg;
29
30 {$mode objfpc}
31 {$H+}
32
33 {$I ide.inc}
34
35 interface
36
37 uses
38 {$IFDEF IDE_MEM_CHECK}
39 MemCheck,
40 {$ENDIF}
41 Classes, SysUtils, LCLType, Controls, Forms, Buttons, StdCtrls,
42 Dialogs, LResources, LazarusIDEStrConsts;
43
44
45 type
46 TMacroPrompDialog = class(TForm)
47 NoteLabel: TLabel;
48 DataEdit: TEdit;
49 OkButton: TButton;
50 CancelButton: TButton;
51 procedure MacroPrompDialogResize(Sender: TObject);
52 procedure OkButtonClick(Sender: TObject);
53 procedure CancelButtonClick(Sender: TObject);
54 procedure DataEditKeyDown(Sender: TObject; var Key:Word; {%H-}Shift:TShiftState);
55 public
56 constructor Create(AnOwner: TComponent); override;
57 end;
58
59
ShowMacroConfirmDialognull60 function ShowMacroConfirmDialog(const InitParam: string): TModalResult;
ShowMacroPromptDialognull61 function ShowMacroPromptDialog(var InitParam: string): TModalResult;
62
63
64 implementation
65
66
ShowMacroConfirmDialognull67 function ShowMacroConfirmDialog(const InitParam: string): TModalResult;
68 begin
69 Result:=MessageDlg(InitParam, mtConfirmation, mbOKCancel, 0);
70 end;
71
ShowMacroPromptDialognull72 function ShowMacroPromptDialog(var InitParam: string): TModalResult;
73 var MacroPrompDialog: TMacroPrompDialog;
74 begin
75 Result:=mrCancel;
76 MacroPrompDialog:=TMacroPrompDialog.Create(nil);
77 try
78 MacroPrompDialog.DataEdit.Text:=InitParam;
79 Result:=MacroPrompDialog.ShowModal;
80 if Result=mrOk then
81 InitParam:=MacroPrompDialog.DataEdit.Text;
82 finally
83 MacroPrompDialog.Free;
84 end;
85 end;
86
87 { TMacroPrompDialog }
88
89 constructor TMacroPrompDialog.Create(AnOwner: TComponent);
90 begin
91 inherited CreateNew(AnOwner);
92 if LazarusResources.Find(ClassName)=nil then begin
93 Width:=300;
94 Height:=150;
95 Position:=poScreenCenter;
96 Caption:=lisMacroPromptEnterData;
97 OnResize:=@MacroPrompDialogResize;
98
99 NoteLabel:=TLabel.Create(Self);
100 with NoteLabel do begin
101 Name:='NoteLabel';
102 Parent:=Self;
103 SetBounds(8,8,200,25);
104 Caption:=lisMacroPromptEnterRunParameters;
105 Visible:=true;
106 end;
107
108 DataEdit:=TEdit.Create(Self);
109 with DataEdit do begin
110 Name:='DataEdit';
111 Parent:=Self;
112 SetBounds(8,NoteLabel.Top+NoteLabel.Height+5,Self.ClientWidth-20,25);
113 OnKeyDown:=@DataEditKeyDown;
114 Visible:=true;
115 end;
116
117 OkButton:=TButton.Create(Self);
118 with OkButton do begin
119 Name:='OkButton';
120 Parent:=Self;
121 SetBounds(Self.ClientWidth-200,Self.ClientHeight-40,80,25);
122 Caption:=lisMenuOk;
123 OnClick:=@OkButtonClick;
124 Visible:=true;
125 end;
126
127 CancelButton:=TButton.Create(Self);
128 with CancelButton do begin
129 Name:='CancelButton';
130 Parent:=Self;
131 SetBounds(Self.ClientWidth-100,Self.ClientHeight-40,80,25);
132 Caption:=lisCancel;
133 OnClick:=@CancelButtonClick;
134 Visible:=true;
135 end;
136
137 end;
138 MacroPrompDialogResize(nil);
139 ActiveControl := DataEdit;
140 end;
141
142 procedure TMacroPrompDialog.MacroPrompDialogResize(Sender: TObject);
143 begin
144 with NoteLabel do begin
145 SetBounds(8,8,200,25);
146 end;
147
148 with DataEdit do begin
149 SetBounds(8,NoteLabel.Top+NoteLabel.Height+5,Self.ClientWidth-20,25);
150 end;
151
152 with OkButton do begin
153 SetBounds(Self.ClientWidth-200,Self.ClientHeight-40,80,25);
154 end;
155
156 with CancelButton do begin
157 SetBounds(Self.ClientWidth-100,Self.ClientHeight-40,80,25);
158 end;
159 end;
160
161 procedure TMacroPrompDialog.OkButtonClick(Sender: TObject);
162 begin
163 ModalResult:=mrOk;
164 end;
165
166 procedure TMacroPrompDialog.CancelButtonClick(Sender: TObject);
167 begin
168 ModalResult:=mrCancel;
169 end;
170
171 procedure TMacroPrompDialog.DataEditKeyDown(Sender: TObject; var Key:Word;
172 Shift:TShiftState);
173 begin
174 if (Key=VK_RETURN) then ModalResult:=mrOk;
175 if (Key=VK_ESCAPE) then ModalResult:=mrCancel;
176 end;
177
178
179 end.
180