1 | unit FormTargetProject;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, LazFileUtils, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
---|
7 | Project;
|
---|
8 |
|
---|
9 | type
|
---|
10 | TShowTargetCodeEvent = procedure(ProjectFile: TProjectFile) of object;
|
---|
11 |
|
---|
12 | { TFormTargetProject }
|
---|
13 |
|
---|
14 | TFormTargetProject = class(TForm)
|
---|
15 | TreeViewProject: TTreeView;
|
---|
16 | procedure TreeViewProjectChange(Sender: TObject; Node: TTreeNode);
|
---|
17 | private
|
---|
18 | FOnShowTargetCode: TShowTargetCodeEvent;
|
---|
19 | procedure UpdateProjectFiles(Node: TTreeNode; Files: TProjectFiles);
|
---|
20 | procedure UpdateProjectTree;
|
---|
21 | public
|
---|
22 | procedure UpdateInterface;
|
---|
23 | property OnShowTargetCode: TShowTargetCodeEvent read FOnShowTargetCode
|
---|
24 | write FOnShowTargetCode;
|
---|
25 | end;
|
---|
26 |
|
---|
27 |
|
---|
28 | implementation
|
---|
29 |
|
---|
30 | {$R *.lfm}
|
---|
31 |
|
---|
32 | uses
|
---|
33 | Core, FormMain, FormTargetCode;
|
---|
34 |
|
---|
35 | procedure TFormTargetProject.UpdateProjectTree;
|
---|
36 | var
|
---|
37 | NewNode: TTreeNode;
|
---|
38 | begin
|
---|
39 | with Core.Core, FormMain.FormMain, TreeViewProject, Items do begin
|
---|
40 | BeginUpdate;
|
---|
41 | Clear;
|
---|
42 | if Assigned(Project) then begin
|
---|
43 | NewNode := AddChild(nil, ExtractFileNameWithoutExt(TargetProject.FileName));
|
---|
44 | UpdateProjectFiles(NewNode, TargetProject.Files);
|
---|
45 | NewNode.Expand(True);
|
---|
46 | end;
|
---|
47 | EndUpdate;
|
---|
48 | if Assigned(TreeViewProject.TopItem) and
|
---|
49 | (TreeViewProject.TopItem.Count > 0) then
|
---|
50 | TreeViewProject.TopItem.Items[0].Selected := True
|
---|
51 | else begin
|
---|
52 | if Assigned(FOnShowTargetCode) then
|
---|
53 | FOnShowTargetCode(nil);
|
---|
54 | end;
|
---|
55 | end;
|
---|
56 | end;
|
---|
57 |
|
---|
58 | procedure TFormTargetProject.UpdateInterface;
|
---|
59 | begin
|
---|
60 | UpdateProjectTree;
|
---|
61 | end;
|
---|
62 |
|
---|
63 | procedure TFormTargetProject.TreeViewProjectChange(Sender: TObject;
|
---|
64 | Node: TTreeNode);
|
---|
65 | begin
|
---|
66 | with FormMain.FormMain do
|
---|
67 | if Assigned(Node) then begin
|
---|
68 | if TProjectFile(Node.Data) is TProjectFile then begin
|
---|
69 | if Assigned(FOnShowTargetCode) then
|
---|
70 | FOnShowTargetCode(TProjectFile(Node.Data))
|
---|
71 | end;
|
---|
72 | end;
|
---|
73 | end;
|
---|
74 |
|
---|
75 | procedure TFormTargetProject.UpdateProjectFiles(Node: TTreeNode; Files: TProjectFiles);
|
---|
76 | var
|
---|
77 | I: Integer;
|
---|
78 | NewNode: TTreeNode;
|
---|
79 | FileName: string;
|
---|
80 | NamePart: string;
|
---|
81 | SelNode: TTreeNode;
|
---|
82 | SubNode: TTreeNode;
|
---|
83 | begin
|
---|
84 | for I := 0 to Files.Count - 1 do begin
|
---|
85 | FileName := TProjectFile(Files[I]).FileName;
|
---|
86 | SelNode := Node;
|
---|
87 | while Pos(DirectorySeparator, FileName) > 0 do begin
|
---|
88 | NamePart := Copy(FileName, 1, Pos(DirectorySeparator, FileName) - 1);
|
---|
89 | Delete(FileName, 1, Length(NamePart) + 1);
|
---|
90 | SubNode := SelNode.FindNode(NamePart);
|
---|
91 | if Assigned(SubNode) then SelNode := SubNode
|
---|
92 | else begin
|
---|
93 | SelNode := TreeViewProject.Items.AddChild(SelNode, NamePart);
|
---|
94 | end;
|
---|
95 | end;
|
---|
96 | NewNode := TreeViewProject.Items.AddChild(SelNode, FileName);
|
---|
97 | NewNode.Data := Pointer(Files[I]);
|
---|
98 | end;
|
---|
99 | end;
|
---|
100 |
|
---|
101 |
|
---|
102 | end.
|
---|
103 |
|
---|