Changeset 21 for trunk/UMainForm.pas
- Timestamp:
- Feb 12, 2012, 8:05:28 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UMainForm.pas
r20 r21 8 8 Classes, SysUtils, FileUtil, SynEdit, Forms, Controls, Graphics, Dialogs, 9 9 Menus, ActnList, StdCtrls, ComCtrls, UBrainFuck, UCoolTranslator, StrUtils, 10 SpecializedList, UCompiler; 10 SpecializedList, UCompiler, Registry, URegistry, ULastOpenedList; 11 12 const 13 RegistryRoot = HKEY_CURRENT_USER; 11 14 12 15 type … … 62 65 MenuItem26: TMenuItem; 63 66 MenuItem27: TMenuItem; 67 MenuItemOpenRecent: TMenuItem; 64 68 MenuItemTarget: TMenuItem; 65 69 MenuItem3: TMenuItem; … … 116 120 Shift: TShiftState; X, Y: Integer); 117 121 private 122 procedure AProjectOpenRecentExecute(Sender: TObject); 118 123 procedure BrainFuckInterpreterChangeState(Sender: TObject); 119 124 procedure MenuItemTargetClick(Sender: TObject); 125 procedure ProjectOpen(FileName: string); 120 126 public 121 127 Modified: Boolean; … … 126 132 BreakPoints: TListInteger; 127 133 Compilers: TListObject; // TListObject<TCompiler> 134 LastOpenedList: TLastOpenedList; 135 OpenProjectOnStart: Boolean; 136 procedure LoadFromRegistry(Root: HKEY; Key: string); 137 procedure SaveToRegistry(Root: HKEY; Key: string); 128 138 procedure UpdateInterface; 129 139 procedure UpdateStatusBar; … … 146 156 procedure TMainForm.FormShow(Sender: TObject); 147 157 begin 148 AProjectNew.Execute; 158 if OpenProjectOnStart and (LastOpenedList.Count > 0) then 159 ProjectOpen(LastOpenedList[0]) 160 else AProjectNew.Execute; 149 161 end; 150 162 … … 190 202 for I := 0 to Parent.Count - 1 do 191 203 if Parent.Items[I].MenuIndex <> MenuIndex then Parent.Items[I].Checked := False 204 end; 205 end; 206 207 procedure TMainForm.ProjectOpen(FileName: string); 208 begin 209 MemoSource.Lines.LoadFromFile(UTF8Decode(FileName)); 210 LastOpenedList.AddItem(FileName); 211 ProjectFileName := FileName; 212 UpdateInterface; 213 Modified := False; 214 end; 215 216 procedure TMainForm.LoadFromRegistry(Root: HKEY; Key: string); 217 begin 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); 227 end; 228 229 procedure TMainForm.SaveToRegistry(Root: HKEY; Key: string); 230 begin 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; 192 239 end; 193 240 end; … … 242 289 Compilers.Add(TBrainFuckCompilerPHP.Create); 243 290 UpdateTergetList; 291 LastOpenedList := TLastOpenedList.Create; 292 LastOpenedList.MenuItem := MenuItemOpenRecent; 293 LastOpenedList.ClickAction := AProjectOpenRecentExecute; 294 LoadFromRegistry(RegistryRoot, ApplicationInfo.RegistryKey); 244 295 end; 245 296 246 297 procedure TMainForm.FormDestroy(Sender: TObject); 247 298 begin 299 SaveToRegistry(RegistryRoot, ApplicationInfo.RegistryKey); 300 LastOpenedList.Free; 248 301 Compilers.Free; 249 302 BrainFuckCompiler.Free; … … 377 430 end; 378 431 432 procedure TMainForm.AProjectOpenRecentExecute(Sender: TObject); 433 begin 434 ProjectOpen(LastOpenedList[TMenuItem(Sender).MenuIndex]); 435 end; 436 379 437 procedure TMainForm.AProjectOpenExecute(Sender: TObject); 380 438 begin 381 439 OpenDialog1.FileName := ProjectFileName; 382 440 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); 387 442 end; 388 443 end;
Note:
See TracChangeset
for help on using the changeset viewer.