Ignore:
Timestamp:
Jun 26, 2012, 7:23:47 AM (12 years ago)
Author:
chronos
Message:
  • Modified: Created main UCore unit and moved non visual code from UFormMain to it.
File:
1 edited

Legend:

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

    r52 r53  
    1616
    1717type
    18 
    19   { TCustomCompiler }
    20 
    21   TCustomCompiler = class(TCompiler)
    22     procedure LoadFromRegistry(Root: HKEY; Key: string);
    23     procedure SaveToRegistry(Root: HKEY; Key: string);
    24   end;
    2518
    2619  { TFormMain }
     
    5447    AProjectClose: TAction;
    5548    ActionList1: TActionList;
    56     CoolTranslator1: TCoolTranslator;
    57     DebugLog1: TDebugLog;
    5849    ImageList1: TImageList;
    5950    MainMenu: TMainMenu;
     
    150141    procedure FormDestroy(Sender: TObject);
    151142  private
    152     LastOpenedFiles: TLastOpenedList;
    153     procedure ProjectTemplatesInit;
    154     procedure CompilerDebugLog(Text: string);
    155143    procedure MenuItemTargetClick(Sender: TObject);
    156     procedure OpenRecentClick(Sender: TObject);
    157     procedure LastOpenedFilesChange(Sender: TObject);
    158144    procedure DockInit;
    159     procedure LoadFromRegistry(Root: HKEY; Key: string);
    160     procedure SaveToRegistry(Root: HKEY; Key: string);
    161     procedure ProjectOpen(FileName: string);
    162145    procedure UpdateMenu;
    163146    procedure UpdateToolbar;
    164147  public
    165     ReopenLastOpenedFile: Boolean;
    166     LogParsing: Boolean;
    167     Project: TProject;
    168     ProjectTemplates: TProjectTemplateList;
    169     TargetProject: TProject;
    170     Compiler: TCustomCompiler;
     148    procedure LoadFromRegistry(Root: HKEY; Key: string);
     149    procedure SaveToRegistry(Root: HKEY; Key: string);
     150    procedure OpenRecentClick(Sender: TObject);
    171151    function GetSource(Name: string; var SourceCode: string): Boolean;
    172152    procedure UpdateInterface;
     
    182162
    183163uses
    184   UFormMessages, UFormSourceCode, UFormProject, UCommon, UFormAbout, UFormOptions,
     164  UCore, UFormMessages, UFormSourceCode, UFormProject, UCommon, UFormAbout, UFormOptions,
    185165  UFormTargets, UTarget, UAnalyzer, UProducer, UExecutor, UFormProjectNew,
    186166  UProjectTemplates, UFormTargetProject;
     
    189169  SNewProject = 'New project';
    190170
    191 { TCustomCompiler }
    192 
    193 procedure TCustomCompiler.LoadFromRegistry(Root: HKEY; Key: string);
    194 var
    195   I: Integer;
    196 begin
    197   with TRegistryEx.Create do
    198     try
    199       RootKey := Root;
    200       for I := 0 to Targets.Count - 1 do
    201       with TTarget(Targets[I]) do begin
    202         OpenKey(Key + '\Targets\' + Name, True);
    203         if ValueExists('CompilerPath') then
    204           Producer.CompilerPath := ReadStringWithDefault('CompilerPath', Producer.CompilerPath);
    205       end;
    206       if ValueExists('SelectedTarget') then
    207       Target := Targets.SearchBySysName(ReadString('SelectedTarget'))
    208         else Target := nil;
    209     finally
    210       Free;
    211     end;
    212 end;
    213 
    214 procedure TCustomCompiler.SaveToRegistry(Root: HKEY; Key: string);
    215 var
    216   I: Integer;
    217 begin
    218   with TRegistryEx.Create do
    219     try
    220       RootKey := Root;
    221       for I := 0 to Targets.Count - 1 do
    222       with TTarget(Targets[I]) do begin
    223         OpenKey(Key + '\Targets\' + Name, True);
    224         if Assigned(Producer) then begin
    225           if Producer.CompilerPath <> '' then WriteString('CompilerPath', Producer.CompilerPath)
    226             else DeleteValue('CompilerPath');
    227         end;
    228       end;
    229       if Assigned(Target) then WriteString('SelectedTarget', Target.SysName)
    230         else DeleteValue('SelectedTarget');
    231     finally
    232       Free;
    233     end;
    234 end;
    235 
    236171{ TFormMain }
    237172
     
    239174begin
    240175  FormSourceCode.Save;
    241 
    242   // Compile project file
     176  with Core do begin
     177    // Compile project file
    243178    Compiler.Init;
    244179
     
    262197    FormProject.TreeViewProjectChange(Self, FormProject.TreeViewProject.Selected);
    263198    FormMessages.Reload;
     199  end;
    264200end;
    265201
    266202procedure TFormMain.AResetExecute(Sender: TObject);
    267203begin
    268   Compiler.Target.Executor.Reset;
     204  Core.Compiler.Target.Executor.Reset;
    269205end;
    270206
     
    272208begin
    273209  ABuildExecute(Self);
    274   Compiler.Target.Executor.Run;
     210  Core.Compiler.Target.Executor.Run;
    275211end;
    276212
    277213procedure TFormMain.ARunToCursorExecute(Sender: TObject);
    278214begin
    279   Compiler.Target.Executor.RunToCursor(0); // determine position
     215  Core.Compiler.Target.Executor.RunToCursor(0); // determine position
    280216end;
    281217
    282218procedure TFormMain.AStepInExecute(Sender: TObject);
    283219begin
    284   Compiler.Target.Executor.StepIn;
     220  Core.Compiler.Target.Executor.StepIn;
    285221end;
    286222
    287223procedure TFormMain.AStepOutExecute(Sender: TObject);
    288224begin
    289   Compiler.Target.Executor.StepOut;
     225  Core.Compiler.Target.Executor.StepOut;
    290226end;
    291227
    292228procedure TFormMain.AStepOverExecute(Sender: TObject);
    293229begin
    294   Compiler.Target.Executor.StepOver;
     230  Core.Compiler.Target.Executor.StepOver;
    295231end;
    296232
    297233procedure TFormMain.AStopExecute(Sender: TObject);
    298234begin
    299   Compiler.Target.Executor.Stop;
     235  Core.Compiler.Target.Executor.Stop;
    300236end;
    301237
     
    340276  F: TFileStream;
    341277begin
    342   FileName := ExtractFileDir(Project.FileName) + Name + '.pas';
     278  FileName := ExtractFileDir(Core.Project.FileName) + Name + '.pas';
    343279  if FileExists(FileName) then
    344280  try
     
    358294  Title: string;
    359295begin
     296  with Core do begin
    360297  Title := ApplicationInfo.Name;
    361298  if Project.FileName <> '' then Title := Project.FileName + ' - ' + Title;
     
    384321  AStepOver.Enabled := AStepIn.Enabled;
    385322  ARunToCursor.Enabled := AStepIn.Enabled;
     323  end;
    386324
    387325  UpdateMenu;
     
    460398      RootKey := Root;
    461399      OpenKey(Key, True);
    462       ReopenLastOpenedFile := ReadBoolWithDefault('ReopenLastOpenedFile', True);
    463       Compiler.Target := Compiler.Targets.SearchBySysName(ReadStringWithDefault('TargetName', ''));
    464       LogParsing := ReadBoolWithDefault('LogParsing', False);
    465       if ValueExists('LanguageCode') then
    466         CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('LanguageCode', ''))
    467         else CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode('');
    468400      PageControlRight.Width := ReadIntegerWithDefault('RightPanelWidth', 120);
    469401      PageControlBottom.Height := ReadIntegerWithDefault('BottomPanelHeight', 100);
     
    471403      Free;
    472404    end;
    473   LastOpenedFiles.LoadFromRegistry(RegistryRootKey, Key + '\LastOpenedFiles');
    474   Compiler.LoadFromRegistry(RegistryRootKey, Key + '\Compiler');
    475405end;
    476406
     
    481411      RootKey := Root;
    482412      OpenKey(Key, True);
    483       WriteBool('ReopenLastOpenedFile', ReopenLastOpenedFile);
    484       if Assigned(Compiler.Target) then
    485         WriteString('TargetName', Compiler.Target.SysName)
    486         else DeleteValue('TargetName');
    487       WriteBool('LogParsing', LogParsing);
    488       if Assigned(CoolTranslator1.Language) and (CoolTranslator1.Language.Code <> '') then
    489         WriteString('LanguageCode', CoolTranslator1.Language.Code)
    490         else DeleteValue('LanguageCode');
    491413      WriteInteger('RightPanelWidth', PageControlRight.Width);
    492414      WriteInteger('BottomPanelHeight', PageControlBottom.Height);
     
    494416      Free;
    495417    end;
    496   LastOpenedFiles.SaveToRegistry(RegistryRootKey, Key + '\LastOpenedFiles');
    497   Compiler.SaveToRegistry(RegistryRootKey, Key + '\Compiler');
    498 end;
    499 
    500 procedure TFormMain.ProjectOpen(FileName: string);
    501 begin
    502   Project.Active := True;
    503   Project.LoadFromFile(FileName);
    504   LastOpenedFiles.AddItem(FileName);
    505   UpdateInterface;
    506418end;
    507419
     
    509421begin
    510422  with TMenuItem(Sender) do begin
    511     Compiler.Target := TTarget(Compiler.Targets[MenuIndex]);
     423    Core.Compiler.Target := TTarget(Core.Compiler.Targets[MenuIndex]);
    512424    UpdateInterface;
    513425  end;
     
    520432begin
    521433  MenuItemProducer.Clear;
     434  with Core do
    522435  for I := 0 to Compiler.Targets.Count - 1 do begin
    523436    NewMenuItem := TMenuItem.Create(MenuItemProducer);
     
    541454begin
    542455  AProjectClose.Execute;
    543   SaveToRegistry(RegistryRootKey, ApplicationInfo.RegistryKey);
     456  Core.SaveToRegistry(RegistryRootKey, ApplicationInfo.RegistryKey);
    544457end;
    545458
     
    548461  I: Integer;
    549462begin
    550   DeleteFile(DebugLog1.FileName);
    551   Compiler := TCustomCompiler.Create;
    552   Project := TProject.Create;
    553   ProjectTemplates := TProjectTemplateList.Create;
    554   TargetProject := TProject.Create;
    555   LastOpenedFiles := TLastOpenedList.Create(nil);
    556   LastOpenedFiles.OnChange := LastOpenedFilesChange;
    557   LastOpenedFiles.ClickAction := OpenRecentClick;
    558463end;
    559464
    560465procedure TFormMain.FormDestroy(Sender: TObject);
    561466begin
    562   ProjectTemplates.Free;
    563   LastOpenedFiles.Free;
    564   TargetProject.Free;
    565   Project.Free;
    566   Compiler.Free;
    567 end;
    568 
    569 procedure TFormMain.ProjectTemplatesInit;
    570 begin
    571   ProjectTemplates.AddTemplate(TProjectTemplateConsoleApp.Create);
    572   ProjectTemplates.AddTemplate(TProjectTemplateGUIApp.Create);
    573   ProjectTemplates.AddTemplate(TProjectTemplatePackage.Create);
    574   ProjectTemplates.AddTemplate(TProjectTemplateUnit.Create);
    575 end;
    576 
    577 procedure TFormMain.CompilerDebugLog(Text: string);
    578 begin
    579   DebugLog1.Add('', Text);
    580467end;
    581468
     
    583470begin
    584471  if Sender is TMenuItem then
    585     ProjectOpen(StringReplace(TMenuItem(Sender).Caption, '&', '', [rfReplaceAll]));
    586 end;
    587 
    588 procedure TFormMain.LastOpenedFilesChange(Sender: TObject);
    589 begin
    590   LastOpenedFiles.LoadToMenuItem(MenuItemOpenRecent);
     472    Core.ProjectOpen(StringReplace(TMenuItem(Sender).Caption, '&', '', [rfReplaceAll]));
    591473end;
    592474
     
    595477  NewProjectFile: TProjectFile;
    596478begin
    597   LoadFromRegistry(RegistryRootKey, ApplicationInfo.RegistryKey);
     479  Core.LoadFromRegistry(RegistryRootKey, ApplicationInfo.RegistryKey);
    598480  DockInit;
    599   ProjectTemplatesInit;
    600 
    601   if ReopenLastOpenedFile and (LastOpenedFiles.Items.Count > 0) then begin
    602     ProjectOpen(LastOpenedFiles.Items[0]);
     481  Core.ProjectTemplatesInit;
     482
     483  if Core.ReopenLastOpenedFile and (Core.LastOpenedFiles.Items.Count > 0) then begin
     484    Core.ProjectOpen(Core.LastOpenedFiles.Items[0]);
    603485  end;
    604486
     
    614496begin
    615497  if OpenDialog1.Execute then begin
    616     ProjectOpen(OpenDialog1.FileName);
     498    Core.ProjectOpen(OpenDialog1.FileName);
    617499  end;
    618500end;
     
    621503begin
    622504  //if Project.Modified then ;
    623   Project.Active := False;
     505  Core.Project.Active := False;
    624506  UpdateInterface;
    625507end;
     
    642524procedure TFormMain.APauseExecute(Sender: TObject);
    643525begin
    644   Compiler.Target.Executor.Pause;
     526  Core.Compiler.Target.Executor.Pause;
    645527end;
    646528
     
    651533  if FormProjectNew.ShowModal = mrOk then begin
    652534    if Assigned(FormProjectNew.ListView1.Selected) then
    653       TProjectTemplate(FormProjectNew.ListView1.Selected.Data).InitProject(Project);
     535      TProjectTemplate(FormProjectNew.ListView1.Selected.Data).InitProject(Core.Project);
    654536  end;
    655537  UpdateInterface;
     
    659541begin
    660542  if SaveDialog1.Execute then begin
    661     Project.Active := True;
    662     Project.SaveToFile(SaveDialog1.FileName);
     543    Core.Project.Active := True;
     544    Core.Project.SaveToFile(SaveDialog1.FileName);
    663545    FormSourceCode.Save;
    664     Project.Save;
     546    Core.Project.Save;
    665547    UpdateInterface;
    666     LastOpenedFiles.AddItem(SaveDialog1.FileName);
     548    Core.LastOpenedFiles.AddItem(SaveDialog1.FileName);
    667549  end;
    668550end;
     
    671553begin
    672554  FormSourceCode.Save;
    673   if not FileExistsUTF8(Project.FileName) then AProjectSaveAs.Execute
    674     else Project.SaveToFile(Project.FileName);
     555  if not FileExistsUTF8(Core.Project.FileName) then AProjectSaveAs.Execute
     556    else Core.Project.SaveToFile(Core.Project.FileName);
    675557end;
    676558
Note: See TracChangeset for help on using the changeset viewer.