Changeset 19 for trunk/Forms/UFormMain.pas
- Timestamp:
- May 4, 2016, 12:54:09 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.pas
r18 r19 16 16 17 17 TFormMain = class(TForm) 18 AAcronymAdd: TAction;19 AAcronymModify: TAction;20 AAcronymRemove: TAction;21 AAcronymRemoveAll: TAction;22 18 AShowAcronyms: TAction; 23 19 AShowCategories: TAction; … … 34 30 CheckBoxExactMath: TCheckBox; 35 31 CoolTranslator1: TCoolTranslator; 32 ImageList1: TImageList; 36 33 LastOpenedList1: TLastOpenedList; 37 34 ListViewAcronyms: TListView; … … 56 53 MenuItem2: TMenuItem; 57 54 MenuItem3: TMenuItem; 58 MenuItem4: TMenuItem;59 MenuItem5: TMenuItem;60 MenuItem6: TMenuItem;61 MenuItem7: TMenuItem;62 55 MenuItem8: TMenuItem; 63 56 MenuItem9: TMenuItem; 64 57 OpenDialog1: TOpenDialog; 65 58 PersistentForm1: TPersistentForm; 66 PopupMenuAcronym: TPopupMenu;67 59 PopupMenuTryIcon: TPopupMenu; 68 60 SaveDialog1: TSaveDialog; 69 61 TrayIcon1: TTrayIcon; 70 procedure AAcronymAddExecute(Sender: TObject);71 procedure AAcronymModifyExecute(Sender: TObject);72 procedure AAcronymRemoveAllExecute(Sender: TObject);73 procedure AAcronymRemoveExecute(Sender: TObject);74 62 procedure AExitExecute(Sender: TObject); 75 63 procedure AFileCloseExecute(Sender: TObject); … … 92 80 procedure LastOpenedList1Change(Sender: TObject); 93 81 procedure ListViewAcronymsData(Sender: TObject; Item: TListItem); 94 procedure ListViewAcronymsDblClick(Sender: TObject);95 procedure ListViewAcronymsKeyPress(Sender: TObject; var Key: char);96 82 procedure ListViewAcronymsSelectItem(Sender: TObject; Item: TListItem; 97 83 Selected: Boolean); … … 102 88 private 103 89 FAlwaysOnTop: Boolean; 104 function CompareStrings(Strings1, Strings2: TStrings): Boolean;105 procedure SetAlwaysOnTop(AValue: Boolean);106 private107 90 RegistryContext: TRegistryContext; 108 91 ProjectClosed: Boolean; 92 procedure SetAlwaysOnTop(AValue: Boolean); 109 93 procedure FilterList(List: TListObject); 110 94 procedure OpenRecentClick(Sender: TObject); … … 115 99 public 116 100 AcronymDb: TAcronymDb; 101 function CompareStrings(Strings1, Strings2: TStrings): Boolean; 117 102 property AlwaysOnTop: Boolean read FAlwaysOnTop write SetAlwaysOnTop; 118 103 end; … … 132 117 SAppExit = 'Application exit'; 133 118 SAppExitQuery = 'Acronyms were modified. Do you want to save them to file before exit?'; 134 SRemoveAllAcronyms = 'Remove all acronyms';135 SRemoveAllAcronymsQuery = 'Do you want to remove all acronyms?';136 SRemoveAcronym = 'Remove acronym';137 SRemoveAcronymQuery = 'Do you want to remove selected acronym?';138 119 139 120 const … … 243 224 end; 244 225 245 procedure TFormMain.AAcronymModifyExecute(Sender: TObject);246 var247 TempEntry: TAcronymEntry;248 TempCategories: TStringList;249 Meaning: TAcronymMeaning;250 I: Integer;251 begin252 if Assigned(ListViewAcronyms.Selected) then253 with TAcronymMeaning(ListViewAcronyms.Selected.Data) do begin254 TempEntry := TAcronymEntry.Create;255 TempEntry.Name := Acronym.Name;256 TempEntry.Meaning := Name;257 TempEntry.Description := Description;258 Categories.AssignToStrings(TempEntry.Categories);259 TempCategories := TStringList.Create;260 TempCategories.Assign(TempEntry.Categories);261 FormAcronym.Load(TempEntry);262 if FormAcronym.ShowModal = mrOk then begin263 FormAcronym.Save(TempEntry);264 if (TempEntry.Name <> Acronym.Name) or265 (TempEntry.Meaning <> Name) or266 (TempEntry.Description <> Description) or267 not CompareStrings(TempEntry.Categories, TempCategories) then begin268 // TODO: Update item inplace if possible269 AcronymDb.RemoveAcronym(Acronym.Name, Name);270 Meaning := AcronymDb.AddAcronym(TempEntry.Name, TempEntry.Meaning);271 Meaning.Description := TempEntry.Description;272 Meaning.Categories.AssignFromStrings(TempEntry.Categories);273 for I := 0 to Meaning.Categories.Count - 1 do274 TAcronymCategory(Meaning.Categories.Items[I]).AcronymMeanings.Add(Meaning);275 UpdateAcronymsList;276 UpdateInterface;277 end;278 end;279 TempEntry.Free;280 TempCategories.Free;281 end;282 end;283 284 procedure TFormMain.AAcronymRemoveAllExecute(Sender: TObject);285 begin286 if MessageDlg(SRemoveAllAcronyms, SRemoveAllAcronymsQuery,287 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin288 AcronymDb.Acronyms.Clear;289 AcronymDb.Modified := True;290 UpdateAcronymsList;291 UpdateInterface;292 end;293 end;294 295 procedure TFormMain.AAcronymRemoveExecute(Sender: TObject);296 begin297 if Assigned(ListViewAcronyms.Selected) then begin298 if MessageDlg(SRemoveAcronym, SRemoveAcronymQuery,299 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin300 AcronymDb.RemoveAcronym(TAcronymMeaning(ListViewAcronyms.Selected.Data).Acronym.Name,301 TAcronymMeaning(ListViewAcronyms.Selected.Data).Name);302 UpdateAcronymsList;303 UpdateInterface;304 end;305 end;306 end;307 308 procedure TFormMain.AAcronymAddExecute(Sender: TObject);309 var310 TempEntry: TAcronymEntry;311 Meaning: TAcronymMeaning;312 I: Integer;313 begin314 TempEntry := TAcronymEntry.Create;315 TempEntry.Name := '';316 TempEntry.Meaning := '';317 TempEntry.Description := '';318 FormAcronym.Load(TempEntry);319 if FormAcronym.ShowModal = mrOk then begin320 FormAcronym.Save(TempEntry);321 Meaning := AcronymDb.AddAcronym(TempEntry.Name, TempEntry.Meaning);322 Meaning.Description := TempEntry.Description;323 Meaning.Categories.AssignFromStrings(TempEntry.Categories);324 for I := 0 to Meaning.Categories.Count - 1 do325 TAcronymCategory(Meaning.Categories.Items[I]).AcronymMeanings.Add(Meaning);326 UpdateAcronymsList;327 UpdateInterface;328 end;329 TempEntry.Free;330 end;331 332 226 procedure TFormMain.AImportExecute(Sender: TObject); 333 227 begin … … 397 291 Item.SubItems.Add(Categories.GetString); 398 292 end; 399 end;400 401 procedure TFormMain.ListViewAcronymsDblClick(Sender: TObject);402 begin403 AAcronymModify.Execute;404 end;405 406 procedure TFormMain.ListViewAcronymsKeyPress(Sender: TObject; var Key: char);407 begin408 293 end; 409 294 … … 528 413 begin 529 414 ListViewAcronyms.Enabled := Assigned(AcronymDb); 530 AAcronymRemove.Enabled := Assigned(AcronymDb) and Assigned(ListViewAcronyms.Selected);531 AAcronymModify.Enabled := Assigned(AcronymDb) and Assigned(ListViewAcronyms.Selected);532 AAcronymAdd.Enabled := Assigned(AcronymDb);533 AAcronymRemoveAll.Enabled := Assigned(AcronymDb) and (AcronymDb.Acronyms.Count > 0);534 415 AFileClose.Enabled := Assigned(AcronymDb); 535 416 AFileSave.Enabled := Assigned(AcronymDb) and AcronymDb.Modified;
Note:
See TracChangeset
for help on using the changeset viewer.