Changeset 138 for trunk/Forms


Ignore:
Timestamp:
Aug 23, 2022, 10:06:54 AM (2 years ago)
Author:
chronos
Message:
  • Added: Allow to configure visible columns in contacts table.
Location:
trunk/Forms
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormContacts.lfm

    r128 r138  
    1313  OnResize = FormResize
    1414  OnShow = FormShow
    15   LCLVersion = '2.2.0.4'
     15  LCLVersion = '2.2.2.0'
    1616  object ListView1: TListView
    1717    Left = 0
    18     Height = 810
     18    Height = 809
    1919    Top = 0
    2020    Width = 1210
     
    6868    Left = 0
    6969    Height = 39
    70     Top = 842
     70    Top = 841
    7171    Width = 1210
    7272    Align = alBottom
     
    116116    Left = 0
    117117    Height = 32
    118     Top = 810
     118    Top = 809
    119119    Width = 1210
    120120    OnChange = ListViewFilter1Change
     
    123123  object StatusBar1: TStatusBar
    124124    Left = 0
    125     Height = 27
    126     Top = 881
     125    Height = 28
     126    Top = 880
    127127    Width = 1210
    128128    Panels = <   
     
    171171    object MenuItem8: TMenuItem
    172172      Action = ASaveToFile
     173    end
     174    object Separator1: TMenuItem
     175      Caption = '-'
     176    end
     177    object MenuItemColumns: TMenuItem
     178      Action = AColumns
    173179    end
    174180  end
     
    233239      ShortCut = 16470
    234240    end
     241    object AColumns: TAction
     242      Caption = 'Columns'
     243      OnExecute = AColumnsExecute
     244    end
    235245  end
    236246  object ListViewSort1: TListViewSort
  • trunk/Forms/UFormContacts.lrj

    r82 r138  
    1818{"hash":304761,"name":"tformcontacts.acopy.caption","sourcebytes":[67,111,112,121],"value":"Copy"},
    1919{"hash":19140,"name":"tformcontacts.acut.caption","sourcebytes":[67,117,116],"value":"Cut"},
    20 {"hash":5671589,"name":"tformcontacts.apaste.caption","sourcebytes":[80,97,115,116,101],"value":"Paste"}
     20{"hash":5671589,"name":"tformcontacts.apaste.caption","sourcebytes":[80,97,115,116,101],"value":"Paste"},
     21{"hash":174310419,"name":"tformcontacts.acolumns.caption","sourcebytes":[67,111,108,117,109,110,115],"value":"Columns"}
    2122]}
  • 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;
  • trunk/Forms/UFormMain.lfm

    r126 r138  
    1515  OnResize = FormResize
    1616  OnShow = FormShow
    17   LCLVersion = '2.2.0.4'
     17  LCLVersion = '2.2.2.0'
    1818  object CoolBar1: TCoolBar
    1919    Left = 0
     
    177177        OnClick = MenuItemToolbarClick
    178178      end
     179      object MenuItemColumns: TMenuItem
     180        Caption = 'Columns'
     181        OnClick = MenuItemColumnsClick
     182      end
    179183    end
    180184    object MenuItemTools: TMenuItem
  • trunk/Forms/UFormMain.lrj

    r81 r138  
    66{"hash":380871,"name":"tformmain.menuitemview.caption","sourcebytes":[86,105,101,119],"value":"View"},
    77{"hash":8267778,"name":"tformmain.menuitemtoolbar.caption","sourcebytes":[77,97,105,110,32,116,111,111,108,98,97,114],"value":"Main toolbar"},
     8{"hash":174310419,"name":"tformmain.menuitemcolumns.caption","sourcebytes":[67,111,108,117,109,110,115],"value":"Columns"},
    89{"hash":5989939,"name":"tformmain.menuitemtools.caption","sourcebytes":[84,111,111,108,115],"value":"Tools"},
    910{"hash":322608,"name":"tformmain.menuitemhelp.caption","sourcebytes":[72,101,108,112],"value":"Help"}
  • trunk/Forms/UFormMain.pas

    r129 r138  
    1919    MenuItem12: TMenuItem;
    2020    MenuItem13: TMenuItem;
     21    MenuItemColumns: TMenuItem;
    2122    MenuItem3: TMenuItem;
    2223    MenuItem4: TMenuItem;
     
    5960    procedure FormResize(Sender: TObject);
    6061    procedure FormShow(Sender: TObject);
     62    procedure MenuItemColumnsClick(Sender: TObject);
    6163    procedure MenuItemToolbarClick(Sender: TObject);
    6264  private
     
    7678
    7779uses
    78   UCore, UFormContacts, UVCard, UVCardFile;
     80  UCore, UFormContacts, UVCard, UVCardFile, URegistry;
    7981
    8082resourcestring
     
    121123    CoolBar1.AutosizeBands;
    122124
     125    FormContacts.Context := TRegistryContext.Create(Core.ApplicationInfo1.RegistryRoot,
     126      Core.ApplicationInfo1.RegistryKey + '\ContactsColumns');
    123127    FormContacts.Contacts := TVCardFile(Core.DataFile).VCard.Contacts;
    124128    FormContacts.ManualDock(Self, nil, alClient);
     
    128132    FormContacts.EndUpdate;
    129133  end;
     134end;
     135
     136procedure TFormMain.MenuItemColumnsClick(Sender: TObject);
     137begin
     138  FormContacts.AColumns.Execute;
    130139end;
    131140
Note: See TracChangeset for help on using the changeset viewer.