示例#1
0
    public void AddUndoRedoAction(IUndoRedoAction action)
    {
        if (enableUndoRedo == 0)
        {
            if (isInApplyUndo)
            {
                Message.Show("Nested ApplyDoUndo calls! This is bad!", "Undo Redo borked", "Ok");
                action.Do();
                return;
            }

            isInApplyUndo = true;

            action.Do();

            RedoStack.Clear();

            if (UndoStack.Count > 0)
            {
                var lastGroup = UndoStack.Peek();

                var currentTime = DateTime.Now;
                var diff        = (currentTime - lastGroup.LastActionTime).TotalMilliseconds;

                if (diff <= GroupingMS)
                {
                    lastGroup.Actions.Add(action);
                    lastGroup.LastActionTime = currentTime;
                }
                else
                {
                    var group = new UndoRedoGroup();
                    group.Actions.Add(action);
                    group.LastActionTime = currentTime;
                    UndoStack.Push(group);
                }
            }
            else
            {
                var group = new UndoRedoGroup();
                group.Actions.Add(action);
                group.LastActionTime = DateTime.Now;
                UndoStack.Push(group);
            }

            RaisePropertyChangedEvent("IsModified");
            RaisePropertyChangedEvent("CanUndo");
            RaisePropertyChangedEvent("CanRedo");
            RaisePropertyChangedEvent("DescriptionStack");

            isInApplyUndo = false;
        }
        else
        {
            action.Do();
        }
    }
示例#2
0
 /// <summary>
 /// Do the given action for the first time.  This method will call the Do() method on he action.
 /// </summary>
 /// <param name="action">The action to do.  The Do() method will be called</param>
 public void Do(IUndoRedoAction action)
 {
     action.Do();
     undoStack.Push(action);
     redoStack.Clear();
 }
示例#3
0
 /// <summary>
 /// Do the given action for the first time.  This method will call the Do() method on he action.
 /// </summary>
 /// <param name="action">The action to do.  The Do() method will be called</param>
 public void Do(IUndoRedoAction action)
 {
     action.Do();
     Done(action);
 }