예제 #1
0
        public UndoTransactionImpl(ITextUndoHistory history, ITextUndoTransaction parent, string description)
        {
            if (history == null)
            {
                throw new ArgumentNullException(nameof(history));
            }

            if (string.IsNullOrEmpty(description))
            {
                throw new ArgumentNullException(nameof(description));
            }

            _history = history as UndoHistoryImpl;

            if (_history == null)
            {
                throw new ArgumentException("Invalid history in registry");
            }

            _parent = parent as UndoTransactionImpl;

            if (_parent == null && parent != null)
            {
                throw new ArgumentException("Invalid parent in transaction");
            }

            Description = description;

            _state       = UndoTransactionState.Open;
            _primitives  = new List <ITextUndoPrimitive>();
            _mergePolicy = NullMergeUndoTransactionPolicy.Instance;
            IsReadOnly   = true;
        }
예제 #2
0
        public UndoTransactionImpl(ITextUndoHistory history, ITextUndoTransaction parent, string description) {
            if (history == null) {
                throw new ArgumentNullException(nameof(history));
            }

            if (string.IsNullOrEmpty(description)) {
                throw new ArgumentNullException(nameof(description));
            }

            _history = history as UndoHistoryImpl;

            if (_history == null) {
                throw new ArgumentException("Invalid history in registry");
            }

            _parent = parent as UndoTransactionImpl;

            if (_parent == null && parent != null) {
                throw new ArgumentException("Invalid parent in transaction");
            }

            Description = description;

            _state = UndoTransactionState.Open;
            _primitives = new List<ITextUndoPrimitive>();
            _mergePolicy = NullMergeUndoTransactionPolicy.Instance;
            IsReadOnly = true;
        }
        public CatchOperationsFromHistoryForDelegatedPrimitive(UndoHistoryImpl history, DelegatedUndoPrimitiveImpl primitive, DelegatedUndoPrimitiveState state) {
            _history = history;
            _primitive = primitive;

            primitive.State = state;
            history.ForwardToUndoOperation(primitive);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <param name="keepAlive"></param>
        /// <returns></returns>
        public ITextUndoHistory RegisterHistory(object context, bool keepAlive) {
            if (context == null) {
                throw new ArgumentNullException(nameof(context));
            }

            ITextUndoHistory result;

            if (_strongContextMapping.ContainsKey(context)) {
                result = _strongContextMapping[context];

                if (!keepAlive) {
                    _strongContextMapping.Remove(context);
                    _weakContextMapping.Add(new WeakReferenceForDictionaryKey(context), result);
                }
            } else if (_weakContextMapping.ContainsKey(new WeakReferenceForDictionaryKey(context))) {
                result = _weakContextMapping[new WeakReferenceForDictionaryKey(context)];

                if (keepAlive) {
                    _weakContextMapping.Remove(new WeakReferenceForDictionaryKey(context));
                    _strongContextMapping.Add(context, result);
                }
            } else {
                result = new UndoHistoryImpl(this);
                _histories.Add(result, 1);

                if (keepAlive) {
                    _strongContextMapping.Add(context, result);
                } else {
                    _weakContextMapping.Add(new WeakReferenceForDictionaryKey(context), result);
                }
            }

            return result;
        }
예제 #5
0
        public CatchOperationsFromHistoryForDelegatedPrimitive(UndoHistoryImpl history, DelegatedUndoPrimitiveImpl primitive, DelegatedUndoPrimitiveState state)
        {
            _history   = history;
            _primitive = primitive;

            primitive.State = state;
            history.ForwardToUndoOperation(primitive);
        }
        public DelegatedUndoPrimitiveImpl(UndoHistoryImpl history, UndoTransactionImpl parent, UndoableOperationCurried operationCurried) {
            RedoOperations = new Stack<UndoableOperationCurried>();
            _undoOperations = new Stack<UndoableOperationCurried>();

            _parent = parent;
            _history = history;
            _state = DelegatedUndoPrimitiveState.Inactive;

            _undoOperations.Push(operationCurried);
        }
예제 #7
0
        public DelegatedUndoPrimitiveImpl(UndoHistoryImpl history, UndoTransactionImpl parent, UndoableOperationCurried operationCurried)
        {
            RedoOperations  = new Stack <UndoableOperationCurried>();
            _undoOperations = new Stack <UndoableOperationCurried>();

            _parent  = parent;
            _history = history;
            _state   = DelegatedUndoPrimitiveState.Inactive;

            _undoOperations.Push(operationCurried);
        }
예제 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="keepAlive"></param>
        /// <returns></returns>
        public ITextUndoHistory RegisterHistory(object context, bool keepAlive)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            ITextUndoHistory result;

            if (_strongContextMapping.ContainsKey(context))
            {
                result = _strongContextMapping[context];

                if (!keepAlive)
                {
                    _strongContextMapping.Remove(context);
                    _weakContextMapping.Add(new WeakReferenceForDictionaryKey(context), result);
                }
            }
            else if (_weakContextMapping.ContainsKey(new WeakReferenceForDictionaryKey(context)))
            {
                result = _weakContextMapping[new WeakReferenceForDictionaryKey(context)];

                if (keepAlive)
                {
                    _weakContextMapping.Remove(new WeakReferenceForDictionaryKey(context));
                    _strongContextMapping.Add(context, result);
                }
            }
            else
            {
                result = new UndoHistoryImpl(this);
                _histories.Add(result, 1);

                if (keepAlive)
                {
                    _strongContextMapping.Add(context, result);
                }
                else
                {
                    _weakContextMapping.Add(new WeakReferenceForDictionaryKey(context), result);
                }
            }

            return(result);
        }
예제 #9
0
        public UndoTransactionImpl(ITextUndoHistory history, ITextUndoTransaction parent, string description)
        {
            Check.ArgumentNull(nameof(history), history);
            Check.ArgumentStringNullOrEmpty(nameof(description), description);

            _history = history as UndoHistoryImpl;
            Check.ArgumentNull(nameof(history), _history);

            _parent = parent as UndoTransactionImpl;
            Check.Argument(nameof(parent), () => _parent != null || parent == null);

            Description = description;

            _state       = UndoTransactionState.Open;
            _primitives  = new List <ITextUndoPrimitive>();
            _mergePolicy = NullMergeUndoTransactionPolicy.Instance;
            IsReadOnly   = true;
        }