1 | unit FormProject;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, LazFileUtils, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
---|
7 | Menus, ActnList, Project;
|
---|
8 |
|
---|
9 | type
|
---|
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 |
|
---|
42 | var
|
---|
43 | FormProject: TFormProject;
|
---|
44 |
|
---|
45 |
|
---|
46 | implementation
|
---|
47 |
|
---|
48 | {$R *.lfm}
|
---|
49 |
|
---|
50 | uses
|
---|
51 | Core, FormMain, FormSourceCode, FormTargetCode, FormCodeTree;
|
---|
52 |
|
---|
53 | resourcestring
|
---|
54 | SRenameSourceFile = 'Rename source file';
|
---|
55 | SEnterNewFileName = 'Enter new file name';
|
---|
56 |
|
---|
57 | { TFormProject }
|
---|
58 |
|
---|
59 | procedure TFormProject.TreeViewProjectChange(Sender: TObject; Node: TTreeNode
|
---|
60 | );
|
---|
61 | begin
|
---|
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;
|
---|
91 | end;
|
---|
92 |
|
---|
93 | procedure TFormProject.TreeViewProjectDblClick(Sender: TObject);
|
---|
94 | begin
|
---|
95 | AShow.Execute;
|
---|
96 | end;
|
---|
97 |
|
---|
98 | procedure TFormProject.AAddExecute(Sender: TObject);
|
---|
99 | begin
|
---|
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;
|
---|
107 | end;
|
---|
108 |
|
---|
109 | procedure TFormProject.ADeleteExecute(Sender: TObject);
|
---|
110 | begin
|
---|
111 | if Assigned(TreeViewProject.Selected) then
|
---|
112 | Core.Core.Project.Files.Remove(TreeViewProject.Selected.Data);
|
---|
113 | UpdateProjectTree;
|
---|
114 | end;
|
---|
115 |
|
---|
116 | procedure TFormProject.ARenameExecute(Sender: TObject);
|
---|
117 | var
|
---|
118 | NewName: string;
|
---|
119 | begin
|
---|
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;
|
---|
126 | end;
|
---|
127 |
|
---|
128 | procedure TFormProject.AShowExecute(Sender: TObject);
|
---|
129 | begin
|
---|
130 | if Assigned(TreeViewProject.Selected) then begin
|
---|
131 | if Assigned(FOnShowProject) then
|
---|
132 | FOnShowProject(TProjectFile(TreeViewProject.Selected.Data));
|
---|
133 | end;
|
---|
134 | end;
|
---|
135 |
|
---|
136 | procedure TFormProject.UpdateProjectTree;
|
---|
137 | var
|
---|
138 | NewNode: TTreeNode;
|
---|
139 | begin
|
---|
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;
|
---|
159 | end;
|
---|
160 |
|
---|
161 | procedure TFormProject.UpdateInterface;
|
---|
162 | begin
|
---|
163 | UpdateProjectTree;
|
---|
164 | end;
|
---|
165 |
|
---|
166 | procedure TFormProject.UpdateProjectFiles(Node: TTreeNode; Files: TProjectFiles);
|
---|
167 | var
|
---|
168 | I: Integer;
|
---|
169 | NewNode: TTreeNode;
|
---|
170 | FileName: string;
|
---|
171 | NamePart: string;
|
---|
172 | SelNode: TTreeNode;
|
---|
173 | SubNode: TTreeNode;
|
---|
174 | begin
|
---|
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;
|
---|
189 | end;
|
---|
190 |
|
---|
191 | end.
|
---|
192 |
|
---|