Exemplo n.º 1
0
 /// <summary>
 /// Add an undo state to the current stage (if one is active) or directly
 /// to the stack as a new stage (if one isn't).
 /// </summary>
 /// <param name="state"></param>
 /// <param name="clearRedo">If true, the redo stack will be invalidated</param>
 public void AddUndoState(UndoState state, bool clearRedo = true)
 {
     if (!Locked && Active)
     {
         if (state != null && state.IsValid)
         {
             if (ActiveStage != null)// && !ActiveStage.Contains(state))
             {
                 ActiveStage.Add(state);
                 if (!UndoStack.Contains(ActiveStage))
                 {
                     AddUndoStage(ActiveStage);
                 }
             }
             else
             {
                 UndoStage stage = new UndoStage();
                 stage.Add(state);
                 AddUndoStage(stage);
             }
         }
         if (clearRedo)
         {
             RedoStack.Clear();
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Revert this stage by restoring the states stored
 /// within this collection
 /// </summary>
 /// <returns>The redo stage necessary to redo this undo.</returns>
 public UndoStage Undo()
 {
     var redo = new UndoStage();
     for (int i = Count - 1; i >= 0; i--)
     {
         UndoState state = this[i];
         if (state.IsValid)
         {
             try
             {
                 redo.Add(state.GenerateRedo());
                 state.Restore();
             }
             catch { }
             
         }
     }
     return redo;
 }