Changeset 121 for branches


Ignore:
Timestamp:
Nov 29, 2017, 1:34:17 PM (7 years ago)
Author:
chronos
Message:
  • Added: Sorting list of rules by name by default.
Location:
branches/generator/Forms
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/generator/Forms/UFormRules.lfm

    r119 r121  
    8686    TabOrder = 1
    8787    ViewStyle = vsReport
     88    OnCompare = ListView1Compare
    8889    OnData = ListView1Data
    8990    OnDblClick = ListView1DblClick
     
    237238    end
    238239  end
     240  object ListViewSort1: TListViewSort
     241    ListView = ListView1
     242    OnCompareItem = ListViewSort1CompareItem
     243    OnFilter = ListViewSort1Filter
     244    Column = 0
     245    Order = soUp
     246    left = 574
     247    top = 212
     248  end
    239249end
  • branches/generator/Forms/UFormRules.pas

    r119 r121  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
    9   ComCtrls, ActnList, Menus, URules;
     9  ComCtrls, ActnList, Menus, URules, UListViewSort;
    1010
    1111type
     
    2020    CoolBar1: TCoolBar;
    2121    ListView1: TListView;
     22    ListViewSort1: TListViewSort;
    2223    MenuItem1: TMenuItem;
    2324    MenuItem2: TMenuItem;
     
    3435    procedure FormCreate(Sender: TObject);
    3536    procedure FormShow(Sender: TObject);
     37    procedure ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
     38      Data: Integer; var Compare: Integer);
    3639    procedure ListView1Data(Sender: TObject; Item: TListItem);
    3740    procedure ListView1DblClick(Sender: TObject);
     
    3942    procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
    4043      Selected: Boolean);
     44    function ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
     45    procedure ListViewSort1Filter(ListViewSort: TListViewSort);
    4146  private
    4247    { private declarations }
     
    6873  ReloadList;
    6974  UpdateInterface;
     75end;
     76
     77procedure TFormRules.ListView1Compare(Sender: TObject; Item1, Item2: TListItem;
     78  Data: Integer; var Compare: Integer);
     79begin
     80
    7081end;
    7182
     
    125136procedure TFormRules.ListView1Data(Sender: TObject; Item: TListItem);
    126137begin
    127   if (Item.Index >= 0) and (Item.Index < Rules.Count) then begin
    128     Item.Caption := Rules[Item.Index].Name;
    129     Item.Data := Rules[Item.Index];
    130     Item.SubItems.Add(BooleanText[Rules[Item.Index].CreateSourceNode]);
    131     Item.SubItems.Add(Rules[Item.Index].Items.GetString);
     138  if (Item.Index >= 0) and (Item.Index < ListViewSort1.List.Count) then
     139  with TRule(ListViewSort1.List[Item.Index]) do begin
     140    Item.Caption := Name;
     141    Item.Data := ListViewSort1.List[Item.Index];
     142    Item.SubItems.Add(BooleanText[CreateSourceNode]);
     143    Item.SubItems.Add(Items.GetString);
    132144  end;
    133145end;
     
    149161end;
    150162
     163function TFormRules.ListViewSort1CompareItem(Item1, Item2: TObject): Integer;
     164begin
     165  Result := 0;
     166  if Assigned(Item1) and Assigned(Item2) and (ListViewSort1.Order <> soNone) then begin
     167    with ListViewSort1 do
     168    case Column of
     169      0: Result := CompareString(TRule(Item1).Name, TRule(Item2).Name);
     170      1: Result := CompareString(BooleanText[TRule(Item1).CreateSourceNode], BooleanText[TRule(Item2).CreateSourceNode]);
     171      2: Result := CompareString(TRule(Item1).GetString, TRule(Item2).GetString);
     172    end;
     173    if ListViewSort1.Order = soDown then Result := -Result;
     174  end else Result := 0;
     175end;
     176
     177procedure TFormRules.ListViewSort1Filter(ListViewSort: TListViewSort);
     178var
     179  I: Integer;
     180begin
     181  ListViewSort1.List.Count := Rules.Count;
     182  for I := 0 to Rules.Count - 1 do
     183    ListViewSort1.List[I] := Rules[I];
     184  //FilterList(ListViewSort1.List);
     185end;
     186
    151187procedure TFormRules.UpdateInterface;
    152188begin
     
    157193procedure TFormRules.ReloadList;
    158194begin
    159   if Assigned(Rules) then ListView1.Items.Count := Rules.Count
    160     else ListView1.Items.Count := 0;
     195  if Assigned(Rules) then ListViewSort1.Refresh
     196    else ListViewSort1.List.Count := 0;
    161197  ListView1.Refresh;
    162198end;
Note: See TracChangeset for help on using the changeset viewer.