Ignore:
Timestamp:
Jun 4, 2024, 12:22:49 AM (5 months ago)
Author:
chronos
Message:
  • Modified: Removed U prefix from unit names.
  • Modified: Updated Common package.
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/IDE/Forms/FormMain.pas

    r74 r75  
    1 unit UFormMain;
    2 
    3 {$MODE Delphi}
     1unit FormMain;
    42
    53interface
     
    75uses
    86  SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,
    9   ComCtrls, ExtCtrls, SynEdit, SynHighlighterPas, Registry,
    10   UProject, FileUtil, Menus, ActnList, DateUtils,
    11   UFormTargetCode, UFormCodeTree, URegistry;
     7  ComCtrls, ExtCtrls, SynEdit, SynHighlighterPas, Registry, Project, FileUtil,
     8  Menus, ActnList, DateUtils, FormTargetCode, FormCodeTree, RegistryEx,
     9  FormMessages, FormSourceCode, FormProject, FormTargetProject, FormTargets,
     10  FormExternalProducerOutput;
    1211
    1312type
     
    145144    procedure UpdateTitle;
    146145    procedure ProducerProcessOutput(Text: string);
     146    procedure ShowProject(ProjectFile: TProjectFile);
     147    procedure ShowTargetCode(ProjectFile: TProjectFile);
    147148  public
     149    FormMessages: TFormMessages;
     150    FormSourceCode: TFormSourceCode;
     151    FormProject: TFormProject;
     152    FormTargetCode: TFormTargetCode;
     153    FormTargetProject: TFormTargetProject;
     154    FormExternalProducerOutput: TFormExternalProducerOutput;
     155    FormTargets: TFormTargets;
     156    FormCodeTree: TFormCodeTree;
    148157    procedure LoadFromRegistry(Root: HKEY; const Key: string);
    149158    procedure SaveToRegistry(Root: HKEY; const Key: string);
     
    162171
    163172uses
    164   UCore, UFormMessages, UFormSourceCode, UFormProject, UCommon, UFormAbout, UFormOptions,
    165   UFormTargets, UTarget, UExecutor, UFormProjectNew,
    166   UFormTargetProject, UFormExternalProducerOutput;
     173  Core, Common, FormAbout, FormOptions, Target, Executor, FormProjectNew;
    167174
    168175resourcestring
     
    175182  FormSourceCode.Save;
    176183  AProjectSave.Execute;
    177   with Core do begin
     184  with Core.Core do begin
    178185    // Compile project file
    179186    Compiler.Init;
     
    214221procedure TFormMain.AResetExecute(Sender: TObject);
    215222begin
    216   Core.Compiler.Target.Executor.Reset;
     223  Core.Core.Compiler.Target.Executor.Reset;
    217224end;
    218225
     
    220227begin
    221228  ABuildExecute(Self);
    222   Core.Compiler.Target.Executor.Run;
     229  Core.Core.Compiler.Target.Executor.Run;
    223230end;
    224231
    225232procedure TFormMain.ARunToCursorExecute(Sender: TObject);
    226233begin
    227   Core.Compiler.Target.Executor.RunToCursor(0); // determine position
     234  Core.Core.Compiler.Target.Executor.RunToCursor(0); // determine position
    228235end;
    229236
    230237procedure TFormMain.AStepInExecute(Sender: TObject);
    231238begin
    232   Core.Compiler.Target.Executor.StepIn;
     239  Core.Core.Compiler.Target.Executor.StepIn;
    233240end;
    234241
    235242procedure TFormMain.AStepOutExecute(Sender: TObject);
    236243begin
    237   Core.Compiler.Target.Executor.StepOut;
     244  Core.Core.Compiler.Target.Executor.StepOut;
    238245end;
    239246
    240247procedure TFormMain.AStepOverExecute(Sender: TObject);
    241248begin
    242   Core.Compiler.Target.Executor.StepOver;
     249  Core.Core.Compiler.Target.Executor.StepOver;
    243250end;
    244251
    245252procedure TFormMain.AStopExecute(Sender: TObject);
    246253begin
    247   Core.Compiler.Target.Executor.Stop;
     254  Core.Core.Compiler.Target.Executor.Stop;
    248255end;
    249256
     
    264271
    265272procedure TFormMain.AViewOptionsExecute(Sender: TObject);
    266 begin
    267   FormOptions.ShowModal;
     273var
     274  FormOptions: TFormOptions;
     275begin
     276  FormOptions := TFormOptions.Create(nil);
     277  try
     278    FormOptions.ShowModal;
     279  finally
     280    FormOptions.Free;
     281  end;
    268282end;
    269283
     
    280294procedure TFormMain.AViewSourceEditorExecute(Sender: TObject);
    281295begin
    282 
    283296end;
    284297
     
    288301  F: TFileStream;
    289302begin
    290   FileName := ExtractFileDir(Core.Project.FileName) + Name + '.pas';
     303  FileName := ExtractFileDir(Core.Core.Project.FileName) + Name + '.pas';
    291304  if FileExists(FileName) then
    292305  try
     
    303316procedure TFormMain.UpdateInterface;
    304317begin
    305   with Core do begin
    306   UpdateTitle;
    307   AProjectClose.Enabled := Assigned(Project);
    308   AProjectSave.Enabled := Assigned(Project) and Project.Modified;
    309   AProjectSaveAs.Enabled := Assigned(Project);
    310   (*AProgramRun.Enabled := Project.Active and (BrainFuckInterpreter.State = rsStopped);
    311   AProgramPause.Enabled := Project.Active and (BrainFuckInterpreter.State = rsRunning);
    312   AProgramStop.Enabled := Project.Active and (BrainFuckInterpreter.State <> rsStopped);*)
    313   ABuild.Enabled := Assigned(Project) and Assigned(Compiler.Target) and
    314     Assigned(Compiler.Target.Producer);
    315   APause.Enabled := Assigned(Project) and Assigned(Compiler.Target) and
    316     Assigned(Compiler.Target.Executor) and (Compiler.Target.Executor.State = rsRunning);
    317   ARun.Enabled := Assigned(Project) and Assigned(Compiler.Target) and
    318     Assigned(Compiler.Target.Executor) and ((Compiler.Target.Executor.State = rsStopped) or
    319     (Compiler.Target.Executor.State = rsPaused));
    320   AStop.Enabled := Assigned(Project) and Assigned(Compiler.Target) and
    321     Assigned(Compiler.Target.Executor) and ((Compiler.Target.Executor.State = rsRunning) or
    322     (Compiler.Target.Executor.State = rsPaused));
    323   AStepIn.Enabled := Assigned(Project) and Assigned(Compiler.Target) and
    324     Assigned(Compiler.Target.Executor) and ((Compiler.Target.Executor.State = rsRunning) or
    325     (Compiler.Target.Executor.State = rsPaused));
    326   AStepOut.Enabled := AStepIn.Enabled;
    327   AStepOver.Enabled := AStepIn.Enabled;
    328   ARunToCursor.Enabled := AStepIn.Enabled;
     318  with Core.Core do begin
     319    UpdateTitle;
     320    AProjectClose.Enabled := Assigned(Project);
     321    AProjectSave.Enabled := Assigned(Project) and Project.Modified;
     322    AProjectSaveAs.Enabled := Assigned(Project);
     323    (*AProgramRun.Enabled := Project.Active and (BrainFuckInterpreter.State = rsStopped);
     324    AProgramPause.Enabled := Project.Active and (BrainFuckInterpreter.State = rsRunning);
     325    AProgramStop.Enabled := Project.Active and (BrainFuckInterpreter.State <> rsStopped);*)
     326    ABuild.Enabled := Assigned(Project) and Assigned(Compiler.Target) and
     327      Assigned(Compiler.Target.Producer);
     328    APause.Enabled := Assigned(Project) and Assigned(Compiler.Target) and
     329      Assigned(Compiler.Target.Executor) and (Compiler.Target.Executor.State = rsRunning);
     330    ARun.Enabled := Assigned(Project) and Assigned(Compiler.Target) and
     331      Assigned(Compiler.Target.Executor) and ((Compiler.Target.Executor.State = rsStopped) or
     332      (Compiler.Target.Executor.State = rsPaused));
     333    AStop.Enabled := Assigned(Project) and Assigned(Compiler.Target) and
     334      Assigned(Compiler.Target.Executor) and ((Compiler.Target.Executor.State = rsRunning) or
     335      (Compiler.Target.Executor.State = rsPaused));
     336    AStepIn.Enabled := Assigned(Project) and Assigned(Compiler.Target) and
     337      Assigned(Compiler.Target.Executor) and ((Compiler.Target.Executor.State = rsRunning) or
     338      (Compiler.Target.Executor.State = rsPaused));
     339    AStepOut.Enabled := AStepIn.Enabled;
     340    AStepOver.Enabled := AStepIn.Enabled;
     341    ARunToCursor.Enabled := AStepIn.Enabled;
    329342  end;
    330343
    331344  UpdateMenu;
    332   Core.Compiler.Targets.LoadToStrings(ComboBoxTarget.Items);
    333   ComboBoxTarget.ItemIndex := Core.Compiler.Targets.IndexOf(Core.Compiler.Target);
     345  Core.Core.Compiler.Targets.LoadToStrings(ComboBoxTarget.Items);
     346  ComboBoxTarget.ItemIndex := Core.Core.Compiler.Targets.IndexOf(Core.Core.Compiler.Target);
    334347  FormSourceCode.UpdateInterface;
    335348  FormTargetCode.UpdateInterface;
     
    435448begin
    436449  with TMenuItem(Sender) do begin
    437     Core.Compiler.Target := TTarget(Core.Compiler.Targets[MenuIndex]);
     450    Core.Core.Compiler.Target := TTarget(Core.Core.Compiler.Targets[MenuIndex]);
    438451    UpdateInterface;
    439452  end;
     
    446459begin
    447460  MenuItemProducer.Clear;
    448   with Core do
     461  with Core.Core do
    449462  for I := 0 to Compiler.Targets.Count - 1 do begin
    450463    NewMenuItem := TMenuItem.Create(MenuItemProducer);
     
    461474  Title: string;
    462475begin
    463   Title := Core.ApplicationInfo.AppName;
    464   if Assigned(Core.Project) then begin
    465     if Core.Project.FileName <> '' then Title := Core.Project.FileName + ' - ' + Title;
    466     if Core.Project.Modified then Title := Title + ' *';
     476  Title := Core.Core.ApplicationInfo.AppName;
     477  if Assigned(Core.Core.Project) then begin
     478    if Core.Core.Project.FileName <> '' then Title := Core.Core.Project.FileName + ' - ' + Title;
     479    if Core.Core.Project.Modified then Title := Title + ' *';
    467480  end;
    468481  Caption := Title;
     
    474487end;
    475488
     489procedure TFormMain.ShowProject(ProjectFile: TProjectFile);
     490begin
     491  FormMain.TabSheetSource.Show;
     492  FormSourceCode.ProjectFile := ProjectFile;
     493end;
     494
     495procedure TFormMain.ShowTargetCode(ProjectFile: TProjectFile);
     496begin
     497  FormTargetCode.ProjectFile := ProjectFile;
     498  FormMain.TabSheetTarget.Show;
     499  FormTargetCode.SynEdit1.Lines.Assign(ProjectFile.Source);
     500end;
     501
    476502procedure TFormMain.FormClose(Sender: TObject; var Action: TCloseAction);
    477503begin
    478504  AProjectClose.Execute;
    479   Core.SaveToRegistry(HKEY(Core.ApplicationInfo.RegistryRoot), Core.ApplicationInfo.RegistryKey);
     505  Core.Core.SaveToRegistry(HKEY(Core.Core.ApplicationInfo.RegistryRoot), Core.Core.ApplicationInfo.RegistryKey);
    480506end;
    481507
     
    484510  I: Integer;
    485511begin
    486   with Core.Compiler.Targets do
     512  FormMessages := TFormMessages.Create(nil);
     513  FormSourceCode := TFormSourceCode.Create(nil);
     514  FormProject := TFormProject.Create(nil);
     515  FormProject.OnShowProject := ShowProject;
     516  FormTargetCode := TFormTargetCode.Create(nil);
     517  FormTargetProject := TFormTargetProject.Create(nil);
     518  FormTargetProject.OnShowTargetCode := ShowTargetCode;
     519  FormExternalProducerOutput := TFormExternalProducerOutput.Create(nil);
     520  FormTargets := TFormTargets.Create(nil);
     521  FormCodeTree := TFormCodeTree.Create(nil);
     522
     523  with Core.Core.Compiler.Targets do
    487524  for I := 0 to Count - 1 do
    488525  with TTarget(Items[I]) do
     
    498535begin
    499536  if Sender is TMenuItem then
    500     Core.ProjectOpen(StringReplace(TMenuItem(Sender).Caption, '&', '', [rfReplaceAll]));
     537    Core.Core.ProjectOpen(StringReplace(TMenuItem(Sender).Caption, '&', '', [rfReplaceAll]));
    501538end;
    502539
    503540procedure TFormMain.FormShow(Sender: TObject);
    504541begin
    505   Core.LoadFromRegistry(HKEY(Core.ApplicationInfo.RegistryRoot), Core.ApplicationInfo.RegistryKey);
     542  Core.Core.LoadFromRegistry(HKEY(Core.Core.ApplicationInfo.RegistryRoot), Core.Core.ApplicationInfo.RegistryKey);
    506543  DockInit;
    507   Core.ProjectTemplatesInit;
    508 
    509   if Core.ReopenLastOpenedFile and (Core.LastOpenedFiles.Items.Count > 0) then
    510   if FileExists(Core.LastOpenedFiles.Items[0]) then
    511     Core.ProjectOpen(Core.LastOpenedFiles.Items[0]);
     544  Core.Core.ProjectTemplatesInit;
     545
     546  if Core.Core.ReopenLastOpenedFile and (Core.Core.LastOpenedFiles.Items.Count > 0) then
     547  if FileExists(Core.Core.LastOpenedFiles.Items[0]) then
     548    Core.Core.ProjectOpen(Core.Core.LastOpenedFiles.Items[0]);
    512549
    513550  WindowState := wsMaximized;
     
    517554procedure TFormMain.AProjectOpenExecute(Sender: TObject);
    518555begin
    519   if Core.LastOpenedFiles.Items.Count > 0 then
    520     OpenDialogProject.FileName := Core.LastOpenedFiles.Items[0]
     556  if Core.Core.LastOpenedFiles.Items.Count > 0 then
     557    OpenDialogProject.FileName := Core.Core.LastOpenedFiles.Items[0]
    521558    else OpenDialogProject.FileName := ExtractFileDir(Application.ExeName);
    522559  if OpenDialogProject.Execute then begin
    523     Core.ProjectOpen(OpenDialogProject.FileName);
     560    Core.Core.ProjectOpen(OpenDialogProject.FileName);
    524561  end;
    525562end;
     
    529566  //if Project.Modified then ;  A
    530567  FormSourceCode.ProjectFile := nil;
    531   FreeAndNil(Core.Project);
     568  FreeAndNil(Core.Core.Project);
    532569  FormProject.UpdateProjectTree;
    533570  UpdateInterface;
     
    540577
    541578procedure TFormMain.AAboutExecute(Sender: TObject);
    542 begin
    543   FormAbout.ShowModal;
     579var
     580  FormAbout: TFormAbout;
     581begin
     582  FormAbout := TFormAbout.Create(nil);
     583  try
     584    FormAbout.ShowModal;
     585  finally
     586    FormAbout.Free;
     587  end;
    544588end;
    545589
    546590procedure TFormMain.AHomepageExecute(Sender: TObject);
    547591begin
    548   OpenWebPage(Core.ApplicationInfo.HomePage);
     592  OpenWebPage(Core.Core.ApplicationInfo.HomePage);
    549593end;
    550594
    551595procedure TFormMain.APauseExecute(Sender: TObject);
    552596begin
    553   Core.Compiler.Target.Executor.Pause;
     597  Core.Core.Compiler.Target.Executor.Pause;
    554598end;
    555599
    556600procedure TFormMain.AProjectNewExecute(Sender: TObject);
    557 begin
     601var
     602  FormProjectNew: TFormProjectNew;
     603begin
     604  FormProjectNew := TFormProjectNew.Create(nil);
    558605  if FormProjectNew.ShowModal = mrOk then begin
    559606    if Assigned(FormProjectNew.ListView1.Selected) then begin
    560607      if TProjectTemplate(FormProjectNew.ListView1.Selected.Data).IsProject then
    561         Core.ProjectNew;
    562       TProjectTemplate(FormProjectNew.ListView1.Selected.Data).InitProject(Core.Project);
     608        Core.Core.ProjectNew;
     609      TProjectTemplate(FormProjectNew.ListView1.Selected.Data).InitProject(Core.Core.Project);
    563610    end;
    564611  end;
     612  FormProjectNew.Free;
    565613  UpdateInterface;
    566614end;
     
    568616procedure TFormMain.AProjectSaveAsExecute(Sender: TObject);
    569617begin
    570   if Core.LastOpenedFiles.Items.Count > 0 then
    571     SaveDialogProject.FileName := Core.LastOpenedFiles.Items[0]
     618  if Core.Core.LastOpenedFiles.Items.Count > 0 then
     619    SaveDialogProject.FileName := Core.Core.LastOpenedFiles.Items[0]
    572620    else SaveDialogProject.FileName := ExtractFileDir(Application.ExeName);
    573   if Assigned(Core.Project) then
     621  if Assigned(Core.Core.Project) then
    574622  if SaveDialogProject.Execute then begin
    575     Core.Project.SaveToFile(SaveDialogProject.FileName);
     623    Core.Core.Project.SaveToFile(SaveDialogProject.FileName);
    576624    FormSourceCode.Save;
    577     Core.Project.Save;
     625    Core.Core.Project.Save;
    578626    UpdateInterface;
    579     Core.LastOpenedFiles.AddItem(SaveDialogProject.FileName);
     627    Core.Core.LastOpenedFiles.AddItem(SaveDialogProject.FileName);
    580628  end;
    581629end;
     
    584632begin
    585633  FormSourceCode.Save;
    586   if not FileExists(Core.Project.FileName) then AProjectSaveAs.Execute
    587     else Core.Project.SaveToFile(Core.Project.FileName);
     634  if not FileExists(Core.Core.Project.FileName) then AProjectSaveAs.Execute
     635    else Core.Core.Project.SaveToFile(Core.Core.Project.FileName);
    588636end;
    589637
     
    591639begin
    592640  with TMenuItem(Sender) do begin
    593     Core.Compiler.Target := TTarget(Core.Compiler.Targets[ComboBoxTarget.ItemIndex]);
     641    Core.Core.Compiler.Target := TTarget(Core.Core.Compiler.Targets[ComboBoxTarget.ItemIndex]);
    594642    UpdateInterface;
    595643  end;
Note: See TracChangeset for help on using the changeset viewer.