Example #1
0
        public bool CanMerge(ITextUndoTransaction newTransaction, ITextUndoTransaction oldTransaction)
        {
            MergeUndoActionPolicy oldPolicy = oldTransaction.MergePolicy as MergeUndoActionPolicy;
            MergeUndoActionPolicy newPolicy = newTransaction.MergePolicy as MergeUndoActionPolicy;

            if (oldPolicy != null && oldPolicy._mergeNext &&
                newPolicy != null && newPolicy._mergePrevious &&
                oldPolicy._actionName == newPolicy._actionName)
            {
                // If one of the transactions is empty, than it is safe to merge
                if (newTransaction.UndoPrimitives.Count == 0 ||
                    oldTransaction.UndoPrimitives.Count == 0)
                {
                    return(true);
                }

                // Make sure that we only merge consecutive edits
                ITextUndoPrimitive newPrimitive = newTransaction.UndoPrimitives[0];
                ITextUndoPrimitive oldPrimitive = oldTransaction.UndoPrimitives[oldTransaction.UndoPrimitives.Count - 1];

                return(newPrimitive.CanMerge(oldPrimitive));
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// AddUndo adds a new primitive to the end of the list when the transaction is Open.
        /// </summary>
        /// <param name="undo"></param>
        public void AddUndo(ITextUndoPrimitive undo)
        {
            _primitives.Add(undo);
            undo.Parent = this;

            MergeMostRecentUndoPrimitive();
        }
Example #3
0
        /// <summary>
        /// This is called by AddUndo, so that primitives are always in a fully merged state as we go.
        /// </summary>
        protected void MergeMostRecentUndoPrimitive()
        {
            // no merging unless there are at least two items
            if (_primitives.Count < 2)
            {
                return;
            }

            var top = _primitives[_primitives.Count - 1];

            ITextUndoPrimitive victim = null;
            var victimIndex           = -1;

            for (var i = _primitives.Count - 2; i >= 0; --i)
            {
                if (top.GetType() == _primitives[i].GetType() && top.CanMerge(_primitives[i]))
                {
                    victim      = _primitives[i];
                    victimIndex = i;
                    break;
                }
            }

            if (victim != null)
            {
                var newPrimitive = top.Merge(victim);
                _primitives.RemoveRange(_primitives.Count - 1, 1);
                _primitives.RemoveRange(victimIndex, 1);
                _primitives.Add(newPrimitive);
            }
        }
Example #4
0
 public ITextUndoPrimitive Merge(ITextUndoPrimitive older)
 {
     if (older == null)
     {
         throw new ArgumentNullException(nameof(older));
     }
     throw new NotSupportedException();            //TODO:
 }
Example #5
0
		public void AddUndo(ITextUndoPrimitive undo) {
			if (undo == null)
				throw new ArgumentNullException(nameof(undo));
			if (State != UndoTransactionState.Open)
				throw new InvalidOperationException();
			undoPrimitives.Add(undo);
			undo.Parent = this;
		}
Example #6
0
 public bool CanMerge(ITextUndoPrimitive older)
 {
     if (older == null)
     {
         throw new ArgumentNullException(nameof(older));
     }
     return(false);           //TODO:
 }
Example #7
0
        /// <summary>
        /// AddUndo adds a new primitive to the end of the list when the transaction is Open.
        /// </summary>
        /// <param name="undo"></param>
        public void AddUndo(ITextUndoPrimitive undo)
        {
            Check.InvalidOperation(() => State == UndoTransactionState.Open, "Cancel called on transation that is not opened");

            _primitives.Add(undo);
            undo.Parent = this;

            MergeMostRecentUndoPrimitive();
        }
Example #8
0
        /// <summary>
        /// AddUndo adds a new primitive to the end of the list when the transaction is Open.
        /// </summary>
        /// <param name="undo"></param>
        public void AddUndo(ITextUndoPrimitive undo)
        {
            if (State != UndoTransactionState.Open)
            {
                throw new InvalidOperationException("Strings.AddUndoCalledOnTransationThatIsNotOpened");
            }

            _primitives.Add(undo);
            undo.Parent = this;

            MergeMostRecentUndoPrimitive();
        }
Example #9
0
 public void AddUndo(ITextUndoPrimitive undo)
 {
     if (undo == null)
     {
         throw new ArgumentNullException(nameof(undo));
     }
     if (State != UndoTransactionState.Open)
     {
         throw new InvalidOperationException();
     }
     undoPrimitives.Add(undo);
     undo.Parent = this;
 }
        public bool CanMerge(ITextUndoTransaction newTransaction, ITextUndoTransaction oldTransaction)
        {
            // Validate
            if (newTransaction == null)
            {
                throw new ArgumentNullException(nameof(newTransaction));
            }

            if (oldTransaction == null)
            {
                throw new ArgumentNullException(nameof(oldTransaction));
            }

            TextTransactionMergePolicy oldPolicy = oldTransaction.MergePolicy as TextTransactionMergePolicy;
            TextTransactionMergePolicy newPolicy = newTransaction.MergePolicy as TextTransactionMergePolicy;

            if (oldPolicy == null || newPolicy == null)
            {
                throw new InvalidOperationException("The MergePolicy for both transactions should be a TextTransactionMergePolicy.");
            }

            // Make sure the merge policy directions permit merging these two transactions.
            if ((oldPolicy._allowableMergeDirections & TextTransactionMergeDirections.Forward) == 0 ||
                (newPolicy._allowableMergeDirections & TextTransactionMergeDirections.Backward) == 0)
            {
                return(false);
            }

            // Only merge text transactions that have the same description
            if (!string.Equals(newTransaction.Description, oldTransaction.Description, StringComparison.Ordinal))
            {
                return(false);
            }

            // If one of the transactions is empty, than it is safe to merge
            if ((newTransaction.UndoPrimitives.Count == 0) || (oldTransaction.UndoPrimitives.Count == 0))
            {
                return(true);
            }

            // Make sure that we only merge consecutive edits
            ITextUndoPrimitive newerBeforeTextChangePrimitive = newTransaction.UndoPrimitives[0];
            ITextUndoPrimitive olderAfterTextChangePrimitive  = oldTransaction.UndoPrimitives[oldTransaction.UndoPrimitives.Count - 1];

            return(newerBeforeTextChangePrimitive.CanMerge(olderAfterTextChangePrimitive));
        }
        public override bool CanMerge(ITextUndoPrimitive older)
        {
            if (older == null)
            {
                throw new ArgumentNullException(nameof(older));
            }

            AfterTextBufferChangeUndoPrimitive olderPrimitive = older as AfterTextBufferChangeUndoPrimitive;

            // We can only merge with IUndoPrimitives of AfterTextBufferChangeUndoPrimitive type
            if (olderPrimitive == null)
            {
                return(false);
            }

            return(olderPrimitive.State.Matches(this.State));
        }
        public override bool CanMerge(ITextUndoPrimitive older)
        {
            if (older == null)
            {
                throw new ArgumentNullException("older");
            }

            AfterTextBufferChangeUndoPrimitive olderPrimitive = older as AfterTextBufferChangeUndoPrimitive;

            // We can only merge with IUndoPrimitives of AfterTextBufferChangeUndoPrimitive type
            if (olderPrimitive == null)
            {
                return(false);
            }

            return((olderPrimitive.CaretIndex == _oldCaretIndex) && (olderPrimitive.CaretVirtualSpace == OldCaretVirtualSpaces));
        }
Example #13
0
 public void AddUndo(ITextUndoPrimitive undo)
 {
 }
Example #14
0
 public ITextUndoPrimitive Merge(ITextUndoPrimitive older)
 {
     throw new NotImplementedException();
 }
Example #15
0
 public void AddUndo(ITextUndoPrimitive undo)
 {
     _primitiveList.Add(undo);
 }
Example #16
0
 public virtual ITextUndoPrimitive Merge(ITextUndoPrimitive older)
 {
     throw new System.NotSupportedException();
 }
 public ITextUndoPrimitive Merge(ITextUndoPrimitive older)
 {
     throw new NotSupportedException();
 }
 public void AddUndo(ITextUndoPrimitive undo)
 {
     _innerTransaction.AddUndo(undo);
 }
Example #19
0
 public void AddUndo(ITextUndoPrimitive undo)
 {
     _innerTransaction.AddUndo(undo);
 }
Example #20
0
 public bool CanMerge(ITextUndoPrimitive older)
 {
     return(false);
 }
 void ITextUndoTransaction.AddUndo(ITextUndoPrimitive undo)
 {
     _primitiveList.Add(undo);
 }
Example #22
0
 void ITextUndoTransaction.AddUndo(ITextUndoPrimitive undo)
 {
     AddUndo(undo);
 }
Example #23
0
 internal void AddUndo(ITextUndoPrimitive undo)
 {
     System.Diagnostics.Debug.Assert(undo.CanUndo);
     _primitiveList.Add(undo);
     undo.Parent = this;
 }
 public ITextUndoPrimitive Merge(ITextUndoPrimitive primitive) {
     throw new InvalidOperationException("Strings.DelegatedUndoPrimitiveCannotMerge");
 }
        /// <summary>
        /// AddUndo adds a new primitive to the end of the list when the transaction is Open.
        /// </summary>
        /// <param name="undo"></param>
        public void AddUndo(ITextUndoPrimitive undo) {
            if (State != UndoTransactionState.Open) {
                throw new InvalidOperationException("Strings.AddUndoCalledOnTransationThatIsNotOpened");
            }

            _primitives.Add(undo);
            undo.Parent = this;

            MergeMostRecentUndoPrimitive();
        }
Example #26
0
 public bool CanMerge(ITextUndoPrimitive older) => false;
Example #27
0
		public bool CanMerge(ITextUndoPrimitive older) {
			if (older == null)
				throw new ArgumentNullException(nameof(older));
			return false;//TODO:
		}
Example #28
0
 public ITextUndoPrimitive Merge(ITextUndoPrimitive primitive)
 {
     throw new InvalidOperationException("Strings.DelegatedUndoPrimitiveCannotMerge");
 }
Example #29
0
 public ITextUndoPrimitive Merge(ITextUndoPrimitive older)
 {
     throw new NotSupportedException();
 }
Example #30
0
		public ITextUndoPrimitive Merge(ITextUndoPrimitive older) {
			if (older == null)
				throw new ArgumentNullException(nameof(older));
			throw new NotSupportedException();//TODO:
		}
 public bool CanMerge(ITextUndoPrimitive older)
 {
     return false;
 }
 public bool CanMerge(ITextUndoPrimitive older) => true;
Example #33
0
 public void AddUndo(ITextUndoPrimitive undo)
 {
     _primitiveList.Add(undo);
 }
 public ITextUndoPrimitive Merge(ITextUndoPrimitive older) => older;
 void ITextUndoTransaction.AddUndo(ITextUndoPrimitive undo)
 {
     _primitiveList.Add(undo);
 }
Example #36
0
 public ITextUndoPrimitive Merge(ITextUndoPrimitive older)
 {
     return(older);
 }
Example #37
0
 public ITextUndoPrimitive Merge(ITextUndoPrimitive older)
 {
     throw new NotImplementedException();
 }
 public ITextUndoPrimitive Merge(ITextUndoPrimitive older) { return older; }