Ignore:
Timestamp:
Nov 30, 2017, 12:02:32 AM (7 years ago)
Author:
chronos
Message:
  • Added: New project Close action.
  • Added: Track project Modified flag and offer project save if modified project is closed.
  • Added: Remember last opened project file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/generator/UCore.pas

    r118 r126  
    66
    77uses
    8   Classes, SysUtils, FileUtil, Controls, ActnList, URules, UPersistentForm;
     8  Classes, SysUtils, XMLConf, FileUtil, Controls, ActnList, URules, DOM,
     9  UPersistentForm;
    910
    1011type
     
    1516    ImageList1: TImageList;
    1617    PersistentForm1: TPersistentForm;
     18    XMLConfig1: TXMLConfig;
    1719    procedure DataModuleCreate(Sender: TObject);
    1820    procedure DataModuleDestroy(Sender: TObject);
     
    2022    { private declarations }
    2123  public
     24    LastOpenedFile: string;
     25    ReopenLastFile: Boolean;
    2226    Grammer: TGrammer;
     27    procedure LoadConfig;
     28    procedure SaveConfig;
     29    procedure Initialize;
    2330  end;
    2431
     
    3037{$R *.lfm}
    3138
     39uses
     40  UFormMain;
     41
    3242{ TCore }
    3343
    3444procedure TCore.DataModuleCreate(Sender: TObject);
    3545begin
    36   Grammer := TGrammer.Create;
    37   Grammer.LoadFromXmlFile('pascal.grm');
     46  ForceDirectories(GetAppConfigDir(False));
     47  XMLConfig1.Filename := GetAppConfigDir(False) + 'Config.xml';
     48  LoadConfig;
    3849end;
    3950
    4051procedure TCore.DataModuleDestroy(Sender: TObject);
    4152begin
    42   Grammer.SaveToXmlFile('pascal.grm');
    43   FreeAndNil(Grammer);
     53  SaveConfig;
     54end;
     55
     56procedure TCore.LoadConfig;
     57begin
     58  with XMLConfig1 do begin
     59    LastOpenedFile := string(GetValue('LastOpenedFile', 'pascal.grm'));
     60    ReopenLastFile := GetValue('ReopenLastFile', True);
     61  end;
     62end;
     63
     64procedure TCore.SaveConfig;
     65begin
     66  with XMLConfig1 do begin
     67    SetValue('LastOpenedFile', DOMString(LastOpenedFile));
     68    SetValue('ReopenLastFile', ReopenLastFile);
     69    Flush;
     70  end;
     71end;
     72
     73procedure TCore.Initialize;
     74begin
     75  FormMain.AProjectNew.Execute;
     76  if ReopenLastFile and FileExists(LastOpenedFile) then
     77    Grammer.LoadFromXmlFile(LastOpenedFile)
    4478end;
    4579
Note: See TracChangeset for help on using the changeset viewer.