Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge spouses when merge family #512

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading