-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreeNodes.pas
109 lines (93 loc) · 2.5 KB
/
TreeNodes.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
{ **
DelphiPI (Delphi Package Installer)
Author : ibrahim dursun (ibrahimdursun gmail)
License : GNU General Public License 2.0
** }
unit TreeNodes;
interface
uses treemodel, packageinfo, Generics.Defaults;
type
TNodeType = (ntNode, ntFolder, ntPackage);
TTreeNode = class(TInterfacedObject, INode)
private
fName: string;
fPath: string;
fSelected: boolean;
fNodeType: TNodeType;
public
constructor Create(const name, path: string);
function GetData: TObject; virtual;
function GetDisplayName: string; virtual;
function GetNodePath: string; virtual;
property NodeType: TNodeType read fNodeType;
property Selected: boolean read fSelected write fSelected;
end;
TPackageTreeNode = class(TTreeNode)
private
fInfo: TPackageInfo;
fMissingPackageName: string;
public
constructor Create(const info: TPackageInfo); virtual;
function GetData: TObject; override;
function GetDisplayName: string; override;
function GetNodePath: string; override;
function ToString: string; override;
property MissingPackageName: string read fMissingPackageName write fMissingPackageName;
end;
TTreeNodeComparer = class(TInterfacedObject, IComparer<TTreeNode>)
function Compare(const Left, Right: TTreeNode): Integer;
end;
implementation
uses JclStrings;
constructor TTreeNode.Create(const name, path: string);
begin
fName := name;
fPath := path;
fNodeType := ntFolder;
fSelected := true;
end;
function TTreeNode.GetData: TObject;
begin
Result := nil;
end;
function TTreeNode.GetDisplayName: string;
begin
Result := fName;
end;
function TTreeNode.GetNodePath: string;
begin
Result := fPath;
end;
constructor TPackageTreeNode.Create(const info: TPackageInfo);
begin
fInfo := info;
fNodeType := ntPackage;
fSelected := true;
end;
function TPackageTreeNode.GetData: TObject;
begin
Result := fInfo;
end;
function TPackageTreeNode.GetDisplayName: string;
begin
Result := fInfo.PackageName;
end;
function TPackageTreeNode.GetNodePath: string;
var
i: integer;
begin
Result := fInfo.FileName;
i := Pos(':', Result);
if i <> 0 then
Result := StrRestOf(Result, i + 2);
end;
function TPackageTreeNode.ToString: string;
begin
Result := fInfo.FileName;
end;
{ TTreeNodeComparer }
function TTreeNodeComparer.Compare(const Left, Right: TTreeNode): Integer;
begin
Result := StrCompare(Left.GetNodePath, Right.GetNodePath, true);
end;
end.