Example #1
0
        public void TestCommandHistory()
        {
            PositiveInt x = new PositiveInt();
            CommandHistory test = new CommandHistory();

            // test initial state
            Assert.IsTrue(!test.CanUndo);
            Assert.IsTrue(!test.CanRedo);
            Assert.IsTrue(!test.Dirty);

            // test adding command
            Command cmd = new IncCommand(x);
            test.Add(cmd);
            cmd.Do();
            Assert.IsTrue(x.Value == 1);
            Assert.IsTrue(test.CanUndo);
            Assert.IsTrue(!test.CanRedo);
            Assert.IsTrue(test.Dirty);

            test.Undo();
            Assert.IsTrue(x.Value == 0);
            Assert.IsTrue(!test.CanUndo);
            Assert.IsTrue(test.CanRedo);
            Assert.IsTrue(!test.Dirty);

            test.Redo();
            Assert.IsTrue(x.Value == 1);
            Assert.IsTrue(test.CanUndo);
            Assert.IsTrue(!test.CanRedo);
            Assert.IsTrue(test.Dirty);

            test.Dirty = false;
            Assert.IsTrue(!test.Dirty);

            cmd = new IncCommand(x);
            test.Add(cmd);
            cmd.Do();
            Assert.IsTrue(test.Dirty);
            test.Undo();
            Assert.IsTrue(!test.Dirty);

            test.Dirty = true;
            Assert.IsTrue(test.Dirty);
        }
Example #2
0
        /// <summary>
        /// Reverts the command count by undoing or redoing to the "clean" point</summary>
        /// <param name="history">Command history to undo or redo</param>
        /// <remarks>Use this method to revert in a multi-document, single command history scenario</remarks>
        public void Revert(CommandHistory history)
        {
            // need to undo?
            while (m_clean < m_current)
            {
                if (!history.CanUndo)
                {
                    break;
                }
                history.Undo();
            }

            // need to redo?
            while (m_clean > m_current)
            {
                if (!history.CanRedo)
                {
                    break;
                }
                history.Redo();
            }
        }
Example #3
0
        /// <summary>
        /// Reverts the command count by undoing or redoing to the "clean" point</summary>
        /// <param name="history">Command history to undo or redo</param>
        /// <remarks>Use this method to revert in a multi-document, single command history scenario</remarks>
        public void Revert(CommandHistory history)
        {
            // need to undo?
            while (m_clean < m_current)
            {
                if (!history.CanUndo)
                    break;
                history.Undo();
            }

            // need to redo?
            while (m_clean > m_current)
            {
                if (!history.CanRedo)
                    break;
                history.Redo();
            }
        }
Example #4
0
 /// <summary>
 /// Constructor</summary>
 public HistoryContext()
 {
     History = new CommandHistory();
 }