1 | unit UFormProject;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
---|
7 | Menus, ActnList, UProject, ULDStudioAPI;
|
---|
8 |
|
---|
9 | type
|
---|
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 |
|
---|
43 | var
|
---|
44 | FormProject: TFormProject;
|
---|
45 |
|
---|
46 | implementation
|
---|
47 |
|
---|
48 | {$R *.lfm}
|
---|
49 |
|
---|
50 | resourcestring
|
---|
51 | SRenameSourceFile = 'Rename source file';
|
---|
52 | SEnterNewFileName = 'Enter new file name';
|
---|
53 |
|
---|
54 | { TFormProject }
|
---|
55 |
|
---|
56 | procedure TFormProject.TreeViewProjectChange(Sender: TObject; Node: TTreeNode
|
---|
57 | );
|
---|
58 | begin
|
---|
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;
|
---|
88 | end;
|
---|
89 |
|
---|
90 | procedure TFormProject.TreeViewProjectDblClick(Sender: TObject);
|
---|
91 | begin
|
---|
92 | AShow.Execute;
|
---|
93 | end;
|
---|
94 |
|
---|
95 | procedure TFormProject.SetProject(AValue: TProject);
|
---|
96 | begin
|
---|
97 | if FProject = AValue then Exit;
|
---|
98 | FProject := AValue;
|
---|
99 | end;
|
---|
100 |
|
---|
101 | procedure TFormProject.AAddExecute(Sender: TObject);
|
---|
102 | begin
|
---|
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;
|
---|
110 | end;
|
---|
111 |
|
---|
112 | procedure TFormProject.ADeleteExecute(Sender: TObject);
|
---|
113 | begin
|
---|
114 | if Assigned(TreeViewProject.Selected) then
|
---|
115 | FProject.Files.Remove(TObject(TreeViewProject.Selected.Data));
|
---|
116 | UpdateProjectTree;
|
---|
117 | end;
|
---|
118 |
|
---|
119 | procedure TFormProject.ARenameExecute(Sender: TObject);
|
---|
120 | var
|
---|
121 | NewName: string;
|
---|
122 | begin
|
---|
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;
|
---|
129 | end;
|
---|
130 |
|
---|
131 | procedure TFormProject.AShowExecute(Sender: TObject);
|
---|
132 | begin
|
---|
133 | if Assigned(TreeViewProject.Selected) then begin
|
---|
134 | API.OpenFile(TProjectFile(TreeViewProject.Selected.Data).FileName);
|
---|
135 | end;
|
---|
136 | end;
|
---|
137 |
|
---|
138 | procedure TFormProject.UpdateProjectTree;
|
---|
139 | var
|
---|
140 | NewNode: TTreeNode;
|
---|
141 | begin
|
---|
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;
|
---|
157 | end;
|
---|
158 |
|
---|
159 | procedure TFormProject.UpdateInterface;
|
---|
160 | begin
|
---|
161 | UpdateProjectTree;
|
---|
162 | end;
|
---|
163 |
|
---|
164 | procedure TFormProject.UpdateProjectFiles(Node: TTreeNode; Files: TProjectFileList);
|
---|
165 | var
|
---|
166 | I: Integer;
|
---|
167 | NewNode: TTreeNode;
|
---|
168 | FileName: string;
|
---|
169 | NamePart: string;
|
---|
170 | SelNode: TTreeNode;
|
---|
171 | SubNode: TTreeNode;
|
---|
172 | begin
|
---|
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;
|
---|
187 | end;
|
---|
188 |
|
---|
189 | end.
|
---|
190 |
|
---|