source: trunk/Forms/UMainForm.pas@ 3

Last change on this file since 3 was 3, checked in by george, 11 years ago
  • Modified: More parsing procedures transformed to functions.
File size: 8.1 KB
Line 
1unit UMainForm;
2
3{$MODE Delphi}
4
5interface
6
7uses
8 SysUtils, Variants, Classes, Graphics, Controls, Forms,
9 Dialogs, StdCtrls, UCompiler, UProducerAsm8051, Registry,
10 UProducerDynamicC, ComCtrls, ExtCtrls, SynEdit, SynHighlighterPas, UProducerTreeView,
11 UProducerPascal, UProject, FileUtil, Menus, ActnList, UCoolDocking,
12 UCompiledForm, UCodeTreeForm, URegistry, ULastOpenedList, UApplicationInfo,
13 UDebugLog;
14
15const
16 RegistryRootKey = HKEY_CURRENT_USER;
17 RegistryKey = 'Software\Transpascal';
18
19type
20 { TMainForm }
21
22 TMainForm = class(TForm)
23 ABuild: TAction;
24 AProjectNew: TAction;
25 AProjectOpen: TAction;
26 AProjectSave: TAction;
27 AProjectSaveAs: TAction;
28 AProjectClose: TAction;
29 ActionList1: TActionList;
30 Button1: TButton;
31 CheckBoxLogParsing: TCheckBox;
32 ComboBoxAnalyzerType: TComboBox;
33 ComboBoxTargetSelection: TComboBox;
34 CoolDockClient1: TCoolDockClient;
35 CoolDockMaster1: TCoolDockMaster;
36 Label1: TLabel;
37 Label2: TLabel;
38 MainMenu1: TMainMenu;
39 MenuItem1: TMenuItem;
40 MenuItem2: TMenuItem;
41 MenuItem3: TMenuItem;
42 MenuItem4: TMenuItem;
43 MenuItem5: TMenuItem;
44 MenuItem6: TMenuItem;
45 MenuItem7: TMenuItem;
46 MenuItem8: TMenuItem;
47 DockPanel: TPanel;
48 MenuItemOpenRecent: TMenuItem;
49 OpenDialog1: TOpenDialog;
50 SaveDialog1: TSaveDialog;
51 Splitter3: TSplitter;
52 ToolBar1: TToolBar;
53 procedure AProjectCloseExecute(Sender: TObject);
54 procedure AProjectOpenExecute(Sender: TObject);
55 procedure AProjectSaveAsExecute(Sender: TObject);
56 procedure ComboBox1Change(Sender: TObject);
57 procedure ComboBoxTargetSelectionChange(Sender: TObject);
58 procedure FormShow(Sender: TObject);
59 procedure FormClose(Sender: TObject; var Action: TCloseAction);
60 procedure ABuildExecute(Sender: TObject);
61 procedure FormCreate(Sender: TObject);
62 procedure FormDestroy(Sender: TObject);
63 private
64 LastOpenedFiles: TLastOpenedList;
65 ReopenLastOpenedFile: Boolean;
66 procedure CompilerDebugLog(Text: string);
67 procedure OpenRecentClick(Sender: TObject);
68 procedure DockInit;
69 procedure LoadFromRegistry;
70 procedure SaveToRegistry;
71 procedure OpenProject(FileName: string);
72 public
73 Project: TProject;
74 Compiler: TCompiler;
75 function GetSource(Name: string; Source: TStringList): Boolean;
76 end;
77
78var
79 MainForm: TMainForm;
80
81implementation
82
83{$R *.lfm}
84
85uses
86 UMessagesForm, UCodeForm, UProjectManager;
87
88{ TMainForm }
89
90procedure TMainForm.ABuildExecute(Sender: TObject);
91begin
92 // Compile project file
93 if CheckBoxLogParsing.Checked then
94 Compiler.Parser.OnDebugLog := CompilerDebugLog
95 else Compiler.Parser.OnDebugLog := nil;
96 Compiler.ProducerType := TProducerType(ComboBoxTargetSelection.ItemIndex);
97 Compiler.Init;
98 Compiler.Parser.OnGetSource := GetSource;
99
100 if Project.Items.Count > 0 then
101 with TProjectFile(Project.Items[0]) do begin
102 Compiler.TargetFolder := Project.RootDir;
103 Compiler.Compile(Parent.GetDir + Name, Source);
104 end;
105
106 ProjectManager.TreeViewProjectChange(Self, ProjectManager.TreeViewProject.Selected);
107 MessagesForm.Reload;
108end;
109
110function TMainForm.GetSource(Name: string; Source: TStringList): Boolean;
111var
112 FileName: string;
113begin
114 FileName := Project.GetDir(True) + Name + '.pas';
115 if FileExists(FileName) then begin
116 Source.LoadFromFile(FileName);
117 Result := True;
118 end else Result := False;
119end;
120
121procedure TMainForm.DockInit;
122var
123 Container1: TCoolDockConjoinForm;
124 Container2: TCoolDockConjoinForm;
125begin
126 ProjectManager.ManualDock(DockPanel, nil, alLeft);
127 ProjectManager.Show;
128
129 Container1 := TCoolDockManager(DockPanel.DockManager).CreateContainer(alRight);
130 Container1.Caption := 'Tools';
131 Container1.Name := 'Tools';
132 Container1.ManualDock(DockPanel, nil, alRight);
133
134 CodeTreeForm.ManualDock(DockPanel, nil, alLeft);
135 CodeTreeForm.Show;
136 Container1.Parent.Parent.Width := MainForm.Width;
137
138 Container2 := TCoolDockManager(DockPanel.DockManager).CreateContainer(alRight);
139 Container2.Caption := 'Panel';
140 Container2.Name := 'Tools2';
141 Container2.ManualDock(Container1.Panel, nil, alRight);
142
143 MessagesForm.ManualDock(Container1.Panel, nil, alBottom);
144 MessagesForm.Show;
145
146 CodeForm.ManualDock(Container2.Panel, nil, alTop);
147 CodeForm.Show;
148
149 CompiledForm.ManualDock(Container2.Panel, nil, alTop);
150 CompiledForm.Show;
151
152 TCoolDockManager(Container2.Panel.DockManager).DockStyle := dsTabs;
153
154 ProjectManager.Parent.Parent.Width := 200;
155 Container2.Parent.Parent.Height := MainForm.Height;
156end;
157
158procedure TMainForm.LoadFromRegistry;
159begin
160 with TRegistryEx.Create do
161 try
162 RootKey := HKEY_CURRENT_USER;
163 OpenKey(RegistryKey, True);
164 ReopenLastOpenedFile := ReadBoolWithDefault('ReopenLastOpenedFile', True);
165 ComboBoxTargetSelection.ItemIndex :=
166 ReadIntegerWithDefault('ProducerType', 0);
167 ComboBoxAnalyzerType.ItemIndex :=
168 ReadIntegerWithDefault('AnalyzerType', 0);
169 CheckBoxLogParsing.Checked := ReadBoolWithDefault('LogParsing', False);
170 finally
171 Free;
172 end;
173 LastOpenedFiles.LoadFromRegistry(RegistryRootKey, RegistryKey);
174end;
175
176procedure TMainForm.SaveToRegistry;
177begin
178 with TRegistryEx.Create do
179 try
180 RootKey := RegistryRootKey;
181 OpenKey(RegistryKey, True);
182 WriteBool('ReopenLastOpenedFile', ReopenLastOpenedFile);
183 WriteInteger('ProducerType', ComboBoxTargetSelection.ItemIndex);
184 WriteInteger('AnalyzerType', ComboBoxAnalyzerType.ItemIndex);
185 WriteBool('LogParsing', CheckBoxLogParsing.Checked);
186 finally
187 Free;
188 end;
189 LastOpenedFiles.SaveToRegistry(RegistryRootKey, RegistryKey);
190 LastOpenedFiles.ReloadMenu;
191end;
192
193procedure TMainForm.OpenProject(FileName: string);
194begin
195 Project.LoadFromFile(FileName);
196 LastOpenedFiles.Add(FileName);
197 LastOpenedFiles.ReloadMenu;
198 ProjectManager.UpdateProjectTree;
199 Caption := ApplicationInfo.Name + ' - ' + Project.Name;
200end;
201
202procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
203begin
204 Project.Save;
205 SaveToRegistry;
206end;
207
208procedure TMainForm.FormCreate(Sender: TObject);
209var
210 ProducerType: TProducerType;
211 AnalyzerType: TAnalyzerType;
212begin
213 DebugLog.FileName := 'DebugLog.txt';
214 DeleteFile(DebugLog.FileName);
215 Compiler := TCompiler.Create;
216 Project := TProject.Create;
217 LastOpenedFiles := TLastOpenedList.Create;
218 LastOpenedFiles.MenuItem := MenuItemOpenRecent;
219 LastOpenedFiles.ClickAction := OpenRecentClick;
220
221 ComboBoxTargetSelection.Clear;
222 for ProducerType := Low(ProducerType) to High(ProducerType) do
223 ComboBoxTargetSelection.AddItem(ProducerTypeName[ProducerType], nil);
224 ComboBoxAnalyzerType.Clear;
225 for AnalyzerType := Low(AnalyzerType) to High(AnalyzerType) do
226 ComboBoxAnalyzerType.AddItem(AnalyzerTypeName[AnalyzerType], nil);
227end;
228
229procedure TMainForm.FormDestroy(Sender: TObject);
230begin
231 LastOpenedFiles.Free;
232 Project.Free;
233 Compiler.Free;
234end;
235
236procedure TMainForm.CompilerDebugLog(Text: string);
237begin
238 DebugLog.Add('', Text);
239end;
240
241procedure TMainForm.OpenRecentClick(Sender: TObject);
242begin
243 if Sender is TMenuItem then
244 OpenProject(StringReplace(TMenuItem(Sender).Caption, '&', '', [rfReplaceAll]));
245end;
246
247procedure TMainForm.FormShow(Sender: TObject);
248var
249 NewProjectFile: TProjectFile;
250begin
251 LoadFromRegistry;
252 DockInit;
253
254 if ReopenLastOpenedFile and (LastOpenedFiles.Count > 0) then begin
255 OpenProject(LastOpenedFiles[0]);
256 end;
257
258 WindowState := wsMaximized;
259end;
260
261procedure TMainForm.ComboBox1Change(Sender: TObject);
262begin
263 ABuildExecute(Self);
264end;
265
266procedure TMainForm.AProjectOpenExecute(Sender: TObject);
267begin
268 if OpenDialog1.Execute then begin
269 OpenProject(OpenDialog1.FileName);
270 end;
271end;
272
273procedure TMainForm.AProjectCloseExecute(Sender: TObject);
274begin
275 Close;
276end;
277
278procedure TMainForm.AProjectSaveAsExecute(Sender: TObject);
279begin
280 if SaveDialog1.Execute then begin
281 Project.SaveToFile(SaveDialog1.FileName);
282 end;
283end;
284
285procedure TMainForm.ComboBoxTargetSelectionChange(Sender: TObject);
286begin
287 ABuildExecute(Self);
288end;
289
290end.
Note: See TracBrowser for help on using the repository browser.