source: trunk/StudioModules/LDModuleProject/UFormProject.pas

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