/// <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); }
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); }
public static void SetProperty(this ActionManager actionManager, object instance, string propertyName, object value) { SetPropertyAction action = new SetPropertyAction(instance, propertyName, value); Execute(actionManager, action); }
/// <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(); }