Changeset 6
- Timestamp:
- Apr 21, 2016, 10:22:08 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UAcronym.pas
r5 r6 76 76 77 77 TAcronymDb = class 78 FileName: string; 78 79 Sources: TObjectList; // TObjectList<TAcronymSource> 79 80 Acronyms: TAcronyms; 80 81 Contexts: TAcronymContexts; 82 Modified: Boolean; 81 83 constructor Create; 82 84 destructor Destroy; override; … … 222 224 AcronymContext: TAcronymContext; 223 225 begin 226 Self.FileName := FileName; 224 227 Acronyms.Clear; 225 228 F := TStringList.Create; … … 261 264 Context.Free; 262 265 end; 266 Modified := False; 263 267 end; 264 268 … … 272 276 Context: TStringList; 273 277 begin 278 Self.FileName := FileName; 274 279 F := TStringList.Create; 275 280 Line := TStringList.Create; … … 299 304 Context.Free; 300 305 end; 306 Modified := False; 301 307 end; 302 308 … … 336 342 Acronym.Meanings.Add(Meaning); 337 343 end; 344 Modified := True; 338 345 end; 339 346 … … 352 359 end; 353 360 end; 361 Modified := True; 354 362 end; 355 363 -
trunk/UFormImport.pas
r2 r6 93 93 end; 94 94 end; 95 if AddedCount > 0 then FormMain.AcronymDb.Modified := True; 95 96 ShowMessage(Format('Imported %d new acronyms.', [AddedCount])); 96 97 end; -
trunk/UFormMain.lfm
r5 r6 1 1 object FormMain: TFormMain 2 Left = 7622 Left = 541 3 3 Height = 446 4 Top = 5874 Top = 352 5 5 Width = 631 6 6 Caption = 'Acronym Decoder' 7 ClientHeight = 4 467 ClientHeight = 421 8 8 ClientWidth = 631 9 Menu = MainMenu1 9 10 OnClose = FormClose 10 11 OnCloseQuery = FormCloseQuery … … 15 16 object ListViewAcronyms: TListView 16 17 Left = 8 17 Height = 3 9118 Top = 4 618 Height = 372 19 Top = 40 19 20 Width = 613 20 21 Anchors = [akTop, akLeft, akRight, akBottom] … … 4392 4393 OnExecute = AAcronymRemoveAllExecute 4393 4394 end 4395 object AFileOpen: TAction 4396 Caption = 'Open' 4397 OnExecute = AFileOpenExecute 4398 end 4399 object AFileNew: TAction 4400 Caption = 'New' 4401 OnExecute = AFileNewExecute 4402 end 4403 object AFileSave: TAction 4404 Caption = 'Save' 4405 OnExecute = AFileSaveExecute 4406 end 4407 object AFileClose: TAction 4408 Caption = 'Close' 4409 OnExecute = AFileCloseExecute 4410 end 4411 object AFileSaveAs: TAction 4412 Caption = 'Save as...' 4413 OnExecute = AFileSaveAsExecute 4414 end 4394 4415 end 4395 4416 object PersistentForm1: TPersistentForm … … 4397 4418 EntireVisible = False 4398 4419 left = 304 4399 top = 1 284420 top = 112 4400 4421 end 4401 4422 object PopupMenuAcronym: TPopupMenu … … 4415 4436 end 4416 4437 end 4438 object MainMenu1: TMainMenu 4439 left = 465 4440 top = 112 4441 object MenuItem8: TMenuItem 4442 Caption = 'File' 4443 object MenuItem10: TMenuItem 4444 Action = AFileNew 4445 end 4446 object MenuItem11: TMenuItem 4447 Action = AFileOpen 4448 end 4449 object MenuItemOpenRecent: TMenuItem 4450 Caption = 'Open recent' 4451 end 4452 object MenuItem12: TMenuItem 4453 Action = AFileSave 4454 end 4455 object MenuItem13: TMenuItem 4456 Action = AFileSaveAs 4457 end 4458 object MenuItem14: TMenuItem 4459 Action = AFileClose 4460 end 4461 object MenuItem15: TMenuItem 4462 Caption = '-' 4463 end 4464 object MenuItem9: TMenuItem 4465 Action = AExit 4466 end 4467 end 4468 end 4469 object OpenDialog1: TOpenDialog 4470 left = 151 4471 top = 85 4472 end 4473 object SaveDialog1: TSaveDialog 4474 left = 48 4475 top = 85 4476 end 4477 object LastOpenedList1: TLastOpenedList 4478 MaxCount = 10 4479 OnChange = LastOpenedList1Change 4480 left = 509 4481 top = 267 4482 end 4417 4483 end -
trunk/UFormMain.pas
r5 r6 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus, 9 9 ComCtrls, StdCtrls, ExtCtrls, ActnList, UAcronym, UPersistentForm, Contnrs, 10 URegistry, Registry;10 URegistry, ULastOpenedList, Registry; 11 11 12 12 type … … 19 19 AAcronymRemove: TAction; 20 20 AAcronymRemoveAll: TAction; 21 AFileSaveAs: TAction; 22 AFileClose: TAction; 23 AFileSave: TAction; 24 AFileNew: TAction; 25 AFileOpen: TAction; 21 26 AImport: TAction; 22 27 AShow: TAction; … … 24 29 ActionList1: TActionList; 25 30 EditSearch: TEdit; 31 LastOpenedList1: TLastOpenedList; 26 32 ListViewAcronyms: TListView; 33 MainMenu1: TMainMenu; 27 34 MenuItem1: TMenuItem; 35 MenuItem10: TMenuItem; 36 MenuItem11: TMenuItem; 37 MenuItem12: TMenuItem; 38 MenuItem13: TMenuItem; 39 MenuItem14: TMenuItem; 40 MenuItem15: TMenuItem; 41 MenuItemOpenRecent: TMenuItem; 28 42 MenuItem2: TMenuItem; 29 43 MenuItem3: TMenuItem; … … 32 46 MenuItem6: TMenuItem; 33 47 MenuItem7: TMenuItem; 48 MenuItem8: TMenuItem; 49 MenuItem9: TMenuItem; 50 OpenDialog1: TOpenDialog; 34 51 PersistentForm1: TPersistentForm; 35 52 PopupMenuAcronym: TPopupMenu; 36 53 PopupMenuTryIcon: TPopupMenu; 54 SaveDialog1: TSaveDialog; 37 55 TrayIcon1: TTrayIcon; 38 56 procedure AAcronymAddExecute(Sender: TObject); … … 41 59 procedure AAcronymRemoveExecute(Sender: TObject); 42 60 procedure AExitExecute(Sender: TObject); 61 procedure AFileCloseExecute(Sender: TObject); 62 procedure AFileNewExecute(Sender: TObject); 63 procedure AFileOpenExecute(Sender: TObject); 64 procedure AFileSaveAsExecute(Sender: TObject); 65 procedure AFileSaveExecute(Sender: TObject); 43 66 procedure AImportExecute(Sender: TObject); 44 67 procedure AShowExecute(Sender: TObject); … … 49 72 procedure FormDestroy(Sender: TObject); 50 73 procedure FormShow(Sender: TObject); 74 procedure LastOpenedList1Change(Sender: TObject); 51 75 procedure ListViewAcronymsData(Sender: TObject; Item: TListItem); 52 76 procedure ListViewAcronymsDblClick(Sender: TObject); … … 57 81 private 58 82 FoundAcronyms: TAcronymMeanings; 83 RegistryContext: TRegistryContext; 84 procedure OpenRecentClick(Sender: TObject); 59 85 procedure UpdateAcronymsList; 60 86 procedure UpdateInterface; 87 procedure LoadConfig; 88 procedure SaveConfig; 61 89 public 62 90 AcronymDb: TAcronymDb; … … 74 102 75 103 const 76 DefaultFileName = 'Acronyms.csv'; 104 ProjectExt = '.adp'; 105 DefaultFileName = 'Acronyms' + ProjectExt; 106 DefaultRegKey = '\Software\Acronym Decoder'; 77 107 78 108 { TFormMain } … … 91 121 procedure TFormMain.FormClose(Sender: TObject; var CloseAction: TCloseAction); 92 122 begin 93 A cronymDB.SaveToFile(DefaultFileName);123 AFileClose.Execute; 94 124 PersistentForm1.Save(Self); 125 SaveConfig; 95 126 end; 96 127 97 128 procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean); 98 begin 129 var 130 ModalResult: TModalResult; 131 begin 132 if Assigned(AcronymDb) and AcronymDb.Modified then begin 133 ModalResult := MessageDlg('Application exit', 134 'Acronyms were modified. Do you want to save them to file before exit?', 135 mtConfirmation, [mbYes, mbNo, mbCancel], 0); 136 if ModalResult = mrYes then AFileSave.Execute 137 else if ModalResult = mrNo then CanClose := True 138 else CanClose := False; 139 end; 99 140 end; 100 141 … … 102 143 begin 103 144 Close; 145 end; 146 147 procedure TFormMain.AFileCloseExecute(Sender: TObject); 148 begin 149 if Assigned(AcronymDb) then begin 150 if AcronymDb.Modified then AFileSave.Execute; 151 FreeAndNil(AcronymDb); 152 UpdateAcronymsList; 153 UpdateInterface; 154 end; 155 end; 156 157 procedure TFormMain.AFileNewExecute(Sender: TObject); 158 begin 159 AFileClose.Execute; 160 AcronymDb := TAcronymDb.Create; 161 AcronymDb.FileName := DefaultFileName; 162 AcronymDb.Acronyms.Clear; 163 UpdateAcronymsList; 164 UpdateInterface; 165 end; 166 167 procedure TFormMain.AFileOpenExecute(Sender: TObject); 168 begin 169 OpenDialog1.DefaultExt := ProjectExt; 170 OpenDialog1.FileName := AcronymDb.FileName; 171 if OpenDialog1.Execute then begin 172 AcronymDb.LoadFromFile(OpenDialog1.FileName); 173 LastOpenedList1.AddItem(OpenDialog1.FileName); 174 UpdateAcronymsList; 175 UpdateInterface; 176 end; 177 end; 178 179 procedure TFormMain.AFileSaveAsExecute(Sender: TObject); 180 begin 181 SaveDialog1.DefaultExt := ProjectExt; 182 SaveDialog1.FileName := AcronymDb.FileName; 183 if SaveDialog1.Execute then begin 184 AcronymDb.SaveToFile(SaveDialog1.FileName); 185 LastOpenedList1.AddItem(SaveDialog1.FileName); 186 UpdateInterface; 187 end; 188 end; 189 190 procedure TFormMain.AFileSaveExecute(Sender: TObject); 191 begin 192 if FileExists(AcronymDb.FileName) then begin 193 AcronymDb.SaveToFile(AcronymDb.FileName); 194 LastOpenedList1.AddItem(AcronymDb.FileName); 195 UpdateInterface; 196 end else AFileSaveAs.Execute; 104 197 end; 105 198 … … 133 226 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin 134 227 AcronymDb.Acronyms.Clear; 228 AcronymDb.Modified := True; 135 229 UpdateAcronymsList; 136 230 UpdateInterface; … … 185 279 186 280 procedure TFormMain.FormShow(Sender: TObject); 187 const 188 DefaultRegKey = '\Software\Acronym Decoder'; 189 begin 190 PersistentForm1.RegistryContext := RegContext(HKEY_CURRENT_USER, DefaultRegKey); 281 begin 282 LoadConfig; 191 283 PersistentForm1.Load(Self); 192 if FileExists(DefaultFileName) then 193 AcronymDB.LoadFromFile(DefaultFileName);194 AcronymDb.FilterList(EditSearch.Text, FoundAcronyms);284 285 if (LastOpenedList1.Items.Count > 0) and FileExists(LastOpenedList1.Items[0]) then 286 AcronymDB.LoadFromFile(LastOpenedList1.Items[0]); 195 287 UpdateAcronymsList; 196 288 UpdateInterface; 289 end; 290 291 procedure TFormMain.LastOpenedList1Change(Sender: TObject); 292 begin 293 LastOpenedList1.LoadToMenuItem(MenuItemOpenRecent, OpenRecentClick); 197 294 end; 198 295 … … 235 332 end; 236 333 334 procedure TFormMain.OpenRecentClick(Sender: TObject); 335 begin 336 AFileClose.Execute; 337 AFileNew.Execute; 338 AcronymDb.LoadFromFile(TMenuItem(Sender).Caption); 339 LastOpenedList1.AddItem(TMenuItem(Sender).Caption); 340 UpdateAcronymsList; 341 UpdateInterface; 342 end; 343 237 344 procedure TFormMain.UpdateAcronymsList; 238 345 begin 239 AcronymDb.Acronyms.Sort(AcronymComparer); 240 AcronymDb.FilterList(EditSearch.Text, FoundAcronyms); 346 if Assigned(AcronymDb) then begin 347 AcronymDb.Acronyms.Sort(AcronymComparer); 348 AcronymDb.FilterList(EditSearch.Text, FoundAcronyms); 349 end else FoundAcronyms.Clear; 241 350 ListViewAcronyms.Items.Count := FoundAcronyms.Count; 242 351 ListViewAcronyms.Refresh; … … 244 353 245 354 procedure TFormMain.UpdateInterface; 246 begin 247 AAcronymRemove.Enabled := Assigned(ListViewAcronyms.Selected); 355 var 356 Title: string; 357 begin 358 ListViewAcronyms.Enabled := Assigned(AcronymDb); 359 AAcronymRemove.Enabled := Assigned(AcronymDb) and Assigned(ListViewAcronyms.Selected); 360 AAcronymModify.Enabled := Assigned(AcronymDb) and Assigned(ListViewAcronyms.Selected); 361 AAcronymAdd.Enabled := Assigned(AcronymDb); 362 AAcronymRemoveAll.Enabled := Assigned(AcronymDb) and (AcronymDb.Acronyms.Count > 0); 363 AFileClose.Enabled := Assigned(AcronymDb); 364 AFileSave.Enabled := Assigned(AcronymDb) and AcronymDb.Modified; 365 AFileSaveAs.Enabled := Assigned(AcronymDb); 366 EditSearch.Enabled := Assigned(AcronymDb); 367 368 Title := Application.Title; 369 if Assigned(AcronymDb) then Title := Title + ' - ' + ExtractFileName(AcronymDb.FileName); 370 if Assigned(AcronymDb) and AcronymDb.Modified then Title := Title + ' (modified)'; 371 Caption := Title; 372 end; 373 374 procedure TFormMain.LoadConfig; 375 begin 376 RegistryContext := RegContext(HKEY_CURRENT_USER, DefaultRegKey); 377 PersistentForm1.RegistryContext := RegistryContext; 378 LastOpenedList1.LoadFromRegistry(RegistryContext); 379 end; 380 381 procedure TFormMain.SaveConfig; 382 begin 383 LastOpenedList1.SaveToRegistry(RegistryContext); 248 384 end; 249 385
Note:
See TracChangeset
for help on using the changeset viewer.