source: trunk/IDE/Forms/FormTargetProject.pas

Last change on this file was 75, checked in by chronos, 6 months ago
  • Modified: Removed U prefix from unit names.
  • Modified: Updated Common package.
File size: 2.6 KB
Line 
1unit FormTargetProject;
2
3interface
4
5uses
6 Classes, SysUtils, LazFileUtils, Forms, Controls, Graphics, Dialogs, ComCtrls,
7 Project;
8
9type
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
28implementation
29
30{$R *.lfm}
31
32uses
33 Core, FormMain, FormTargetCode;
34
35procedure TFormTargetProject.UpdateProjectTree;
36var
37 NewNode: TTreeNode;
38begin
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;
56end;
57
58procedure TFormTargetProject.UpdateInterface;
59begin
60 UpdateProjectTree;
61end;
62
63procedure TFormTargetProject.TreeViewProjectChange(Sender: TObject;
64 Node: TTreeNode);
65begin
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;
73end;
74
75procedure TFormTargetProject.UpdateProjectFiles(Node: TTreeNode; Files: TProjectFiles);
76var
77 I: Integer;
78 NewNode: TTreeNode;
79 FileName: string;
80 NamePart: string;
81 SelNode: TTreeNode;
82 SubNode: TTreeNode;
83begin
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;
99end;
100
101
102end.
103
Note: See TracBrowser for help on using the repository browser.