source: trunk/Forms/UFormMain.pas @ 114

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