From c139c799d1ccdb515865d339b56ecc4ca6593256 Mon Sep 17 00:00:00 2001 From: David Smith Date: Fri, 4 Sep 2015 17:09:22 -0500 Subject: [PATCH] When merging ranked votes of different ranks, instead of merging the votes, the text of the 'from' vote is changed to be the text of the destination vote. Track vote list before and after the merge, to allow re-adding the newly changed vote to the display list. --- NetTally/MergeVotesWindow.xaml.cs | 11 +++++++++++ TallyCore/VoteCounter.cs | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/NetTally/MergeVotesWindow.xaml.cs b/NetTally/MergeVotesWindow.xaml.cs index fd26e1d3..f442d409 100644 --- a/NetTally/MergeVotesWindow.xaml.cs +++ b/NetTally/MergeVotesWindow.xaml.cs @@ -225,9 +225,20 @@ private void merge_Click(object sender, RoutedEventArgs e) try { + var votesPrior = VoteCounter.GetVotesCollection(CurrentVoteType).Keys.ToList(); + if (VoteCounter.Merge(fromVote, toVote, CurrentVoteType)) { + var votesAfter = VoteCounter.GetVotesCollection(CurrentVoteType).Keys.ToList(); + var votesDiff = votesAfter.Except(votesPrior); + VoteCollection.Remove(fromVote); + if (votesDiff.Count() == 1) + { + VoteCollection.Add(votesDiff.First()); + } + + VoterView1.Refresh(); VoterView2.Refresh(); } diff --git a/TallyCore/VoteCounter.cs b/TallyCore/VoteCounter.cs index fe0489ba..9cf224b1 100644 --- a/TallyCore/VoteCounter.cs +++ b/TallyCore/VoteCounter.cs @@ -192,6 +192,22 @@ public bool Merge(string fromVote, string toVote, VoteType voteType) if (!votesSet.TryGetValue(toVote, out toVoters)) throw new ArgumentException(nameof(toVote) + " does not exist."); + if (voteType == VoteType.Rank) + { + string markFrom = VoteString.GetVoteMarker(fromVote); + string markTo = VoteString.GetVoteMarker(toVote); + + // If ranked votes are being merged, but of different ranks, the "to" vote will simply be a text change + if (markFrom != markTo) + { + string toContent = VoteString.GetVoteContent(toVote); + string revisedFrom = VoteString.ModifyVoteLine(fromVote, content: toContent); + Rename(fromVote, revisedFrom, voteType); + return true; + } + } + + toVoters.UnionWith(fromVoters); votesSet.Remove(fromVote);