1 | unit FormMain;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, FileUtil, Forms, Controls, FormCPU, FormInput,
|
---|
7 | Graphics, Dialogs, Menus, ActnList, ComCtrls, ExtCtrls, Target, Registry,
|
---|
8 | LazFileUtils, FormOptions, FormMessages, FormTargets,
|
---|
9 | FormOutput, FormMemory, FormSourceCode, FormTargetCode, FormLog,
|
---|
10 | FormCompileMultiple;
|
---|
11 |
|
---|
12 | type
|
---|
13 |
|
---|
14 | { TFormMain }
|
---|
15 |
|
---|
16 | TFormMain = class(TForm)
|
---|
17 | AProgramCompileMultiple: TAction;
|
---|
18 | AViewLog: TAction;
|
---|
19 | AProgramShowExecutionPoint: TAction;
|
---|
20 | AShowSourcePosition: TAction;
|
---|
21 | AShowTargetPosition: TAction;
|
---|
22 | AProgramCompile: TAction;
|
---|
23 | AAbout: TAction;
|
---|
24 | ABreakpointToggle: TAction;
|
---|
25 | AViewCompilers: TAction;
|
---|
26 | AOptions: TAction;
|
---|
27 | AProgramStepOut: TAction;
|
---|
28 | AProgramRunToCursor: TAction;
|
---|
29 | AProgramStepOver: TAction;
|
---|
30 | AProgramStepInto: TAction;
|
---|
31 | AProgramPause: TAction;
|
---|
32 | AProgramStop: TAction;
|
---|
33 | AHelp: TAction;
|
---|
34 | AProgramRun: TAction;
|
---|
35 | AProjectNew: TAction;
|
---|
36 | AExit: TAction;
|
---|
37 | AProjectSaveAs: TAction;
|
---|
38 | AProjectClose: TAction;
|
---|
39 | AProjectSave: TAction;
|
---|
40 | AProjectOpen: TAction;
|
---|
41 | ActionList1: TActionList;
|
---|
42 | MainMenu1: TMainMenu;
|
---|
43 | MenuItem1: TMenuItem;
|
---|
44 | MenuItem10: TMenuItem;
|
---|
45 | MenuItem11: TMenuItem;
|
---|
46 | MenuItem12: TMenuItem;
|
---|
47 | MenuItem13: TMenuItem;
|
---|
48 | MenuItem14: TMenuItem;
|
---|
49 | MenuItem15: TMenuItem;
|
---|
50 | MenuItem16: TMenuItem;
|
---|
51 | MenuItem17: TMenuItem;
|
---|
52 | MenuItem18: TMenuItem;
|
---|
53 | MenuItem19: TMenuItem;
|
---|
54 | MenuItem2: TMenuItem;
|
---|
55 | MenuItem20: TMenuItem;
|
---|
56 | MenuItem21: TMenuItem;
|
---|
57 | MenuItem22: TMenuItem;
|
---|
58 | MenuItem24: TMenuItem;
|
---|
59 | MenuItem25: TMenuItem;
|
---|
60 | MenuItem27: TMenuItem;
|
---|
61 | MenuItem28: TMenuItem;
|
---|
62 | MenuItem30: TMenuItem;
|
---|
63 | MenuItem31: TMenuItem;
|
---|
64 | MenuItem32: TMenuItem;
|
---|
65 | MenuItem33: TMenuItem;
|
---|
66 | MenuItem34: TMenuItem;
|
---|
67 | MenuItem35: TMenuItem;
|
---|
68 | MenuItemOpenRecent: TMenuItem;
|
---|
69 | MenuItemTarget: TMenuItem;
|
---|
70 | MenuItem3: TMenuItem;
|
---|
71 | MenuItem4: TMenuItem;
|
---|
72 | MenuItem5: TMenuItem;
|
---|
73 | MenuItem6: TMenuItem;
|
---|
74 | MenuItem7: TMenuItem;
|
---|
75 | MenuItem8: TMenuItem;
|
---|
76 | MenuItem9: TMenuItem;
|
---|
77 | OpenDialog1: TOpenDialog;
|
---|
78 | PageControlMain: TPageControl;
|
---|
79 | PageControlRight: TPageControl;
|
---|
80 | PageControlBottom: TPageControl;
|
---|
81 | PanelLeft: TPanel;
|
---|
82 | PanelMemory: TPanel;
|
---|
83 | PanelCPU: TPanel;
|
---|
84 | PanelOutput: TPanel;
|
---|
85 | PanelInput: TPanel;
|
---|
86 | PopupMenuTargets: TPopupMenu;
|
---|
87 | PopupMenuRecentFiles: TPopupMenu;
|
---|
88 | SaveDialog1: TSaveDialog;
|
---|
89 | Splitter1: TSplitter;
|
---|
90 | Splitter2: TSplitter;
|
---|
91 | Splitter3: TSplitter;
|
---|
92 | Splitter4: TSplitter;
|
---|
93 | Splitter5: TSplitter;
|
---|
94 | StatusBarMain: TStatusBar;
|
---|
95 | TabSheetMessages: TTabSheet;
|
---|
96 | TabSheetDebug: TTabSheet;
|
---|
97 | TabSheetSource: TTabSheet;
|
---|
98 | TabSheetTarget: TTabSheet;
|
---|
99 | TimerRefresh: TTimer;
|
---|
100 | ToolBarMain: TToolBar;
|
---|
101 | ToolButton1: TToolButton;
|
---|
102 | ToolButton10: TToolButton;
|
---|
103 | ToolButton11: TToolButton;
|
---|
104 | ToolButton12: TToolButton;
|
---|
105 | ToolButton13: TToolButton;
|
---|
106 | ToolButton14: TToolButton;
|
---|
107 | ToolButton15: TToolButton;
|
---|
108 | ToolButtonTarget: TToolButton;
|
---|
109 | ToolButton2: TToolButton;
|
---|
110 | ToolButton3: TToolButton;
|
---|
111 | ToolButton4: TToolButton;
|
---|
112 | ToolButton5: TToolButton;
|
---|
113 | ToolButton6: TToolButton;
|
---|
114 | ToolButton7: TToolButton;
|
---|
115 | ToolButton8: TToolButton;
|
---|
116 | ToolButton9: TToolButton;
|
---|
117 | procedure AAboutExecute(Sender: TObject);
|
---|
118 | procedure ABreakpointToggleExecute(Sender: TObject);
|
---|
119 | procedure AExitExecute(Sender: TObject);
|
---|
120 | procedure AOptionsExecute(Sender: TObject);
|
---|
121 | procedure AProgramCompileExecute(Sender: TObject);
|
---|
122 | procedure AProgramCompileMultipleExecute(Sender: TObject);
|
---|
123 | procedure AProgramPauseExecute(Sender: TObject);
|
---|
124 | procedure AProgramRunToCursorExecute(Sender: TObject);
|
---|
125 | procedure AProgramRunExecute(Sender: TObject);
|
---|
126 | procedure AProgramShowExecutionPointExecute(Sender: TObject);
|
---|
127 | procedure AProgramStepIntoExecute(Sender: TObject);
|
---|
128 | procedure AProgramStepOutExecute(Sender: TObject);
|
---|
129 | procedure AProgramStepOverExecute(Sender: TObject);
|
---|
130 | procedure AProgramStopExecute(Sender: TObject);
|
---|
131 | procedure AProjectCloseExecute(Sender: TObject);
|
---|
132 | procedure AProjectNewExecute(Sender: TObject);
|
---|
133 | procedure AProjectOpenExecute(Sender: TObject);
|
---|
134 | procedure AProjectSaveAsExecute(Sender: TObject);
|
---|
135 | procedure AProjectSaveExecute(Sender: TObject);
|
---|
136 | procedure AShowSourcePositionExecute(Sender: TObject);
|
---|
137 | procedure AShowTargetPositionExecute(Sender: TObject);
|
---|
138 | procedure AViewCompilersExecute(Sender: TObject);
|
---|
139 | procedure AViewInterpretterExecute(Sender: TObject);
|
---|
140 | procedure AViewLogExecute(Sender: TObject);
|
---|
141 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
142 | procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
---|
143 | procedure FormCreate(Sender: TObject);
|
---|
144 | procedure FormDestroy(Sender: TObject);
|
---|
145 | procedure FormShow(Sender: TObject);
|
---|
146 | procedure TimerRefreshTimer(Sender: TObject);
|
---|
147 | private
|
---|
148 | FormCPU: TFormCPU;
|
---|
149 | FormInput: TFormInput;
|
---|
150 | FormLog: TFormLog;
|
---|
151 | FormMemory: TFormMemory;
|
---|
152 | FormMessages: TFormMessages;
|
---|
153 | FormOutput: TFormOutput;
|
---|
154 | FormSourceCode: TFormSourceCode;
|
---|
155 | FormTargetCode: TFormTargetCode;
|
---|
156 | procedure AProjectOpenRecentExecute(Sender: TObject);
|
---|
157 | procedure MenuItemTargetClick(Sender: TObject);
|
---|
158 | procedure ProjectOpen(FileName: string);
|
---|
159 | procedure UpdateToolBarHints;
|
---|
160 | procedure DockForm(Form: TForm; DockSite: TWinControl);
|
---|
161 | procedure DockInit;
|
---|
162 | procedure LastOpenedListChange(Sender: TObject);
|
---|
163 | procedure CurrentTargetChangeExecute(Sender: TObject);
|
---|
164 | public
|
---|
165 | procedure MessagesChanged(Sender: TObject);
|
---|
166 | procedure TargetLogExecute(Lines: TStrings);
|
---|
167 | procedure TargetStateChanged(Sender: TObject);
|
---|
168 | procedure UpdateInterface;
|
---|
169 | procedure UpdateStatusBar;
|
---|
170 | procedure UpdateTargetList;
|
---|
171 | end;
|
---|
172 |
|
---|
173 |
|
---|
174 | implementation
|
---|
175 |
|
---|
176 | {$R *.lfm}
|
---|
177 |
|
---|
178 | uses
|
---|
179 | Core, TargetInterpretter, BFTarget, Common;
|
---|
180 |
|
---|
181 | resourcestring
|
---|
182 | SProgramStarted = 'Program started';
|
---|
183 | SProgramStopped = 'Program stopped';
|
---|
184 | SNewProject = 'New project';
|
---|
185 | SCompileStart = 'Compiling...';
|
---|
186 | SDone = 'Done';
|
---|
187 | SChanged = 'Changed';
|
---|
188 | SUnsavedChanges = 'Unsaved changes';
|
---|
189 | SDoYouWantToSaveProject = 'There are unsaved changes in project. Do you want to save them?';
|
---|
190 | SCloseProjectFirst = 'Project need to be closed before it can be openned';
|
---|
191 | SError = 'Error';
|
---|
192 | SFileNotFound = 'File %s not found.';
|
---|
193 |
|
---|
194 | const
|
---|
195 | ExamplesDir = 'Examples';
|
---|
196 |
|
---|
197 | { TFormMain }
|
---|
198 |
|
---|
199 | procedure TFormMain.FormShow(Sender: TObject);
|
---|
200 | begin
|
---|
201 | Core.Core.Init;
|
---|
202 | PageControlMain.TabIndex := 0;
|
---|
203 | try
|
---|
204 | if Core.Core.OpenProjectOnStart and (Core.Core.LastOpenedList.Items.Count > 0) and
|
---|
205 | FileExists(Core.Core.LastOpenedList.Items[0]) then
|
---|
206 | ProjectOpen(Core.Core.LastOpenedList.Items[0])
|
---|
207 | else AProjectNew.Execute;
|
---|
208 | finally
|
---|
209 | LastOpenedListChange(nil);
|
---|
210 | UpdateInterface;
|
---|
211 | UpdateToolBarHints;
|
---|
212 | UpdateTargetList;
|
---|
213 | DockInit;
|
---|
214 | Core.Core.PersistentForm1.Load(Self, True);
|
---|
215 | Core.Core.ThemeManager.UseTheme(Self);
|
---|
216 | FormSourceCode.UpdateTheme;
|
---|
217 | end;
|
---|
218 | Core.Core.Messages.OnChange := MessagesChanged;
|
---|
219 | end;
|
---|
220 |
|
---|
221 | procedure TFormMain.TimerRefreshTimer(Sender: TObject);
|
---|
222 | begin
|
---|
223 | FormCPU.Reload;
|
---|
224 | FormOutput.Reload;
|
---|
225 | FormMemory.Reload;
|
---|
226 | end;
|
---|
227 |
|
---|
228 | procedure TFormMain.TargetLogExecute(Lines: TStrings);
|
---|
229 | begin
|
---|
230 | if Assigned(FormLog) then
|
---|
231 | FormLog.Memo1.Lines.AddStrings(Lines);
|
---|
232 | end;
|
---|
233 |
|
---|
234 | procedure TFormMain.TargetStateChanged(Sender: TObject);
|
---|
235 | begin
|
---|
236 | UpdateInterface;
|
---|
237 | if Core.Core.CurrentTarget.State = rsPaused then
|
---|
238 | AProgramShowExecutionPoint.Execute;
|
---|
239 | if Core.Core.CurrentTarget.State = rsStopped then
|
---|
240 | Core.Core.Messages.AddMessage(SProgramStopped);
|
---|
241 | end;
|
---|
242 |
|
---|
243 | procedure TFormMain.MessagesChanged(Sender: TObject);
|
---|
244 | begin
|
---|
245 | FormMessages.Reload;
|
---|
246 | end;
|
---|
247 |
|
---|
248 | procedure TFormMain.MenuItemTargetClick(Sender: TObject);
|
---|
249 | var
|
---|
250 | I: Integer;
|
---|
251 | begin
|
---|
252 | if Sender is TMenuItem then
|
---|
253 | with TMenuItem(Sender) do begin
|
---|
254 | Core.Core.CurrentTarget := Core.Core.Targets[MenuIndex];
|
---|
255 | Checked := True;
|
---|
256 | for I := 0 to Parent.Count - 1 do
|
---|
257 | if Parent.Items[I].MenuIndex <> MenuIndex then Parent.Items[I].Checked := False;
|
---|
258 | end;
|
---|
259 | end;
|
---|
260 |
|
---|
261 | procedure TFormMain.ProjectOpen(FileName: string);
|
---|
262 | begin
|
---|
263 | with Core.Core do begin
|
---|
264 | if Project.Openned then
|
---|
265 | raise Exception.Create(SCloseProjectFirst);
|
---|
266 | FormSourceCode.SynEditSource.Lines.LoadFromFile(FileName);
|
---|
267 | AddItemToLastOpenedList(FileName);
|
---|
268 | Project.FileName := FileName;
|
---|
269 | Project.Openned := True;
|
---|
270 | CurrentTarget.Compiled := False;
|
---|
271 | end;
|
---|
272 | UpdateInterface;
|
---|
273 | end;
|
---|
274 |
|
---|
275 | procedure TFormMain.UpdateToolBarHints;
|
---|
276 | var
|
---|
277 | I: Integer;
|
---|
278 | begin
|
---|
279 | for I := 0 to ToolBarMain.ControlCount - 1 do
|
---|
280 | ToolBarMain.Controls[I].Hint := ToolBarMain.Controls[I].Caption;
|
---|
281 | end;
|
---|
282 |
|
---|
283 | procedure TFormMain.DockForm(Form: TForm; DockSite: TWinControl);
|
---|
284 | begin
|
---|
285 | Form.ManualDock(DockSite, nil, alClient);
|
---|
286 | Form.Align := alClient;
|
---|
287 | Form.Show;
|
---|
288 | end;
|
---|
289 |
|
---|
290 | procedure TFormMain.DockInit;
|
---|
291 | begin
|
---|
292 | DockForm(FormSourceCode, TabSheetSource);
|
---|
293 | DockForm(FormTargetCode, TabSheetTarget);
|
---|
294 | DockForm(FormCPU, PanelCPU);
|
---|
295 | DockForm(FormInput, PanelInput);
|
---|
296 | DockForm(FormOutput, PanelOutput);
|
---|
297 | DockForm(FormMemory, PanelMemory);
|
---|
298 | DockForm(FormMessages, TabSheetMessages);
|
---|
299 | PageControlRight.Width := Width div 3;
|
---|
300 | PageControlBottom.Height := Height div 5;
|
---|
301 | end;
|
---|
302 |
|
---|
303 | procedure TFormMain.LastOpenedListChange(Sender: TObject);
|
---|
304 | begin
|
---|
305 | Core.Core.LastOpenedList.LoadToMenuItem(MenuItemOpenRecent, AProjectOpenRecentExecute);
|
---|
306 | Core.Core.LastOpenedList.LoadToMenuItem(PopupMenuRecentFiles.Items, AProjectOpenRecentExecute);
|
---|
307 | end;
|
---|
308 |
|
---|
309 | procedure TFormMain.CurrentTargetChangeExecute(Sender: TObject);
|
---|
310 | begin
|
---|
311 | UpdateTargetList;
|
---|
312 | UpdateInterface;
|
---|
313 | end;
|
---|
314 |
|
---|
315 | procedure TFormMain.UpdateInterface;
|
---|
316 | var
|
---|
317 | Title: string;
|
---|
318 | CanDebug: Boolean;
|
---|
319 | begin
|
---|
320 | Title := '';
|
---|
321 | with Core.Core do begin
|
---|
322 | if Project.FileName <> '' then Title := Project.FileName;
|
---|
323 | if Project.Modified then Title := Title + ' (' + SChanged + ')';
|
---|
324 | Title:= Title + ' - ' + ApplicationInfo.AppName;
|
---|
325 | Caption := Title;
|
---|
326 | AProjectSave.Enabled := Project.Modified;
|
---|
327 | FormSourceCode.SynEditSource.Enabled := Project.Openned;
|
---|
328 | AProjectClose.Enabled := Project.Openned;
|
---|
329 | AProjectSaveAs.Enabled := Project.Openned;
|
---|
330 | AProgramRun.Enabled := (tcRun in CurrentTarget.Capabilities) and
|
---|
331 | Project.Openned and (CurrentTarget.State = rsStopped) or (CurrentTarget.State = rsPaused);
|
---|
332 | AProgramPause.Enabled := (tcPause in CurrentTarget.Capabilities) and
|
---|
333 | Project.Openned and (CurrentTarget.State = rsRunning);
|
---|
334 | AProgramStop.Enabled := (tcStop in CurrentTarget.Capabilities) and
|
---|
335 | Project.Openned and (CurrentTarget.State <> rsStopped);
|
---|
336 | AProgramCompile.Enabled := (tcCompile in CurrentTarget.Capabilities) and
|
---|
337 | Project.Openned;
|
---|
338 | CanDebug := DebugEnabled and Project.Openned and
|
---|
339 | ((CurrentTarget.State = rsPaused) or (CurrentTarget.State = rsStopped));
|
---|
340 | AProgramStepInto.Enabled := CanDebug and (tcStepInto in CurrentTarget.Capabilities);
|
---|
341 | AProgramStepOut.Enabled := CanDebug and (tcStepOut in CurrentTarget.Capabilities);
|
---|
342 | AProgramRunToCursor.Enabled := CanDebug and (tcRunToCursor in CurrentTarget.Capabilities);
|
---|
343 | AProgramStepOver.Enabled := CanDebug and (tcStepOver in CurrentTarget.Capabilities);
|
---|
344 | AProgramShowExecutionPoint.Enabled := CanDebug and (tcPause in CurrentTarget.Capabilities);
|
---|
345 | AShowSourcePosition.Enabled := CurrentTarget.Compiled;
|
---|
346 | AShowTargetPosition.Enabled := CurrentTarget.Compiled;
|
---|
347 | end;
|
---|
348 | UpdateStatusBar;
|
---|
349 | end;
|
---|
350 |
|
---|
351 | procedure TFormMain.UpdateStatusBar;
|
---|
352 | begin
|
---|
353 | StatusBarMain.Panels[0].Text := IntToStr(FormSourceCode.SynEditSource.CaretXY.X) +
|
---|
354 | ', ' + IntToStr(FormSourceCode.SynEditSource.CaretXY.Y);
|
---|
355 | end;
|
---|
356 |
|
---|
357 | procedure TFormMain.UpdateTargetList;
|
---|
358 | var
|
---|
359 | I: Integer;
|
---|
360 | begin
|
---|
361 | Core.Core.Targets.LoadToMenuItem(MenuItemTarget, MenuItemTargetClick, Core.Core.CurrentTarget);
|
---|
362 | Core.Core.Targets.LoadToMenuItem(PopupMenuTargets.Items, MenuItemTargetClick, Core.Core.CurrentTarget);
|
---|
363 |
|
---|
364 | // Update toolbutton
|
---|
365 | I := Core.Core.Targets.IndexOf(Core.Core.CurrentTarget);
|
---|
366 | if I <> -1 then
|
---|
367 | with TTarget(Core.Core.Targets[I]) do begin
|
---|
368 | ToolButtonTarget.ImageIndex := ImageIndex;
|
---|
369 | ToolButtonTarget.Caption := Name;
|
---|
370 | ToolButtonTarget.OnClick := MenuItemTargetClick();
|
---|
371 | end;
|
---|
372 | end;
|
---|
373 |
|
---|
374 | procedure TFormMain.FormCreate(Sender: TObject);
|
---|
375 | begin
|
---|
376 | Core.Core.Translator.TranslateComponentRecursive(Self);
|
---|
377 | Core.Core.ThemeManager.UseTheme(Self);
|
---|
378 |
|
---|
379 | FormSourceCode := TFormSourceCode.Create(nil);
|
---|
380 | FormCPU := TFormCPU.Create(nil);
|
---|
381 | FormInput := TFormInput.Create(nil);
|
---|
382 | FormLog := TFormLog.Create(nil);
|
---|
383 | FormMemory := TFormMemory.Create(nil);
|
---|
384 | FormMessages := TFormMessages.Create(nil);
|
---|
385 | FormOutput := TFormOutput.Create(nil);
|
---|
386 | FormTargetCode := TFormTargetCode.Create(nil);
|
---|
387 |
|
---|
388 | UpdateTargetList;
|
---|
389 | with Core.Core do begin
|
---|
390 | LastOpenedList.OnChange := LastOpenedListChange;
|
---|
391 | OnCurrentTargetChange := CurrentTargetChangeExecute;
|
---|
392 | OnTargetChangeState := TargetStateChanged;
|
---|
393 | OnTargetLog := TargetLogExecute;
|
---|
394 | end;
|
---|
395 | end;
|
---|
396 |
|
---|
397 | procedure TFormMain.FormDestroy(Sender: TObject);
|
---|
398 | begin
|
---|
399 | FreeAndNil(FormSourceCode);
|
---|
400 | FreeAndNil(FormCPU);
|
---|
401 | FreeAndNil(FormInput);
|
---|
402 | FreeAndNil(FormLog);
|
---|
403 | FreeAndNil(FormMemory);
|
---|
404 | FreeAndNil(FormMessages);
|
---|
405 | FreeAndNil(FormOutput);
|
---|
406 | FreeAndNil(FormTargetCode);
|
---|
407 | end;
|
---|
408 |
|
---|
409 | procedure TFormMain.AProgramRunExecute(Sender: TObject);
|
---|
410 | begin
|
---|
411 | if Core.Core.CurrentTarget is TTargetInterpretter then
|
---|
412 | TTargetInterpretter(Core.Core.CurrentTarget).Input := FormInput.MemoInput.Lines.Text;
|
---|
413 | if not Core.Core.CurrentTarget.Compiled then AProgramCompile.Execute;
|
---|
414 | Core.Core.CurrentTarget.Run;
|
---|
415 | Core.Core.Messages.AddMessage(SProgramStarted);
|
---|
416 | end;
|
---|
417 |
|
---|
418 | procedure TFormMain.AShowSourcePositionExecute(Sender: TObject);
|
---|
419 | var
|
---|
420 | DebugStep: TDebugStep;
|
---|
421 | begin
|
---|
422 | DebugStep := Core.Core.CurrentTarget.DebugSteps.SearchByTargetPos(FormTargetCode.SynEditTarget.SelStart - 1);
|
---|
423 | if Assigned(DebugStep) then begin
|
---|
424 | FormSourceCode.SynEditSource.SelStart := DebugStep.SourcePosition + 1;
|
---|
425 | PageControlMain.TabIndex := 0;
|
---|
426 | end;
|
---|
427 | end;
|
---|
428 |
|
---|
429 | procedure TFormMain.AShowTargetPositionExecute(Sender: TObject);
|
---|
430 | var
|
---|
431 | DebugStep: TDebugStep;
|
---|
432 | begin
|
---|
433 | DebugStep := Core.Core.CurrentTarget.DebugSteps.SearchBySourcePos(FormSourceCode.SynEditSource.SelStart - 1);
|
---|
434 | if Assigned(DebugStep) then begin
|
---|
435 | FormTargetCode.SynEditTarget.SelStart := DebugStep.TargetPosition + 1;
|
---|
436 | PageControlMain.TabIndex := 1;
|
---|
437 | end;
|
---|
438 | end;
|
---|
439 |
|
---|
440 | procedure TFormMain.AViewCompilersExecute(Sender: TObject);
|
---|
441 | begin
|
---|
442 | with TFormTargets.Create(nil) do
|
---|
443 | try
|
---|
444 | ShowModal;
|
---|
445 | finally
|
---|
446 | Free;
|
---|
447 | end;
|
---|
448 | end;
|
---|
449 |
|
---|
450 | procedure TFormMain.AViewInterpretterExecute(Sender: TObject);
|
---|
451 | begin
|
---|
452 | FormCPU.Show;
|
---|
453 | end;
|
---|
454 |
|
---|
455 | procedure TFormMain.AViewLogExecute(Sender: TObject);
|
---|
456 | begin
|
---|
457 | if not Assigned(FormLog) then FormLog := TFormLog.Create(Self);
|
---|
458 | FormLog.Show;
|
---|
459 | end;
|
---|
460 |
|
---|
461 | procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
462 | begin
|
---|
463 | Core.Core.PersistentForm1.Save(Self);
|
---|
464 | Application.Terminate;
|
---|
465 | end;
|
---|
466 |
|
---|
467 | procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
---|
468 | begin
|
---|
469 | if Core.Core.Project.Modified then begin
|
---|
470 | AProjectClose.Execute;
|
---|
471 | if Core.Core.Project.Openned then CanClose := False;
|
---|
472 | end;
|
---|
473 | end;
|
---|
474 |
|
---|
475 | procedure TFormMain.AExitExecute(Sender: TObject);
|
---|
476 | begin
|
---|
477 | Close;
|
---|
478 | end;
|
---|
479 |
|
---|
480 | procedure TFormMain.AOptionsExecute(Sender: TObject);
|
---|
481 | var
|
---|
482 | FormOptions: TFormOptions;
|
---|
483 | begin
|
---|
484 | FormOptions := TFormOptions.Create(nil);
|
---|
485 | try
|
---|
486 | FormOptions.Load;
|
---|
487 | if FormOptions.ShowModal = mrOK then begin
|
---|
488 | FormOptions.Save;
|
---|
489 | if Assigned(Core.Core.CurrentTarget) then begin
|
---|
490 | Core.Core.CurrentTarget.OptimizationLevel := Core.Core.OptimizationLevel;
|
---|
491 | if Core.Core.CurrentTarget is TBFTarget then begin
|
---|
492 | TBFTarget(Core.Core.CurrentTarget).CellSize := Core.Core.CellSize;
|
---|
493 | TBFTarget(Core.Core.CurrentTarget).MemorySize := Core.Core.MemorySize;
|
---|
494 | end;
|
---|
495 | end;
|
---|
496 | Core.Core.ThemeManager.UseTheme(Self);
|
---|
497 | FormSourceCode.UpdateTheme;
|
---|
498 | Core.Core.SaveToRegistry(Core.Core.ApplicationInfo.GetRegistryContext);
|
---|
499 | end;
|
---|
500 | finally
|
---|
501 | FormOptions.Free;
|
---|
502 | end;
|
---|
503 | end;
|
---|
504 |
|
---|
505 | procedure TFormMain.AProgramCompileExecute(Sender: TObject);
|
---|
506 | begin
|
---|
507 | with Core.Core, CurrentTarget do
|
---|
508 | try
|
---|
509 | Messages.Clear;
|
---|
510 | AProgramStop.Execute;
|
---|
511 | SourceCode := FormSourceCode.SynEditSource.Text;
|
---|
512 | ProjectFileName := Project.FileName;
|
---|
513 | ProgramName := ExtractFileNameOnly(Project.FileName);
|
---|
514 | if CurrentTarget is TBFTarget then
|
---|
515 | TBFTarget(CurrentTarget).Optimizations := Optimizations;
|
---|
516 | DebugEnabled := DebugEnabled;
|
---|
517 | Messages.AddMessage(SCompileStart);
|
---|
518 | Application.ProcessMessages;
|
---|
519 | Compile;
|
---|
520 | Messages.AppendMessage(SDone);
|
---|
521 | FormTargetCode.SynEditTarget.Text := TargetCode;
|
---|
522 | FormTargetCode.SetHighlighter(CurrentTarget.SourceExtension);
|
---|
523 | UpdateInterface;
|
---|
524 | except
|
---|
525 | on E: Exception do
|
---|
526 | MessageDlg(SError, E.Message, mtError, [mbOk], 0);
|
---|
527 | end;
|
---|
528 | end;
|
---|
529 |
|
---|
530 | procedure TFormMain.AProgramCompileMultipleExecute(Sender: TObject);
|
---|
531 | var
|
---|
532 | I: Integer;
|
---|
533 | begin
|
---|
534 | AProgramStop.Execute;
|
---|
535 | with TFormCompileMultiple.Create(nil) do
|
---|
536 | try
|
---|
537 | Targets := Core.Core.Targets;
|
---|
538 | if ShowModal = mrOk then begin
|
---|
539 | Core.Core.Messages.Clear;
|
---|
540 | for I := 0 to Targets.Count - 1 do
|
---|
541 | with Targets[I] do
|
---|
542 | if Selected then
|
---|
543 | try
|
---|
544 | AProgramStop.Execute;
|
---|
545 | SourceCode := FormSourceCode.SynEditSource.Text;
|
---|
546 | ProjectFileName := Core.Core.Project.FileName;
|
---|
547 | ProgramName := ExtractFileNameOnly(Core.Core.Project.FileName);
|
---|
548 | if Targets[I] is TBFTarget then
|
---|
549 | TBFTarget(Targets[I]).Optimizations := Core.Core.Optimizations;
|
---|
550 | DebugEnabled := Core.Core.DebugEnabled;
|
---|
551 | Core.Core.Messages.AddMessage(Name + ' ' + SCompileStart);
|
---|
552 | Application.ProcessMessages;
|
---|
553 | Compile;
|
---|
554 | Core.Core.Messages.AppendMessage(SDone);
|
---|
555 | FormTargetCode.SynEditTarget.Text := TargetCode;
|
---|
556 | FormTargetCode.SetHighlighter(Core.Core.CurrentTarget.SourceExtension);
|
---|
557 | UpdateInterface;
|
---|
558 | except
|
---|
559 | on E: Exception do
|
---|
560 | MessageDlg(SError, E.Message, mtError, [mbOk], 0);
|
---|
561 | end;
|
---|
562 | end;
|
---|
563 | finally
|
---|
564 | Free;
|
---|
565 | end;
|
---|
566 | end;
|
---|
567 |
|
---|
568 | procedure TFormMain.ABreakpointToggleExecute(Sender: TObject);
|
---|
569 | var
|
---|
570 | DebugStep: TDebugStep;
|
---|
571 | BreakPoint: TBreakPoint;
|
---|
572 | begin
|
---|
573 | DebugStep := Core.Core.CurrentTarget.DebugSteps.SearchBySourcePos(FormSourceCode.SynEditSource.SelStart - 1);
|
---|
574 | if Assigned(DebugStep) then begin
|
---|
575 | BreakPoint := Core.Core.CurrentTarget.BreakPoints.SearchByTargetPos(DebugStep.ProgramPosition);
|
---|
576 | if Assigned(BreakPoint) then
|
---|
577 | Core.Core.CurrentTarget.BreakPoints.Delete(Core.Core.CurrentTarget.BreakPoints.IndexOf(BreakPoint))
|
---|
578 | else Core.Core.CurrentTarget.BreakPoints.AddItem(DebugStep.ProgramPosition);
|
---|
579 | end;
|
---|
580 | end;
|
---|
581 |
|
---|
582 | procedure TFormMain.AAboutExecute(Sender: TObject);
|
---|
583 | begin
|
---|
584 | Core.Core.AboutDialog.Show;
|
---|
585 | end;
|
---|
586 |
|
---|
587 | procedure TFormMain.AProgramPauseExecute(Sender: TObject);
|
---|
588 | begin
|
---|
589 | Core.Core.CurrentTarget.Pause;
|
---|
590 | end;
|
---|
591 |
|
---|
592 | procedure TFormMain.AProgramRunToCursorExecute(Sender: TObject);
|
---|
593 | var
|
---|
594 | DebugStep: TDebugStep;
|
---|
595 | begin
|
---|
596 | if Core.Core.CurrentTarget.State = rsStopped then begin
|
---|
597 | if not Core.Core.CurrentTarget.Compiled then AProgramCompile.Execute;
|
---|
598 | DebugStep := Core.Core.CurrentTarget.DebugSteps.SearchBySourcePos(FormSourceCode.SynEditSource.SelStart - 1);
|
---|
599 | Core.Core.CurrentTarget.BreakPoints.SetSystem(DebugStep.ProgramPosition);
|
---|
600 | AProgramRun.Execute;
|
---|
601 | end else begin
|
---|
602 | DebugStep := Core.Core.CurrentTarget.DebugSteps.SearchBySourcePos(FormSourceCode.SynEditSource.SelStart - 1);
|
---|
603 | Core.Core.CurrentTarget.RunToCursor(DebugStep.ProgramPosition);
|
---|
604 | end;
|
---|
605 | end;
|
---|
606 |
|
---|
607 | procedure TFormMain.AProgramShowExecutionPointExecute(Sender: TObject);
|
---|
608 | var
|
---|
609 | DebugStep: TDebugStep;
|
---|
610 | begin
|
---|
611 | DebugStep := Core.Core.CurrentTarget.DebugSteps.SearchByProgramPos(
|
---|
612 | Core.Core.CurrentTarget.ExecutionPosition);
|
---|
613 | FormSourceCode.SynEditSource.SelStart := DebugStep.SourcePosition + 1;
|
---|
614 | FormTargetCode.SynEditTarget.SelStart := DebugStep.TargetPosition + 1;
|
---|
615 | if PageControlMain.TabIndex = 0 then FormSourceCode.SynEditSource.SetFocus;
|
---|
616 | if PageControlMain.TabIndex = 1 then FormTargetCode.SynEditTarget.SetFocus;
|
---|
617 | end;
|
---|
618 |
|
---|
619 | procedure TFormMain.AProgramStepIntoExecute(Sender: TObject);
|
---|
620 | begin
|
---|
621 | if Core.Core.CurrentTarget.State = rsStopped then begin
|
---|
622 | if not Core.Core.CurrentTarget.Compiled then AProgramCompile.Execute;
|
---|
623 | Core.Core.CurrentTarget.BreakPoints.SetSystem(
|
---|
624 | Core.Core.CurrentTarget.DebugSteps.First.ProgramPosition);
|
---|
625 | AProgramRun.Execute;
|
---|
626 | end else Core.Core.CurrentTarget.StepInto;
|
---|
627 | end;
|
---|
628 |
|
---|
629 | procedure TFormMain.AProgramStepOutExecute(Sender: TObject);
|
---|
630 | begin
|
---|
631 | Core.Core.CurrentTarget.StepOut;
|
---|
632 | end;
|
---|
633 |
|
---|
634 | procedure TFormMain.AProgramStepOverExecute(Sender: TObject);
|
---|
635 | begin
|
---|
636 | if Core.Core.CurrentTarget.State = rsStopped then begin
|
---|
637 | if not Core.Core.CurrentTarget.Compiled then AProgramCompile.Execute;
|
---|
638 | Core.Core.CurrentTarget.BreakPoints.SetSystem(
|
---|
639 | TDebugStep(Core.Core.CurrentTarget.DebugSteps.First).ProgramPosition);
|
---|
640 | AProgramRun.Execute;
|
---|
641 | end else Core.Core.CurrentTarget.StepOver;
|
---|
642 | end;
|
---|
643 |
|
---|
644 | procedure TFormMain.AProgramStopExecute(Sender: TObject);
|
---|
645 | begin
|
---|
646 | Core.Core.CurrentTarget.Stop;
|
---|
647 | end;
|
---|
648 |
|
---|
649 | procedure TFormMain.AProjectCloseExecute(Sender: TObject);
|
---|
650 | var
|
---|
651 | DialogResult: TModalResult;
|
---|
652 | begin
|
---|
653 | DialogResult := mrNo;
|
---|
654 | if Core.Core.Project.Modified then begin
|
---|
655 | DialogResult := MessageDlg(SUnsavedChanges, SDoYouWantToSaveProject, mtConfirmation, [mbYes, mbNo, mbCancel], 0);
|
---|
656 | if DialogResult = mrYes then begin
|
---|
657 | AProjectSave.Execute;
|
---|
658 | end;
|
---|
659 | end;
|
---|
660 | if (DialogResult = mrNo) or (DialogResult = mrYes) then begin
|
---|
661 | AProgramStop.Execute;
|
---|
662 | Core.Core.Project.Openned := False;
|
---|
663 | FormSourceCode.SynEditSource.Clear;
|
---|
664 | UpdateInterface;
|
---|
665 | end;
|
---|
666 | end;
|
---|
667 |
|
---|
668 | procedure TFormMain.AProjectNewExecute(Sender: TObject);
|
---|
669 | begin
|
---|
670 | AProjectClose.Execute;
|
---|
671 | if Core.Core.Project.Openned then Exit;
|
---|
672 | Core.Core.Project.FileName := CombinePaths(Core.Core.DataDir, ExamplesDir + DirectorySeparator + SNewProject + '.b');
|
---|
673 | FormSourceCode.SynEditSource.Clear;
|
---|
674 | Core.Core.Project.Openned := True;
|
---|
675 | Core.Core.CurrentTarget.Compiled := False;
|
---|
676 | UpdateInterface;
|
---|
677 | end;
|
---|
678 |
|
---|
679 | procedure TFormMain.AProjectOpenRecentExecute(Sender: TObject);
|
---|
680 | var
|
---|
681 | FileName: string;
|
---|
682 | begin
|
---|
683 | FileName := Core.Core.LastOpenedList.Items[TMenuItem(Sender).MenuIndex];
|
---|
684 | if FileExists(FileName) then begin
|
---|
685 | AProjectClose.Execute;
|
---|
686 | if Core.Core.Project.Openned then Exit;
|
---|
687 | ProjectOpen(FileName);
|
---|
688 | end else ShowMessage(Format(SFileNotFound, [FileName]));
|
---|
689 | end;
|
---|
690 |
|
---|
691 | procedure TFormMain.AProjectOpenExecute(Sender: TObject);
|
---|
692 | var
|
---|
693 | FileName: string;
|
---|
694 | begin
|
---|
695 | if Core.Core.LastOpenedList.Items.Count > 0 then
|
---|
696 | FileName := Core.Core.LastOpenedList.Items[0]
|
---|
697 | else FileName := CombinePaths(Core.Core.DataDir, ExamplesDir);
|
---|
698 | OpenDialog1.InitialDir := ExtractFileDir(FileName);
|
---|
699 | OpenDialog1.FileName := ExtractFileName(FileName);
|
---|
700 | if OpenDialog1.Execute then begin
|
---|
701 | AProjectClose.Execute;
|
---|
702 | if Core.Core.Project.Openned then Exit;
|
---|
703 | ProjectOpen(OpenDialog1.FileName);
|
---|
704 | end;
|
---|
705 | end;
|
---|
706 |
|
---|
707 | procedure TFormMain.AProjectSaveAsExecute(Sender: TObject);
|
---|
708 | begin
|
---|
709 | SaveDialog1.InitialDir := ExtractFileDir(Core.Core.Project.FileName);
|
---|
710 | SaveDialog1.FileName := ExtractFileName(Core.Core.Project.FileName);
|
---|
711 | if SaveDialog1.Execute then begin
|
---|
712 | FormSourceCode.SynEditSource.Lines.SaveToFile(SaveDialog1.FileName);
|
---|
713 | Core.Core.Project.FileName := SaveDialog1.FileName;
|
---|
714 | Core.Core.AddItemToLastOpenedList(SaveDialog1.FileName);
|
---|
715 | Core.Core.Project.Modified := False;
|
---|
716 | UpdateInterface;
|
---|
717 | end;
|
---|
718 | end;
|
---|
719 |
|
---|
720 | procedure TFormMain.AProjectSaveExecute(Sender: TObject);
|
---|
721 | begin
|
---|
722 | if Core.Core.Project.Modified and FileExists(Core.Core.Project.FileName) then begin
|
---|
723 | FormSourceCode.SynEditSource.Lines.SaveToFile(Core.Core.Project.FileName);
|
---|
724 | Core.Core.AddItemToLastOpenedList(Core.Core.Project.FileName);
|
---|
725 | Core.Core.Project.Modified := False;
|
---|
726 | UpdateInterface;
|
---|
727 | end else AProjectSaveAs.Execute;
|
---|
728 | end;
|
---|
729 |
|
---|
730 | end.
|
---|
731 |
|
---|