示例#1
0
 public void SetCurrentAsSaveState()
 {
     if (undoList.Count > 0)
     {
         lastSaveState = undoList.Last();
     }
 }
示例#2
0
        // return reversed command for Undo. Redo is not reversed
        static public UndoableCommand GetReversedForUndo(UndoableCommand command)
        {
            UndoableCommand reversed = null;

            if (command.type == UndoableCommandType.InsertComponent)
            {
                reversed      = command.Clone() as UndoableCommand;
                reversed.type = UndoableCommandType.DeleteComponent;
            }
            else if (command.type == UndoableCommandType.DeleteComponent)
            {
                reversed      = command.Clone() as UndoableCommand;
                reversed.type = UndoableCommandType.InsertComponent;
            }
            else if (command.type == UndoableCommandType.ChangeComponentProperty)
            {
                reversed = UndoableCommand_Property.GetReversed(command as UndoableCommand_Property);
            }
            else if (command.type == UndoableCommandType.RoutedCommand)
            {
                reversed = UndoableCommand_Routed.GetReversed(command as UndoableCommand_Routed);
            }
            else
            {
                throw new Exception(String.Format("Command type {0} cannot be reversed", command.type));
            }
            return(reversed);
        }
示例#3
0
        public UndoableCommand Redo()
        {
            if (redoList.Count == 0)
            {
                return(null);
            }

            UndoableCommand command = redoList.Last();

            redoList.RemoveLast();
            // when Redoing, push the command back to Undo list
            undoList.AddLast(command);
            CommandManager.InvalidateRequerySuggested();
            return(command);
        }
示例#4
0
 public void PushCommand(UndoableCommand command)
 {
     undoList.AddLast(command);
     if (undoList.Count > MAX_STATES)
     {
         // if over capacity, remove old command
         if (lastSaveState != null && undoList.First() == lastSaveState)
         {
             lastSaveState = null;
         }
         undoList.RemoveFirst();
     }
     // when pushing a command, the redo list always becomes empty
     redoList.Clear();
     CommandManager.InvalidateRequerySuggested();
 }