This is a sample action that can change any property on any object It can also undo what it did
Inheritance: AbstractAction
Exemplo n.º 1
0
        /// <summary>
        /// Subsequent changes of the same property on the same object are consolidated into one action
        /// </summary>
        /// <param name="followingAction">Subsequent action that is being recorded</param>
        /// <returns>true if it agreed to merge with the next action,
        /// false if the next action should be recorded separately</returns>
        public override bool TryToMerge(IAction followingAction)
        {
            SetPropertyAction next = followingAction as SetPropertyAction;

            if (next != null && next.ParentObject == this.ParentObject && next.Property == this.Property)
            {
                Value = next.Value;
                Property.SetValue(ParentObject, Value, null);
                return(true);
            }
            return(false);
        }
Exemplo 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);
 }
Exemplo n.º 3
0
        public static void SetProperty(this ActionManager actionManager, object instance, string propertyName, object value)
        {
            SetPropertyAction action = new SetPropertyAction(instance, propertyName, value);

            Execute(actionManager, action);
        }
Exemplo n.º 4
0
 /// <summary>
 /// API to update the object model from the UI
 /// Creates an action and registers it with the action manager
 /// This is the interesting part of the demo
 /// </summary>
 void SetProperty(string propertyName, object propertyValue)
 {
     if (reentrancyGuard)
     {
         return;
     }
     SetPropertyAction action = new SetPropertyAction(joe, propertyName, propertyValue);
     actionManager.RecordAction(action);
     UpdateUndoRedoButtons();
 }