Ejemplo n.º 1
0
        public void Undo()
        {
            if (!history.CanUndo)
            {
                return;
            }
            HistoryAction action = history.Undo();

            action.Undo(this);
        }
Ejemplo n.º 2
0
        public void Redo()
        {
            if (!history.CanRedo)
            {
                return;
            }
            HistoryAction action = history.Redo();

            action.Redo(this);
        }
Ejemplo n.º 3
0
        public HistoryAction Redo()
        {
            if (!CanRedo)
            {
                throw new Exception("Cannot redo.");
            }
            HistoryAction action = redoStack.Pop();

            undoStack.Push(action);
            return(action);
        }
Ejemplo n.º 4
0
        public void Add(HistoryAction action)
        {
            if (!isActive)
            {
                return;
            }

            if (!TryMerge(action))
            {
                undoStack.Push(action);
            }

            redoStack.Clear();
        }
Ejemplo n.º 5
0
 private bool TryMerge(HistoryAction action)
 {
     if (!(action is IMergable))
     {
         return(false);
     }
     if (undoStack.Count == 0)
     {
         return(false);
     }
     if (!(undoStack.Peek() is IMergable))
     {
         return(false);
     }
     return((undoStack.Peek() as IMergable).Merge(action));
 }
        public bool Merge(HistoryAction action)
        {
            if (!(action is TextAction))
            {
                return(false);
            }
            TextAction newAction = (action as TextAction);

            if (this.ActiveSheet != newAction.ActiveSheet)
            {
                return(false);
            }
            if (this.RowNumber != newAction.RowNumber)
            {
                return(false);
            }

            if (this.isTyping && newAction.isTyping &&
                this.typingAtIndex + 1 == newAction.typingAtIndex &&                 //typing continues from same position
                this.NewText[typingAtIndex] != ' ')                    //break action at space
            {
                this.NewText       = newAction.NewText;
                this.typingAtIndex = newAction.typingAtIndex;
                return(true);
            }

            if (this.isDeleting && newAction.isDeleting &&
                this.deletingAtIndex - 1 == newAction.deletingAtIndex &&                 //deleting continues from same position
                this.PreviousText[deletingAtIndex] != ' ')                    //break action at space
            {
                this.NewText         = newAction.NewText;
                this.deletingAtIndex = newAction.deletingAtIndex;
                return(true);
            }

            return(false);
        }