-
Notifications
You must be signed in to change notification settings - Fork 2
/
unUkazHistorii.pas
412 lines (363 loc) · 13 KB
/
unUkazHistorii.pas
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
unit unUkazHistorii;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, vte_edittree,VirtualTrees,
Forms, Controls, Graphics, Dialogs, Menus,LocalizedForms,
LCLProc,typinfo;
type
PTreeData = ^TTreeData; { Ukazatel na data v node }
TTreeData = record
Column0: String;
end;
{ TfrmUkazHistorii }
TfrmUkazHistorii = class(TLocalizedForm)
menuItemClear: TMenuItem;
menuItemUndo: TMenuItem;
popUpVetItem: TPopupMenu;
VET: TVirtualEditTree;
vetRedo: TVirtualEditTree;
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure menuItemClearClick(Sender: TObject);
procedure menuItemUndoClick(Sender: TObject);
procedure popUpVetItemPopup(Sender: TObject);
procedure VETChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure vetRedoChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure VETFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex);
procedure vetRedoFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex);
procedure VETFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure vetRedoFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure VETGetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
procedure vetRedoGetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
procedure VETGetPopupMenu(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; const P: TPoint; var AskParent: Boolean;
var aPopupMenu: TPopupMenu);
procedure VETGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
procedure vetRedoGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
procedure VETInitNode(Sender: TBaseVirtualTree; ParentNode,
Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
procedure vetRedoInitNode(Sender: TBaseVirtualTree; ParentNode,
Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
procedure UpdateTranslation(ALang: String); override;
procedure VETStructureChange(Sender: TBaseVirtualTree; Node: PVirtualNode;
Reason: TChangeReason);
procedure vetRedoStructureChange(Sender: TBaseVirtualTree; Node: PVirtualNode;
Reason: TChangeReason);
private
{ private declarations }
public
{ public declarations }
checkBuffersSize:Boolean;
end;
var
frmUkazHistorii: TfrmUkazHistorii;
implementation
{$R *.frm}
uses
unit1, // kvůli rsUndoBufferIt a rsRedoBufferIt - strings for automatic translation
unHistory ;
{ TfrmUkazHistorii }
{ OnChange }
procedure TfrmUkazHistorii.VETChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
//var pom,pom2: string;
begin
vet.Refresh;
end;
procedure TfrmUkazHistorii.vetRedoChange(Sender: TBaseVirtualTree;
Node: PVirtualNode);
begin
vetRedo.Refresh;
end;
procedure TfrmUkazHistorii.FormClose(Sender: TObject;
var CloseAction: TCloseAction);
begin
// Application.ReleaseComponent(frmUkazHistorii);
globalHistory.isfrmUkazHistoriiShown:=False;
checkBuffersSize:=True;
end;
procedure TfrmUkazHistorii.FormActivate(Sender: TObject);
begin
//globalHistory.undoPolozky.printHistoryVector; // při větším počtu položek uzké hrdlo
end;
procedure TfrmUkazHistorii.FormCreate(Sender: TObject);
var
XNodeRoot,XNodeRoot1: PVirtualNode;
// Data: PTreeData;
begin
vet.Header.Columns.Items[0].Text:=rsUndoBufferIt;
vetRedo.Header.Columns.Items[0].Text:=rsRedoBufferIt;
XNodeRoot:=VET.AddChild(nil);
XNodeRoot1:=vetRedo.AddChild(nil);
end;
procedure TfrmUkazHistorii.FormShow(Sender: TObject);
var
StartMS: Comp;
XNodeRoot: PVirtualNode;
Data: PTreeData;
begin
StartMS:=timestamptomsecs(datetimetotimestamp(now));
vet.ReinitNode(vet.RootNode,true);
DebuglnThreadLog(format('%s',
['ReinitStromu VET - ukazHistorii.FormShow:']));
vetRedo.ReinitNode(vetRedo.RootNode,true);
DebuglnThreadLog(format('%s',
['ReinitStromu vetRedo - ukazHistorii.FormShow:']));
globalHistory.isfrmUkazHistoriiShown:=True;
checkBuffersSize:=False;
globalHistory.undoPolozky.printHistoryVector;
globalHistory.redoPolozky.printHistoryVector;
checkBuffersSize:=True;
//DebuglnThreadLog('Výpis historie trval: '+floattostr(timestamptomsecs(datetimetotimestamp(now))-StartMS)+' ms');
end;
procedure TfrmUkazHistorii.menuItemClearClick(Sender: TObject);
begin
// tady to by mělo být součástí Controlleru (MVC) a ne View :-)
globalHistory.clearAndPrintUndoAndRedo;
end;
procedure TfrmUkazHistorii.menuItemUndoClick(Sender: TObject);
var
vybrane: TNodeArray;
indexVybraneNode: Cardinal;
level: Cardinal;
begin
vybrane:=vet.GetSortedSelection(True);
if not assigned(vybrane) then
begin
vet.Selected[vet.RootNode]:=True; // pravděpodobně je prohozeno RootNode s RootNode^.lastchild
setlength(vybrane,1); // protože s RootNode^.lastchild to maže celou 0 a
vybrane[0]:=vet.RootNode; // s RootNode jenom poslední položku z úrovně 1
end;
level:=vet.GetNodeLevel(vybrane[0]);
case level of // přímo k TvirtualEditTree
0: begin
vybrane[0]:=vet.RootNode; // s RootNode jenom poslední položku
indexVybraneNode:=vybrane[0]^.Index; // z úrovně 1 viz. poznámka výše
end;
1: indexVybraneNode:=vybrane[0]^.Index;
2: indexVybraneNode:=vybrane[0]^.Parent^.Index;
3: indexVybraneNode:=vybrane[0]^.Parent^.Parent^.Index;
end;
// tady to by mělo být součástí Controlleru (MVC) a ne View :-)
// kopíruj vybranou položku historie na konec undoPolozky:
globalHistory.undoPolozky.historyVector.PushBack(
globalHistory.undoPolozky.historyVector[indexVybraneNode]);
// vymaž vybranou položku z undoPoložky
globalHistory.undoPolozky.historyVector.Erase(indexVybraneNode);
vet.DeleteNode(vybrane[0]);
// zavolej normální undo
globalHistory.doUndo;
end;
procedure TfrmUkazHistorii.popUpVetItemPopup(Sender: TObject);
// GetPopupMenu z TVirtualEditTree nejde použít protože:
// 1. blokuje používání CTR+Z tzn. klávesových zkratky pro dynamicky
// přidělovaná popMenu nefungují
// 2. je voláno pouze v případě, že není přiřazeno popupMenu
var
level: Cardinal;
Data: PTreeData;
Node: PVirtualNode;
begin
if globalHistory.undoPolozky.historyVector.Size = 0 then
begin
MenuItemUndo.Enabled:=False;
exit;
end
else
MenuItemUndo.Enabled:=True;
Node:=vet.FocusedNode;
level:=VET.GetNodeLevel(Node);
if node = nil then exit;
case level of // přímo k TvirtualEditTree
0: exit {aPopupMenu:=popUpVetRootNode};
1: Data:=VET.GetNodeData(Node);
2: Data:=VET.GetNodeData(node^.Parent);
3: Data:=VET.GetNodeData(node^.Parent^.Parent);
end;
popUpVetItem.Items.Items[0].Caption:=rsUndoHistoryI+Data^.Column0;
end;
{ OnFokusChanged }
procedure TfrmUkazHistorii.VETFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex);
begin
//vet.FocusedNode^.States:=vet.FocusedNode^.States - [vsSelected];
VeT.Refresh;
//showmessage('Invalidate');
//frmUkazHistorii.VET.Invalidate;
end;
procedure TfrmUkazHistorii.vetRedoFocusChanged(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex);
begin
vetRedo.FocusedNode^.States:=vetRedo.FocusedNode^.States - [vsSelected];
vetRedo.FocusedNode:=vetRedo.RootNode;
vetRedo.Refresh;
end;
{ OnFreeNode }
procedure TfrmUkazHistorii.VETFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
var
Data: PTreeData;
globHistPom:THistoryVector;
begin
Data:=VET.GetNodeData(Node);
if Assigned(Data) then
begin
Data^.Column0 := '';
end;
end;
procedure TfrmUkazHistorii.vetRedoFreeNode(Sender: TBaseVirtualTree;
Node: PVirtualNode);
var
Data: PTreeData;
begin
Data:=VET.GetNodeData(Node);
if Assigned(Data) then
Data^.Column0 := '';
end;
{ OnGetNodeDataSize }
procedure TfrmUkazHistorii.VETGetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
begin
NodeDataSize := SizeOf(TTreeData);
end;
procedure TfrmUkazHistorii.vetRedoGetNodeDataSize(Sender: TBaseVirtualTree;
var NodeDataSize: Integer);
begin
NodeDataSize := SizeOf(TTreeData);
end;
procedure TfrmUkazHistorii.VETGetPopupMenu(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex; const P: TPoint;
var AskParent: Boolean; var aPopupMenu: TPopupMenu);
begin
end;
{ OnGetText - klíčová pro zobrazení sloupce }
procedure TfrmUkazHistorii.VETGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
var
globHistPom:THistoryVector;
Data:PTreeData;
begin
Data := VET.GetNodeData(Node);
//case Column of
// 0: CellText := Data^.Column0;
//end
if (Column <= 0) then
begin
try
globHistPom:=globalHistory.undoPolozky.historyVector; // pomocná
case Sender.GetNodeLevel(Node) of
0:begin
Data^.Column0:=globalHistory.undoPolozky.name;
CellText:=Data^.Column0;
end;
1:begin
Data^.Column0:=globHistPom[node^.Index].jmenoPolozky;
CellText:=Data^.Column0;
end;
2:begin
Data^.Column0 := GetEnumName(Typeinfo(TsqlTypProUndo),
ord(globHistPom[Node^.Parent^.Index].polePolozek[node^.Index].operaceUndo));
CellText:=Data^.Column0;
end;
3: begin
Data^.Column0:=globHistPom[Node^.Parent^.Parent^.Index].polePolozek[Node^.Parent^.Index].hodnoty[node^.index];
CellText:=Data^.Column0;
end;
end;
except
On E: Exception do
DebuglnThreadLog(format('%s %s %3d %3d',
['Error GetText',E.ToString,Node^.Parent^.Index,node^.Index]));
end;
end;
end;
procedure TfrmUkazHistorii.vetRedoGetText(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
var CellText: String);
var
globHistPom:THistoryVector;
Data:PTreeData;
begin
Data := VET.GetNodeData(Node);
if (Column <= 0) then
begin
try
globHistPom:=globalHistory.redoPolozky.historyVector; // pomocná
case Sender.GetNodeLevel(Node) of
0:begin
Data^.Column0:=globalHistory.redoPolozky.name;
CellText:=Data^.Column0;
end;
1:begin
Data^.Column0:=globHistPom[node^.Index].jmenoPolozky;
CellText:=Data^.Column0;
end;
2:begin
Data^.Column0 := GetEnumName(Typeinfo(TsqlTypProUndo),
ord(globHistPom[Node^.Parent^.Index].polePolozek[node^.Index].operaceRedo));
CellText:=Data^.Column0;
end;
3: begin
Data^.Column0:=globHistPom[Node^.Parent^.Parent^.Index].polePolozek[Node^.Parent^.Index].hodnoty[node^.index];
CellText:=Data^.Column0;
end;
end;
except
On E: Exception do
DebuglnThreadLog(format('%s %s %3d %3d',
['Error GetText',E.ToString,Node^.Parent^.Index,node^.Index]));
end;
end;
end;
procedure TfrmUkazHistorii.VETInitNode(Sender: TBaseVirtualTree; ParentNode,
Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
begin
case Sender.GetNodeLevel(Node) of
0: begin
Sender.ChildCount[Node]:=globalHistory.undoPolozky.historyVector.Size;
Sender.Expanded[Node] := TRUE;
end;
1: Sender.ChildCount[Node]:=
globalHistory.undoPolozky.historyVector[Node^.Index].polePolozek.Size;
2: Sender.ChildCount[Node] := 11;
end;
end;
procedure TfrmUkazHistorii.vetRedoInitNode(Sender: TBaseVirtualTree;
ParentNode, Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
begin
case Sender.GetNodeLevel(Node) of
0: begin
Sender.ChildCount[Node]:=globalHistory.redoPolozky.historyVector.Size;
Sender.Expanded[Node] := TRUE;
end;
1: Sender.ChildCount[Node]:=
globalHistory.redoPolozky.historyVector[Node^.Index].polePolozek.Size;
2: Sender.ChildCount[Node] := 11;
end;
end;
procedure TfrmUkazHistorii.UpdateTranslation(ALang: String);
begin
inherited UpdateTranslation(ALang);
globalHistory.undoPolozky.printHistoryVector;
globalHistory.redoPolozky.printHistoryVector;
end;
procedure TfrmUkazHistorii.VETStructureChange(Sender: TBaseVirtualTree;
Node: PVirtualNode; Reason: TChangeReason); // upraví text v hlavničce stromu
begin
VET.Header.Columns.Items[0].Text:=rsUndoBufferIt +': ' +
inttostr(globalHistory.undoPolozky.historyVector.Size);
end;
procedure TfrmUkazHistorii.vetRedoStructureChange(Sender: TBaseVirtualTree;
Node: PVirtualNode; Reason: TChangeReason);
begin
vetRedo.Header.Columns.items[0].Text:=rsRedoBufferIt+': '+
inttostr(globalHistory.redoPolozky.historyVector.Size);
end;
end.