Changeset 21 for trunk/UMainForm.pas


Ignore:
Timestamp:
Feb 12, 2012, 8:05:28 PM (12 years ago)
Author:
chronos
Message:
  • Added: Storing last opened project list in registry.
  • Added: Opiton to reopen last opened project.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UMainForm.pas

    r20 r21  
    88  Classes, SysUtils, FileUtil, SynEdit, Forms, Controls, Graphics, Dialogs,
    99  Menus, ActnList, StdCtrls, ComCtrls, UBrainFuck, UCoolTranslator, StrUtils,
    10   SpecializedList, UCompiler;
     10  SpecializedList, UCompiler, Registry, URegistry, ULastOpenedList;
     11
     12const
     13  RegistryRoot = HKEY_CURRENT_USER;
    1114
    1215type
     
    6265    MenuItem26: TMenuItem;
    6366    MenuItem27: TMenuItem;
     67    MenuItemOpenRecent: TMenuItem;
    6468    MenuItemTarget: TMenuItem;
    6569    MenuItem3: TMenuItem;
     
    116120      Shift: TShiftState; X, Y: Integer);
    117121  private
     122    procedure AProjectOpenRecentExecute(Sender: TObject);
    118123    procedure BrainFuckInterpreterChangeState(Sender: TObject);
    119124    procedure MenuItemTargetClick(Sender: TObject);
     125    procedure ProjectOpen(FileName: string);
    120126  public
    121127    Modified: Boolean;
     
    126132    BreakPoints: TListInteger;
    127133    Compilers: TListObject; // TListObject<TCompiler>
     134    LastOpenedList: TLastOpenedList;
     135    OpenProjectOnStart: Boolean;
     136    procedure LoadFromRegistry(Root: HKEY; Key: string);
     137    procedure SaveToRegistry(Root: HKEY; Key: string);
    128138    procedure UpdateInterface;
    129139    procedure UpdateStatusBar;
     
    146156procedure TMainForm.FormShow(Sender: TObject);
    147157begin
    148   AProjectNew.Execute;
     158  if OpenProjectOnStart and (LastOpenedList.Count > 0) then
     159    ProjectOpen(LastOpenedList[0])
     160    else AProjectNew.Execute;
    149161end;
    150162
     
    190202    for I := 0 to Parent.Count - 1 do
    191203      if Parent.Items[I].MenuIndex <> MenuIndex then Parent.Items[I].Checked := False
     204  end;
     205end;
     206
     207procedure TMainForm.ProjectOpen(FileName: string);
     208begin
     209  MemoSource.Lines.LoadFromFile(UTF8Decode(FileName));
     210  LastOpenedList.AddItem(FileName);
     211  ProjectFileName := FileName;
     212  UpdateInterface;
     213  Modified := False;
     214end;
     215
     216procedure TMainForm.LoadFromRegistry(Root: HKEY; Key: string);
     217begin
     218  with TRegistryEx.Create do
     219  try
     220    RootKey := Root;
     221    OpenKey(Key, True);
     222    OpenProjectOnStart := ReadBoolWithDefault('OpenProjectOnStart', True);
     223  finally
     224    Free;
     225  end;
     226  LastOpenedList.LoadFromRegistry(Root, Key);
     227end;
     228
     229procedure TMainForm.SaveToRegistry(Root: HKEY; Key: string);
     230begin
     231  LastOpenedList.SaveToRegistry(Root, Key);
     232  with TRegistryEx.Create do
     233  try
     234    RootKey := Root;
     235    OpenKey(Key, True);
     236    WriteBool('OpenProjectOnStart', OpenProjectOnStart);
     237  finally
     238    Free;
    192239  end;
    193240end;
     
    242289  Compilers.Add(TBrainFuckCompilerPHP.Create);
    243290  UpdateTergetList;
     291  LastOpenedList := TLastOpenedList.Create;
     292  LastOpenedList.MenuItem := MenuItemOpenRecent;
     293  LastOpenedList.ClickAction := AProjectOpenRecentExecute;
     294  LoadFromRegistry(RegistryRoot, ApplicationInfo.RegistryKey);
    244295end;
    245296
    246297procedure TMainForm.FormDestroy(Sender: TObject);
    247298begin
     299  SaveToRegistry(RegistryRoot, ApplicationInfo.RegistryKey);
     300  LastOpenedList.Free;
    248301  Compilers.Free;
    249302  BrainFuckCompiler.Free;
     
    377430end;
    378431
     432procedure TMainForm.AProjectOpenRecentExecute(Sender: TObject);
     433begin
     434  ProjectOpen(LastOpenedList[TMenuItem(Sender).MenuIndex]);
     435end;
     436
    379437procedure TMainForm.AProjectOpenExecute(Sender: TObject);
    380438begin
    381439  OpenDialog1.FileName := ProjectFileName;
    382440  if OpenDialog1.Execute then begin
    383     MemoSource.Lines.LoadFromFile(UTF8Decode(OpenDialog1.FileName));
    384     ProjectFileName := OpenDialog1.FileName;
    385     UpdateInterface;
    386     Modified := False;
     441    ProjectOpen(OpenDialog1.FileName);
    387442  end;
    388443end;
Note: See TracChangeset for help on using the changeset viewer.