This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ClassesListDockingForms.pas
778 lines (683 loc) · 29.3 KB
/
ClassesListDockingForms.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
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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
//****************************************************************
//** Auto completion for custom PHP classes (ACCPC) **
//** **
//** Written by Stanislav Eckert, 2013-2015 **
//** Base plugin template by Damjan Zobo Cvetko **
//****************************************************************
unit ClassesListDockingForms;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms,
Vcl.Dialogs, NppDockingForms, Vcl.StdCtrls, NppPlugin, Vcl.ComCtrls,
Vcl.ExtCtrls, Vcl.ImgList, ccchelperfunctions, AnalyzerPHP, VirtualTrees,
SciSupport, System.WideStrUtils;
type
TClassesListDockingForm = class(TNppDockingForm)
StatusBar: TStatusBar;
edtSearch: TLabeledEdit;
cbxShowPrivateProtected: TCheckBox;
cbxShowSeparately: TCheckBox;
TreeViewImageList: TImageList;
ClassLinkingListStartTimer: TTimer;
ClassListTreeView: TVirtualStringTree;
cbxShowMethodParameters: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure FormHide(Sender: TObject);
procedure FormFloat(Sender: TObject);
procedure FormDock(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure cbxShowPrivateProtectedClick(Sender: TObject);
procedure cbxShowSeparatelyClick(Sender: TObject);
procedure edtSearchChange(Sender: TObject);
procedure ClassLinkingListStartTimerTimer(Sender: TObject);
procedure ClassListTreeViewGetText(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
var CellText: string);
procedure ClassListTreeViewGetImageIndex(Sender: TBaseVirtualTree;
Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean; var ImageIndex: Integer);
procedure ClassListTreeViewNodeDblClick(Sender: TBaseVirtualTree;
const HitInfo: THitInfo);
procedure ClassListTreeViewDrawText(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
const Text: string; const CellRect: TRect; var DefaultDraw: Boolean);
procedure cbxShowMethodParametersClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
DockingFormActive: Boolean;
procedure BuildClassLinkingList(var analyzer: TAnalyzerPHP);
end;
rTreeData = record
nodeType: Integer; // 1=class node, 2=file entry, 3=attribute and/or method node, 4=attribute entry, 5=method entry
ImageIndex: Integer;
Value: String;
Text: String;
// Spezialized settings
Visibility: as_visibility;
classNodeMoved: Boolean; // Needed while moving temporary classes to top of the list
classIndex: Integer;
methodIndex: Integer;
fileOffset: UINT32;
end;
var
ClassesListDockingForm: TClassesListDockingForm;
implementation
uses
cccplugin;
{$R *.dfm}
//---------------------------------------------------------------------------
function CountVisibleChildNodes(list: TVirtualStringTree; node: PVirtualNode): Integer;
begin
Result := 0;
node := node.FirstChild;
while (node <> nil) do
begin
if (list.IsVisible[node]) then
Inc(Result);
node := node.NextSibling;
end;
end;
//---------------------------------------------------------------------------
procedure TClassesListDockingForm.cbxShowPrivateProtectedClick(Sender: TObject);
var
Node1, Node2, Node3: PVirtualNode;
NodeData: ^rTreeData;
begin
// Save setting
WritePrivateProfileString('settings', 'ClassLinkingList_ShowPrivateProtected', PWideChar(String(iif(self.cbxShowPrivateProtected.Checked, '1', '0'))), PWideChar(settingsPath + settingsFile));
// Update list without rebuilding it (just make entries visible)
Node1 := ClassListTreeView.RootNode.FirstChild;
while (Node1 <> nil) do
begin
Node2 := Node1.FirstChild;
while (Node2 <> nil) do
begin
NodeData := ClassListTreeView.GetNodeData(Node2);
if (NodeData.nodeType = 3) then
begin
// Show or hide attributes / methods
Node3 := Node2.FirstChild;
while (Node3 <> nil) do
begin
NodeData := ClassListTreeView.GetNodeData(Node3);
if
(
(NodeData.Visibility = asvPrivate) or
(NodeData.Visibility = asvProtected)
)
then begin
ClassListTreeView.IsVisible[Node3] := cbxShowPrivateProtected.Checked;
end;
Node3 := Node3.NextSibling;
end;
// Show or hide entire attribute/method node
ClassListTreeView.IsVisible[Node2] := (CountVisibleChildNodes(ClassListTreeView, Node2) > 0);
end;
Node2 := Node2.NextSibling;
end;
Node1 := Node1.NextSibling;
end;
end;
//---------------------------------------------------------------------------
procedure TClassesListDockingForm.cbxShowSeparatelyClick(Sender: TObject);
begin
inherited;
// Save setting
WritePrivateProfileString('settings', 'ClassLinkingList_ShowSeparated', PWideChar(String(iif(self.cbxShowSeparately.Checked, '1', '0'))), PWideChar(settingsPath + settingsFile));
// Rebuild list
BuildClassLinkingList(php_analyzer);
end;
//---------------------------------------------------------------------------
procedure TClassesListDockingForm.cbxShowMethodParametersClick(Sender: TObject);
begin
inherited;
// Save setting
WritePrivateProfileString('settings', 'ClassLinkingList_ShowMethodParameters', PWideChar(String(iif(self.cbxShowSeparately.Checked, '1', '0'))), PWideChar(settingsPath + settingsFile));
// Rebuild list
BuildClassLinkingList(php_analyzer);
end;
//---------------------------------------------------------------------------
procedure TClassesListDockingForm.ClassLinkingListStartTimerTimer(Sender: TObject);
var
iOKLoad: Integer;
settingsVersion: UINT32;
begin
inherited;
// Wait until plugin initialized fully and then rebuild class linking list
if (bInitialized) then
begin
// Disable timer
ClassLinkingListStartTimer.Enabled := false;
// Load settings. Note: We need to do this here, since NPP calls the function to create the docking form before plugin fully initialized (TODO: Check)
iOKLoad := IDYES;
settingsVersion := GetPrivateProfileInt('settings', 'version', iAppVersion, PWideChar(settingsPath + settingsFile));
if not settingsCompatibleVersions.Contains(settingsVersion) then
begin
iOKLoad := Application.MessageBox('Settings file seems to be incompatible.'+ #10 +'Loading it may mess things up.'+ #10#10 +'Do you want to try to load it?', 'ACCPC - Loading configuration file', 4+48);
end;
if (iOKLoad = IDYES) then
begin
self.cbxShowPrivateProtected.Checked := Boolean(GetPrivateProfileInt('settings', 'ClassLinkingList_ShowPrivateProtected', 0, PWideChar(settingsPath + settingsFile)));
self.cbxShowSeparately.Checked := Boolean(GetPrivateProfileInt('settings', 'ClassLinkingList_ShowSeparated', 1, PWideChar(settingsPath + settingsFile)));
self.cbxShowMethodParameters.Checked := Boolean(GetPrivateProfileInt('settings', 'ClassLinkingList_ShowMethodParameters', 1, PWideChar(settingsPath + settingsFile)));
end;
// Rebuild list
BuildClassLinkingList(php_analyzer);
end;
end;
//---------------------------------------------------------------------------
procedure TClassesListDockingForm.ClassListTreeViewDrawText(
Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode;
Column: TColumnIndex; const Text: string; const CellRect: TRect;
var DefaultDraw: Boolean);
var
NodeData1, NodeData2: ^rTreeData;
iDisplayedShiftX: Integer;
nodeSelected: Boolean;
i: Integer;
parameters: ^TStringList;
begin
inherited;
NodeData1 := Sender.GetNodeData(Node);
nodeSelected := ClassListTreeView.Selected[Node];
if (not php_analyzer.isAnalyzing) then
begin
// Draw method nodes separately (because of optional parameters)
// Note: Currently right-to-left texts are not supported in the list (like in autocompletion popup). They will be shown from left-to-right like other texts.
if
(
(NodeData1.nodeType = 5) and
(cbxShowMethodParameters.Checked)
)
then begin
NodeData2 := Sender.GetNodeData(Node.Parent.Parent);
parameters := @php_analyzer.classes.Items[NodeData2.classIndex].methods.Items[NodeData1.methodIndex].parameters;
// Prevent list from drawing the text
DefaultDraw := false;
// Draw name of method (+ parameters)
TargetCanvas.Brush.Style := bsClear;
iDisplayedShiftX := CellRect.Left;
if Pos('(', Text) > 0 then
begin
// Draw brackets with parameters
TargetCanvas.Font.Color := iif(nodeSelected, clHighlightText, clWindowText);
TargetCanvas.TextOut(iDisplayedShiftX, CellRect.Top + 2, Copy(Text, 1, Pos('(', Text))); // Draw with bracket
iDisplayedShiftX := iDisplayedShiftX + TargetCanvas.TextWidth(Copy(Text, 1, Pos('(', Text)));
for i := 0 to parameters.Count-1 do
begin
if Pos('=', parameters.Strings[i]) > 0 then
begin
TargetCanvas.Font.Color := iif(nodeSelected, clLtGray, clGray);
TargetCanvas.TextOut(iDisplayedShiftX, CellRect.Top + 2, TrimRight(Copy(parameters.Strings[i], 1, Pos('=', parameters.Strings[i])-1)));
iDisplayedShiftX := iDisplayedShiftX + TargetCanvas.TextWidth(TrimRight(Copy(parameters.Strings[i], 1, Pos('=', parameters.Strings[i])-1)));
end
else
begin
TargetCanvas.Font.Color := iif(nodeSelected, clHighlightText, clWindowText);
TargetCanvas.TextOut(iDisplayedShiftX, CellRect.Top + 2, parameters.Strings[i]);
iDisplayedShiftX := iDisplayedShiftX + TargetCanvas.TextWidth(parameters.Strings[i]);
end;
if (i < parameters.Count-1) then
begin
TargetCanvas.Font.Color := iif(nodeSelected, clHighlightText, clWindowText);
TargetCanvas.TextOut(iDisplayedShiftX, CellRect.Top + 2, ', ');
iDisplayedShiftX := iDisplayedShiftX + TargetCanvas.TextWidth(', ');
end;
end;
// Draw last bracket
TargetCanvas.Font.Color := iif(nodeSelected, clHighlightText, clWindowText);
TargetCanvas.TextOut(iDisplayedShiftX, CellRect.Top + 2, ')'); // Draw with bracket
end
else
begin
TargetCanvas.Font.Color := clWindowText;
TargetCanvas.TextOut(iDisplayedShiftX, CellRect.Top + 2, Text);
end;
end;
end;
end;
//---------------------------------------------------------------------------
procedure TClassesListDockingForm.ClassListTreeViewGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean; var ImageIndex: Integer);
var
NodeData: ^rTreeData;
begin
NodeData := Sender.GetNodeData(Node);
ImageIndex := NodeData.ImageIndex;
end;
//---------------------------------------------------------------------------
procedure TClassesListDockingForm.ClassListTreeViewGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
var
NodeData: ^rTreeData;
begin
NodeData := Sender.GetNodeData(Node);
CellText := NodeData.Text;
end;
//---------------------------------------------------------------------------
procedure TClassesListDockingForm.ClassListTreeViewNodeDblClick(Sender: TBaseVirtualTree; const HitInfo: THitInfo);
var
fileNode: PVirtualNode;
NodeData: ^rTreeData;
fileOffset: UINT32;
classFile: String;
classFileSL: TStringList;
classFileS: String;
classFileSUTF8: UTF8String;
hCurrentEditView: HWND;
begin
inherited;
NodeData := Sender.GetNodeData(HitInfo.HitNode);
// Double click on file node, opens the file
if
(
(NodeData.nodeType = 2) and
(NodeData.Value <> '')
)
then begin
if (FileExists(NodeData.Value))
then begin
Npp.DoOpen(NodeData.Value);
Windows.SetFocus(Npp.GetCurrentScintilla);
end
else
Application.MessageBox(PWideChar('File "'+ NodeData.Value + '" cannot be opened, because it is not available anymore.'), 'Notepad++ - Failed to open file', 64);
end
// Double click on attribute / method node, opens the file and goes to position where the attribute / method was defined
else if
(
(NodeData.nodeType = 4) or
(NodeData.nodeType = 5)
)
then begin
fileOffset := NodeData.fileOffset;
classFile := '';
fileNode := HitInfo.HitNode.Parent.Parent.FirstChild;
// Find file name of class of attribute/method by getting the last file node
while (fileNode <> nil) do
begin
NodeData := Sender.GetNodeData(fileNode);
if
(
(NodeData.nodeType = 2) and // if file node
(NodeData.Value <> '') and
(FileExists(NodeData.Value))
)
then
classFile := NodeData.Value;
fileNode := fileNode.NextSibling;
end;
if (classFile <> '') then
begin
// Open file
Npp.DoOpen(classFile);
// Get file contents (use TStringList, since easier)
classFileSL := TStringList.Create();
classFileSL.LoadFromFile(classFile, TEncoding.ANSI); // TODO: Is this required or can we always load as UTF-8?
if (IsUTF8String(classFileSL.Text)) then
classFileSL.LoadFromFile(classFile, TEncoding.UTF8);
classFileS := classFileSL.Text;
classFileSL.Free();
// Calculate ANSI Pos of Unicode Pos
SetLength(classFileS, fileOffset - 1);
SetLength(classFileSUTF8, Length(classFileS) * SizeOf(char) + 1);
fileOffset := UnicodeToUtf8(PAnsiChar(classFileSUTF8), Length(classFileSUTF8), PWideChar(classFileS), Length(classFileS));
fileOffset := fileOffset - 1; // since VCL strings start with 1 and not 0
// Tell Scintilla to jump to the offset
hCurrentEditView := Npp.GetCurrentScintilla();
SendMessage(hCurrentEditView, SciSupport.SCI_GOTOPOS, fileOffset, 0);
Windows.SetFocus(hCurrentEditView);
end;
end;
end;
//---------------------------------------------------------------------------
procedure TClassesListDockingForm.edtSearchChange(Sender: TObject);
begin
inherited;
// Rebuild list
BuildClassLinkingList(php_analyzer);
end;
//---------------------------------------------------------------------------
procedure TClassesListDockingForm.FormCreate(Sender: TObject);
begin
self.NppDefaultDockingMask := DWS_DF_CONT_RIGHT; // whats the default docking position
self.KeyPreview := true; // special hack for input forms
self.OnFloat := self.FormFloat;
self.OnDock := self.FormDock;
self.DockingFormActive := false;
// Load image list
ILAddMasked(self.TreeViewImageList, 'CLDF_ATTRIBUTEMETHOD', clLime);
ILAddMasked(self.TreeViewImageList, 'CLDF_CLASS', clLime);
ILAddMasked(self.TreeViewImageList, 'CLDF_FILE', clLime);
ILAddMasked(self.TreeViewImageList, 'CLDF_PRIVATE', clLime);
ILAddMasked(self.TreeViewImageList, 'CLDF_PROTECTED', clLime);
ILAddMasked(self.TreeViewImageList, 'CLDF_PUBLIC', clLime);
// Tell virtual tree view the size of node data record
ClassListTreeView.NodeDataSize := SizeOf(rTreeData);
inherited;
end;
//---------------------------------------------------------------------------
// special hack for input forms
// This is the best possible hack I could came up for
// memo boxes that don't process enter keys for reasons
// too complicated... Has something to do with Dialog Messages
// I sends a Ctrl+Enter in place of Enter
procedure TClassesListDockingForm.FormKeyPress(Sender: TObject;
var Key: Char);
begin
inherited;
//if (Key = #13) and (self.ClassListTreeView.Focused) then self.ClassListTreeView.Perform(WM_CHAR, 10, 0);
end;
//---------------------------------------------------------------------------
// Docking code calls this when the form is hidden by either "x" or self.Hide
procedure TClassesListDockingForm.FormHide(Sender: TObject);
begin
inherited;
SendMessage(self.Npp.NppData.NppHandle, NPPM_SETMENUITEMCHECK, self.CmdID, 0);
self.DockingFormActive := false;
end;
//---------------------------------------------------------------------------
procedure TClassesListDockingForm.FormDock(Sender: TObject);
begin
SendMessage(self.Npp.NppData.NppHandle, NPPM_SETMENUITEMCHECK, self.CmdID, 1);
end;
//---------------------------------------------------------------------------
procedure TClassesListDockingForm.FormFloat(Sender: TObject);
begin
SendMessage(self.Npp.NppData.NppHandle, NPPM_SETMENUITEMCHECK, self.CmdID, 1);
end;
//---------------------------------------------------------------------------
procedure TClassesListDockingForm.FormShow(Sender: TObject);
begin
inherited;
SendMessage(self.Npp.NppData.NppHandle, NPPM_SETMENUITEMCHECK, self.CmdID, 1);
self.DockingFormActive := true;
end;
//---------------------------------------------------------------------------
procedure TClassesListDockingForm.BuildClassLinkingList(var analyzer: TAnalyzerPHP);
var
Node1, Node2, Node3, tmpNode1, tmpNode2, tmpNode3: PVirtualNode;
NodeData: ^rTreeData;
i, j, k, l: Integer;
sSearchText: String;
sFullMethodString: String;
bFoundAttributeOrMethodNode: Boolean;
begin
ClassListTreeView.BeginUpdate();
// Clear list
ClassListTreeView.Clear();
// Build list
for i := 0 to analyzer.classLinkingList.Count-1 do
begin
// Create class node
Node1 := ClassListTreeView.AddChild(nil);
NodeData := ClassListTreeView.GetNodeData(Node1);
NodeData.Text := analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].name;
NodeData.nodeType := 1;
NodeData.Value := analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].name;
NodeData.ImageIndex := 1;
NodeData.classNodeMoved := false;
NodeData.classIndex := analyzer.classLinkingList.Items[i].classIndex;
NodeData.fileOffset := analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].fileOffset;
// Create file entries in which class is defined
for j := 0 to analyzer.classLinkingList.Items[i].fileIndices.Count-1 do
begin
if (analyzer.classLinkingList.Items[i].fileIndices.Items[j] = -1) then
begin
Node2 := ClassListTreeView.AddChild(Node1);
NodeData := ClassListTreeView.GetNodeData(Node2);
NodeData.Text := 'File: <Current View>';
NodeData.nodeType := 2;
NodeData.Value := '';
NodeData.ImageIndex := 2;
end
else
begin
Node2 := ClassListTreeView.AddChild(Node1);
NodeData := ClassListTreeView.GetNodeData(Node2);
NodeData.Text := 'File: ' + (*ExtractShortPathName*)(analyzer.dbfiles.Items[analyzer.classLinkingList.Items[i].fileIndices.Items[j]].sFile);
NodeData.nodeType := 2;
NodeData.Value := analyzer.dbfiles.Items[analyzer.classLinkingList.Items[i].fileIndices.Items[j]].sFile;
NodeData.ImageIndex := 2;
end;
end;
// Create attribute node
Node2 := ClassListTreeView.AddChild(Node1);
NodeData := ClassListTreeView.GetNodeData(Node2);
if (ClassesListDockingForm.cbxShowSeparately.Checked) then
begin
NodeData.Text := 'Attributes';
NodeData.nodeType := 3;
NodeData.Value := '';
NodeData.ImageIndex := 0;
end
else
begin
NodeData.Text := 'Attributes & Methods';
NodeData.nodeType := 3;
NodeData.Value := '';
NodeData.ImageIndex := 0;
end;
// Create attribute entries
for j := 0 to analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].attributes.Count-1 do
begin
Node3 := ClassListTreeView.AddChild(Node2);
NodeData := ClassListTreeView.GetNodeData(Node3);
NodeData.Text := analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].attributes.Items[j].name;
NodeData.nodeType := 4;
NodeData.Value := analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].attributes.Items[j].name;
NodeData.Visibility := analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].attributes.Items[j].visibility;
NodeData.fileOffset := analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].attributes.Items[j].fileOffset;
case analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].attributes.Items[j].visibility of
asvPublic: NodeData.ImageIndex := 5;
asvProtected: NodeData.ImageIndex := 4;
asvPrivate: NodeData.ImageIndex := 3;
else NodeData.ImageIndex := 5;
end;
// Also append if static or constant
if
(
(analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].attributes.Items[j].bStatic) or
(analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].attributes.Items[j].bConst)
)
then begin
NodeData.Text := NodeData.Text + ' [';
if (analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].attributes.Items[j].bStatic) then
begin
NodeData.Text := NodeData.Text + 'static';
if (analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].attributes.Items[j].bConst) then
NodeData.Text := NodeData.Text + ', constant';
end
else
begin
if (analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].attributes.Items[j].bConst) then
NodeData.Text := NodeData.Text + 'constant';
end;
NodeData.Text := NodeData.Text + ']';
end;
// Hide node
if
(
(not cbxShowPrivateProtected.Checked) and
(analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].attributes.Items[j].visibility <> asvPublic) and
(analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].attributes.Items[j].visibility <> asvUnknown)
)
then begin
ClassListTreeView.IsVisible[Node3] := false;
end;
end;
// Hide entire attribute node if no (visible) attributes found.
// Do this only if separated attributes and methods (if together, then this will be done later below)
if
(
(CountVisibleChildNodes(ClassListTreeView, Node2) = 0) and
(ClassesListDockingForm.cbxShowSeparately.Checked)
)
then begin
ClassListTreeView.IsVisible[Node2] := false;
end;
// Create method node
if (ClassesListDockingForm.cbxShowSeparately.Checked) then
begin
Node2 := ClassListTreeView.AddChild(Node1);
NodeData := ClassListTreeView.GetNodeData(Node2);
NodeData.Text := 'Methods';
NodeData.nodeType := 3;
NodeData.Value := '';
NodeData.ImageIndex := 0;
end;
// Create method entries
for j := 0 to analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].methods.Count-1 do
begin
Node3 := ClassListTreeView.AddChild(Node2);
NodeData := ClassListTreeView.GetNodeData(Node3);
NodeData.Text := ''; // see below
NodeData.nodeType := 5;
NodeData.Value := analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].methods.Items[j].name;
NodeData.Visibility := analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].methods.Items[j].visibility;
NodeData.methodIndex := j;
NodeData.fileOffset := analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].methods.Items[j].fileOffset;
case analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].methods.Items[j].visibility of
asvPublic: NodeData.ImageIndex := 5;
asvProtected: NodeData.ImageIndex := 4;
asvPrivate: NodeData.ImageIndex := 3;
else NodeData.ImageIndex := 5;
end;
// Create a prebuild string so TVirtualStringTree can calculate the text wide. Text will be colored later.
sFullMethodString := analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].methods.Items[j].name;
sFullMethodString := sFullMethodString + '(';
if (cbxShowMethodParameters.Checked) then
begin
k := analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].methods.Items[j].parameters.Count;
for l := 0 to k-1 do
begin
sFullMethodString := sFullMethodString + analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].methods.Items[j].parameters.Strings[l];
if (l < k-1) then
begin
sFullMethodString := sFullMethodString + ',';
end;
end;
end;
sFullMethodString := sFullMethodString + ')';
sFullMethodString := GetFormattedMethodString(sFullMethodString);
NodeData.Text := sFullMethodString;
// Append if method is static
if (analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].methods.Items[j].bStatic) then
NodeData.Text := NodeData.Text + ' [static]';
// Hide node
if
(
(not cbxShowPrivateProtected.Checked) and
(analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].methods.Items[j].visibility <> asvPublic) and
(analyzer.classes.Items[analyzer.classLinkingList.Items[i].classIndex].methods.Items[j].visibility <> asvUnknown)
)
then begin
ClassListTreeView.IsVisible[Node3] := false;
end;
end;
// Hide entire method node (or the single node if not separated) if no (visible) methods (and attributes) found
if (CountVisibleChildNodes(ClassListTreeView, Node2) = 0) then
begin
ClassListTreeView.IsVisible[Node2] := false;
end;
end;
// Move temporary defined classes to the top position of list.
// Also append an asterisk (*) to the class name (can be interpreted as unsaved classes ;-)
Node1 := ClassListTreeView.RootNode.LastChild;
while (Node1 <> nil) do
begin
NodeData := ClassListTreeView.GetNodeData(Node1);
Node3 := Node1.PrevSibling;
if (not NodeData.classNodeMoved) then
begin
// Check the file sub-nodes
Node2 := Node1.FirstChild;
while (Node2 <> nil) do
begin
NodeData := ClassListTreeView.GetNodeData(Node2);
// If node = 2 (file) and value is empty, class is temporarily defined
if
(
(NodeData.nodeType = 2) and
(NodeData.Value = '')
)
then begin
// Set classNodeMoved property of class node and append asterisk
NodeData := ClassListTreeView.GetNodeData(Node1);
NodeData.classNodeMoved := true;
NodeData.Text := NodeData.Text + '*';
// Move to top
ClassListTreeView.MoveTo(Node1, ClassListTreeView.RootNode.FirstChild, TVTNodeAttachMode.amInsertBefore, false);
Break;
end;
Node2 := Node2.NextSibling;
end;
end;
Node1 := Node3;
end;
// Perform search
if (edtSearch.Text <> '') then
begin
sSearchText := LowerCase(edtSearch.Text);
// Iterate through all classes
Node1 := ClassListTreeView.RootNode.LastChild;
while (Node1 <> nil) do
begin
Node2 := Node1.LastChild;
tmpNode3 := Node1.PrevSibling;
while (Node2 <> nil) do
begin
NodeData := ClassListTreeView.GetNodeData(Node2);
tmpNode2 := Node2.PrevSibling;
// If attribute/method node
if (NodeData.nodeType = 3) then
begin
// Remove attribute / method entry
Node3 := Node2.LastChild;
while (Node3 <> nil) do
begin
tmpNode1 := Node3.PrevSibling;
NodeData := ClassListTreeView.GetNodeData(Node3);
if (Pos(sSearchText, LowerCase(NodeData.Value)) = 0) then
ClassListTreeView.DeleteNode(Node3);
Node3 := tmpNode1;
end;
// If attribute/method node empty, remove it too
if (CountVisibleChildNodes(ClassListTreeView, Node2) = 0) then
begin
ClassListTreeView.DeleteNode(Node2);
end;
end;
Node2 := tmpNode2;
end;
// Iterate through class subnodes again. If no method/attribute nodes found
// and class name does not match too, remove entire class node.
bFoundAttributeOrMethodNode := false;
Node2 := Node1.LastChild;
while (Node2 <> nil) do
begin
NodeData := ClassListTreeView.GetNodeData(Node2);
if (NodeData.nodeType = 3) then
begin
bFoundAttributeOrMethodNode := true;
break;
end;
Node2 := Node2.PrevSibling;
end;
NodeData := ClassListTreeView.GetNodeData(Node1);
if
(
(not bFoundAttributeOrMethodNode) and
(Pos(sSearchText, LowerCase(NodeData.Value)) = 0)
)
then ClassListTreeView.DeleteNode(Node1);
Node1 := tmpNode3;
end;
end;
ClassListTreeView.EndUpdate();
// Update status bar
StatusBar.SimpleText := IntToStr(ClassListTreeView.RootNodeCount) + ' classes';
end;
//---------------------------------------------------------------------------
end.