Changeset 18 for trunk


Ignore:
Timestamp:
May 4, 2016, 12:28:37 PM (9 years ago)
Author:
chronos
Message:
  • Modified: Ability to search acronyms by exact match and by columns in main window.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormAcronyms.lfm

    r17 r18  
    11object FormAcronyms: TFormAcronyms
    22  Left = 466
    3   Height = 575
    4   Top = 212
     3  Height = 558
     4  Top = 297
    55  Width = 740
    66  Caption = 'Acronyms'
    7   ClientHeight = 575
     7  ClientHeight = 558
    88  ClientWidth = 740
    99  OnShow = FormShow
     
    1111  object ListViewAcronyms: TListView
    1212    Left = 8
    13     Height = 527
     13    Height = 510
    1414    Top = 40
    1515    Width = 725
     
    4949    OnFilter = ListViewSort1Filter
    5050    Column = 0
    51     Order = soNone
     51    Order = soDown
    5252    left = 248
    5353    top = 168
  • trunk/Forms/UFormAcronyms.pas

    r17 r18  
    4242
    4343procedure TFormAcronyms.ListViewAcronymsData(Sender: TObject; Item: TListItem);
    44 var
    45   I: Integer;
    4644begin
    4745  if Item.Index < ListViewSort1.List.Count then
  • trunk/Forms/UFormMain.lfm

    r17 r18  
    11object FormMain: TFormMain
    2   Left = 394
     2  Left = 393
    33  Height = 446
    4   Top = 395
     4  Top = 405
    55  Width = 631
    66  Caption = 'Acronym Decoder'
     
    1616  object ListViewAcronyms: TListView
    1717    Left = 8
    18     Height = 372
    19     Top = 40
     18    Height = 340
     19    Top = 72
    2020    Width = 613
    2121    Anchors = [akTop, akLeft, akRight, akBottom]
     
    4444    OnSelectItem = ListViewAcronymsSelectItem
    4545  end
    46   object EditSearch: TEdit
     46  object ListViewFilter1: TListViewFilter
    4747    Left = 8
    48     Height = 28
    49     Top = 8
    50     Width = 611
     48    Height = 30
     49    Top = 32
     50    Width = 613
     51    OnChange = ListViewFilter1Change
    5152    Anchors = [akTop, akLeft, akRight]
    52     OnChange = EditSearchChange
    53     TabOrder = 1
     53  end
     54  object CheckBoxExactMath: TCheckBox
     55    Left = 8
     56    Height = 24
     57    Top = 3
     58    Width = 104
     59    Caption = 'Exact match'
     60    OnChange = CheckBoxExactMathChange
     61    TabOrder = 2
    5462  end
    5563  object TrayIcon1: TTrayIcon
     
    45194527    top = 144
    45204528  end
     4529  object ListViewSort1: TListViewSort
     4530    ListView = ListViewAcronyms
     4531    OnCompareItem = ListViewSort1CompareItem
     4532    OnFilter = ListViewSort1Filter
     4533    Column = 0
     4534    Order = soDown
     4535    left = 464
     4536    top = 208
     4537  end
    45214538end
  • trunk/Forms/UFormMain.lrt

    r17 r18  
    33TFORMMAIN.LISTVIEWACRONYMS.COLUMNS[1].CAPTION=Description
    44TFORMMAIN.LISTVIEWACRONYMS.COLUMNS[2].CAPTION=Categories
     5TFORMMAIN.CHECKBOXEXACTMATH.CAPTION=Exact match
    56TFORMMAIN.AEXIT.CAPTION=Exit
    67TFORMMAIN.ASHOW.CAPTION=Show
  • trunk/Forms/UFormMain.pas

    r17 r18  
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
    99  ComCtrls, StdCtrls, ExtCtrls, ActnList, UAcronym, UPersistentForm, Contnrs,
    10   URegistry, ULastOpenedList, UCoolTranslator, Registry;
     10  URegistry, ULastOpenedList, UListViewSort, UCoolTranslator, Registry,
     11  SpecializedList, LazUTF8;
    1112
    1213type
     
    3132    AExit: TAction;
    3233    ActionList1: TActionList;
     34    CheckBoxExactMath: TCheckBox;
    3335    CoolTranslator1: TCoolTranslator;
    34     EditSearch: TEdit;
    3536    LastOpenedList1: TLastOpenedList;
    3637    ListViewAcronyms: TListView;
     38    ListViewFilter1: TListViewFilter;
     39    ListViewSort1: TListViewSort;
    3740    MainMenu1: TMainMenu;
    3841    MenuItem1: TMenuItem;
     
    8083    procedure AShowCategoriesExecute(Sender: TObject);
    8184    procedure AShowExecute(Sender: TObject);
     85    procedure CheckBoxExactMathChange(Sender: TObject);
    8286    procedure EditSearchChange(Sender: TObject);
    8387    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     
    9296    procedure ListViewAcronymsSelectItem(Sender: TObject; Item: TListItem;
    9397      Selected: Boolean);
     98    procedure ListViewFilter1Change(Sender: TObject);
     99    function ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
     100    procedure ListViewSort1Filter(ListViewSort: TListViewSort);
    94101    procedure TrayIcon1Click(Sender: TObject);
    95102  private
     
    98105    procedure SetAlwaysOnTop(AValue: Boolean);
    99106  private
    100     FoundAcronyms: TAcronymMeanings;
    101107    RegistryContext: TRegistryContext;
    102108    ProjectClosed: Boolean;
     109    procedure FilterList(List: TListObject);
    103110    procedure OpenRecentClick(Sender: TObject);
    104111    procedure UpdateAcronymsList;
     
    140147begin
    141148  AcronymDb := TAcronymDb.Create;
    142   FoundAcronyms := TAcronymMeanings.Create(False);
    143149end;
    144150
     
    355361end;
    356362
     363procedure TFormMain.CheckBoxExactMathChange(Sender: TObject);
     364begin
     365  UpdateAcronymsList;
     366end;
     367
    357368procedure TFormMain.FormDestroy(Sender: TObject);
    358369begin
    359   FreeAndNil(FoundAcronyms);
    360370  FreeAndNil(AcronymDb);
    361371end;
     
    369379    AcronymDB.LoadFromFile(LastOpenedList1.Items[0]);
    370380  UpdateAcronymsList;
     381  ListViewFilter1.UpdateFromListView(ListViewAcronyms);
    371382  UpdateInterface;
    372383end;
     
    378389
    379390procedure 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
     391begin
     392  if Item.Index < ListViewSort1.List.Count then
     393  with TAcronymMeaning(ListViewSort1.List[Item.Index]) do begin
    386394    Item.Caption := Acronym.Name;
    387395    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);
    394398  end;
    395399end;
     
    408412begin
    409413  UpdateInterface;
     414end;
     415
     416procedure TFormMain.ListViewFilter1Change(Sender: TObject);
     417begin
     418  UpdateAcronymsList;
     419end;
     420
     421function TFormMain.ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
     422begin
     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;
     433end;
     434
     435procedure TFormMain.ListViewSort1Filter(ListViewSort: TListViewSort);
     436begin
     437  AcronymDb.Acronyms.Sort(AcronymComparer);
     438  AcronymDb.AssignToList(ListViewSort1.List);
     439  FilterList(ListViewSort1.List);
    410440end;
    411441
     
    436466end;
    437467
     468procedure TFormMain.FilterList(List: TListObject);
     469var
     470  I: Integer;
     471  FoundCount: Integer;
     472  EnteredCount: Integer;
     473begin
     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;
     504end;
     505
    438506procedure TFormMain.OpenRecentClick(Sender: TObject);
    439507begin
     
    451519begin
    452520  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;
    458523end;
    459524
     
    470535  AFileSave.Enabled := Assigned(AcronymDb) and AcronymDb.Modified;
    471536  AFileSaveAs.Enabled := Assigned(AcronymDb);
    472   EditSearch.Enabled := Assigned(AcronymDb);
    473537  AImport.Enabled := Assigned(AcronymDb);
    474538  AShowCategories.Enabled := Assigned(AcronymDb);
     
    494558      else CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode('');
    495559    AlwaysOnTop := ReadBoolWithDefault('AlwaysOnTop', False);
     560    CheckBoxExactMath.Checked := ReadBoolWithDefault('ExactMatch', False);
    496561  finally
    497562    Free;
     
    511576      else DeleteValue('LanguageCode');
    512577    WriteBool('AlwaysOnTop', AlwaysOnTop);
     578    WriteBool('ExactMatch', CheckBoxExactMath.Checked);
    513579  finally
    514580    Free;
  • trunk/Languages/AcronymDecoder.cs.po

    r17 r18  
    208208msgstr "Acronym Decoder"
    209209
     210#: tformmain.checkboxexactmath.caption
     211msgid "Exact match"
     212msgstr ""
     213
    210214#: tformmain.listviewacronyms.columns[0].caption
    211215msgctxt "tformmain.listviewacronyms.columns[0].caption"
  • trunk/Languages/AcronymDecoder.po

    r17 r18  
    196196msgstr ""
    197197
     198#: tformmain.checkboxexactmath.caption
     199msgid "Exact match"
     200msgstr ""
     201
    198202#: tformmain.listviewacronyms.columns[0].caption
    199203msgctxt "tformmain.listviewacronyms.columns[0].caption"
Note: See TracChangeset for help on using the changeset viewer.