Пример #1
0
 private bool CanMerge(HistoryPoint newPoint, Stack<HistoryPoint> undostack, TimeSpan mergeTime)
 {
     if (!undostack.Any())
         return false;
     var hp = undostack.Peek();
     if (!ReferenceEquals(hp.Control, newPoint.Control))
         return false;
     var dt = newPoint.Timestamp - hp.Timestamp;
     return dt < mergeTime;
 }
Пример #2
0
 private void Merge(HistoryPoint newPoint, Stack<HistoryPoint> undostack, TimeSpan mergeTime)
 {
     if (!CanMerge(newPoint, undostack, mergeTime))
         throw new InvalidOperationException("Cannot merge call CanMerge() before");
     var hp = undostack.Pop();
     undostack.Push(newPoint);
 }
Пример #3
0
 internal void Update(HistoryPoint historyPoint)
 {
     var cv = _undoStack.FirstOrDefault(x => x.UpdateReason != UpdateReason.DataUpdated && ReferenceEquals(x.Control, historyPoint.Control));
     if (cv != null && Equals(cv.Value, historyPoint.Value))
         return;
     if (_redoStack.Any())
     {
         HistoryPoint redoPoint = _redoStack.Peek();
         if (ReferenceEquals(redoPoint.Control, historyPoint.Control) && Equals(redoPoint.Value, historyPoint.Value))
             return;
     }
     if (CanMerge(historyPoint, UndoStack, _mergeTime))
     {
         Merge(historyPoint, UndoStack, _mergeTime);
         return;
     }
     _undoStack.Push(historyPoint);
     _redoStack.Clear();
     OnOnChanged();
 }