Exemple #1
0
        private static void RunTest(TestArchetypesRun run)
        {
            var undoRedo = new UndoRedoService(100);
            // We don't have easy access to the context and the graphes, let's use dynamic for simplicity
            dynamic dynamicRun = run;
            var     context    = dynamicRun.Context;

            ((AssetPropertyGraph)context.BaseGraph).Changed        += new AssetSlimContainer(undoRedo, context.BaseGraph).AssetPropertyChanged;
            ((AssetPropertyGraph)context.DerivedGraph).Changed     += new AssetSlimContainer(undoRedo, context.DerivedGraph).AssetPropertyChanged;
            ((AssetPropertyGraph)context.BaseGraph).ItemChanged    += new AssetSlimContainer(undoRedo, context.BaseGraph).AssetPropertyChanged;
            ((AssetPropertyGraph)context.DerivedGraph).ItemChanged += new AssetSlimContainer(undoRedo, context.DerivedGraph).AssetPropertyChanged;
            using (undoRedo.CreateTransaction())
            {
                run.FirstChange();
            }
            using (undoRedo.CreateTransaction())
            {
                run.SecondChange();
            }
            run.SecondChangeCheck();
            undoRedo.Undo();
            run.FirstChangeCheck();
            undoRedo.Undo();
            run.InitialCheck();
            undoRedo.Redo();
            run.FirstChangeCheck();
            undoRedo.Redo();
            run.SecondChangeCheck();
        }
Exemple #2
0
        public void BasicPropertyChangeIsRecordedWithFiltering()
        {
            var initialBool = _recordedModel.IsTrue;
            var initialText = "";

            _recordedModel.SubClassB.Text = initialText;
            var initialNumber = _recordedModel.Number;

            _modelRecorder.Record(_undoRedoService, _recordedModel);

            _recordedModel.IsTrue = !_recordedModel.IsTrue;
            _recordedModel.Number++;
            _recordedModel.IsTrue          = !_recordedModel.IsTrue;
            _recordedModel.SubClassB.Text += "ABC";

            _recordedModel.IsTrue = !_recordedModel.IsTrue;
            _recordedModel.Number++;
            _recordedModel.SubClassB.Text += "ABC";

            _recordedModel.Number++;
            _recordedModel.IsTrue = !_recordedModel.IsTrue;
            _recordedModel.Number++;
            _recordedModel.IsTrue = !_recordedModel.IsTrue;

            _recordedModel.IsTrue = !initialBool;

            _recordedModel.SubClassB.Text += "ABC";

            Assert.AreEqual(0, _modelRecorder.UndoRedoService.NbUndo);
            Assert.AreEqual(0, _modelRecorder.UndoRedoService.NbRedo);

            Wait(2000);

            Assert.AreEqual(3, _modelRecorder.UndoRedoService.NbUndo);
            Assert.AreEqual(0, _modelRecorder.UndoRedoService.NbRedo);

            _undoRedoService.Undo();
            Assert.AreEqual(2, _modelRecorder.UndoRedoService.NbUndo);
            Assert.AreEqual(1, _modelRecorder.UndoRedoService.NbRedo);

            _undoRedoService.Undo();
            Assert.AreEqual(1, _modelRecorder.UndoRedoService.NbUndo);
            Assert.AreEqual(2, _modelRecorder.UndoRedoService.NbRedo);

            _undoRedoService.Undo();
            Assert.AreEqual(0, _modelRecorder.UndoRedoService.NbUndo);
            Assert.AreEqual(3, _modelRecorder.UndoRedoService.NbRedo);

            Assert.AreEqual(initialBool, _recordedModel.IsTrue);
            Assert.AreEqual(initialText, _recordedModel.SubClassB.Text);
            Assert.AreEqual(initialNumber, _recordedModel.Number);
        }
        private void Update()
        {
            // 按键 S 表示 Record (记录) 步骤操作;

            if (Input.GetKeyDown(KeyCode.S))
            {
                UndoRedoService.Record();


                UnityTool.Log("Record");
            }

            // 按键 U 表示 Undo (撤销) 操作;

            if (Input.GetKeyDown(KeyCode.U))
            {
                UndoRedoService.Undo();

                UnityTool.Log("Undo");
            }

            // 按键 R 表示 Redo (重做) 操作;

            if (Input.GetKeyDown(KeyCode.R))
            {
                UndoRedoService.Redo();

                UnityTool.Log("Redo");
            }
        }
 public override void Execute(object parameter)
 {
     if (_isUndo)
     {
         _undoRedoService.Undo();
     }
     else
     {
         _undoRedoService.Redo();
     }
 }
Exemple #5
0
        public void BasicPropertyChangeIsRecorded()
        {
            _modelRecorder.Record(_undoRedoService, _recordedModel);

            var initialValue = _recordedModel.IsTrue;

            Assert.IsFalse(_undoRedoService.CanUndo);
            Assert.IsFalse(_undoRedoService.CanRedo);

            _recordedModel.IsTrue = !initialValue;
            Assert.IsTrue(_undoRedoService.CanUndo);
            Assert.IsFalse(_undoRedoService.CanRedo);

            _undoRedoService.Undo();
            Assert.AreEqual(_recordedModel.IsTrue, initialValue);
            Assert.IsFalse(_undoRedoService.CanUndo);
            Assert.IsTrue(_undoRedoService.CanRedo);

            _undoRedoService.Redo();
            Assert.AreEqual(_recordedModel.IsTrue, !initialValue);
            Assert.IsTrue(_undoRedoService.CanUndo);
            Assert.IsFalse(_undoRedoService.CanRedo);
        }