Ignore:
Timestamp:
Aug 2, 2016, 11:21:21 AM (8 years ago)
Author:
chronos
Message:
  • Added: Text filtering in list of import sources.
  • Fixed: Now checkboxes in list of import sources are visible and working for enabling item.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormImportSources.pas

    r72 r73  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    9   ActnList, Menus, UAcronym, UJobProgressView;
     9  ActnList, Menus, UAcronym, UJobProgressView, UListViewSort, SpecializedList,
     10  LazUTF8;
    1011
    1112type
     
    2324    JobProgressView1: TJobProgressView;
    2425    ListView1: TListView;
     26    ListViewFilter1: TListViewFilter;
     27    ListViewSort1: TListViewSort;
    2528    MenuItem1: TMenuItem;
    2629    MenuItem2: TMenuItem;
     
    4346    procedure FormCreate(Sender: TObject);
    4447    procedure FormShow(Sender: TObject);
     48    procedure ListView1Change(Sender: TObject; Item: TListItem;
     49      Change: TItemChange);
     50    procedure ListView1Click(Sender: TObject);
    4551    procedure ListView1Data(Sender: TObject; Item: TListItem);
    4652    procedure ListView1DblClick(Sender: TObject);
     53    procedure ListView1Resize(Sender: TObject);
    4754    procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
    4855      Selected: Boolean);
     56    procedure ListViewFilter1Change(Sender: TObject);
     57    function ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
     58    procedure ListViewSort1Filter(ListViewSort: TListViewSort);
    4959  private
    5060    procedure ProcessImportJob(Job: TJob);
    51     { private declarations }
     61    procedure FilterList(List: TListObject);
    5262  public
    5363    ImportSources: TImportSources;
     
    7787procedure TFormImportSources.ListView1Data(Sender: TObject; Item: TListItem);
    7888begin
    79   if Item.Index < ImportSources.Count then
    80   with TImportSource(ImportSources[Item.Index]) do begin
     89  if Item.Index < ListViewSort1.List.Count then
     90  with TImportSource(ListViewSort1.List[Item.Index]) do begin
    8191    Item.Caption := Name;
    82     Item.Data := ImportSources[Item.Index];
     92    Item.Data := ListViewSort1.List[Item.Index];
    8393    Item.SubItems.Add(URL);
    8494    Item.SubItems.Add(Categories.GetString);
     
    96106end;
    97107
     108procedure TFormImportSources.ListView1Resize(Sender: TObject);
     109begin
     110  ListViewFilter1.UpdateFromListView(ListView1);
     111end;
     112
    98113procedure TFormImportSources.ListView1SelectItem(Sender: TObject;
    99114  Item: TListItem; Selected: Boolean);
     
    102117end;
    103118
     119procedure TFormImportSources.ListViewFilter1Change(Sender: TObject);
     120begin
     121  UpdateList;
     122end;
     123
     124function TFormImportSources.ListViewSort1CompareItem(Item1, Item2: TObject
     125  ): Integer;
     126begin
     127  Result := 0;
     128  if Assigned(Item1) and Assigned(Item2) and (ListViewSort1.Order <> soNone) then begin
     129    with ListViewSort1 do
     130    case Column of
     131      0: Result := CompareString(TImportSource(Item1).Name, TImportSource(Item2).Name);
     132      1: Result := CompareString(TImportSource(Item1).URL, TImportSource(Item2).URL);
     133      2: Result := CompareString(TImportSource(Item1).Categories.GetString, TImportSource(Item2).Categories.GetString);
     134      3: Result := CompareInteger(TImportSource(Item1).ItemCount, TImportSource(Item2).ItemCount);
     135      4: Result := CompareTime(TImportSource(Item1).LastImportTime, TImportSource(Item2).LastImportTime);
     136    end;
     137    if ListViewSort1.Order = soDown then Result := -Result;
     138  end else Result := 0;
     139end;
     140
     141procedure TFormImportSources.ListViewSort1Filter(ListViewSort: TListViewSort);
     142begin
     143  ImportSources.AssignToList(ListViewSort1.List);
     144  FilterList(ListViewSort1.List);
     145end;
     146
    104147procedure TFormImportSources.UpdateList;
    105148begin
    106   ListView1.Items.Count := ImportSources.Count;
    107   ListView1.Refresh;
     149  ListViewSort1.Refresh;
    108150  UpdateInterface;
    109151end;
     
    118160begin
    119161  UpdateList;
     162end;
     163
     164procedure TFormImportSources.ListView1Change(Sender: TObject; Item: TListItem;
     165  Change: TItemChange);
     166begin
     167  if Assigned(Item) and (Change = ctState) then begin
     168    TImportSource(Item.Data).Enabled := Item.Checked;
     169  end;
     170end;
     171
     172procedure TFormImportSources.ListView1Click(Sender: TObject);
     173begin
     174
    120175end;
    121176
     
    200255end;
    201256
     257procedure TFormImportSources.FilterList(List: TListObject);
     258var
     259  I: Integer;
     260  FoundCount: Integer;
     261  EnteredCount: Integer;
     262begin
     263  EnteredCount := ListViewFilter1.TextEnteredCount;
     264  for I := List.Count - 1 downto 0 do begin
     265    if List.Items[I] is TImportSource then begin
     266      with TImportSource(List.Items[I]) do begin
     267         with ListViewFilter1 do
     268         if Visible and (EnteredCount > 0) then begin
     269           FoundCount := 0;
     270           if Pos(UTF8LowerCase(StringGrid.Cells[0, 0]),
     271             UTF8LowerCase(TImportSource(List.Items[I]).Name)) > 0 then Inc(FoundCount);
     272           if Pos(UTF8LowerCase(StringGrid.Cells[1, 0]),
     273             UTF8LowerCase(TImportSource(List.Items[I]).URL)) > 0 then Inc(FoundCount);
     274           if Pos(UTF8LowerCase(StringGrid.Cells[2, 0]),
     275             UTF8LowerCase(TImportSource(List.Items[I]).Categories.GetString)) > 0 then Inc(FoundCount);
     276           if Pos(UTF8LowerCase(StringGrid.Cells[2, 0]),
     277             UTF8LowerCase(IntToStr(TImportSource(List.Items[I]).ItemCount))) > 0 then Inc(FoundCount);
     278           if Pos(UTF8LowerCase(StringGrid.Cells[2, 0]),
     279             UTF8LowerCase(DateTimeToStr(TImportSource(List.Items[I]).LastImportTime))) > 0 then Inc(FoundCount);
     280           if FoundCount <> EnteredCount then List.Delete(I);
     281         end;
     282      end;
     283    end else
     284    if TImportSource(List.Items[I]) is TImportSource then begin
     285      List.Delete(I);
     286    end;
     287  end;
     288end;
     289
    202290procedure TFormImportSources.ARemoveExecute(Sender: TObject);
    203291var
Note: See TracChangeset for help on using the changeset viewer.