Changeset 73 for trunk/UCore.pas


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/UCore.pas

    r72 r73  
    1111
    1212type
    13 
    14   { TMergeResult }
    15 
    16   TMergeResult = record
    17     Loaded: Integer;
    18     New: Integer;
    19     Updated: Integer;
    20     procedure Clear;
    21     class operator Add(const A, B: TMergeResult): TMergeResult;
    22   end;
    2313
    2414  { TCore }
     
    3020    AGenerate: TAction;
    3121    AFindDuplicate: TAction;
    32     AFileMerge: TAction;
     22    AFileCombine: TAction;
    3323    ASettings: TAction;
    3424    AFileOpenRecent: TAction;
     
    5343    procedure AAboutExecute(Sender: TObject);
    5444    procedure AExitExecute(Sender: TObject);
    55     procedure AFileMergeExecute(Sender: TObject);
     45    procedure AFileCombineExecute(Sender: TObject);
    5646    procedure AFileNewExecute(Sender: TObject);
    5747    procedure AFileOpenExecute(Sender: TObject);
     
    9585    procedure FileOpen(FileName: string);
    9686    procedure FileClose;
    97     function FileMerge(FileName: string): TMergeResult;
    9887    procedure Initialize;
    9988    procedure UpdateInterface;
     
    118107  SFileSplitFinishedOpenDirectory = 'Total %d contact files saved. Do you want to open the directory %s?';
    119108  SFileNotFound = 'File ''%s'' not found.';
    120   SMergedContacts = 'Contacts merged. Loaded: %d, New: %d, Updated: %d';
     109  SCombinedContacts = 'Combined %d contact files.';
    121110  SLine = 'Line %d: %s';
    122111
    123 { TMergeResult }
    124 
    125 procedure TMergeResult.Clear;
    126 begin
    127   Loaded := 0;
    128   New := 0;
    129   Updated := 0;
    130 end;
    131 
    132 class operator TMergeResult.Add(const A, B: TMergeResult): TMergeResult;
    133 begin
    134   Result.Loaded := A.Loaded + B.Loaded;
    135   Result.New := A.New + B.New;
    136   Result.Updated := A.Updated + B.Updated;
    137 end;
    138 
    139112{ TCore }
    140113
     
    144117end;
    145118
    146 procedure TCore.AFileMergeExecute(Sender: TObject);
     119procedure TCore.AFileCombineExecute(Sender: TObject);
    147120var
    148121  TempFile: TDataFile;
    149122  I: Integer;
    150   MergeResult: TMergeResult;
    151   TotalMergeResult: TMergeResult;
     123  LoadedFiles: Integer;
    152124begin
    153125  TempFile := DefaultDataFileClass.Create;
     
    164136  OpenDialog1.Options := OpenDialog1.Options + [ofAllowMultiSelect];
    165137  if OpenDialog1.Execute then begin
    166     TotalMergeResult.Clear;
     138    LoadedFiles := 0;
    167139    for I := 0 to OpenDialog1.Files.Count - 1 do begin
    168       MergeResult := FileMerge(OpenDialog1.Files[I]);
    169       TotalMergeResult := TotalMergeResult + MergeResult;
     140      if FileExists(OpenDialog1.Files[I]) then begin
     141        TempFile := TContactsFile.Create;
     142        try
     143          TempFile.LoadFromFile(OpenDialog1.Files[I]);
     144          TContactsFile(DataFile).Contacts.AddContacts(TContactsFile(TempFile).Contacts);
     145          Inc(LoadedFiles);
     146        finally
     147          TempFile.Free;
     148        end;
     149      end;
    170150    end;
    171     ShowMessage(Format(SMergedContacts, [TotalMergeResult.Loaded,
    172       TotalMergeResult.New, TotalMergeResult.Updated]));
     151    if LoadedFiles > 0 then TContactsFile(DataFile).Modified := True;
     152    ShowMessage(Format(SCombinedContacts, [LoadedFiles]));
    173153    UpdateFile;
    174154  end;
     
    411391end;
    412392
    413 function TCore.FileMerge(FileName: string): TMergeResult;
    414 var
    415   TempFile: TContactsFile;
    416   NewContact: TContact;
    417   I: Integer;
    418 begin
    419   Result.Clear;
    420   if FileExists(FileName) then begin
    421     TempFile := TContactsFile.Create;
    422     try
    423       TempFile.LoadFromFile(FileName);
    424       Result.Loaded := TempFile.Contacts.Count;
    425       for I := 0 to TempFile.Contacts.Count - 1 do begin
    426         NewContact := TContactsFile(DataFile).Contacts.Search(TempFile.Contacts[I].Fields[cfFullName]);
    427         if not Assigned(NewContact) then begin
    428           NewContact := TContact.Create;
    429           NewContact.Assign(TempFile.Contacts[I]);
    430           NewContact.Parent := TContactsFile(DataFile);
    431           TContactsFile(DataFile).Contacts.Add(NewContact);
    432           Inc(Result.New);
    433         end else begin
    434           if NewContact.UpdateFrom(TempFile.Contacts[I]) then
    435             Inc(Result.Updated);
    436         end;
    437       end;
    438       TContactsFile(DataFile).Modified := True;
    439     finally
    440       TempFile.Free;
    441     end;
    442   end else ShowMessage(Format(SFileNotFound, [FileName]));
    443 end;
    444 
    445393procedure TCore.FileNew;
    446394begin
     
    540488  AFileClose.Enabled := Assigned(DataFile);
    541489  AFileSplit.Enabled := Assigned(DataFile);
    542   AFileMerge.Enabled := Assigned(DataFile);
     490  AFileCombine.Enabled := Assigned(DataFile);
    543491  AFindDuplicate.Enabled := Assigned(DataFile);
    544492  AGenerate.Enabled := Assigned(DataFile);
Note: See TracChangeset for help on using the changeset viewer.