Ignore:
Timestamp:
Dec 3, 2021, 7:44:05 PM (3 years ago)
Author:
chronos
Message:
  • Added: Clone context menu action for list of contacts and contact properties.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormContacts.pas

    r43 r51  
    1515  TFormContacts = class(TForm)
    1616    AAdd: TAction;
     17    AClone: TAction;
    1718    ASelectAll: TAction;
    1819    ARemove: TAction;
     
    2627    MenuItem3: TMenuItem;
    2728    MenuItem4: TMenuItem;
     29    MenuItem5: TMenuItem;
    2830    PopupMenuContact: TPopupMenu;
    2931    StatusBar1: TStatusBar;
     
    3234    ToolButton2: TToolButton;
    3335    ToolButton3: TToolButton;
     36    ToolButton4: TToolButton;
    3437    procedure AAddExecute(Sender: TObject);
     38    procedure ACloneExecute(Sender: TObject);
    3539    procedure AModifyExecute(Sender: TObject);
    3640    procedure ARemoveExecute(Sender: TObject);
     
    8084
    8185procedure TFormContacts.ListView1Data(Sender: TObject; Item: TListItem);
     86
     87  procedure AddItem(Text: string; IsCaption: Boolean = False);
     88  begin
     89    if IsCaption then begin
     90      if Text <> '' then Item.Caption := Text
     91        else Item.Caption := ' ';
     92    end else begin
     93      if Text <> '' then Item.SubItems.Add(Text)
     94        else Item.SubItems.Add(' ');
     95    end;
     96  end;
     97
    8298begin
    8399  if Item.Index < ListViewSort1.List.Count then
    84100  with TContact(ListViewSort1.List[Item.Index]) do begin
    85     Item.Caption := Fields[cfFullName];
    86     Item.SubItems.Add(Fields[cfFirstName]);
    87     Item.SubItems.Add(Fields[cfMiddleName]);
    88     Item.SubItems.Add(Fields[cfLastName]);
    89     Item.SubItems.Add(Fields[cfTelCell]);
    90     Item.SubItems.Add(Fields[cfTelHome]);
     101
     102    AddItem(Fields[cfFullName], True);
     103    AddItem(Fields[cfFirstName]);
     104    AddItem(Fields[cfMiddleName]);
     105    AddItem(Fields[cfLastName]);
     106    AddItem(Fields[cfTelCell]);
     107    AddItem(Fields[cfTelHome]);
    91108    Item.Data := ListViewSort1.List[Item.Index];
    92109  end;
     
    228245      if FormContact.ShowModal = mrOK then begin
    229246        Contacts.Add(Contact);
     247        Core.DataFile.Modified := True;
     248        ReloadList;
     249        UpdateInterface;
     250        Contact := nil;
     251      end;
     252    finally
     253      if Assigned(Contact) then
     254        Contact.Free;
     255    end;
     256  finally
     257    FormContact.Free;
     258  end;
     259end;
     260
     261procedure TFormContacts.ACloneExecute(Sender: TObject);
     262var
     263  FormContact: TFormContact;
     264  Contact: TContact;
     265begin
     266  FormContact := TFormContact.Create(nil);
     267  try
     268    Contact := TContact.Create;
     269    try
     270      Contact.Assign(TContact(ListView1.Selected.Data));
     271      FormContact.Contact := Contact;
     272      FormContact.OnPrevious := FormContactPrevious;
     273      FormContact.OnNext := FormContactNext;
     274      if FormContact.ShowModal = mrOK then begin
     275        Contacts.Add(Contact);
    230276        Contact := nil;
    231277        Core.DataFile.Modified := True;
     
    250296  try
    251297    Contact := TContact.Create;
    252     Contact.Assign(TContact(ListView1.Selected.Data));
    253     FormContact.Contact := Contact;
    254     FormContact.OnPrevious := FormContactPrevious;
    255     FormContact.OnNext := FormContactNext;
    256298    try
     299      Contact.Assign(TContact(ListView1.Selected.Data));
     300      FormContact.Contact := Contact;
     301      FormContact.OnPrevious := FormContactPrevious;
     302      FormContact.OnNext := FormContactNext;
    257303      if FormContact.ShowModal = mrOK then begin
    258304        TContact(ListView1.Selected.Data).Assign(Contact);
Note: See TracChangeset for help on using the changeset viewer.