Changeset 53 for trunk/IDE/Forms/UFormMain.pas
- Timestamp:
- Jun 26, 2012, 7:23:47 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/IDE/Forms/UFormMain.pas
r52 r53 16 16 17 17 type 18 19 { TCustomCompiler }20 21 TCustomCompiler = class(TCompiler)22 procedure LoadFromRegistry(Root: HKEY; Key: string);23 procedure SaveToRegistry(Root: HKEY; Key: string);24 end;25 18 26 19 { TFormMain } … … 54 47 AProjectClose: TAction; 55 48 ActionList1: TActionList; 56 CoolTranslator1: TCoolTranslator;57 DebugLog1: TDebugLog;58 49 ImageList1: TImageList; 59 50 MainMenu: TMainMenu; … … 150 141 procedure FormDestroy(Sender: TObject); 151 142 private 152 LastOpenedFiles: TLastOpenedList;153 procedure ProjectTemplatesInit;154 procedure CompilerDebugLog(Text: string);155 143 procedure MenuItemTargetClick(Sender: TObject); 156 procedure OpenRecentClick(Sender: TObject);157 procedure LastOpenedFilesChange(Sender: TObject);158 144 procedure DockInit; 159 procedure LoadFromRegistry(Root: HKEY; Key: string);160 procedure SaveToRegistry(Root: HKEY; Key: string);161 procedure ProjectOpen(FileName: string);162 145 procedure UpdateMenu; 163 146 procedure UpdateToolbar; 164 147 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); 171 151 function GetSource(Name: string; var SourceCode: string): Boolean; 172 152 procedure UpdateInterface; … … 182 162 183 163 uses 184 U FormMessages, UFormSourceCode, UFormProject, UCommon, UFormAbout, UFormOptions,164 UCore, UFormMessages, UFormSourceCode, UFormProject, UCommon, UFormAbout, UFormOptions, 185 165 UFormTargets, UTarget, UAnalyzer, UProducer, UExecutor, UFormProjectNew, 186 166 UProjectTemplates, UFormTargetProject; … … 189 169 SNewProject = 'New project'; 190 170 191 { TCustomCompiler }192 193 procedure TCustomCompiler.LoadFromRegistry(Root: HKEY; Key: string);194 var195 I: Integer;196 begin197 with TRegistryEx.Create do198 try199 RootKey := Root;200 for I := 0 to Targets.Count - 1 do201 with TTarget(Targets[I]) do begin202 OpenKey(Key + '\Targets\' + Name, True);203 if ValueExists('CompilerPath') then204 Producer.CompilerPath := ReadStringWithDefault('CompilerPath', Producer.CompilerPath);205 end;206 if ValueExists('SelectedTarget') then207 Target := Targets.SearchBySysName(ReadString('SelectedTarget'))208 else Target := nil;209 finally210 Free;211 end;212 end;213 214 procedure TCustomCompiler.SaveToRegistry(Root: HKEY; Key: string);215 var216 I: Integer;217 begin218 with TRegistryEx.Create do219 try220 RootKey := Root;221 for I := 0 to Targets.Count - 1 do222 with TTarget(Targets[I]) do begin223 OpenKey(Key + '\Targets\' + Name, True);224 if Assigned(Producer) then begin225 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 finally232 Free;233 end;234 end;235 236 171 { TFormMain } 237 172 … … 239 174 begin 240 175 FormSourceCode.Save; 241 242 // Compile project file176 with Core do begin 177 // Compile project file 243 178 Compiler.Init; 244 179 … … 262 197 FormProject.TreeViewProjectChange(Self, FormProject.TreeViewProject.Selected); 263 198 FormMessages.Reload; 199 end; 264 200 end; 265 201 266 202 procedure TFormMain.AResetExecute(Sender: TObject); 267 203 begin 268 Co mpiler.Target.Executor.Reset;204 Core.Compiler.Target.Executor.Reset; 269 205 end; 270 206 … … 272 208 begin 273 209 ABuildExecute(Self); 274 Co mpiler.Target.Executor.Run;210 Core.Compiler.Target.Executor.Run; 275 211 end; 276 212 277 213 procedure TFormMain.ARunToCursorExecute(Sender: TObject); 278 214 begin 279 Co mpiler.Target.Executor.RunToCursor(0); // determine position215 Core.Compiler.Target.Executor.RunToCursor(0); // determine position 280 216 end; 281 217 282 218 procedure TFormMain.AStepInExecute(Sender: TObject); 283 219 begin 284 Co mpiler.Target.Executor.StepIn;220 Core.Compiler.Target.Executor.StepIn; 285 221 end; 286 222 287 223 procedure TFormMain.AStepOutExecute(Sender: TObject); 288 224 begin 289 Co mpiler.Target.Executor.StepOut;225 Core.Compiler.Target.Executor.StepOut; 290 226 end; 291 227 292 228 procedure TFormMain.AStepOverExecute(Sender: TObject); 293 229 begin 294 Co mpiler.Target.Executor.StepOver;230 Core.Compiler.Target.Executor.StepOver; 295 231 end; 296 232 297 233 procedure TFormMain.AStopExecute(Sender: TObject); 298 234 begin 299 Co mpiler.Target.Executor.Stop;235 Core.Compiler.Target.Executor.Stop; 300 236 end; 301 237 … … 340 276 F: TFileStream; 341 277 begin 342 FileName := ExtractFileDir( Project.FileName) + Name + '.pas';278 FileName := ExtractFileDir(Core.Project.FileName) + Name + '.pas'; 343 279 if FileExists(FileName) then 344 280 try … … 358 294 Title: string; 359 295 begin 296 with Core do begin 360 297 Title := ApplicationInfo.Name; 361 298 if Project.FileName <> '' then Title := Project.FileName + ' - ' + Title; … … 384 321 AStepOver.Enabled := AStepIn.Enabled; 385 322 ARunToCursor.Enabled := AStepIn.Enabled; 323 end; 386 324 387 325 UpdateMenu; … … 460 398 RootKey := Root; 461 399 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') then466 CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('LanguageCode', ''))467 else CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode('');468 400 PageControlRight.Width := ReadIntegerWithDefault('RightPanelWidth', 120); 469 401 PageControlBottom.Height := ReadIntegerWithDefault('BottomPanelHeight', 100); … … 471 403 Free; 472 404 end; 473 LastOpenedFiles.LoadFromRegistry(RegistryRootKey, Key + '\LastOpenedFiles');474 Compiler.LoadFromRegistry(RegistryRootKey, Key + '\Compiler');475 405 end; 476 406 … … 481 411 RootKey := Root; 482 412 OpenKey(Key, True); 483 WriteBool('ReopenLastOpenedFile', ReopenLastOpenedFile);484 if Assigned(Compiler.Target) then485 WriteString('TargetName', Compiler.Target.SysName)486 else DeleteValue('TargetName');487 WriteBool('LogParsing', LogParsing);488 if Assigned(CoolTranslator1.Language) and (CoolTranslator1.Language.Code <> '') then489 WriteString('LanguageCode', CoolTranslator1.Language.Code)490 else DeleteValue('LanguageCode');491 413 WriteInteger('RightPanelWidth', PageControlRight.Width); 492 414 WriteInteger('BottomPanelHeight', PageControlBottom.Height); … … 494 416 Free; 495 417 end; 496 LastOpenedFiles.SaveToRegistry(RegistryRootKey, Key + '\LastOpenedFiles');497 Compiler.SaveToRegistry(RegistryRootKey, Key + '\Compiler');498 end;499 500 procedure TFormMain.ProjectOpen(FileName: string);501 begin502 Project.Active := True;503 Project.LoadFromFile(FileName);504 LastOpenedFiles.AddItem(FileName);505 UpdateInterface;506 418 end; 507 419 … … 509 421 begin 510 422 with TMenuItem(Sender) do begin 511 Co mpiler.Target := TTarget(Compiler.Targets[MenuIndex]);423 Core.Compiler.Target := TTarget(Core.Compiler.Targets[MenuIndex]); 512 424 UpdateInterface; 513 425 end; … … 520 432 begin 521 433 MenuItemProducer.Clear; 434 with Core do 522 435 for I := 0 to Compiler.Targets.Count - 1 do begin 523 436 NewMenuItem := TMenuItem.Create(MenuItemProducer); … … 541 454 begin 542 455 AProjectClose.Execute; 543 SaveToRegistry(RegistryRootKey, ApplicationInfo.RegistryKey);456 Core.SaveToRegistry(RegistryRootKey, ApplicationInfo.RegistryKey); 544 457 end; 545 458 … … 548 461 I: Integer; 549 462 begin 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;558 463 end; 559 464 560 465 procedure TFormMain.FormDestroy(Sender: TObject); 561 466 begin 562 ProjectTemplates.Free;563 LastOpenedFiles.Free;564 TargetProject.Free;565 Project.Free;566 Compiler.Free;567 end;568 569 procedure TFormMain.ProjectTemplatesInit;570 begin571 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 begin579 DebugLog1.Add('', Text);580 467 end; 581 468 … … 583 470 begin 584 471 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])); 591 473 end; 592 474 … … 595 477 NewProjectFile: TProjectFile; 596 478 begin 597 LoadFromRegistry(RegistryRootKey, ApplicationInfo.RegistryKey);479 Core.LoadFromRegistry(RegistryRootKey, ApplicationInfo.RegistryKey); 598 480 DockInit; 599 ProjectTemplatesInit;600 601 if ReopenLastOpenedFile and (LastOpenedFiles.Items.Count > 0) then begin602 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]); 603 485 end; 604 486 … … 614 496 begin 615 497 if OpenDialog1.Execute then begin 616 ProjectOpen(OpenDialog1.FileName);498 Core.ProjectOpen(OpenDialog1.FileName); 617 499 end; 618 500 end; … … 621 503 begin 622 504 //if Project.Modified then ; 623 Project.Active := False;505 Core.Project.Active := False; 624 506 UpdateInterface; 625 507 end; … … 642 524 procedure TFormMain.APauseExecute(Sender: TObject); 643 525 begin 644 Co mpiler.Target.Executor.Pause;526 Core.Compiler.Target.Executor.Pause; 645 527 end; 646 528 … … 651 533 if FormProjectNew.ShowModal = mrOk then begin 652 534 if Assigned(FormProjectNew.ListView1.Selected) then 653 TProjectTemplate(FormProjectNew.ListView1.Selected.Data).InitProject( Project);535 TProjectTemplate(FormProjectNew.ListView1.Selected.Data).InitProject(Core.Project); 654 536 end; 655 537 UpdateInterface; … … 659 541 begin 660 542 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); 663 545 FormSourceCode.Save; 664 Project.Save;546 Core.Project.Save; 665 547 UpdateInterface; 666 LastOpenedFiles.AddItem(SaveDialog1.FileName);548 Core.LastOpenedFiles.AddItem(SaveDialog1.FileName); 667 549 end; 668 550 end; … … 671 553 begin 672 554 FormSourceCode.Save; 673 if not FileExistsUTF8( Project.FileName) then AProjectSaveAs.Execute674 else Project.SaveToFile(Project.FileName);555 if not FileExistsUTF8(Core.Project.FileName) then AProjectSaveAs.Execute 556 else Core.Project.SaveToFile(Core.Project.FileName); 675 557 end; 676 558
Note:
See TracChangeset
for help on using the changeset viewer.