This repository has been archived by the owner on Jul 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathPageShowPackageList.pas
806 lines (721 loc) · 23.4 KB
/
PageShowPackageList.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
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
{ **
DelphiPI (Delphi Package Installer)
Author : ibrahim dursun (ibrahimdursun gmail)
License : GNU General Public License 2.0
** }
unit PageShowPackageList;
interface
uses
CompilationData, Windows, Messages, SysUtils, Variants, Classes, Graphics, StdCtrls, Vcl.Controls, Forms,
Dialogs, PageBase, ComCtrls, PackageInfo, ImgList, WizardIntfs, Menus, VirtualTrees, PackageDependencyVerifier,
ActnList, InstalledPackageResolver, TreeModel, ListViewModel, ToolWin, Generics.Collections, TreeNodes,
System.Actions;
type
PNodeData = ^TNodeData;
TNodeData = record
Node: TTreeNode;
end;
TPackageViewType = (pvtTree, pvtList, pvtDelphiVersion);
TShowPackageListPage = class(TWizardPage)
pmSelectPopupMenu: TPopupMenu;
miSelectAll: TMenuItem;
miUnselectAll: TMenuItem;
miSelectMatching: TMenuItem;
N1: TMenuItem;
ImageList: TImageList;
miUnselectMatching: TMenuItem;
fPackageTree: TVirtualStringTree;
lblWait: TLabel;
N2: TMenuItem;
miCollapse: TMenuItem;
miExpand: TMenuItem;
ActionList: TActionList;
actRemove: TAction;
Remove1: TMenuItem;
N3: TMenuItem;
toolbar: TToolBar;
btnFolderView: TToolButton;
sepearator1: TToolButton;
ilActionImages: TImageList;
actChangeViewToTree: TAction;
actChangeViewToList: TAction;
actSelectAll: TAction;
actUnselectAll: TAction;
actSelectMatching: TAction;
actUnselectMatching: TAction;
actExpand: TAction;
actCollapse: TAction;
btnChangeToListView: TToolButton;
btnAddFolder: TToolButton;
actAddPackagesFromFolder: TAction;
actAddPackages: TAction;
btnAddPackage: TToolButton;
seperator2: TToolButton;
btnSelectMatching: TToolButton;
btnUnselectMatching: TToolButton;
btnViewDelphiVersion: TToolButton;
actChangeViewToDelphiVersion: TAction;
actRefresh: TAction;
btnRefresh: TToolButton;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure packageTreeChecked(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure packageTreeGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: Integer);
procedure packageTreeGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean;
var ImageIndex: Integer);
procedure fPackageTreeGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle;
var HintText: string);
procedure fPackageTreeGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
procedure fPackageTreePaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
TextType: TVSTTextType);
procedure fPackageTreeKeyAction(Sender: TBaseVirtualTree; var CharCode: Word; var Shift: TShiftState; var DoDefault: Boolean);
procedure fPackageTreeInitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
procedure fPackageTreeInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode; var ChildCount: Cardinal);
procedure actRemoveExecute(Sender: TObject);
procedure actRemoveUpdate(Sender: TObject);
procedure actChangeViewToTreeExecute(Sender: TObject);
procedure actChangeViewToListExecute(Sender: TObject);
procedure actSelectAllExecute(Sender: TObject);
procedure actUnselectAllExecute(Sender: TObject);
procedure actSelectMatchingExecute(Sender: TObject);
procedure actUnselectMatchingExecute(Sender: TObject);
procedure actCollapseExecute(Sender: TObject);
procedure actExpandExecute(Sender: TObject);
procedure PackageListActionsUpdate(Sender: TObject);
procedure actChangeViewToDelphiVersionExecute(Sender: TObject);
procedure actAddPackagesFromFolderExecute(Sender: TObject);
procedure actRefreshExecute(Sender: TObject);
procedure actAddPackagesExecute(Sender: TObject);
private
packageLoadThread: TThread;
fSelectMask: string;
fDependencyVerifier: TPackageDependencyVerifier;
fInstalledPackageResolver: TInstalledPackageResolver;
fModel: TTreeModelBase<TTreeNode>;
fNodes: TList<TTreeNode>;
procedure PackageLoadCompleted(Sender: TObject);
procedure ChangeState(Node: PVirtualNode; checkState: TCheckState; recursive:Boolean = true);
procedure VerifyDependencies;
procedure SetView(const viewType: TPackageViewType);
procedure actNextUpdate(sender: TObject);
private
class var criticalSection: TRTLCriticalSection;
class constructor Create;
class destructor Destroy;
procedure LoadPackages(const directory, pattern: string; nodes: TList<TTreeNode>); overload;
procedure LoadPackages(const fileList: TStrings; nodes: TList<TTreeNode>); overload;
public
constructor Create(Owner: TComponent; const CompilationData: TCompilationData); override;
procedure UpdateWizardState; override;
end;
implementation
uses JclFileUtils, JclStrings, gnugettext, Utils, TreeViewModel, PackageLoadThread, DelphiVersionTreeViewModel, FileCtrl, PackageInfoFactory, CustomTypes;
{$R *.dfm}
var
threadWorking: Boolean;
type
TVirtualTreeHelper = class helper for TBaseVirtualTree
private
procedure InternalTraverse(Node: PVirtualNode; handler: TProc<PVirtualNode>);
public
procedure Traverse(Node: PVirtualNode; handler: TProc<PVirtualNode>); overload;
procedure Traverse(handler: TProc<PVirtualNode>); overload;
procedure TraverseWithData(handler: TProc<PVirtualNode, PNodeData>);
end;
{ TShowPackageListPage }
constructor TShowPackageListPage.Create(Owner: TComponent; const CompilationData: TCompilationData);
var
previousBaseFolder: TString;
begin
inherited;
fCompilationData := CompilationData;
if not SysUtils.DirectoryExists(fCompilationData.BaseFolder) then
exit;
fInstalledPackageResolver := TInstalledPackageResolver.Create(CompilationData);
fInstalledPackageResolver.AddDefaultPackageList;
fInstalledPackageResolver.AddIDEPackageList(CompilationData);
fDependencyVerifier := TPackageDependencyVerifier.Create;
previousBaseFolder := Wizard.GetState('base-folder') as TString;
if (previousBaseFolder <> nil) and (previousBaseFolder.Value = fCompilationData.BaseFolder) then
begin
fNodes := Wizard.GetState('nodes') as TList<TTreeNode>;
end;
if fNodes = nil then
fNodes := TList<TTreeNode>.Create(TTreeNodeComparer.Create);
SetView(pvtTree);
if fNodes.Count = 0 then
begin
LoadPackages(fCompilationData.BaseFolder, fCompilationData.Pattern, fNodes);
end else begin
actChangeViewToTree.Execute;
end;
end;
class constructor TShowPackageListPage.Create;
begin
InitializeCriticalSection(criticalSection);
end;
class destructor TShowPackageListPage.Destroy;
begin
DeleteCriticalSection(criticalSection);
end;
procedure TShowPackageListPage.FormClose(Sender: TObject; var Action: TCloseAction);
var
node: TTreeNode;
begin
inherited;
if threadWorking then
begin
TPackageLoadThread(packageLoadThread).Active := false;
packageLoadThread.Terminate;
packageLoadThread.WaitFor;
packageLoadThread.Free;
exit;
end;
fCompilationData.PackageList.Clear;
for node in fNodes do
begin
if node.Selected then
fCompilationData.PackageList.Add(node.GetData as TPackageInfo);
end;
Wizard.SetState('nodes', fNodes);
Wizard.SetState('base-folder', TString.Create(fCompilationData.BaseFolder));
FreeAndNil(fDependencyVerifier);
FreeAndNil(fInstalledPackageResolver);
FreeAndNil(fModel);
end;
procedure TShowPackageListPage.FormCreate(Sender: TObject);
begin
inherited;
TranslateComponent(Self);
end;
procedure TShowPackageListPage.PackageListActionsUpdate(Sender: TObject);
begin
inherited;
TAction(Sender).Enabled := not threadWorking;
end;
procedure TShowPackageListPage.PackageLoadCompleted(Sender: TObject);
begin
threadWorking := false;
fPackageTree.BeginUpdate;
try
fPackageTree.Clear;
fPackageTree.RootNodeCount := fModel.GetChildCount(nil);
fPackageTree.FullExpand;
VerifyDependencies;
finally
fPackageTree.EndUpdate;
lblWait.Visible := false;
fPackageTree.Visible := true;
end;
end;
procedure TShowPackageListPage.ChangeState(Node: PVirtualNode; checkState: TCheckState; recursive:Boolean = true);
var
data: PNodeData;
child: PVirtualNode;
begin
if Node = nil then
exit;
Node.checkState := checkState;
data := fPackageTree.GetNodeData(Node);
if data <> nil then
data.Node.Selected := checkState = csCheckedNormal;
if not recursive then
exit;
child := Node.FirstChild;
while child <> nil do
begin
ChangeState(child, checkState, true);
child := child.NextSibling;
end;
end;
procedure TShowPackageListPage.UpdateWizardState;
var
action: TAction;
begin
inherited;
wizard.SetHeader(_('Select Packages'));
wizard.SetDescription(_('Select packages that you want to compile.'));
action := wizard.GetAction(wbtNext);
action.Enabled := (not threadWorking);
action := wizard.GetAction(wbtNext);
action.Caption := _('Compile');
action.OnUpdate := actNextUpdate;
end;
procedure TShowPackageListPage.VerifyDependencies;
var
selectedPackages: TList<TPackageInfo>;
info: TPackageInfo;
modelNode: TTreeNode;
begin
selectedPackages := TList<TPackageInfo>.Create;
try
for modelNode in fNodes do
begin
if modelNode.Selected then
selectedPackages.Add(modelNode.GetData as TPackageInfo);
end;
fDependencyVerifier.Verify(selectedPackages, fInstalledPackageResolver);
finally
selectedPackages.Free;
end;
fPackageTree.BeginUpdate;
try
for modelNode in fNodes do
begin
if modelNode.NodeType <> ntPackage then
continue;
info := modelNode.GetData as TPackageInfo;
TPackageTreeNode(modelNode).MissingPackageName := fDependencyVerifier.MissingPackages[info.PackageName];
end;
finally
fPackageTree.EndUpdate;
end;
end;
procedure TShowPackageListPage.packageTreeChecked(Sender: TBaseVirtualTree; Node: PVirtualNode);
begin
fPackageTree.BeginUpdate;
try
ChangeState(Node, Node.checkState, true);
VerifyDependencies;
fPackageTree.InvalidateChildren(Node, true);
finally
fPackageTree.EndUpdate;
end;
UpdateWizardState;
end;
procedure TShowPackageListPage.packageTreeGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: Integer);
begin
NodeDataSize := sizeof(TNodeData);
end;
procedure TShowPackageListPage.SetView(const viewType: TPackageViewType);
begin
EnterCriticalSection(criticalSection);
try
if assigned(fModel) then
FreeAndNil(fModel);
case viewType of
pvtTree:
fModel := TTreeViewModel<TTreeNode>.Create(fNodes);
pvtList:
fModel := TListViewModel<TTreeNode>.Create(fNodes);
pvtDelphiVersion:
fModel := TCachedDelphiVersionTreeViewModel<TTreeNode>.Create(fNodes);
else
raise Exception.Create('Invalid View');
end;
fModel.OnCreateLogicalNode := function(name, path: string): TTreeNode
begin
Result := TTreeNode.Create(name, path);
end;
finally
LeaveCriticalSection(criticalSection);
end;
end;
procedure TShowPackageListPage.packageTreeGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean; var ImageIndex: Integer);
var
data: PNodeData;
begin
if Column <> 0 then
exit;
data := Sender.GetNodeData(Node);
case data.Node.NodeType of
ntFolder:
ImageIndex := 0;
ntPackage:
ImageIndex := 1;
end;
end;
procedure TShowPackageListPage.actAddPackagesExecute(Sender: TObject);
var
dialog: TOpenDialog;
begin
dialog := TOpenDialog.Create(self);
try
dialog.DefaultExt := 'dpk';
dialog.Options := dialog.Options + [ofAllowMultiSelect];
//dialog.Options := [TOpenDialog.fdoAllowMultiSelect];
dialog.Filter := 'Delphi Package (*.dpk)|*.dpk';
dialog.InitialDir := fCompilationData.BaseFolder;
if (dialog.Execute) and (dialog.Files.Count > 0) then
begin
LoadPackages(dialog.Files, fNodes);
end;
finally
dialog.Free;
end;
end;
procedure TShowPackageListPage.actAddPackagesFromFolderExecute(Sender: TObject);
var
directory: string;
begin
directory := '';
if SelectDirectory(_('Select folder where packages are'),'',directory) then
begin
with TPackageLoadThread.Create(directory, '*.dpk',fNodes) do
begin
FreeOnTerminate := true;
OnTerminate := PackageLoadCompleted;
Start;
end;
end;
end;
procedure TShowPackageListPage.actChangeViewToDelphiVersionExecute(
Sender: TObject);
begin
fPackageTree.BeginUpdate;
try
fPackageTree.Clear;
SetView(pvtDelphiVersion);
fPackageTree.RootNodeCount := fModel.GetChildCount(nil);
fPackageTree.FullExpand;
VerifyDependencies;
finally
fPackageTree.EndUpdate;
end;
end;
procedure TShowPackageListPage.actChangeViewToListExecute(Sender: TObject);
begin
inherited;
fPackageTree.BeginUpdate;
try
fPackageTree.Clear;
SetView(pvtList);
fPackageTree.RootNodeCount := fModel.GetChildCount(nil);
fPackageTree.FullExpand;
VerifyDependencies;
finally
fPackageTree.EndUpdate;
end;
end;
procedure TShowPackageListPage.actChangeViewToTreeExecute(Sender: TObject);
begin
inherited;
fPackageTree.BeginUpdate;
try
fPackageTree.Clear;
SetView(pvtTree);
fPackageTree.RootNodeCount := fModel.GetChildCount(nil);
fPackageTree.FullExpand;
VerifyDependencies;
finally
fPackageTree.EndUpdate;
end;
end;
procedure TShowPackageListPage.actCollapseExecute(Sender: TObject);
begin
fPackageTree.FullCollapse(fPackageTree.FocusedNode);
end;
procedure TShowPackageListPage.actExpandExecute(Sender: TObject);
begin
fPackageTree.FullExpand(fPackageTree.FocusedNode);
end;
procedure TShowPackageListPage.actNextUpdate(sender: TObject);
var
i, selectedPackageCount:Integer;
action: TAction;
begin
action := TAction(sender);
selectedPackageCount := 0;
for i := 0 to fNodes.Count-1 do
begin
if TPackageTreeNode(FNodes[i]).Selected then
inc(selectedPackageCount);
end;
action.Enabled := (selectedPackageCount > 0) and (not threadWorking);
end;
procedure TShowPackageListPage.actRefreshExecute(Sender: TObject);
begin
inherited;
fPackageTree.Clear;
fNodes.Clear;
LoadPackages(fCompilationData.BaseFolder, fCompilationData.Pattern, fNodes);
end;
procedure TShowPackageListPage.actRemoveExecute(Sender: TObject);
var
nodes: TNodeArray;
I: Integer;
begin
if fPackageTree.SelectedCount > 0 then
begin
nodes := fPackageTree.GetSortedSelection(true);
for I := 0 to Length(nodes) - 1 do
begin
fPackageTree.Traverse(nodes[i], procedure(node: PVirtualNode)
var
nodeData: TTreeNode;
begin
nodeData := PNodeData(fPackageTree.GetNodeData(node)).Node;
nodeData.Selected := false; // because it is being deleted;
fNodes.Remove(nodeData); //remove from collection
end);
end;
fPackageTree.DeleteSelectedNodes;
VerifyDependencies;
end;
end;
procedure TShowPackageListPage.actRemoveUpdate(Sender: TObject);
begin
TAction(Sender).Enabled := fPackageTree.SelectedCount > 0;
end;
procedure TShowPackageListPage.actSelectAllExecute(Sender: TObject);
begin
fPackageTree.BeginUpdate;
try
ChangeState(fPackageTree.RootNode, csCheckedNormal, true);
VerifyDependencies;
finally
fPackageTree.EndUpdate;
end;
end;
procedure TShowPackageListPage.actUnselectAllExecute(Sender: TObject);
begin
fPackageTree.BeginUpdate;
try
ChangeState(fPackageTree.RootNode, csUncheckedNormal, true);
VerifyDependencies;
finally
fPackageTree.EndUpdate;
end;
end;
procedure TShowPackageListPage.actSelectMatchingExecute(Sender: TObject);
var
value: string;
begin
fPackageTree.BeginUpdate;
try
value := fCompilationData.Pattern;
if InputQuery(_('Select Matching...'), _('File Mask'), value) then
begin
fSelectMask := value;
fPackageTree.TraverseWithData(procedure(Node: PVirtualNode; data: PNodeData)
var
info: TPackageInfo;
begin
info := data.Node.GetData as TPackageInfo;
if IsFileNameMatch(info.PackageName + '.dpk', fSelectMask) then
ChangeState(Node, csCheckedNormal, false);
end);
VerifyDependencies;
end;
finally
fPackageTree.EndUpdate;
end;
end;
procedure TShowPackageListPage.actUnselectMatchingExecute(Sender: TObject);
var
value: string;
begin
fPackageTree.BeginUpdate;
try
value := fCompilationData.Pattern;
if InputQuery(_('Unselect Matching...'), _('File Mask'), value) then
begin
fSelectMask := value;
fPackageTree.TraverseWithData(procedure(Node: PVirtualNode; data: PNodeData)
var info: TPackageInfo;
begin
info := data.Node.GetData as TPackageInfo;
if IsFileNameMatch(info.PackageName + '.dpk', fSelectMask) then
ChangeState(Node, csUncheckedNormal, false);
end);
VerifyDependencies;
end;
finally
fPackageTree.EndUpdate;
end;
end;
procedure TShowPackageListPage.fPackageTreeGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex;
var LineBreakStyle: TVTTooltipLineBreakStyle; var HintText: string);
var
data: PNodeData;
_type: string;
info: TPackageInfo;
builder: TStringBuilder;
modelNode: TPackageTreeNode;
begin
data := Sender.GetNodeData(Node);
if data.Node.NodeType <> ntPackage then
exit;
modelNode := TPackageTreeNode(data.Node);
info := modelNode.GetData as TPackageInfo;
_type := _('Designtime Package');
if (info.RunOnly) then
_type := _('Runtime Package');
builder := TStringBuilder.Create;
try
builder.Append(_('FullPath: ') + info.FileName).AppendLine;
builder.Append(_('Description: ') + info.Description).AppendLine;
builder.Append(_('Type: ') + _type).AppendLine;
builder.Append(_('Requires: ')).AppendLine;
builder.Append(info.RequiredPackageList.Text).AppendLine;
if modelNode.MissingPackageName <> '' then
builder.Append(_('Missing Package: ') + modelNode.MissingPackageName);
HintText := builder.ToString;
finally
builder.Free;
end;
end;
procedure TShowPackageListPage.fPackageTreeGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
var CellText: string);
var
data: PNodeData;
info: TPackageInfo;
begin
CellText := '';
data := Sender.GetNodeData(Node);
info := data.Node.GetData as TPackageInfo;
case Column of
0:
CellText := data.Node.GetDisplayName;
1:
if data.Node.NodeType = ntPackage then
CellText := info.Description;
2:
if data.Node.NodeType = ntPackage then
begin
if info.RunOnly then
CellText := _('runtime')
else
CellText := _('design');
end;
end;
end;
procedure TShowPackageListPage.fPackageTreeInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode; var ChildCount: Cardinal);
var
data: PNodeData;
begin
data := Sender.GetNodeData(Node);
if data.Node.NodeType = ntFolder then
begin
ChildCount := fModel.GetChildCount(data.Node);
end;
end;
procedure TShowPackageListPage.fPackageTreeInitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode;
var InitialStates: TVirtualNodeInitStates);
var
data: PNodeData;
parentData: PNodeData;
parentNodeData: TTreeNode;
begin
Node.CheckType := ctCheckBox;
parentData := Sender.GetNodeData(ParentNode);
parentNodeData := nil;
if parentData <> nil then
parentNodeData := parentData.Node;
data := Sender.GetNodeData(Node);
data.Node := fModel.GetChild(parentNodeData, Node.Index);
if data.Node.Selected then
Node.checkState := csCheckedNormal;
if fModel.GetChildCount(data.Node) > 0 then
Include(InitialStates, ivsHasChildren);
end;
procedure TShowPackageListPage.fPackageTreeKeyAction(Sender: TBaseVirtualTree; var CharCode: Word; var Shift: TShiftState; var DoDefault: Boolean);
begin
if CharCode = VK_DELETE then
begin
actRemove.Execute;
end;
end;
procedure TShowPackageListPage.fPackageTreePaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
TextType: TVSTTextType);
var
data: PNodeData;
begin
inherited;
if fPackageTree.FocusedNode = Node then
begin
TargetCanvas.Font.Color := clWhite;
exit;
end;
data := Sender.GetNodeData(Node);
if Column = 0 then
begin
if (data.Node.NodeType = ntPackage) and (TPackageTreeNode(data.Node).MissingPackageName <> '') then
TargetCanvas.Font.Color := clRed
else
TargetCanvas.Font.Color := clBlack;
end;
end;
procedure TShowPackageListPage.LoadPackages(const fileList: TStrings;
nodes: TList<TTreeNode>);
var
fileName: string;
node: TPackageTreeNode;
packageInfoFactory: TPackageInfoFactory;
begin
packageInfoFactory := TPackageInfoFactory.Create;
try
for fileName in fileList do
begin
if StrCompare(ExtractFileExt(fileName), '.dpk') <> 0 then
Continue;
node := TPackageTreeNode.Create(packageInfoFactory.CreatePackageInfo(fileName));
if nodes.Contains(node) then
Continue;
nodes.Add(node);
end;
finally
packageInfoFactory.Free;
end;
PackageLoadCompleted(nil);
end;
procedure TShowPackageListPage.LoadPackages(const directory, pattern: string;
nodes: TList<TTreeNode>);
begin
packageLoadThread := TPackageLoadThread.Create(directory, pattern, nodes);
with packageLoadThread do
begin
OnTerminate := PackageLoadCompleted;
lblWait.Visible := true;
threadWorking := true;
fPackageTree.Visible := false;
Start;
end;
end;
{ TVirtualTreeHelper }
procedure TVirtualTreeHelper.InternalTraverse(Node: PVirtualNode; handler: TProc<PVirtualNode>);
var
queue: TQueue<PVirtualNode>;
current, child: PVirtualNode;
begin
queue := TQueue<PVirtualNode>.Create;
queue.Enqueue(Node);
try
while queue.Count > 0 do
begin
current := queue.Dequeue;
if current.FirstChild <> nil then
begin
child := current.FirstChild;
repeat
queue.Enqueue(child);
child := child.NextSibling;
until child = nil;
end;
handler(current);
end;
finally
queue.Free;
end;
end;
procedure TVirtualTreeHelper.Traverse(Node: PVirtualNode; handler: TProc<PVirtualNode>);
begin
InternalTraverse(Node, handler)
end;
procedure TVirtualTreeHelper.Traverse(handler: TProc<PVirtualNode>);
begin
Traverse(RootNode, handler);
end;
procedure TVirtualTreeHelper.TraverseWithData(handler: TProc<PVirtualNode, PNodeData>);
begin
InternalTraverse(Self.RootNode, procedure(Node: PVirtualNode)
var
data: PNodeData;
begin
data := Self.GetNodeData(Node);
if (data <> nil) and (data.Node <> nil) and (data.Node.GetData <> nil) then
handler(Node, data);
end);
end;
end.