Changeset 18 for trunk/Forms/UFormMain.pas
- Timestamp:
- May 4, 2016, 12:28:37 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.pas
r17 r18 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus, 9 9 ComCtrls, StdCtrls, ExtCtrls, ActnList, UAcronym, UPersistentForm, Contnrs, 10 URegistry, ULastOpenedList, UCoolTranslator, Registry; 10 URegistry, ULastOpenedList, UListViewSort, UCoolTranslator, Registry, 11 SpecializedList, LazUTF8; 11 12 12 13 type … … 31 32 AExit: TAction; 32 33 ActionList1: TActionList; 34 CheckBoxExactMath: TCheckBox; 33 35 CoolTranslator1: TCoolTranslator; 34 EditSearch: TEdit;35 36 LastOpenedList1: TLastOpenedList; 36 37 ListViewAcronyms: TListView; 38 ListViewFilter1: TListViewFilter; 39 ListViewSort1: TListViewSort; 37 40 MainMenu1: TMainMenu; 38 41 MenuItem1: TMenuItem; … … 80 83 procedure AShowCategoriesExecute(Sender: TObject); 81 84 procedure AShowExecute(Sender: TObject); 85 procedure CheckBoxExactMathChange(Sender: TObject); 82 86 procedure EditSearchChange(Sender: TObject); 83 87 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); … … 92 96 procedure ListViewAcronymsSelectItem(Sender: TObject; Item: TListItem; 93 97 Selected: Boolean); 98 procedure ListViewFilter1Change(Sender: TObject); 99 function ListViewSort1CompareItem(Item1, Item2: TObject): Integer; 100 procedure ListViewSort1Filter(ListViewSort: TListViewSort); 94 101 procedure TrayIcon1Click(Sender: TObject); 95 102 private … … 98 105 procedure SetAlwaysOnTop(AValue: Boolean); 99 106 private 100 FoundAcronyms: TAcronymMeanings;101 107 RegistryContext: TRegistryContext; 102 108 ProjectClosed: Boolean; 109 procedure FilterList(List: TListObject); 103 110 procedure OpenRecentClick(Sender: TObject); 104 111 procedure UpdateAcronymsList; … … 140 147 begin 141 148 AcronymDb := TAcronymDb.Create; 142 FoundAcronyms := TAcronymMeanings.Create(False);143 149 end; 144 150 … … 355 361 end; 356 362 363 procedure TFormMain.CheckBoxExactMathChange(Sender: TObject); 364 begin 365 UpdateAcronymsList; 366 end; 367 357 368 procedure TFormMain.FormDestroy(Sender: TObject); 358 369 begin 359 FreeAndNil(FoundAcronyms);360 370 FreeAndNil(AcronymDb); 361 371 end; … … 369 379 AcronymDB.LoadFromFile(LastOpenedList1.Items[0]); 370 380 UpdateAcronymsList; 381 ListViewFilter1.UpdateFromListView(ListViewAcronyms); 371 382 UpdateInterface; 372 383 end; … … 378 389 379 390 procedure TFormMain.ListViewAcronymsData(Sender: TObject; Item: TListItem); 380 var 381 I: Integer; 382 ContextCombined: string; 383 begin 384 if Item.Index < FoundAcronyms.Count then 385 with TAcronymMeaning(FoundAcronyms[Item.Index]) do begin 391 begin 392 if Item.Index < ListViewSort1.List.Count then 393 with TAcronymMeaning(ListViewSort1.List[Item.Index]) do begin 386 394 Item.Caption := Acronym.Name; 387 395 Item.SubItems.Add(Name); 388 Item.Data := TAcronymMeaning(FoundAcronyms[Item.Index]); 389 ContextCombined := ''; 390 for I := 0 to Categories.Count - 1 do 391 ContextCombined := ContextCombined + TAcronymCategory(Categories[I]).Name + ','; 392 Delete(ContextCombined, Length(ContextCombined), 1); 393 Item.SubItems.Add(ContextCombined); 396 Item.Data := TAcronymMeaning(ListViewSort1.List[Item.Index]); 397 Item.SubItems.Add(Categories.GetString); 394 398 end; 395 399 end; … … 408 412 begin 409 413 UpdateInterface; 414 end; 415 416 procedure TFormMain.ListViewFilter1Change(Sender: TObject); 417 begin 418 UpdateAcronymsList; 419 end; 420 421 function TFormMain.ListViewSort1CompareItem(Item1, Item2: TObject): Integer; 422 begin 423 Result := 0; 424 if Assigned(Item1) and Assigned(Item2) and (ListViewSort1.Order <> soNone) then begin 425 with ListViewSort1 do 426 case Column of 427 0: Result := CompareString(TAcronymMeaning(Item1).Acronym.Name, TAcronymMeaning(Item2).Acronym.Name); 428 1: Result := CompareString(TAcronymMeaning(Item1).Description, TAcronymMeaning(Item2).Description); 429 2: Result := CompareString(TAcronymMeaning(Item1).Categories.GetString, TAcronymMeaning(Item2).Categories.GetString); 430 end; 431 if ListViewSort1.Order = soDown then Result := -Result; 432 end else Result := 0; 433 end; 434 435 procedure TFormMain.ListViewSort1Filter(ListViewSort: TListViewSort); 436 begin 437 AcronymDb.Acronyms.Sort(AcronymComparer); 438 AcronymDb.AssignToList(ListViewSort1.List); 439 FilterList(ListViewSort1.List); 410 440 end; 411 441 … … 436 466 end; 437 467 468 procedure TFormMain.FilterList(List: TListObject); 469 var 470 I: Integer; 471 FoundCount: Integer; 472 EnteredCount: Integer; 473 begin 474 EnteredCount := ListViewFilter1.TextEnteredCount; 475 for I := List.Count - 1 downto 0 do begin 476 if List.Items[I] is TAcronymMeaning then begin 477 with TAcronymMeaning(List.Items[I]) do begin 478 with ListViewFilter1 do 479 if Visible and (EnteredCount > 0) then begin 480 FoundCount := 0; 481 if CheckBoxExactMath.Checked then begin 482 if TextEnteredColumn(0) and (StringGrid.Cells[0, 0] = 483 TAcronymMeaning(List.Items[I]).Acronym.Name) then Inc(FoundCount); 484 if TextEnteredColumn(1) and (StringGrid.Cells[1, 0] = 485 TAcronymMeaning(List.Items[I]).Name) then Inc(FoundCount); 486 if TextEnteredColumn(2) and (StringGrid.Cells[2, 0] = 487 TAcronymMeaning(List.Items[I]).Categories.GetString) then Inc(FoundCount); 488 end else begin 489 if Pos(UTF8LowerCase(StringGrid.Cells[0, 0]), 490 UTF8LowerCase(TAcronymMeaning(List.Items[I]).Acronym.Name)) > 0 then Inc(FoundCount); 491 if Pos(UTF8LowerCase(StringGrid.Cells[1, 0]), 492 UTF8LowerCase(TAcronymMeaning(List.Items[I]).Name)) > 0 then Inc(FoundCount); 493 if Pos(UTF8LowerCase(StringGrid.Cells[2, 0]), 494 UTF8LowerCase(TAcronymMeaning(List.Items[I]).Categories.GetString)) > 0 then Inc(FoundCount); 495 end; 496 if FoundCount <> EnteredCount then List.Delete(I); 497 end else List.Delete(I); 498 end; 499 end else 500 if TAcronymMeaning(List.Items[I]) is TAcronymMeaning then begin 501 List.Delete(I); 502 end; 503 end; 504 end; 505 438 506 procedure TFormMain.OpenRecentClick(Sender: TObject); 439 507 begin … … 451 519 begin 452 520 if Assigned(AcronymDb) then begin 453 AcronymDb.Acronyms.Sort(AcronymComparer); 454 AcronymDb.FilterList(EditSearch.Text, FoundAcronyms); 455 end else FoundAcronyms.Clear; 456 ListViewAcronyms.Items.Count := FoundAcronyms.Count; 457 ListViewAcronyms.Refresh; 521 ListViewSort1.Refresh; 522 end else ListViewSort1.List.Clear; 458 523 end; 459 524 … … 470 535 AFileSave.Enabled := Assigned(AcronymDb) and AcronymDb.Modified; 471 536 AFileSaveAs.Enabled := Assigned(AcronymDb); 472 EditSearch.Enabled := Assigned(AcronymDb);473 537 AImport.Enabled := Assigned(AcronymDb); 474 538 AShowCategories.Enabled := Assigned(AcronymDb); … … 494 558 else CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(''); 495 559 AlwaysOnTop := ReadBoolWithDefault('AlwaysOnTop', False); 560 CheckBoxExactMath.Checked := ReadBoolWithDefault('ExactMatch', False); 496 561 finally 497 562 Free; … … 511 576 else DeleteValue('LanguageCode'); 512 577 WriteBool('AlwaysOnTop', AlwaysOnTop); 578 WriteBool('ExactMatch', CheckBoxExactMath.Checked); 513 579 finally 514 580 Free;
Note:
See TracChangeset
for help on using the changeset viewer.