Ignore:
Timestamp:
Jan 24, 2017, 1:55:43 PM (8 years ago)
Author:
chronos
Message:
  • Added: Allow to disable selected acronym categories so acronyms without any enabled category won't be shown in main acronym search filter.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormCategories.pas

    r123 r145  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    9   ActnList, Menus, UAcronym;
     9  ActnList, Menus, UAcronym, UListViewSort;
    1010
    1111type
     
    1515  TFormCategories = class(TForm)
    1616    AAdd: TAction;
     17    AEnable: TAction;
     18    ADisable: TAction;
    1719    ASelectAll: TAction;
    1820    ARemove: TAction;
     
    2022    ActionList1: TActionList;
    2123    ListViewCategories: TListView;
     24    ListViewSort1: TListViewSort;
    2225    MenuItem1: TMenuItem;
    2326    MenuItem2: TMenuItem;
    2427    MenuItem3: TMenuItem;
    2528    MenuItem4: TMenuItem;
     29    MenuItem5: TMenuItem;
     30    MenuItem6: TMenuItem;
     31    MenuItem7: TMenuItem;
    2632    PopupMenuCategory: TPopupMenu;
    2733    ToolBar1: TToolBar;
     
    3036    ToolButton3: TToolButton;
    3137    procedure AAddExecute(Sender: TObject);
     38    procedure ADisableExecute(Sender: TObject);
     39    procedure AEnableExecute(Sender: TObject);
    3240    procedure AModifyExecute(Sender: TObject);
    3341    procedure ARemoveExecute(Sender: TObject);
     
    3644    procedure FormCreate(Sender: TObject);
    3745    procedure FormShow(Sender: TObject);
     46    procedure ListViewCategoriesChange(Sender: TObject; Item: TListItem;
     47      Change: TItemChange);
    3848    procedure ListViewCategoriesData(Sender: TObject; Item: TListItem);
    3949    procedure ListViewCategoriesDblClick(Sender: TObject);
     
    4151    procedure ListViewCategoriesSelectItem(Sender: TObject; Item: TListItem;
    4252      Selected: Boolean);
     53    function ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
     54    procedure ListViewSort1Filter(ListViewSort: TListViewSort);
    4355  private
    4456    { private declarations }
     
    7385  UpdateList;
    7486  Core.ScaleDPI1.ScaleControl(ToolBar1, Core.ScaleDPI1.DesignDPI);
     87end;
     88
     89procedure TFormCategories.ListViewCategoriesChange(Sender: TObject;
     90  Item: TListItem; Change: TItemChange);
     91begin
     92  if Assigned(Item) and (Change = ctState) then begin
     93    TAcronymCategory(Item.Data).Enabled := Item.Checked;
     94    Core.AcronymDb.Modified := True;
     95  end;
    7596end;
    7697
     
    87108    end else ShowMessage(Format(SCategoryAlreadyExists, [S]));
    88109  end;
     110end;
     111
     112procedure TFormCategories.ADisableExecute(Sender: TObject);
     113var
     114  I: Integer;
     115begin
     116  for I := ListViewCategories.Items.Count - 1 downto 0 do
     117  if ListViewCategories.Items[I].Selected then begin
     118    TAcronymCategory(ListViewCategories.Items[I].Data).Enabled := False;
     119    Core.AcronymDb.Modified := True;
     120  end;
     121  UpdateList;
     122end;
     123
     124procedure TFormCategories.AEnableExecute(Sender: TObject);
     125var
     126  I: Integer;
     127begin
     128  for I := ListViewCategories.Items.Count - 1 downto 0 do
     129  if ListViewCategories.Items[I].Selected then begin
     130    TAcronymCategory(ListViewCategories.Items[I].Data).Enabled := True;
     131    Core.AcronymDb.Modified := True;
     132  end;
     133  UpdateList;
    89134end;
    90135
     
    145190procedure TFormCategories.ListViewCategoriesData(Sender: TObject; Item: TListItem);
    146191begin
    147   if Item.Index < Core.AcronymDb.Categories.Count then
    148   with TAcronymCategory(Core.AcronymDb.Categories[Item.Index]) do begin
     192  if Item.Index < ListViewSort1.List.Count then
     193  with TAcronymCategory(ListViewSort1.List[Item.Index]) do begin
    149194    Item.Caption := Name;
    150     Item.Data := Core.AcronymDb.Categories[Item.Index];
     195    Item.Data := ListViewSort1.List[Item.Index];
    151196    Item.SubItems.Add(IntToStr(AcronymMeanings.Count));
     197    Item.Checked := Enabled;
    152198  end;
    153199end;
     
    170216end;
    171217
     218function TFormCategories.ListViewSort1CompareItem(Item1, Item2: TObject
     219  ): Integer;
     220begin
     221  Result := 0;
     222  if Assigned(Item1) and Assigned(Item2) and (ListViewSort1.Order <> soNone) then begin
     223    with ListViewSort1 do
     224    case Column of
     225      0: Result := CompareString(TAcronymCategory(Item1).Name, TAcronymCategory(Item2).Name);
     226      1: Result := CompareInteger(TAcronymCategory(Item1).AcronymMeanings.Count, TAcronymCategory(Item2).AcronymMeanings.Count);
     227    end;
     228    if ListViewSort1.Order = soDown then Result := -Result;
     229  end else Result := 0;
     230end;
     231
     232procedure TFormCategories.ListViewSort1Filter(ListViewSort: TListViewSort);
     233begin
     234  Core.AcronymDb.Categories.AssignToList(ListViewSort1.List);
     235end;
     236
    172237procedure TFormCategories.UpdateList;
    173238begin
     239  ListViewSort1.Refresh;
    174240  ListViewCategories.Items.Count := Core.AcronymDb.Categories.Count;
    175241  ListViewCategories.Refresh;
Note: See TracChangeset for help on using the changeset viewer.