Ignore:
Timestamp:
Dec 13, 2021, 11:33:11 PM (3 years ago)
Author:
chronos
Message:
  • Added: Copy, cut and paste context menu action in contacts list.
  • Modified: Merge multiple files action replaced by Combine action. During Combine action files are simply added into final contacts list even with duplicate contacts.
  • Modified: Added Merge button into Find duplicate window to merge contacts by selected contact field.
  • Modified: Show only used contact fields in Find duplicates window.
  • Fixed: Wrong items were removed if contacts and properties lists were in filtered state.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormContacts.pas

    r72 r73  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, Menus, ActnList, UContact, UListViewSort, fgl, LazUTF8;
     9  ComCtrls, Menus, ActnList, UContact, UListViewSort, fgl, LazUTF8, Clipbrd;
    1010
    1111type
     
    1616    AAdd: TAction;
    1717    AClone: TAction;
     18    ACopy: TAction;
     19    ACut: TAction;
     20    APaste: TAction;
    1821    ALoadFromFile: TAction;
    1922    ASaveToFile: TAction;
     
    2629    ListViewSort1: TListViewSort;
    2730    MenuItem1: TMenuItem;
     31    MenuItem10: TMenuItem;
     32    MenuItem11: TMenuItem;
     33    MenuItem12: TMenuItem;
    2834    MenuItem2: TMenuItem;
    2935    MenuItem3: TMenuItem;
     
    3339    MenuItem7: TMenuItem;
    3440    MenuItem8: TMenuItem;
     41    MenuItem9: TMenuItem;
    3542    OpenDialog1: TOpenDialog;
    3643    PopupMenuContact: TPopupMenu;
     
    4754    procedure AAddExecute(Sender: TObject);
    4855    procedure ACloneExecute(Sender: TObject);
     56    procedure ACopyExecute(Sender: TObject);
     57    procedure ACutExecute(Sender: TObject);
    4958    procedure ALoadFromFileExecute(Sender: TObject);
    5059    procedure AModifyExecute(Sender: TObject);
     60    procedure APasteExecute(Sender: TObject);
    5161    procedure ARemoveExecute(Sender: TObject);
    5262    procedure ASaveToFileExecute(Sender: TObject);
     
    334344end;
    335345
     346procedure TFormContacts.ACopyExecute(Sender: TObject);
     347var
     348  Text: string;
     349  Strings: TStringList;
     350  I: Integer;
     351begin
     352  Strings := TStringList.Create;
     353  try
     354  Text := '';
     355  for I := 0 to ListView1.Items.Count - 1 do
     356    if ListView1.Items[I].Selected then begin
     357      TContact(ListView1.Items[I].Data).SaveToStrings(Strings);
     358      Text := Text + Strings.Text;
     359    end;
     360    Clipboard.AsText := Text;
     361  finally
     362    Strings.Free;
     363  end;
     364end;
     365
     366procedure TFormContacts.ACutExecute(Sender: TObject);
     367var
     368  Text: string;
     369  Strings: TStringList;
     370  I: Integer;
     371begin
     372  Strings := TStringList.Create;
     373  try
     374    Text := '';
     375    for I := 0 to ListView1.Items.Count - 1 do
     376      if ListView1.Items[I].Selected then begin
     377        TContact(ListView1.Items[I].Data).SaveToStrings(Strings);
     378        Text := Text + Strings.Text;
     379      end;
     380    Clipboard.AsText := Text;
     381    for I := 0 to ListView1.Items.Count - 1 do
     382      if ListView1.Items[I].Selected then begin
     383        Contacts.Delete(Contacts.IndexOf(ListView1.Items[I].Data));
     384      end;
     385    ReloadList;
     386    ListView1.ClearSelection;
     387    UpdateInterface;
     388  finally
     389    Strings.Free;
     390  end;
     391end;
     392
    336393procedure TFormContacts.ALoadFromFileExecute(Sender: TObject);
    337394var
     
    384441end;
    385442
     443procedure TFormContacts.APasteExecute(Sender: TObject);
     444var
     445  PasteContacts: TContactsFile;
     446  Lines: TStringList;
     447begin
     448  PasteContacts := TContactsFile.Create;
     449  Lines := TStringList.Create;
     450  try
     451    Lines.Text := Clipboard.AsText;
     452    PasteContacts.LoadFromStrings(Lines);
     453    if PasteContacts.Contacts.Count > 0 then begin
     454      if Assigned(ListView1.Selected) then begin
     455        Contacts.InsertContacts(Contacts.IndexOf(ListView1.Selected.Data),
     456          PasteContacts.Contacts);
     457      end else Contacts.AddContacts(PasteContacts.Contacts);
     458      Core.DataFile.Modified := True;
     459      ReloadList;
     460      UpdateInterface;
     461    end;
     462  finally
     463    Lines.Free;
     464    PasteContacts.Free;
     465  end;
     466end;
     467
    386468procedure TFormContacts.ARemoveExecute(Sender: TObject);
    387469var
     
    393475    for I := ListView1.Items.Count - 1 downto 0 do
    394476      if ListView1.Items[I].Selected then begin
    395         Contacts.Delete(I);
     477        Contacts.Delete(Contacts.IndexOf(ListView1.Items[I].Data));
    396478      end;
    397479    Core.DataFile.Modified := True;
Note: See TracChangeset for help on using the changeset viewer.