示例#1
0
        /// <summary>
        /// Implicity implememntation of <see cref="IMemento&lt;T&gt;.Restore(T)"/>, which returns <see cref="CompoundMemento&lt;T&gt;"/>
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public CompoundMemento <T> Restore(T target)
        {
            CompoundMemento <T> inverse = new CompoundMemento <T>();

            // Starts from the last action
            for (int i = mementos.Count - 1; i >= 0; i--)
            {
                inverse.Add(mementos[i].Restore(target));
            }
            return(inverse);
        }
        /// <summary>
        /// Pushes an memento into the undo stack, any time the state of <see cref="subject"/> changes.
        /// </summary>
        /// <param name="m"></param>
        /// <remarks>
        /// This method MUST be properly involked by programmers right before (preferably) or right after
        /// the state of <see cref="subject"/> is changed.
        /// Whenever <see cref="Do(IMemento&lt;T&gt;)"/> is called, the status of <see cref="InUndoRedo"/>
        /// should aways be checked first. See details at <see cref="InUndoRedo"/>.
        /// This method causes redo stack to be cleared.
        /// </remarks>
        /// <seealso cref="InUndoRedo"/>
        /// <seealso cref="Undo()"/>
        /// <seealso cref="Redo()"/>
        public void Do(IMemento <T> m)
        {
            if (inUndoRedo)
            {
                throw new InvalidOperationException("Involking do within an undo/redo action.");
            }

            if (tempMemento == null)
            {
                _Do(m);
            }
            else
            {
                tempMemento.Add(m);
            }
        }
示例#3
0
        /// <summary>
        /// Pushes an memento into the undo stack, any time the state of <see cref="subject"/> changes.
        /// </summary>
        /// <param name="m"></param>
        /// <remarks>
        /// This method MUST be properly involked by programmers right before (preferably) or right after
        /// the state of <see cref="subject"/> is changed.
        /// Whenever <see cref="Do(IMemento&lt;T&gt;)"/> is called, the status of <see cref="InUndoRedo"/>
        /// should aways be checked first. See details at <see cref="InUndoRedo"/>.
        /// This method causes redo stack to be cleared.
        /// </remarks>
        /// <seealso cref="InUndoRedo"/>
        /// <seealso cref="Undo()"/>
        /// <seealso cref="Redo()"/>
        public void Do(IMemento <T> m)
        {
            Debug.WriteLine(string.Format("UndoRedo.Do {0}", m.ToString()));
            if (inUndoRedo)
            {
                throw new InvalidOperationException("Involking do within an undo/redo action.");
            }

            if (tempMemento == null)
            {
                _Do(m);
            }
            else
            {
                tempMemento.Add(m);
            }
        }