Ignore:
Timestamp:
Dec 3, 2021, 8:50:43 PM (3 years ago)
Author:
chronos
Message:
  • Fixed: Wrong object reference to contact Parent after Merge files action.
  • Modified: Optimized select all action.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormContacts.pas

    r51 r52  
    5353  private
    5454    FContacts: TContacts;
     55    FUpdateCount: Integer;
    5556    procedure FilterList(List: TFPGObjectList<TObject>);
    5657    procedure SetContacts(AValue: TContacts);
    5758    procedure FormContactPrevious(Sender: TObject);
    5859    procedure FormContactNext(Sender: TObject);
     60    procedure DoUpdateInterface;
    5961  public
    6062    property Contacts: TContacts read FContacts write SetContacts;
    6163    procedure ReloadList;
     64    procedure BeginUpdate;
     65    procedure EndUpdate;
    6266    procedure UpdateInterface;
    6367  end;
     
    8084  SFiltered = 'Filtered';
    8185  SSelected = 'Selected';
     86  SEndUpdateTooLow = 'Update counter error';
    8287
    8388{ TFormContacts }
     
    99104  if Item.Index < ListViewSort1.List.Count then
    100105  with TContact(ListViewSort1.List[Item.Index]) do begin
    101 
    102106    AddItem(Fields[cfFullName], True);
    103107    AddItem(Fields[cfFirstName]);
     
    220224end;
    221225
     226procedure TFormContacts.DoUpdateInterface;
     227var
     228  Text: string;
     229  SelectedCount: Integer;
     230begin
     231  AAdd.Enabled := Assigned(Contacts);
     232  AModify.Enabled := Assigned(Contacts) and Assigned(ListView1.Selected);
     233  ARemove.Enabled := Assigned(Contacts) and Assigned(ListView1.Selected);
     234
     235  Text := '';
     236  if Assigned(Contacts) then begin
     237    Text := STotal + ': ' + IntToStr(Contacts.Count);
     238    if ListView1.Items.Count < Contacts.Count then
     239      Text := Text + ', ' + SFiltered + ': ' + IntToStr(ListView1.Items.Count);
     240    SelectedCount := ListView1.SelCount;
     241    if SelectedCount > 0 then
     242      Text := Text + ', ' + SSelected + ': ' + IntToStr(SelectedCount);
     243  end;
     244  StatusBar1.Panels[0].Text := Text;
     245end;
     246
    222247procedure TFormContacts.FormShow(Sender: TObject);
    223248begin
     
    268293    Contact := TContact.Create;
    269294    try
     295      Contact.Parent := Contacts.ContactsFile;
    270296      Contact.Assign(TContact(ListView1.Selected.Data));
    271297      FormContact.Contact := Contact;
     
    297323    Contact := TContact.Create;
    298324    try
     325      Contact.Parent := Contacts.ContactsFile;
    299326      Contact.Assign(TContact(ListView1.Selected.Data));
    300327      FormContact.Contact := Contact;
     
    333360
    334361procedure TFormContacts.ASelectAllExecute(Sender: TObject);
    335 begin
    336   ListView1.SelectAll;
    337   UpdateInterface;
     362var
     363  I: Integer;
     364begin
     365  BeginUpdate;
     366  ListView1.BeginUpdate;
     367  for I := 0 to ListView1.Items.Count - 1 do
     368    ListView1.Items[I].Selected := True;
     369  //ListView1.SelectAll;
     370  ListView1.EndUpdate;
     371  EndUpdate;
    338372end;
    339373
     
    360394end;
    361395
     396procedure TFormContacts.BeginUpdate;
     397begin
     398  Inc(FUpdateCount);
     399end;
     400
     401procedure TFormContacts.EndUpdate;
     402begin
     403  if FUpdateCount <= 0 then raise Exception(SEndUpdateTooLow);
     404  Dec(FUpdateCount);
     405  if FUpdateCount = 0 then DoUpdateInterface;
     406end;
     407
    362408procedure TFormContacts.UpdateInterface;
    363 var
    364   Text: string;
    365   SelectedCount: Integer;
    366 begin
    367   AAdd.Enabled := Assigned(Contacts);
    368   AModify.Enabled := Assigned(Contacts) and Assigned(ListView1.Selected);
    369   ARemove.Enabled := Assigned(Contacts) and Assigned(ListView1.Selected);
    370 
    371   Text := '';
    372   if Assigned(Contacts) then begin
    373     Text := STotal + ': ' + IntToStr(Contacts.Count);
    374     if ListView1.Items.Count < Contacts.Count then
    375       Text := Text + ', ' + SFiltered + ': ' + IntToStr(ListView1.Items.Count);
    376     SelectedCount := ListView1.SelCount;
    377     if SelectedCount > 0 then
    378       Text := Text + ', ' + SSelected + ': ' + IntToStr(SelectedCount);
    379   end;
    380   StatusBar1.Panels[0].Text := Text;
     409begin
     410  if FUpdateCount = 0 then DoUpdateInterface;
    381411end;
    382412
Note: See TracChangeset for help on using the changeset viewer.