Esempio n. 1
0
            public void ReturnsOneForBatchWithOneAction()
            {
                var model = new Mocks.MockModel();

                var batch = new Batch();
                batch.AddAction(new PropertyChangeUndo(model, "Value", model.Value));

                Assert.AreEqual(1, batch.ActionCount);
            }
Esempio n. 2
0
            public void ReturnsFalseForBatchWithOneAction()
            {
                var model = new Mocks.MockModel();

                var batch = new Batch();
                batch.AddAction(new PropertyChangeUndo(model, "Value", model.Value));

                Assert.IsFalse(batch.IsEmptyBatch);
            }
Esempio n. 3
0
            public void ReturnsFalseForBatchWithMultipleActions()
            {
                var model1 = new Mocks.MockModel();
                var model2 = new Mocks.MockModel();

                var batch = new Batch();
                batch.AddAction(new PropertyChangeUndo(model1, "Value", model1.Value));
                batch.AddAction(new PropertyChangeUndo(model2, "Value", model2.Value));

                Assert.IsFalse(batch.IsEmptyBatch);
            }
Esempio n. 4
0
            public void ReturnsFalseForEmptyBatch()
            {
                var batch = new Batch();

                Assert.IsFalse(batch.IsSingleActionBatch);
            }
Esempio n. 5
0
 public void ReturnsTrueForEmptyBatch()
 {
     var batch = new Batch();
     
     Assert.IsTrue(batch.IsEmptyBatch);
 }
Esempio n. 6
0
            public void ReturnsZeroForEmptyBatch()
            {
                var batch = new Batch();

                Assert.AreEqual(0, batch.ActionCount);
            }
Esempio n. 7
0
            public void IsTrueWhenAtLeastOneActionCanRedo()
            {
                var model1 = new Mocks.MockModel();
                var model2 = new Mocks.MockModel();

                var batch = new Batch();
                batch.AddAction(new PropertyChangeUndo(model1, "Value", model1.Value));
                batch.AddAction(new PropertyChangeUndo(model2, "Value", model2.Value));

                Assert.IsTrue(batch.CanRedo);
            }
Esempio n. 8
0
            public void IsFalseWhenNoActionsCanRedo()
            {
                var model1 = new Mocks.MockModel();

                var batch = new Batch();
                batch.AddAction(new ActionUndo(model1, () => model1.Value = "Value"));

                Assert.IsFalse(batch.CanRedo);
            }
Esempio n. 9
0
        /// <summary>
        /// Adds a new undo operation to the stack.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="noInsertIfExecutingOperation">Do not insert record if currently running undo/redo.</param>
        /// <returns><c>true</c> if undo operation was added to stack; otherwise <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="operation"/> is <c>null</c>.</exception>
        public bool Add(IMementoSupport operation, bool noInsertIfExecutingOperation = true)
        {
            Argument.IsNotNull("operation", operation);

            if (!IsEnabled)
            {
                return false;
            }

            if (noInsertIfExecutingOperation && _isUndoingOperation)
            {
                return false;
            }

            lock (_lock)
            {
                if (_currentBatch != null)
                {
                    _currentBatch.AddAction(operation);
                }
                else
                {
                    var batch = new Batch();
                    batch.AddAction(operation);

                    Add(batch);
                }
            }

            return true;
        }
Esempio n. 10
0
        /// <summary>
        /// Ends the current batch and adds it to the stack by calling <see cref="Add(Catel.Memento.IMementoBatch,bool)"/>.
        /// <para />
        /// If there is currently no batch, this method will silently exit.
        /// </summary>
        /// <returns>The <see cref="IMementoBatch"/> that has just been ended or <c>null</c> if there was no current batch.</returns>
        public IMementoBatch EndBatch()
        {
            if (_currentBatch == null)
            {
                return null;
            }

            var batch = _currentBatch;

            Add(batch);

            _currentBatch = null;

            Log.Debug("Ended batch with title '{0}' and description '{1}' with '{2}' actions", ObjectToStringHelper.ToString(batch.Title),
                ObjectToStringHelper.ToString(batch.Description), batch.ActionCount);

            return batch;
        }
Esempio n. 11
0
        /// <summary>
        /// Begins a new batch. 
        /// <para />
        /// Note that this method will always call <see cref="EndBatch"/> before creating the new batch to ensure
        /// that a new batch is actually created.
        /// <para />
        /// All operations added via the <see cref="Add(Catel.Memento.IMementoSupport,bool)"/> will belong the this batch
        /// and be handled as a single operation.
        /// </summary>
        /// <param name="title">The title which can be used to display this batch i a user interface.</param>
        /// <param name="description">The description which can be used to display this batch i a user interface.</param>
        /// <returns>The <see cref="IMementoBatch" /> that has just been created.</returns>
        public IMementoBatch BeginBatch(string title = null, string description = null)
        {
            EndBatch();

            var batch = new Batch
                {
                    Title = title,
                    Description = description
                };

            Log.Debug("Starting batch with title '{0}' and description '{1}'", ObjectToStringHelper.ToString(batch.Title),
                ObjectToStringHelper.ToString(batch.Description));

            _currentBatch = batch;

            return batch;
        }