Ignore:
Timestamp:
Dec 8, 2021, 2:02:17 PM (3 years ago)
Author:
chronos
Message:
  • Added: Allow to load from file or save to file individual selected contacts from the list.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormContacts.pas

    r52 r53  
    1616    AAdd: TAction;
    1717    AClone: TAction;
     18    ALoadFromFile: TAction;
     19    ASaveToFile: TAction;
    1820    ASelectAll: TAction;
    1921    ARemove: TAction;
     
    2830    MenuItem4: TMenuItem;
    2931    MenuItem5: TMenuItem;
     32    MenuItem6: TMenuItem;
     33    MenuItem7: TMenuItem;
     34    MenuItem8: TMenuItem;
     35    OpenDialog1: TOpenDialog;
    3036    PopupMenuContact: TPopupMenu;
     37    SaveDialog1: TSaveDialog;
    3138    StatusBar1: TStatusBar;
    3239    ToolBar1: TToolBar;
     
    3542    ToolButton3: TToolButton;
    3643    ToolButton4: TToolButton;
     44    ToolButton5: TToolButton;
     45    ToolButton6: TToolButton;
     46    ToolButton7: TToolButton;
    3747    procedure AAddExecute(Sender: TObject);
    3848    procedure ACloneExecute(Sender: TObject);
     49    procedure ALoadFromFileExecute(Sender: TObject);
    3950    procedure AModifyExecute(Sender: TObject);
    4051    procedure ARemoveExecute(Sender: TObject);
     52    procedure ASaveToFileExecute(Sender: TObject);
    4153    procedure ASelectAllExecute(Sender: TObject);
    4254    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     
    314326end;
    315327
     328procedure TFormContacts.ALoadFromFileExecute(Sender: TObject);
     329var
     330  TempFile: TContactsFile;
     331begin
     332  if Assigned(ListView1.Selected) then begin
     333    TempFile := TContactsFile.Create;
     334    try
     335      OpenDialog1.Filter := TempFile.GetFileFilter;
     336      OpenDialog1.DefaultExt := TempFile.GetFileExt;
     337    finally
     338      TempFile.Free;
     339    end;
     340    OpenDialog1.InitialDir := ExtractFileDir(Core.LastContactFileName);
     341    OpenDialog1.FileName := ExtractFileName(Core.LastContactFileName);
     342    if OpenDialog1.Execute then begin
     343      TContact(ListView1.Selected.Data).LoadFromFile(OpenDialog1.FileName);
     344      Core.LastContactFileName := OpenDialog1.FileName;
     345      ReloadList;
     346    end;
     347  end;
     348end;
     349
    316350procedure TFormContacts.AModifyExecute(Sender: TObject);
    317351var
     
    359393end;
    360394
     395procedure TFormContacts.ASaveToFileExecute(Sender: TObject);
     396var
     397  TempFile: TContactsFile;
     398begin
     399  if Assigned(ListView1.Selected) then begin
     400    TempFile := TContactsFile.Create;
     401    try
     402      SaveDialog1.Filter := TempFile.GetFileFilter;
     403      SaveDialog1.DefaultExt := TempFile.GetFileExt;
     404    finally
     405      TempFile.Free;
     406    end;
     407    SaveDialog1.InitialDir := ExtractFileDir(Core.LastContactFileName);
     408    SaveDialog1.FileName := TContact(ListView1.Selected.Data).Fields[cfFullName] +
     409      VCardFileExt;
     410    if SaveDialog1.Execute then begin
     411      TContact(ListView1.Selected.Data).SaveToFile(SaveDialog1.FileName);
     412      Core.LastContactFileName := SaveDialog1.FileName;
     413    end;
     414  end;
     415end;
     416
    361417procedure TFormContacts.ASelectAllExecute(Sender: TObject);
    362418var
     
    409465begin
    410466  if FUpdateCount = 0 then DoUpdateInterface;
     467  ALoadFromFile.Enabled := Assigned(ListView1.Selected);
     468  ASaveToFile.Enabled := Assigned(ListView1.Selected);
     469  AModify.Enabled := Assigned(ListView1.Selected);
     470  AClone.Enabled := Assigned(ListView1.Selected);
     471  ARemove.Enabled := Assigned(ListView1.Selected);
     472  ASelectAll.Enabled := ListView1.Items.Count > 0;
    411473end;
    412474
Note: See TracChangeset for help on using the changeset viewer.