Ignore:
Timestamp:
Aug 23, 2022, 10:06:54 AM (21 months ago)
Author:
chronos
Message:
  • Added: Allow to configure visible columns in contacts table.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormContacts.pas

    r134 r138  
    55uses
    66  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    7   Menus, ActnList, UVCard, UListViewSort, LazUTF8, Clipbrd,
    8   Generics.Collections;
     7  Menus, ActnList, UVCard, UListViewSort, LazUTF8, Clipbrd, URegistry,
     8  Generics.Collections, Types;
    99
    1010type
     
    1616    AClone: TAction;
    1717    ACopy: TAction;
     18    AColumns: TAction;
    1819    ACut: TAction;
    1920    APaste: TAction;
     
    3132    MenuItem11: TMenuItem;
    3233    MenuItem12: TMenuItem;
     34    Separator1: TMenuItem;
     35    MenuItemColumns: TMenuItem;
    3336    MenuItem2: TMenuItem;
    3437    MenuItem3: TMenuItem;
     
    5356    procedure AAddExecute(Sender: TObject);
    5457    procedure ACloneExecute(Sender: TObject);
     58    procedure AColumnsExecute(Sender: TObject);
    5559    procedure ACopyExecute(Sender: TObject);
    5660    procedure ACutExecute(Sender: TObject);
     
    8387    procedure DoUpdateInterface;
    8488    procedure UpdateColumns;
     89    procedure LoadFromRegistry(Context: TRegistryContext);
     90    procedure SaveToRegistry(Context: TRegistryContext);
    8591  public
    8692    ListViewColumns: TContactFieldIndexes;
    8793    FilterItems: TContactFilterItems;
    88     property Contacts: TContacts read FContacts write SetContacts;
     94    Context: TRegistryContext;
    8995    procedure ReloadList;
    9096    procedure BeginUpdate;
    9197    procedure EndUpdate;
    9298    procedure UpdateInterface;
     99    property Contacts: TContacts read FContacts write SetContacts;
    93100  end;
    94101
     
    102109
    103110uses
    104   UFormContact, UCore, UVCardFile;
     111  UFormContact, UCore, UVCardFile, UFormColumns;
    105112
    106113resourcestring
     
    315322end;
    316323
     324procedure TFormContacts.LoadFromRegistry(Context: TRegistryContext);
     325var
     326  I: Integer;
     327  Registry: TRegistryEx;
     328  ContactFieldIndex: TContactFieldIndex;
     329begin
     330  Registry := TRegistryEx.Create;
     331  with Registry do
     332  try
     333    RootKey := Context.RootKey;
     334    OpenKey(Context.Key, True);
     335    ListViewColumns.Clear;
     336    I := 0;
     337    while ValueExists('Column' + IntToStr(I)) do begin
     338      ContactFieldIndex := TContactFieldIndex(ReadIntegerWithDefault('Column' + IntToStr(I), -1));
     339      ListViewColumns.Add(ContactFieldIndex);
     340      Inc(I);
     341    end;
     342
     343    if ListViewColumns.Count = 0 then begin
     344      with ListViewColumns do begin
     345        Add(cfFullName);
     346        Add(cfFirstName);
     347        Add(cfMiddleName);
     348        Add(cfLastName);
     349        Add(cfTel);
     350        Add(cfTelCell);
     351        Add(cfTelHome);
     352        Add(cfTelWork);
     353        Add(cfEmailWork);
     354        Add(cfOrganization);
     355      end;
     356    end;
     357  finally
     358    Free;
     359  end;
     360end;
     361
     362procedure TFormContacts.SaveToRegistry(Context: TRegistryContext);
     363var
     364  I: Integer;
     365  Registry: TRegistryEx;
     366begin
     367  Registry := TRegistryEx.Create;
     368  with Registry do
     369  try
     370    RootKey := Context.RootKey;
     371    OpenKey(Context.Key, True);
     372    for I := 0 to ListViewColumns.Count - 1 do
     373      WriteInteger('Column' + IntToStr(I), Integer(ListViewColumns[I]));
     374
     375    // Remove old columns
     376    I := ListViewColumns.Count;
     377    while ValueExists('Column' + IntToStr(I)) do begin
     378      DeleteValue('Column' + IntToStr(I));
     379      Inc(I);
     380    end;
     381  finally
     382    Free;
     383  end;
     384end;
     385
    317386procedure TFormContacts.FormShow(Sender: TObject);
    318387begin
     
    320389  Core.ThemeManager1.UseTheme(Self);
    321390  Core.PersistentForm1.Load(Self);
     391  LoadFromRegistry(Context);
    322392  ReloadList;
    323393  UpdateInterface;
     
    385455end;
    386456
     457procedure TFormContacts.AColumnsExecute(Sender: TObject);
     458var
     459  FormColumns: TFormColumns;
     460  I: Integer;
     461  Field: TContactField;
     462begin
     463  FormColumns := TFormColumns.Create(nil);
     464  with FormColumns do
     465  try
     466    for I := 0 to ListViewColumns.Count - 1 do begin
     467      Field := TContact.GetFields.GetByIndex(ListViewColumns[I]);
     468      if Assigned(Field) then
     469        ActiveColumns.AddObject(Field.Title, Field);
     470    end;
     471    for I := 0 to TContact.GetFields.Count - 1 do begin
     472      Field := TContact.GetFields[I];
     473      if ListViewColumns.IndexOf(Field.Index) = -1 then
     474        AvailableColumns.AddObject(Field.Title, Field);
     475    end;
     476    if ShowModal = mrOK then begin
     477      ListViewColumns.Clear;
     478      for I := 0 to ActiveColumns.Count - 1 do begin
     479        ListViewColumns.Add(TContactField(ActiveColumns.Objects[I]).Index);
     480      end;
     481      UpdateColumns;
     482      ReloadList;
     483    end;
     484  finally
     485    Free;
     486  end;
     487end;
     488
    387489procedure TFormContacts.ACopyExecute(Sender: TObject);
    388490var
     
    571673  );
    572674begin
     675  SaveToRegistry(Context);
    573676  Core.PersistentForm1.Save(Self);
    574677end;
     
    579682begin
    580683  FilterItems := TContactFilterItems.Create;
    581 
    582684  ListViewColumns := TContactFieldIndexes.Create;
    583   with ListViewColumns do begin
    584     Add(cfFullName);
    585     Add(cfFirstName);
    586     Add(cfMiddleName);
    587     Add(cfLastName);
    588     Add(cfTel);
    589     Add(cfTelCell);
    590     Add(cfTelHome);
    591     Add(cfTelWork);
    592     Add(cfEmailWork);
    593   end;
    594685
    595686  FContacts := nil;
Note: See TracChangeset for help on using the changeset viewer.