source: trunk/IDE/Forms/FormProject.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: 5.3 KB
Line 
1unit FormProject;
2
3interface
4
5uses
6 Classes, SysUtils, LazFileUtils, Forms, Controls, Graphics, Dialogs, ComCtrls,
7 Menus, ActnList, Project;
8
9type
10 TShowProjectEvent = procedure (ProjectFile: TProjectFile) of object;
11
12 { TFormProject }
13
14 TFormProject = class(TForm)
15 AAdd: TAction;
16 AShow: TAction;
17 ARename: TAction;
18 ADelete: TAction;
19 ActionList1: TActionList;
20 MenuItem1: TMenuItem;
21 MenuItem2: TMenuItem;
22 MenuItem3: TMenuItem;
23 MenuItem4: TMenuItem;
24 OpenDialog1: TOpenDialog;
25 PopupMenuFile: TPopupMenu;
26 TreeViewProject: TTreeView;
27 procedure AAddExecute(Sender: TObject);
28 procedure ADeleteExecute(Sender: TObject);
29 procedure ARenameExecute(Sender: TObject);
30 procedure AShowExecute(Sender: TObject);
31 procedure TreeViewProjectChange(Sender: TObject; Node: TTreeNode);
32 procedure TreeViewProjectDblClick(Sender: TObject);
33 private
34 FOnShowProject: TShowProjectEvent;
35 procedure UpdateProjectFiles(Node: TTreeNode; Files: TProjectFiles);
36 public
37 procedure UpdateProjectTree;
38 procedure UpdateInterface;
39 property OnShowProject: TShowProjectEvent read FOnShowProject write FOnShowProject;
40 end;
41
42var
43 FormProject: TFormProject;
44
45
46implementation
47
48{$R *.lfm}
49
50uses
51 Core, FormMain, FormSourceCode, FormTargetCode, FormCodeTree;
52
53resourcestring
54 SRenameSourceFile = 'Rename source file';
55 SEnterNewFileName = 'Enter new file name';
56
57{ TFormProject }
58
59procedure TFormProject.TreeViewProjectChange(Sender: TObject; Node: TTreeNode
60 );
61begin
62 if Assigned(Node) then begin
63 if TProjectFile(Node.Data) is TProjectFile then begin
64 TreeViewProject.PopupMenu := PopupMenuFile;
65 AShow.Execute;
66(* if FileExists(TProjectFile(Node.Data).ProducedFileName) then
67 CompiledForm.SynEdit1.Lines.LoadFromFile(FileName) else
68 CompiledForm.SynEdit1.Lines.Clear;
69 if ComboBoxTargetSelection.ItemIndex = 0 then
70 CompiledForm.SynEdit1.Highlighter := CompiledForm.SynPasSyn1;
71 if ComboBoxTargetSelection.ItemIndex = 1 then
72 CompiledForm.SynEdit1.Highlighter := CompiledForm.SynCppSyn1;
73 if ComboBoxTargetSelection.ItemIndex = 2 then
74 CompiledForm.SynEdit1.Highlighter := nil;
75 if ComboBoxTargetSelection.ItemIndex = 3 then
76 CompiledForm.SynEdit1.Highlighter := CompiledForm.SynXMLSyn1;
77 *)
78 (*// Load code tree view
79 Compiler.Producer.Free;
80 Compiler.Producer := TProducerTreeView.Create;
81 Compiler.Init;
82 Compiler.Parser.OnGetSource := GetSource;
83 with TProjectFile(Project.Items[0]) do begin
84 Compiler.Compile(Parent.GetDir + Name, Source);
85 end;
86 //CodeTreeForm.TreeView1.Assign(TProducerTreeView(Compiler.Producer).TreeView);
87 *)
88 end else
89 TreeViewProject.PopupMenu := nil;
90 end;
91end;
92
93procedure TFormProject.TreeViewProjectDblClick(Sender: TObject);
94begin
95 AShow.Execute;
96end;
97
98procedure TFormProject.AAddExecute(Sender: TObject);
99begin
100 if Sender is TMenuItem then
101 with TMenuItem(Sender) do begin
102 if OpenDialog1.Execute then begin
103
104 UpdateProjectTree;
105 end;
106 end;
107end;
108
109procedure TFormProject.ADeleteExecute(Sender: TObject);
110begin
111 if Assigned(TreeViewProject.Selected) then
112 Core.Core.Project.Files.Remove(TreeViewProject.Selected.Data);
113 UpdateProjectTree;
114end;
115
116procedure TFormProject.ARenameExecute(Sender: TObject);
117var
118 NewName: string;
119begin
120 if Assigned(TreeViewProject.Selected) then begin
121 NewName := TProjectFile(TreeViewProject.Selected.Data).FileName;
122 if InputQuery(SRenameSourceFile, SEnterNewFileName, NewName) then
123 TProjectFile(TreeViewProject.Selected.Data).FileName := NewName;
124 UpdateProjectTree;
125 end;
126end;
127
128procedure TFormProject.AShowExecute(Sender: TObject);
129begin
130 if Assigned(TreeViewProject.Selected) then begin
131 if Assigned(FOnShowProject) then
132 FOnShowProject(TProjectFile(TreeViewProject.Selected.Data));
133 end;
134end;
135
136procedure TFormProject.UpdateProjectTree;
137var
138 NewNode: TTreeNode;
139begin
140 with Core.Core, TreeViewProject, Items do
141 try
142 BeginUpdate;
143 Clear;
144 if Assigned(Project) then begin
145 NewNode := AddChildObject(nil, ExtractFileNameWithoutExt(Project.FileName), Project);
146 UpdateProjectFiles(NewNode, Project.Files);
147 NewNode.Expand(True);
148 end;
149 if Assigned(TreeViewProject.TopItem) and
150 (TreeViewProject.TopItem.Count > 0) then
151 TreeViewProject.TopItem.Items[0].Selected := True
152 else begin
153 if Assigned(FOnShowProject) then
154 FOnShowProject(nil);
155 end;
156 finally
157 EndUpdate;
158 end;
159end;
160
161procedure TFormProject.UpdateInterface;
162begin
163 UpdateProjectTree;
164end;
165
166procedure TFormProject.UpdateProjectFiles(Node: TTreeNode; Files: TProjectFiles);
167var
168 I: Integer;
169 NewNode: TTreeNode;
170 FileName: string;
171 NamePart: string;
172 SelNode: TTreeNode;
173 SubNode: TTreeNode;
174begin
175 for I := 0 to Files.Count - 1 do begin
176 FileName := TProjectFile(Files[I]).FileName;
177 SelNode := Node;
178 while Pos(DirectorySeparator, FileName) > 0 do begin
179 NamePart := Copy(FileName, 1, Pos(DirectorySeparator, FileName) - 1);
180 Delete(FileName, 1, Length(NamePart) + 1);
181 SubNode := SelNode.FindNode(NamePart);
182 if Assigned(SubNode) then SelNode := SubNode
183 else begin
184 SelNode := TreeViewProject.Items.AddChild(SelNode, NamePart);
185 end;
186 end;
187 NewNode := TreeViewProject.Items.AddChildObject(SelNode, FileName, Pointer(Files[I]));
188 end;
189end;
190
191end.
192
Note: See TracBrowser for help on using the repository browser.