/// <summary> /// Run any stored merges on the current data. /// </summary> public void RunMergeActions() { if (Quest != null) { var recordedMerges = UserMerges.GetMergeRecordList(Quest.PartitionMode); foreach (var mergeData in recordedMerges) { if (mergeData.UndoActionType == UndoActionType.ReplaceTask) { UndoBuffer.Push(new UndoAction(mergeData.UndoActionType, VoteStorage, storageVote: mergeData.FromVote)); } else { UndoBuffer.Push(new UndoAction(mergeData.UndoActionType, VoteStorage)); } if (mergeData.UndoActionType == UndoActionType.Split && mergeData.ToVotes.Count > 0) { SplitImplWrapper(mergeData.FromVote, mergeData.ToVotes); } else if (mergeData.UndoActionType == UndoActionType.ReplaceTask) { ReplaceTaskImplWrapper(mergeData.FromVote, mergeData.ToVote.Task); } else { MergeImplWrapper(mergeData.FromVote, mergeData.ToVote); } } } }
/// <summary> /// Undoes the most recently performed modification to the vote count. /// </summary> /// <returns>Returns true if it performed an undo action. Otherwise, false.</returns> public bool Undo() { if (!HasUndoActions) { return(false); } if (Quest is null) { throw new InvalidOperationException("Quest is null."); } UndoAction undoAction = UndoBuffer.Pop(); UserMerges.RemoveLastMergeRecord(Quest.PartitionMode, undoAction.ActionType); if (undoAction.Undo(this)) { OnPropertyChanged("Votes"); OnPropertyChanged("Voters"); OnPropertyChanged(nameof(HasUndoActions)); return(true); } return(false); }
/// <summary> /// Merge the vote supporters from one vote into several other votes. /// </summary> /// <param name="fromVote">The originating vote.</param> /// <param name="toVotes">The destination votes.</param> /// <returns>Returns true if successfully completed.</returns> public bool Split(VoteLineBlock fromVote, List <VoteLineBlock> toVotes) { UndoBuffer.Push(new UndoAction(UndoActionType.Split, VoteStorage)); UserMerges.AddMergeRecord(fromVote, toVotes, UndoActionType.Split, Quest !.PartitionMode); bool merged = SplitImplWrapper(fromVote, toVotes); if (merged) { OnPropertyChanged("Votes"); OnPropertyChanged("Voters"); OnPropertyChanged(nameof(HasUndoActions)); } else { UndoBuffer.Pop(); } return(merged); }
/// <summary> /// Replace the task on the provided vote with the requested task. /// </summary> /// <param name="vote">The vote to update the task on.</param> /// <param name="task">The new task label.</param> /// <returns>Returns true if the task was updated.</returns> public bool ReplaceTask(VoteLineBlock vote, string task) { if (StringComparer.OrdinalIgnoreCase.Equals(vote.Task, task)) { return(false); } UndoBuffer.Push(new UndoAction(UndoActionType.ReplaceTask, VoteStorage, vote)); VoteLineBlock originalVote = vote.Clone(); if (ReplaceTaskImplWrapper(vote, task)) { UserMerges.AddMergeRecord(originalVote, vote, UndoActionType.ReplaceTask, Quest !.PartitionMode); OnPropertyChanged("Votes"); OnPropertyChanged(nameof(HasUndoActions)); return(true); } UndoBuffer.Pop(); return(false); }
/// <summary> /// Reset any merges the user has made. /// </summary> public void ResetUserMerges() { UserMerges.Reset(); }