Changeset 62 for trunk/UCore.pas


Ignore:
Timestamp:
Dec 9, 2021, 10:53:52 PM (3 years ago)
Author:
chronos
Message:
  • Added: New feature to split multiple contacts into separate files. Accessible from File menu.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r56 r62  
    2727    AAbout: TAction;
    2828    AboutDialog1: TAboutDialog;
     29    AFileSplit: TAction;
    2930    AGenerate: TAction;
    3031    AFindDuplicate: TAction;
     
    4142    ActionList1: TActionList;
    4243    ApplicationInfo1: TApplicationInfo;
     44    SelectDirectoryDialog1: TSelectDirectoryDialog;
    4345    Translator: TTranslator;
    4446    ImageList1: TImageList;
     
    5860    procedure AFileSaveAsExecute(Sender: TObject);
    5961    procedure AFileCloseExecute(Sender: TObject);
     62    procedure AFileSplitExecute(Sender: TObject);
    6063    procedure AFindDuplicateExecute(Sender: TObject);
    6164    procedure AGenerateExecute(Sender: TObject);
     
    7073    LoadErrors: string;
    7174    ProfileImage: TImage;
     75    LastSplitDir: string;
    7276    procedure FileModified(Sender: TObject);
    7377    function FindFirstNonOption: string;
     
    108112  SAppExit = 'Application exit';
    109113  SAppExitQuery = 'File was modified. Do you want to save it before exit?';
     114  SFileSplit = 'Contacts split';
     115  SFileSplitFinishedOpenDirectory = 'Total %d contact files saved. Do you want to open the directory %s?';
    110116  SFileNotFound = 'File ''%s'' not found.';
    111117  SMergedContacts = 'Contacts merged. Loaded: %d, New: %d, Updated: %d';
     
    175181  FileClose;
    176182  UpdateFile;
     183end;
     184
     185procedure TCore.AFileSplitExecute(Sender: TObject);
     186var
     187  I: Integer;
     188  C: Integer;
     189  FileName: string;
     190  ModalResult: TModalResult;
     191begin
     192  C := 0;
     193  SelectDirectoryDialog1.FileName := LastSplitDir;
     194  if SelectDirectoryDialog1.Execute then begin
     195    LastSplitDir := SelectDirectoryDialog1.FileName;
     196    with TContactsFile(DataFile).Contacts do
     197    for I := 0 to Count - 1 do begin
     198      if Items[I].Fields[cfFullName] <> '' then begin
     199        FileName := SelectDirectoryDialog1.FileName + DirectorySeparator +
     200          Items[I].Fields[cfFullName] + VCardFileExt;
     201        Items[I].SaveToFile(FileName);
     202        Inc(C);
     203      end;
     204    end;
     205    ModalResult := MessageDlg(SFileSplit,
     206     Format(SFileSplitFinishedOpenDirectory, [C,
     207     SelectDirectoryDialog1.FileName]), mtConfirmation, [mbYes, mbNo], 0);
     208    if ModalResult = mrYes then begin
     209      {$IFDEF WINDOWS}
     210      ExecuteProgram('explorer.exe', ['"' + SelectDirectoryDialog1.FileName + '"']);
     211      {$ENDIF}
     212    end;
     213  end;
    177214end;
    178215
     
    434471    LastContactTabIndex := ReadIntegerWithDefault('LastContactTabIndex', 0);
    435472    LastContactFileName := ReadStringWithDefault('LastContactFileName', '');
     473    LastSplitDir := ReadStringWithDefault('LastSplitDir', '');
    436474  finally
    437475    Free;
     
    457495    WriteInteger('LastContactTabIndex', LastContactTabIndex);
    458496    WriteString('LastContactFileName', LastContactFileName);
     497    WriteString('LastSplitDir', LastSplitDir);
    459498  finally
    460499    Free;
     
    484523  AFileSaveAs.Enabled := Assigned(DataFile);
    485524  AFileClose.Enabled := Assigned(DataFile);
     525  AFileSplit.Enabled := Assigned(DataFile);
     526  AFileMerge.Enabled := Assigned(DataFile);
    486527end;
    487528
Note: See TracChangeset for help on using the changeset viewer.