source: trunk/Forms/UFormMain.pas @ 113

Last change on this file since 113 was 113, checked in by chronos, 15 months ago
File size: 22.0 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    end;
490  finally
491    FormOptions.Free;
492  end;
493end;
494
495procedure TFormMain.AProgramCompileExecute(Sender: TObject);
496begin
497  with Core.CurrentTarget do
498  try
499    AProgramStop.Execute;
500    SourceCode := FormSourceCode.SynEditSource.Text;
501    ProjectFileName := Core.Project.FileName;
502    ProgramName := ExtractFileNameOnly(Core.Project.FileName);
503    if Core.CurrentTarget is TBFTarget then
504      TBFTarget(Core.CurrentTarget).Optimizations := Core.Optimizations;
505    Core.CurrentTarget.Messages.AddMessage(SCompileStart);
506    Application.ProcessMessages;
507    Compile;
508    Core.CurrentTarget.Messages.AppendMessage(SDone);
509    FormTargetCode.SynEditTarget.Text := TargetCode;
510    FormTargetCode.SetHighlighter(Core.CurrentTarget.SourceExtension);
511    UpdateInterface;
512  except
513    on E: Exception do
514      MessageDlg(SError, E.Message, mtError, [mbOk], 0);
515  end;
516end;
517
518procedure TFormMain.ABreakpointToggleExecute(Sender: TObject);
519var
520  DebugStep: TDebugStep;
521  BreakPoint: TBreakPoint;
522begin
523  DebugStep := Core.CurrentTarget.DebugSteps.SearchBySourcePos(FormSourceCode.SynEditSource.SelStart - 1);
524  if Assigned(DebugStep) then begin
525    BreakPoint := Core.CurrentTarget.BreakPoints.SearchByTargetPos(DebugStep.TargetPosition);
526    if Assigned(BreakPoint) then
527      Core.CurrentTarget.BreakPoints.Delete(Core.CurrentTarget.BreakPoints.IndexOf(BreakPoint))
528      else Core.CurrentTarget.BreakPoints.AddItem(DebugStep.TargetPosition);
529  end;
530end;
531
532procedure TFormMain.AAboutExecute(Sender: TObject);
533begin
534  FormAbout := TFormAbout.Create(nil);
535  try
536    FormAbout.ApplicationInfo := Core.ApplicationInfo;
537    FormAbout.CoolTranslator := Core.CoolTranslator1;
538    Core.ScaleDPI1.ScaleControl(FormAbout, Core.ScaleDPI1.DesignDPI);
539    FormAbout.ShowModal;
540  finally
541    FreeAndNil(FormAbout);
542  end;
543end;
544
545procedure TFormMain.AProgramPauseExecute(Sender: TObject);
546begin
547  Core.CurrentTarget.Pause;
548end;
549
550procedure TFormMain.AProgramRunToCursorExecute(Sender: TObject);
551var
552  DebugStep: TDebugStep;
553begin
554  if Core.CurrentTarget.State = rsStopped then begin
555    if not Core.CurrentTarget.Compiled then AProgramCompile.Execute;
556    DebugStep := Core.CurrentTarget.DebugSteps.SearchBySourcePos(FormSourceCode.SynEditSource.SelStart - 1);
557    Core.CurrentTarget.BreakPoints.SetSystem(DebugStep.TargetPosition);
558    AProgramRun.Execute;
559  end else begin
560    DebugStep := Core.CurrentTarget.DebugSteps.SearchBySourcePos(FormSourceCode.SynEditSource.SelStart - 1);
561    Core.CurrentTarget.RunToCursor(DebugStep.TargetPosition);
562  end;
563end;
564
565procedure TFormMain.AProgramShowExecutionPointExecute(Sender: TObject);
566var
567  DebugStep: TDebugStep;
568begin
569  DebugStep := Core.CurrentTarget.DebugSteps.SearchByTargetPos(Core.CurrentTarget.ExecutionPosition);
570  FormSourceCode.SynEditSource.SelStart := DebugStep.SourcePosition + 1;
571  FormTargetCode.SynEditTarget.SelStart := DebugStep.TargetPosition + 1;
572  if PageControlMain.TabIndex = 0 then FormSourceCode.SynEditSource.SetFocus;
573  if PageControlMain.TabIndex = 1 then FormTargetCode.SynEditTarget.SetFocus;
574end;
575
576procedure TFormMain.AProgramStepIntoExecute(Sender: TObject);
577begin
578  if Core.CurrentTarget.State = rsStopped then begin
579    if not Core.CurrentTarget.Compiled then AProgramCompile.Execute;
580    Core.CurrentTarget.BreakPoints.SetSystem(TDebugStep(Core.CurrentTarget.DebugSteps.First).TargetPosition);
581    AProgramRun.Execute;
582  end else Core.CurrentTarget.StepInto;
583end;
584
585procedure TFormMain.AProgramStepOutExecute(Sender: TObject);
586begin
587  Core.CurrentTarget.StepOut;
588end;
589
590procedure TFormMain.AProgramStepOverExecute(Sender: TObject);
591begin
592  if Core.CurrentTarget.State = rsStopped then begin
593    if not Core.CurrentTarget.Compiled then AProgramCompile.Execute;
594    Core.CurrentTarget.BreakPoints.SetSystem(TDebugStep(Core.CurrentTarget.DebugSteps.First).TargetPosition);
595    AProgramRun.Execute;
596  end else Core.CurrentTarget.StepOver;
597end;
598
599procedure TFormMain.AProgramStopExecute(Sender: TObject);
600begin
601  Core.CurrentTarget.Stop;
602end;
603
604procedure TFormMain.AProjectCloseExecute(Sender: TObject);
605var
606  DialogResult: TModalResult;
607begin
608  DialogResult := mrNo;
609  if Core.Project.Modified then begin
610    DialogResult := MessageDlg(SUnsavedChanges, SDoYouWantToSaveProject, mtConfirmation, [mbYes, mbNo, mbCancel], 0);
611    if DialogResult = mrYes then begin
612      AProjectSave.Execute;
613    end;
614  end;
615  if (DialogResult = mrNo) or (DialogResult = mrYes) then begin
616    AProgramStop.Execute;
617    Core.Project.Openned := False;
618    FormSourceCode.SynEditSource.Clear;
619    UpdateInterface;
620  end;
621end;
622
623procedure TFormMain.AProjectNewExecute(Sender: TObject);
624begin
625  AProjectClose.Execute;
626  if Core.Project.Openned then Exit;
627  Core.Project.FileName := 'Examples' + DirectorySeparator + SNewProject + '.b';
628  FormSourceCode.SynEditSource.Clear;
629  Core.Project.Openned := True;
630  Core.CurrentTarget.Compiled := False;
631  UpdateInterface;
632end;
633
634procedure TFormMain.AProjectOpenRecentExecute(Sender: TObject);
635begin
636  AProjectClose.Execute;
637  if Core.Project.Openned then Exit;
638  ProjectOpen(Core.LastOpenedList.Items[TMenuItem(Sender).MenuIndex]);
639end;
640
641procedure TFormMain.AProjectOpenExecute(Sender: TObject);
642begin
643  if Core.LastOpenedList.Items.Count > 0 then
644    OpenDialog1.FileName := Core.LastOpenedList.Items[0]
645    else OpenDialog1.FileName := ExtractFileDir(Application.ExeName) + DirectorySeparator + 'Examples';
646  OpenDialog1.InitialDir := ExtractFileDir(OpenDialog1.FileName);
647  if OpenDialog1.Execute then begin
648    AProjectClose.Execute;
649    if Core.Project.Openned then Exit;
650    ProjectOpen(OpenDialog1.FileName);
651  end;
652end;
653
654procedure TFormMain.AProjectSaveAsExecute(Sender: TObject);
655begin
656  SaveDialog1.FileName := Core.Project.FileName;
657  if SaveDialog1.Execute then begin
658    FormSourceCode.SynEditSource.Lines.SaveToFile(SaveDialog1.FileName);
659    Core.Project.FileName := SaveDialog1.FileName;
660    Core.LastOpenedList.AddItem(SaveDialog1.FileName);
661    Core.Project.Modified := False;
662    UpdateInterface;
663  end;
664end;
665
666procedure TFormMain.AProjectSaveExecute(Sender: TObject);
667begin
668  if Core.Project.Modified and FileExists(Core.Project.FileName) then begin
669    FormSourceCode.SynEditSource.Lines.SaveToFile(Core.Project.FileName);
670    Core.Project.Modified := False;
671    UpdateInterface;
672  end else AProjectSaveAs.Execute;
673end;
674
675end.
676
Note: See TracBrowser for help on using the repository browser.