Skip to content

Commit

Permalink
Merge spouses when merge family
Browse files Browse the repository at this point in the history
  • Loading branch information
hazzik committed Nov 7, 2023
1 parent 3a50d77 commit 05a5912
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
24 changes: 18 additions & 6 deletions projects/GKCore/GDModel/GDMFamilyRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,32 @@ public override void MoveTo(GDMRecord targetRecord)

base.MoveTo(targetRecord);

targetFamily.RemoveSpouse(fTree.GetPtrValue<GDMIndividualRecord>(targetFamily.Husband));
targetFamily.Husband.XRef = fHusband.XRef;
MoveSpouse(fTree, targetFamily, fHusband, targetFamily.Husband);
MoveSpouse(fTree, targetFamily, fWife, targetFamily.Wife);

targetFamily.RemoveSpouse(fTree.GetPtrValue<GDMIndividualRecord>(targetFamily.Wife));
targetFamily.Wife.XRef = fWife.XRef;

targetFamily.Status = fStatus;
if (fStatus != GDMMarriageStatus.Unknown) {
targetFamily.Status = fStatus;
}

while (fChildren.Count > 0) {
var obj = fChildren.Extract(0);
targetFamily.Children.Add(obj);
}
}

private void MoveSpouse(GDMTree tree, GDMFamilyRecord targetFamily, GDMPointer from, GDMPointer to)
{
var fromSpouse = tree.GetPtrValue<GDMIndividualRecord>(from);
var toSpouse = tree.GetPtrValue<GDMIndividualRecord>(to);
RemoveSpouse(fromSpouse);
if (toSpouse == null) {
targetFamily.AddSpouse(fromSpouse);
} else if (fromSpouse != null && !ReferenceEquals(fromSpouse, toSpouse)) {
fromSpouse.MoveTo(toSpouse);
tree.DeleteRecord(fromSpouse);
}
}

public override void ReplaceXRefs(GDMXRefReplacer map)
{
base.ReplaceXRefs(map);
Expand Down
2 changes: 1 addition & 1 deletion projects/GKCore/GDModel/GDMTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public void SetXRef(string oldXRef, GDMRecord record, bool removeOldXRef)

public List<T> GetRecords<T>() where T : GDMRecord
{
List<T> result = new List<T>();
List<T> result = new List<T>(fRecords.Count);

for (int i = 0; i < fRecords.Count; i++) {
T rec = fRecords[i] as T;
Expand Down
22 changes: 11 additions & 11 deletions projects/GKCore/GKCore/Tools/TreeTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,22 +380,22 @@ public static void MergeRecord(IBaseWindow baseWin, GDMRecord targetRec, GDMReco
using (var repMap = new GDMXRefReplacer()) {
repMap.AddXRef(sourceRec, sourceRec.XRef, targetRec.XRef);

GDMTree tree = baseWin.Context.Tree;
int num = tree.RecordsCount;
for (int i = 0; i < num; i++) {
tree[i].ReplaceXRefs(repMap);
}

sourceRec.MoveTo(targetRec);
baseWin.Context.DeleteRecord(sourceRec);

if (targetRec.RecordType == GDMRecordType.rtIndividual && bookmark) {
((GDMIndividualRecord)targetRec).Bookmark = true;
int num = baseWin.Context.Tree.RecordsCount;
for (int i = 0; i < num; i++) {
baseWin.Context.Tree[i].ReplaceXRefs(repMap);
}

baseWin.NotifyRecord(targetRec, RecordAction.raEdit);
baseWin.RefreshLists(false);
baseWin.Context.Tree.DeleteRecord(sourceRec);
}

if (targetRec.RecordType == GDMRecordType.rtIndividual && bookmark) {
((GDMIndividualRecord)targetRec).Bookmark = true;
}

baseWin.NotifyRecord(targetRec, RecordAction.raEdit);
baseWin.RefreshLists(false);
}

#endregion
Expand Down

0 comments on commit 05a5912

Please sign in to comment.