Exemple #1
0
        /// <summary>
        /// Construct a Change instance with actions for undo / redo.
        /// </summary>
        /// <param name="instance">The instance that changed.</param>
        /// <param name="propertyName">The property name that changed. (Case sensitive, used by reflection.)</param>
        /// <param name="oldValue">The old value of the property.</param>
        /// <param name="newValue">The new value of the property.</param>
        /// <returns>A Change that can be added to the UndoRoot's undo stack.</returns>
        public static Change GetChange(ISongElement instance, string propertyName, object oldValue, object newValue)
        {
            var change = new DelegateChange(instance,
                                            () => instance.GetType().GetProperty(propertyName).SetValue(instance, oldValue, null),
                                            () => instance.GetType().GetProperty(propertyName).SetValue(instance, newValue, null),
                                            new ChangeKey <object, string>(instance, propertyName)
                                            );

            return(change);
        }
Exemple #2
0
        /// <summary>
        /// Construct a Change instance with actions for undo / redo.
        /// </summary>
        /// <param name="instance">The instance that changed.</param>
        /// <param name="propertyName">The property name that changed. (Case sensitive, used by reflection.)</param>
        /// <param name="oldValue">The old value of the property.</param>
        /// <param name="newValue">The new value of the property.</param>
        /// <returns>A Change that can be added to the UndoRoot's undo stack.</returns>
        public static Change GetChange(ISongElement instance, string propertyName, object oldValue, object newValue)
        {
            var change = new DelegateChange(instance,
                                () => instance.GetType().GetProperty(propertyName).SetValue(instance, oldValue, null),
                                () => instance.GetType().GetProperty(propertyName).SetValue(instance, newValue, null),
                                new ChangeKey<object, string>(instance, propertyName)
                            );

            return change;
        }
Exemple #3
0
        public static void OnChanging(ISongElement instance, Action undoAction, Action redoAction, string description)
        {
            if (!instance.Root.IsUndoEnabled)
            {
                return;
            }

            var ch = new DelegateChange(instance, undoAction, redoAction, new ChangeKey <object, string>(instance, description));

            instance.Root.UndoManager.Root.AddChange(ch, description);
        }
Exemple #4
0
        public void UndoRoot_Supports_Adding_ChangeSets_Directly()
        {
            var change = new DelegateChange(Document1.A,
                                            () => Document1.A.Name = "Original",
                                            () => Document1.A.Name = "NewValue",
                                            new Tuple <object, string>(Document1.A, "Name"));

            var undoRoot = UndoService.Current[Document1];

            // var changeSet = new ChangeSet(undoRoot, "Change Document.A.Name", change);

            undoRoot.AddChange(change, "Change Document.A.Name");

            Assert.AreEqual(1, undoRoot.UndoStack.Count());
            Assert.AreEqual(0, undoRoot.RedoStack.Count());

            var origValue = Document1.A.Name;

            undoRoot.Undo();
            Assert.AreEqual("Original", Document1.A.Name);

            undoRoot.Redo();
            Assert.AreEqual("NewValue", Document1.A.Name);
        }
Exemple #5
0
        public static void OnChanging(ISongElement instance, Action undoAction, Action redoAction, string description)
        {
            if (!instance.Root.IsUndoEnabled)
                return;

            var ch = new DelegateChange(instance, undoAction, redoAction, new ChangeKey<object, string>(instance, description));
            instance.Root.UndoManager.Root.AddChange(ch, description);
        }