| 1 | unit UCore;
|
|---|
| 2 |
|
|---|
| 3 | {$mode delphi}{$H+}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, XMLConf, FileUtil, Controls, ActnList, UGrammer,
|
|---|
| 9 | UPersistentForm, ULastOpenedList, UApplicationInfo, UCoolTranslator;
|
|---|
| 10 |
|
|---|
| 11 | type
|
|---|
| 12 |
|
|---|
| 13 | { TCore }
|
|---|
| 14 |
|
|---|
| 15 | TCore = class(TDataModule)
|
|---|
| 16 | ApplicationInfo1: TApplicationInfo;
|
|---|
| 17 | CoolTranslator1: TCoolTranslator;
|
|---|
| 18 | ImageList1: TImageList;
|
|---|
| 19 | PersistentForm1: TPersistentForm;
|
|---|
| 20 | XMLConfig1: TXMLConfig;
|
|---|
| 21 | procedure DataModuleCreate(Sender: TObject);
|
|---|
| 22 | procedure DataModuleDestroy(Sender: TObject);
|
|---|
| 23 | private
|
|---|
| 24 | { private declarations }
|
|---|
| 25 | public
|
|---|
| 26 | ReopenLastFile: Boolean;
|
|---|
| 27 | Grammer: TGrammer;
|
|---|
| 28 | procedure LoadConfig;
|
|---|
| 29 | procedure SaveConfig;
|
|---|
| 30 | procedure Initialize;
|
|---|
| 31 | procedure Finalize;
|
|---|
| 32 | end;
|
|---|
| 33 |
|
|---|
| 34 | var
|
|---|
| 35 | Core: TCore;
|
|---|
| 36 |
|
|---|
| 37 | implementation
|
|---|
| 38 |
|
|---|
| 39 | {$R *.lfm}
|
|---|
| 40 |
|
|---|
| 41 | uses
|
|---|
| 42 | UFormMain;
|
|---|
| 43 |
|
|---|
| 44 | { TCore }
|
|---|
| 45 |
|
|---|
| 46 | procedure TCore.DataModuleCreate(Sender: TObject);
|
|---|
| 47 | begin
|
|---|
| 48 | ForceDirectories(GetAppConfigDir(False));
|
|---|
| 49 | XMLConfig1.Filename := GetAppConfigDir(False) + 'Config.xml';
|
|---|
| 50 | end;
|
|---|
| 51 |
|
|---|
| 52 | procedure TCore.DataModuleDestroy(Sender: TObject);
|
|---|
| 53 | begin
|
|---|
| 54 | end;
|
|---|
| 55 |
|
|---|
| 56 | procedure TCore.LoadConfig;
|
|---|
| 57 | begin
|
|---|
| 58 | with XMLConfig1 do begin
|
|---|
| 59 | ReopenLastFile := GetValue('ReopenLastFile', True);
|
|---|
| 60 | CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(String(GetValue('Language', '')));
|
|---|
| 61 | end;
|
|---|
| 62 | end;
|
|---|
| 63 |
|
|---|
| 64 | procedure TCore.SaveConfig;
|
|---|
| 65 | begin
|
|---|
| 66 | with XMLConfig1 do begin
|
|---|
| 67 | SetValue('ReopenLastFile', ReopenLastFile);
|
|---|
| 68 | SetValue('Language', WideString(CoolTranslator1.Language.Code));
|
|---|
| 69 | Flush;
|
|---|
| 70 | end;
|
|---|
| 71 | end;
|
|---|
| 72 |
|
|---|
| 73 | procedure TCore.Initialize;
|
|---|
| 74 | begin
|
|---|
| 75 | PersistentForm1.RegistryContext := ApplicationInfo1.GetRegistryContext;
|
|---|
| 76 | LoadConfig;
|
|---|
| 77 | FormMain.LoadConfig(XMLConfig1);
|
|---|
| 78 | if ReopenLastFile and FileExists(FormMain.LastOpenedList1.GetFirstFileName) then
|
|---|
| 79 | FormMain.ProjectOpen(FormMain.LastOpenedList1.GetFirstFileName)
|
|---|
| 80 | else FormMain.AProjectNew.Execute;
|
|---|
| 81 | end;
|
|---|
| 82 |
|
|---|
| 83 | procedure TCore.Finalize;
|
|---|
| 84 | begin
|
|---|
| 85 | FormMain.SaveConfig(XMLConfig1);
|
|---|
| 86 | SaveConfig;
|
|---|
| 87 | end;
|
|---|
| 88 |
|
|---|
| 89 | end.
|
|---|
| 90 |
|
|---|