-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAssistantGui.pas
More file actions
526 lines (441 loc) · 13.7 KB
/
AssistantGui.pas
File metadata and controls
526 lines (441 loc) · 13.7 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
{**
@Abstract Assistant GUI
@Author Prof1983 <[email protected]>
@Created 12.11.2012
@LastMod 15.11.2012
}
unit AssistantGui;
interface
uses
Classes, ComCtrls, Controls, ExtCtrls, Forms, Menus, StdCtrls, SysUtils, ValEdit,
ABase, ASplitterControl, AShablonForm, ASystem, ASystemUtils, ATypes, AUiDialogs,
AssistantAgentControl, AssistantChatControl, AssistantCommandsControl, AssistantData,
AssistantDeveloperControl, AssistantProgram, AssistantMemoControl, AssistantTasksControl,
AiConsts;
type
//** @abstract(Òèï âêëàäêè ãëàâíîé îáëàñòè)
TabMainTypeEnum = Integer;
const
tmNone = $00000000;
tmMemo = $00000001;
tmUncnown = $00008000;
type
//** @abstract(Òèï âêëàäêè ïàíåëè ñîîáùåíèé)
TabMessageTypeEnum = Integer;
const
tmsgNone = $00000000;
tmsgMessages = $00000001;
tmsgLog = $00000002;
tmsgCommands = $00000004;
tmsgTasks = $00000008;
tmsgUncnown = $00008000;
// ----
type
TProfItem = class
private
FTreeNode: TTreeNode;
public
property TreeNode: TTreeNode read FTreeNode write FTreeNode;
end;
// ----
type //** Ãëàâíàÿ ôîðìà Assistant
TAssistantForm = class(TfmShablon)
private
procedure CreateMenu();
protected
procedure miHelpAboutClick(Sender: TObject);
public
{** Ñðàáàòûâàåò ïðè âûïîëíåíèè äåéñòâèÿ Run }
procedure DoActionRun(Sender: TObject); virtual;
{** Ñðàáàòûâàåò ïðè çàêðûòèè îêíà }
procedure DoClose(var Action: TCloseAction); override;
{** Ñðàáàòûâàåò ïðè ñîçäàíèè }
procedure DoCreate(); override;
procedure DoRefreshClick(Sender: TObject); virtual;
public
function AddMainTab(ATabType: TabMainTypeEnum; const ACaption: WideString): TWinControl;
function AddMessage(const Msg: WideString): AInt;
{** Äîáàâëÿåò âêëàäêó â îáëàñòè ñîîáùåíèé }
function AddTabMessage(ATabType: TabMessageTypeEnum; const ACaption: WideString): TWinControl;
function AddToLog(LogGroup: TLogGroupMessage; LogType: TLogTypeMessage; const StrMsg: WideString): Integer;
{** Çàãðóçàåò êîíôèãóðàöèè }
function ConfigureLoad(Config: AConfig{IProfNode = nil}): AError;
{** Ñîõðàíÿåò êîíôèãóðàöèè }
function ConfigureSave(Config: AConfig{IProfNode = nil}): AError;
function GetTreeItemByNode(Node: TTreeNode): TProfItem;
{** Èíèöèàëèçèðóåò }
function Initialize(): AError;
{** Ñîçäàòü íîâûé ýëåìåíò äåðåâà }
//function NewTreeItem(Parent: TProfItem; const Caption: WideString): TProfItem;
public
{** Êîíòðîë äëÿ àãåíòà }
//property AgentControl: TAgentControl read FAgentControl;
//property OnExit: AProc read FOnExit write FOnExit;
end;
implementation
var
// -- TfmDeveloper3 --
miHelp: TMenuItem;
miHelpAbout: TMenuItem;
miHelpHelp: TMenuItem;
mmMain: TMainMenu;
pbH1: TProgressBar;
//pnButtons: TPanel;
pnMain: TPanel;
pnMessages: TPanel;
pnObjects: TPanel;
pnTool: TPanel;
sbMain: TStatusBar;
//spButtons: TSplitterControl;
spMessages: TSplitterControl;
spObjects: TSplitterControl;
spTool: TSplitterControl;
// -- TfmDeveloperA --
spObjectsH: TSplitterControl;
tvObjects: TTreeView;
vleObjects: TValueListEditor;
// -- TfmDeveloperB --
pcMain: TPageControl;
// -- TfmDeveloperC --
miRun: TMenuItem;
miRunRun: TMenuItem;
miView: TMenuItem;
miViewRefresh: TMenuItem;
// -- TfmDeveloperD --
pcMessages: TPageControl;
tsCommands: TTabSheet;
tsLogs: TTabSheet;
tsMessages: TTabSheet;
// -- TDeveloperFormI --
FItems: array of TProfItem;
// --- AssistantForm ---
memMessages: TMemo;
{ TAssistantForm }
function TAssistantForm.AddMainTab(ATabType: TabMainTypeEnum; const ACaption: WideString): TWinControl;
begin
Result := TTabSheet.Create(Self);
TTabSheet(Result).PageControl := pcMain;
TTabSheet(Result).Caption := ACaption;
end;
function TAssistantForm.AddMessage(const Msg: WideString): Integer;
begin
Result := AssistantChatControl_AddMessageP(Msg);
end;
(*function TAssistantForm.AddMessageX(Msg: AMessage{IProfNode}): AInt;
// TODO: Âîçíèêàåò îøèáêà ( Msg.ChildNodes = error )
var
content: IProfNode;
i: Integer;
module: IProfNode;
begin
if not(Assigned(Msg)) then Exit;
// Ñ÷èòàåì ÷òî ïðèøåäøåå ñîîáùåíèå îòâåò íà êîìàíäó Core.GetMessages
Self.tvObjects.Items.Clear();
content := Msg.ChildNodes.NodeByName[ACL_CONTENT];
for i := 0 to content.ChildNodes.NodeCount - 1 do
begin
module := content.ChildNodes.NodeByIndex[i];
Self.NewTreeItem(nil, module.Name);
end;
end;*)
function TAssistantForm.AddTabMessage(ATabType: TabMessageTypeEnum; const ACaption: WideString): TWinControl;
begin
Result := TTabSheet.Create(Self);
TTabSheet(Result).PageControl := pcMessages;
TTabSheet(Result).Caption := ACaption;
end;
function TAssistantForm.AddToLog(LogGroup: TLogGroupMessage; LogType: TLogTypeMessage; const StrMsg: WideString): Integer;
begin
Result := AssistantAgentControl_AddToLog(LogGroup, LogType, StrMsg);
end;
function TAssistantForm.ConfigureLoad(Config: AConfig{IProfNode}): AError;
//var
//i: Integer;
//tmpConfig: IProfNode;
begin
{if Assigned(AConfig) then
tmpConfig := AConfig
else
tmpConfig := FConfig;}
{if TProfXmlNode.ReadIntegerA(tmpConfig, 'ObjectsWidth', i) then
if i > 0 then
pnObjects.Width := i
else
pnObjects.Visible := False;
if TProfXmlNode.ReadIntegerA(tmpConfig, 'ToolWidth', i) then
if i > 0 then
pnTool.Width := i
else
pnTool.Visible := False;
if TProfXmlNode.ReadIntegerA(tmpConfig, 'ButtonsHeight', i) then
if i > 0 then
pnButtons.Height := i
else
pnButtons.Visible := False;
if TProfXmlNode.ReadIntegerA(tmpConfig, 'MessagesHeight', i) then
if i > 0 then
pnMessages.Height := i
else
pnMessages.Visible := False;}
{if TProfXmlNode.ReadIntegerA(tmpConfig, 'ObjectTreeViewHeight', i) then tvObjects.Height := i;
if TProfXmlNode.ReadIntegerA(tmpConfig, 'ObjectPropertyCol0Width', i) then vleObjects.ColWidths[0] := i;}
Result := 0;
end;
function TAssistantForm.ConfigureSave(Config: AConfig{IProfNode}): AError;
//var
//tmpConfig: IProfNode;
begin
{if Assigned(AConfig) then
tmpConfig := AConfig
else
tmpConfig := FConfig;}
{TProfXmlNode.WriteIntegerA(tmpConfig, 'ObjectsWidth', pnObjects.Width);
TProfXmlNode.WriteIntegerA(tmpConfig, 'ToolWidth', pnTool.Width);
TProfXmlNode.WriteIntegerA(tmpConfig, 'ButtonsHeight', pnButtons.Height);
TProfXmlNode.WriteIntegerA(tmpConfig, 'MessagesHeight', pnMessages.Height);}
{TProfXmlNode.WriteIntegerA(tmpConfig, 'ObjectTreeViewHeight', tvObjects.Height);
TProfXmlNode.WriteIntegerA(tmpConfig, 'ObjectPropertyCol0Width', vleObjects.ColWidths[0]);}
Result := 0;
end;
procedure TAssistantForm.CreateMenu();
begin
// Ñîçäàåì ìåíþ
miView := TMenuItem.Create(Self);
miView.Caption := 'Âèä'; //'View';
miViewRefresh := TMenuItem.Create(Self);
miViewRefresh.Caption := 'Îáíîâèòü'; //'Refresh';
miViewRefresh.OnClick := DoRefreshClick;
miView.Add(miViewRefresh);
mmMain.Items.Insert(0, miView);
miRun := TMenuItem.Create(Self);
miRun.Caption := 'Âûïîëíèòü'; //'Run';
mmMain.Items.Insert(1, miRun);
miRunRun := TMenuItem.Create(Self);
miRunRun.Caption := 'Run';
miRunRun.OnClick := DoActionRun;
miRun.Add(miRunRun);
miHelp := TMenuItem.Create(Self);
miHelp.Caption := '?';
mmMain.Items.Add(miHelp);
miHelpHelp := TMenuItem.Create(Self);
miHelpHelp.Caption := 'Ïîìîùü'; //'Help';
miHelp.Add(miHelpHelp);
miHelpAbout := TMenuItem.Create(Self);
miHelpAbout.Caption := 'Î ïðîãðàììå...'; //'About';
miHelp.Add(miHelpAbout);
miHelpAbout.OnClick := miHelpAboutClick;
end;
procedure TAssistantForm.DoActionRun(Sender: TObject);
begin
//AssistantJavaControl_RunAction();
end;
procedure TAssistantForm.DoClose(var Action: TCloseAction);
begin
inherited;
if Assigned(Assistant_OnExit) then
Assistant_OnExit();
end;
procedure TAssistantForm.DoCreate();
begin
Caption := 'Assistant';
// ---
Self.Left := 0;
Self.Top := 0;
Self.Height := 420;
Self.Width := 640;
mmMain := TMainMenu.Create(Self);
Self.Menu := mmMain;
CreateMenu();
{pnButtons := TPanel.Create(Self);
pnButtons.Parent := Self;
pnButtons.Height := 30;
pnButtons.Align := alTop;}
{spButtons := TSplitterControl.Create(Self);
spButtons.Control := pnButtons;
spButtons.Parent := Self;
spButtons.Align := alTop;}
pnMessages := TPanel.Create(Self);
pnMessages.Parent := Self;
pnMessages.Height := 70;
pnMessages.Align := alBottom;
spMessages := TSplitterControl.Create(Self);
spMessages.Control := pnMessages;
spMessages.Parent := Self;
spMessages.Align := alBottom;
pnObjects := TPanel.Create(Self);
pnObjects.Parent := Self;
pnObjects.Width := 100;
pnObjects.Align := alLeft;
spObjects := TSplitterControl.Create(Self);
spObjects.Control := pnObjects;
spObjects.Parent := Self;
spObjects.Left := pnObjects.Width + 10;
spObjects.Align := alLeft;
pnTool := TPanel.Create(Self);
pnTool.Parent := Self;
pnTool.Width := 100;
pnTool.Align := alRight;
spTool := TSplitterControl.Create(Self);
spTool.Control := pnTool;
spTool.Parent := Self;
spTool.Align := alRight;
pnMain := TPanel.Create(Self);
pnMain.Parent := Self;
pnMain.Align := alClient;
pbH1 := TProgressBar.Create(pnMain);
pbH1.Parent := pnMain;
pbH1.Align := alBottom;
pbH1.Height := 6;
pbH1.Smooth := True;
pbH1.Max := 255;
sbMain := TStatusBar.Create(Self);
sbMain.Top := 2000;
sbMain.Align := alBottom;
// ---
tvObjects := TTreeView.Create(pnObjects);
tvObjects.Parent := pnObjects;
tvObjects.Height := pnObjects.Height div 2;
tvObjects.Align := alTop;
spObjectsH := TSplitterControl.Create(Self);
spObjectsH.Parent := pnObjects;
spObjectsH.Align := alTop;
vleObjects := TValueListEditor.Create(pnObjects);
vleObjects.Parent := pnObjects;
vleObjects.Align := alClient;
pcMain := TPageControl.Create(pnMain);
pcMain.Parent := pnMain;
pcMain.Align := alClient;
pcMessages := TPageControl.Create(Self);
pcMessages.Parent := pnMessages;
pcMessages.Align := alClient;
pcMessages.TabPosition := tpBottom;
tsCommands := TTabSheet.Create(Self);
tsCommands.PageControl := pcMessages;
tsCommands.Caption := 'Êîìàíäû'; //'Commands';
tsMessages := TTabSheet.Create(Self);
tsMessages.PageControl := pcMessages;
tsMessages.Caption := 'Ñîîáùåíèÿ'; //'Messages';
tsLogs := TTabSheet.Create(Self);
tsLogs.PageControl := pcMessages;
tsLogs.Caption := 'Ëîãè'; //'Logs';
end;
function TAssistantForm.Initialize(): AError;
var
pr: TAssistantProgram;
ts: TWinControl;
S: string;
FExePath: APascalString;
begin
pr := TAssistantProgram.GetInstance();
vleObjects.ColWidths[0] := 50;
pnMessages.Height := 100;
pnObjects.Width := 150;
//ts := AddMainTab(0, 'Work');
//AssistantWorkControl_Init(ts);
// Êîíòðîë ÷àòà
ts := AddMainTab(0, 'Chat');
AssistantChatControl_Init(ts, AddMessage, AddToLog);
FExePath := ASystem.GetDirectoryPathP();
ts := AddMainTab(0, 'Ïðåäëîæåíèå');
AssistantMemoControl_Init(ts, AddMessage);
try
S := NormalizePath2(FExePath + AiDataDir) + 'First.txt';
S := SysUtils.ExpandFileName(S);
if FileExists(S) then
AssistantMemoControl_LoadFromFileP(S)
else
begin
S := FExePath + 'First.txt';
if FileExists(S) then
AssistantMemoControl_LoadFromFileP(S);
end;
except
end;
ts := AddMainTab(0, 'Àññèñòåíò');
AssistantAgentControl_Init(ts, AddMessage);
ts := AddMainTab(0, 'Çàäàíèÿ');
AssistantTasksControl_Init(ts, AddMessage);
ts := AddMainTab(0, 'Developer');
AssistantDeveloperControl_Init(ts, AddMessage);
{// Êîíòðîë ôðåéìîâ
ts := TTabSheet(AddMainTab(tmUncnown, 'Frames')); // Ñîçäàåì âêëàäêó
FFramesControl := TAIFramesControl.Create();
FFramesControl.Control := ts;
FFramesControl.Initialize();}
// Âûâîä ñîîáùåíèé
memMessages := TMemo.Create(Self);
memMessages.Parent := tsMessages;
memMessages.Align := alClient;
memMessages.Lines.Add('Ðàä âèäåòü òåáÿ çäåñü.');
// Êîíòðîë êîìàíä
AssistantCommandsControl_Init(tsCommands);
{Refresh();
ToolBar1 := TToolBar.Create(Self);
ToolBar1.Parent := Self.pnButtons;
tbFileNew := TToolButton.Create(ToolBar1);
tbFileNew.Parent := ToolBar1;
tbFileNew.Caption := 'New';
tbFileNew.OnClick := DoFileCreate;
tbFileOpen := TToolButton.Create(ToolBar1);
tbFileOpen.Parent := ToolBar1;
tbFileOpen.Caption := 'Open';
tbFileOpen.OnClick := DoFileOpen;
tbFileSave := TToolButton.Create(ToolBar1);
tbFileSave.Parent := ToolBar1;
tbFileSave.Caption := 'Save';
tbFileSave.OnClick := DoFileSave;}
// Óñòàíàâëèâàåì Focus íà memInput
// memInput.SetFocus();
AddToLog(lgNone, ltNone, '-');
if Assigned(pr) then
AddToLog(lgNone, ltNone, 'Assistant '+pr.ProgramVersionStr)
else
AddToLog(lgNone, ltNone, 'Assistant');
AddToLog(lgNone, ltNone, '-');
DoRefreshClick(Self);
Result := 0;
end;
procedure TAssistantForm.DoRefreshClick(Sender: TObject);
begin
{AddMessage(ARL_PREFIX + ARL + ' ' +
ARL_ASSISTANT_FORM + ' ' +
ARL_CORE + ' ' +
ARL_CMD_CORE_GET_MODULES);}
end;
function TAssistantForm.GetTreeItemByNode(Node: TTreeNode): TProfItem;
var
i: Integer;
begin
Result := nil;
for i := 0 to High(FItems) do
begin
if FItems[i].TreeNode = Node then
begin
Result := FItems[i];
Exit;
end;
end;
end;
procedure TAssistantForm.miHelpAboutClick(Sender: TObject);
begin
AUi_ExecuteAboutDialog();
end;
{function TAssistantForm.NewTreeItem(Parent: TProfItem; const Caption: WideString): TProfItem;
var
ptn: TTreeNode;
tn: TTreeNode;
i: Integer;
begin
if Assigned(Parent) then
ptn := Parent.TreeNode
else
ptn := nil;
//tn := tvObjects.Items.Add(ptn, Caption);
tn := tvObjects.Items.AddChild(ptn, Caption);
i := Length(FItems);
SetLength(FItems, i + 1);
FItems[i] := TProfItem.Create();
FItems[i].TreeNode := tn;
Result := FItems[i];
end;}
end.