RecordAction() public method

Central method to add and execute a new action.
public RecordAction ( IAction action ) : void
action IAction
return void
Esempio n. 1
0
 public static void Execute(this ActionManager actionManager, IAction action)
 {
     if (actionManager == null)
     {
         action.Execute();
     }
     else
     {
         actionManager.RecordAction(action);
     }
 }
Esempio n. 2
0
 public void SetPropertyActionWorks()
 {
     var instance = new Exception();
     SetPropertyAction action = new SetPropertyAction(instance, "Source", "foo");
     ActionManager am = new ActionManager();
     am.RecordAction(action);
     Assert.AreEqual("foo", instance.Source);
     am.Undo();
     Assert.AreEqual(null, instance.Source);
     am.Redo();
     Assert.AreEqual("foo", instance.Source);
 }
Esempio n. 3
0
 public void AddItemActionWorks()
 {
     List<string> list = new List<string>();
     AddItemAction<string> action = new AddItemAction<string>(list.Add, s => list.Remove(s), "foo");
     ActionManager am = new ActionManager();
     am.RecordAction(action);
     Assert.AreEqual("foo", list[0]);
     am.Undo();
     Assert.AreEqual(0, list.Count);
     am.Redo();
     Assert.AreEqual("foo", list[0]);
 }
Esempio n. 4
0
 public void CallMethodActionWorks()
 {
     bool capturedFlag = false;
     ActionManager am = new ActionManager();
     CallMethodAction action = new CallMethodAction(
         () => capturedFlag = true,
         () => capturedFlag = false);
     am.RecordAction(action);
     Assert.IsTrue(capturedFlag);
     am.Undo();
     Assert.IsFalse(capturedFlag);
     am.Redo();
     Assert.IsTrue(capturedFlag);
 }
Esempio n. 5
0
 public static void SetFocus(this Block toFocus, SetFocusOptions options, ActionManager actionManager)
 {
     SetFocusAction action = new SetFocusAction(toFocus, options);
     actionManager.RecordAction(action);
 }
Esempio n. 6
0
 public void ThrowingActionInsideTransactionWillRollback()
 {
     ActionManager am = new ActionManager();
     var log = new LogAction();
     var throwing = new ThrowingAction();
     try
     {
         using (Transaction.Create(am))
         {
             am.RecordAction(log);
             am.RecordAction(throwing);
         }
     }
     catch (NotImplementedException)
     {
     }
     Assert.AreEqual(0, log.ExecutesCount);
     Assert.AreEqual(0, log.UnexecutesCount);
     Assert.AreEqual(0, am.TransactionStack.Count);
     Assert.AreEqual(false, am.ActionIsExecuting);
 }