1 {
2 *****************************************************************************
3 * *
4 * This file is part of the ZCAD *
5 * *
6 * See the file COPYING.modifiedLGPL.txt, included in this distribution, *
7 * for details about the copyright. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
12 * *
13 *****************************************************************************
14 }
15 {
16 @author(Andrey Zubarev <zamtmn@yandex.ru>)
17 }
18
19 unit uzcfcommandline;
20 {$INCLUDE def.inc}
21 interface
22 uses
23 uzcguimanager,uzbpaths,Themes,buttons,uzcsysvars,uzcstrconsts,uzbstrproc,
24 uzcsysinfo,lclproc,LazUTF8,sysutils, StdCtrls,ExtCtrls,Controls,Classes,
25 menus,Forms,fileutil,graphics, uzbtypes, uzbmemman,uzcdrawings,uzccommandsmanager,
26 varman,languade,varmandef,
27 uzegeometry,uzctnrvectorgdbstring,uzcinterface,uzctreenode,uzclog,strmy,
28 uzccommandlineutil,uztoolbarsmanager,uzmenusmanager,uzccommandsabstract,gzctnrvectortypes;
29
30 const
31 cheight=48;
32 type
33 TCLine = class(TForm)
34 procedure AfterConstruction; override;
35 public
36 //utfpresent:boolean;
37 utflen:integer;
38 procedure keypressmy(Sender: TObject; var Key: char);
39 procedure SetMode(m:TCLineMode);virtual;
40 procedure DoOnResize; override;
41 procedure MyResize;
42 procedure mypaint(sender:tobject);
43 procedure FormCreate(Sender: TObject);
44 procedure ButtonPressed(Sender: TObject);
GetCLineFocusPrioritynull45 function GetCLineFocusPriority:TControlWithPriority;
46
47 destructor Destroy;override;
48 end;
49 var
50 CLine: TCLine;
51 cmdedit:TComboBox;
52 prompt:TLabel;
53 panel:tpanel;
54 HistoryLine:TMemo;
55
56 HintText:TLabel;
57 //historychanged:boolean;
58
59 implementation
60
61 //var
62 // historychanged:boolean;
63
64 procedure TCLine.mypaint(sender:tobject);
65 begin
66 canvas.Line(0,0,100,100);
67 end;
68
69 procedure TCLine.SetMode(m:TCLineMode);
70 begin
71 {if m=mode then
72 exit;}
73 case m of
74 CLCOMMANDREDY:
75 begin
76 prompt.Caption:=commandprefix+rsdefaultpromot+commandsuffix;
77 cmdedit.AutoComplete:=true;
78 cmdedit.AutoDropDown:=true;
79 end;
80 CLCOMMANDRUN:
81 begin
82 prompt.Caption:=commandsuffix;
83 cmdedit.AutoComplete:=false;
84 cmdedit.AutoDropDown:=false;
85 end;
86 end;
87 mode:=m;
88 end;
89 procedure HandleCommandLineMode(GUIMode:TZMessageID);
90 begin
91 if GUIMode=ZMsgID_GUICMDLineReadyMode then begin
92 if assigned(CLine) then
93 CLine.SetMode(CLCOMMANDREDY)
94 end
95 else if GUIMode=ZMsgID_GUICMDLineRunMode then begin
96 if assigned(CLine) then
97 CLine.SetMode(CLCOMMANDRUN)
98 end;
99 end;
100
101 procedure TCLine.ButtonPressed(Sender: TObject);
102 var
103 menu:TPopupMenu;
104 begin
105 menu:=MenusManager.GetPopupMenu('LASTCOMMANDSCXMENU',nil);
106 if menu<>nil then
107 begin
108 menu.PopUp;
109 end;
110 end;
GetCLineFocusPrioritynull111 function TCLine.GetCLineFocusPriority:TControlWithPriority;
112 begin
113 result.priority:=UnPriority;
114 result.control:=nil;
115
116 if assigned(cmdedit) then
117 if cmdedit.Enabled then
118 if cmdedit.IsVisible then
119 if cmdedit.CanFocus then begin
120 result.priority:=CLinePriority;
121 result.control:=cmdedit;
122 end;
123 end;
124 procedure DisableCmdLine;
125 begin
126 if assigned(uzcfcommandline.cmdedit) then
127 uzcfcommandline.cmdedit.Enabled:=false;
128 if assigned(prompt) then begin
129 prompt.Enabled:=false;
130 prompt.Color:=clBtnFace;
131 end;
132 end;
133
134 procedure EnableCmdLine;
135 begin
136 if assigned(uzcfcommandline.cmdedit) then
137 uzcfcommandline.cmdedit.Enabled:=true;
138 if assigned(prompt) then begin
139 prompt.Enabled:=true;
140 prompt.Color:=clDefault;
141 end;
142 end;
143 procedure HideCmdLine;
144 begin
145 DisableCmdLine;
146 if assigned(panel) then
147 panel.visible:=false;
148 ZCStatekInterface.SetState(ZCSGUIChanged);
149 end;
150 procedure ShowCmdLine;
151 begin
152 EnableCmdLine;
153 if assigned(panel) then
154 panel.visible:=true;
155 ZCStatekInterface.SetState(ZCSGUIChanged);
156 end;
157 procedure HandleCmdLine(GUIMode:TZMessageID);
158 begin
159 if GUIMode in [ZMsgID_GUICMDLineCheck] then begin
160 if INTFCommandLineEnabled then
161 ShowCmdLine
162 else
163 HideCmdLine;
164 end;
165 if GUIMode in [ZMsgID_GUIDisable] then
166 DisableCmdLine
167 else if (GUIMode in [ZMsgID_GUIEnable])then
168 EnableCmdLine;
169 end;
170 procedure TCLine.FormCreate(Sender: TObject);
171 var
172 //bv:tbevel;
173 //pint:PGDBInteger;
174 sbutton:TmySpeedButton;
175 p:PCommandObjectDef;
176 ir:itrec;
177 clist:TZctnrVectorGDBString;
178 begin
179 self.Constraints.MinHeight:=36;
180 //utfpresent:=false;
181 UTFLen:=0;
182 //height:=100;
183 //self.DoubleBuffered:=true;
184
185 panel:=TPanel.create(self);
186 panel.parent:=self;
187 panel.top:=0;
188 //panel.Constraints.MinHeight:=17;
189 //panel.Constraints.MaxHeight:=17;
190 panel.AutoSize:=true; ;
191 panel.BorderStyle:=bsNone;
192 panel.BevelOuter:=bvnone;
193 panel.BorderWidth:=0;
194 panel.Align:=alBottom;
195
196 with TBevel.Create(self) do
197 begin
198 parent:={self}panel;
199 top:=0;
200 height:=2;
201 Align:={alBottom}altop;
202 //---------------BevelOuter:=bvraised;
203 end;
204
205 HistoryLine:=TMemo.create(self);
206 HistoryLine.Align:=alClient;
207 HistoryLine.ReadOnly:=true;
208 HistoryLine.BorderStyle:=bsnone;
209 HistoryLine.BorderWidth:=0;
210 HistoryLine.ScrollBars:=ssAutoBoth;
211 HistoryLine.Height:=self.clientheight-22;
212 HistoryLine.parent:=self;
213 //HistoryLine.:=
214
215 //HistoryLine.DoubleBuffered:=true;
216
217 panel.Color:=HistoryLine.Brush.Color;
218
219 prompt:=TLabel.create(panel);
220 prompt.Align:=alLeft;
221 prompt.Layout:=tlCenter;
222 //prompt.Width:=1;
223 //prompt.BorderStyle:=sbsSingle;
224 prompt.AutoSize:=true;
225 //prompt.Caption:='Command';
226 //prompt.Text:='Command';
227 prompt.parent:=panel;
228 //prompt.Canvas.Brush:=prompt.Canvas.Brush;
229
230 sbutton:=TmySpeedButton.Create(self);
231 sbutton.OnClick:=ButtonPressed;
232 //sbutton.Width:=panel.Constraints.MinHeight;
233 sbutton.Align:=alLeft;
234 with ThemeServices.GetDetailSize(ThemeServices.GetElementDetails(tsArrowBtnDownNormal)) do
235 begin
236 if cx>0 then
237 sbutton.width:=cx
238 else
239 sbutton.width:=15;
240 end;
241 sbutton.Color:=panel.Color;
242 sbutton.parent:=panel;
243
244 cmdedit:=TComboBox.create(panel);
245 cmdedit.Style:=csOwnerDrawEditableVariable;
246 clist.init(200);
247 p:=commandmanager.beginiterate(ir);
248 if p<>nil then
249 repeat
250 clist.PushBackData(p^.CommandName);
251 p:=commandmanager.iterate(ir);
252 until p=nil;
253 clist.sort;
254 cmdedit.Items.Text:=clist.GetTextWithEOL;
255 clist.done;
256 cmdedit.AutoComplete:=true;
257 cmdedit.AutoDropDown:=true;
258 cmdedit.Align:=alClient;
259 cmdedit.BorderStyle:=bsnone;
260 cmdedit.BorderWidth:=0;
261 //cmdedit.BevelOuter:=bvnone;
262 cmdedit.parent:=panel;
263 cmdedit.DoubleBuffered:=true;
264 cmdedit.AutoSize:=true;
265 {with cmdedit.Constraints do
266 begin
267 MaxHeight:=22;
268 end;}
269 {with prompt.Constraints do
270 begin
271 MaxHeight:=22;
272 end;}
273 SetMode(CLCOMMANDREDY);
274
275 cmdedit.OnKeyPress:=keypressmy;
276
277 BorderStyle:=BSsingle;
278 BorderWidth:=0;
279 //---------------BevelOuter:=bvnone;
280
281 aliases.init(100);
282 aliases.loadfromfile(expandpath('*menu/default.cla'));
283
284 //DMenu:=TDMenuWnd.Create(self);
285
286 {pint:=SavedUnit.FindValue('DMenuX');
287 if assigned(pint)then
288 DMenu.Left:=pint^;
289 pint:=SavedUnit.FindValue('DMenuY');
290 if assigned(pint)then
291 DMenu.Top:=pint^;}
292 //CWindow:=TCWindow.CreateNew(application);
293 //CWindow.Show;
294 ZCMsgCallBackInterface.RegisterHandler_GUIMode(HandleCommandLineMode);
295 HandleCmdLine(ZMsgID_GUICMDLineCheck);
296 // SetCommandLineMode:=self.SetMode;
297 end;
298 destructor TCLine.Destroy;
299 begin
300 aliases.Done;
301 inherited;
302 end;
303
304 procedure TCLine.AfterConstruction;
305 begin
306 name:='MainForm123';
307 oncreate:=FormCreate;
308 inherited;
309 end;
310 procedure TCLine.MyResize;
311 begin
312 if assigned(HistoryLine) then
313 HistoryLine.Height:=self.clientheight-22;
314 end;
315
316 procedure TCLine.DoOnResize;
317 begin
318 inherited;
319 myresize;
320 end;
321
322 procedure TCLine.keypressmy(Sender: TObject; var Key: char);
323 var
324 s:string;
325 begin
326 if ord(key)=13 then
327 begin
328 s:=CmdEdit.text;
329 CmdEdit.text:='';
330 processcommand(s);
331 end;
332 end;
333
334 procedure HistoryOut(s: pansichar); export;
335 var
336 a:string;
337 begin
338 if assigned(HistoryLine) then
339 begin
340 a:=(s);
341 if HistoryLine.Lines.Count=0 then
342 CLine.utflen:=CLine.utflen+{$IFDEF WINDOWS}UTF8Length(a){$ELSE}Length(a){$ENDIF}
343 else
344 CLine.utflen:=2+CLine.utflen+{$IFDEF WINDOWS}UTF8Length(a){$ELSE}Length(a){$ENDIF};
345 {$IFNDEF DELPHI}
346 HistoryLine.Append(a);
347 {$ENDIF}
348 //{$IFDEF WINDOWS}
349 HistoryLine.SelStart:=CLine.utflen;
350 HistoryLine.SelLength:=2;
351 HistoryLine.ClearSelection;
352 //{$ENDIF}
353 end;
354 end;
355 procedure HistoryOutStr(s:String);
356 begin
357 HistoryOut(pansichar(s));
358 end;
359 procedure StatusLineTextOut(s:String);
360 begin
361 if assigned(HintText) then
362 HintText.caption:=(s);
363 //HintText.{Update}repaint;
364 end;
365 procedure LogError(errstr:String); export;
366 begin
367 {errstr:=rserrorprefix+errstr;
368 if assigned(HistoryLine) then
369 begin
370 HistoryOutStr(errstr);
371 end;}
372 programlog.logoutstr(errstr,0,LM_Error);
373 end;
374 begin
375 //historychanged:=false;
376 ZCADGUIManager.RegisterZCADFormInfo('CommandLine',rsCommandLineWndName,TCLine,rect(200,100,600,100),nil,nil,@CLine);
377
378 ZCMsgCallBackInterface.RegisterHandler_HistoryOut(HistoryOutStr);
379 //uzcinterface.HistoryOutStr:=HistoryOutStr;
380
381 ZCMsgCallBackInterface.RegisterHandler_GUIMode(HandleCmdLine);
382
383 ZCMsgCallBackInterface.RegisterHandler_StatusLineTextOut(StatusLineTextOut);
384 //uzcinterface.StatusLineTextOut:=StatusLineTextOut;
385 ZCMsgCallBackInterface.RegisterHandler_LogError(LogError);
386 ZCMsgCallBackInterface.RegisterHandler_GetFocusedControl(CLine.GetCLineFocusPriority);
387 //uzcinterface.TMWOSilentShowError:=LogError;
388 end.
389