Beispiel #1
0
        public CatchOperationsFromHistoryForDelegatedPrimitive(MockTextUndoHistory history, MockTextUndoPrimitive primitive, DelegatedUndoPrimitiveState state)
        {
            _history   = history;
            _primitive = primitive;

            primitive.State = state;
            history.ForwardToUndoOperation(primitive);
        }
Beispiel #2
0
        public MockTextUndoTransaction(ITextUndoHistory history, ITextUndoTransaction parent, string description)
        {
            _history = history as MockTextUndoHistory;
            _parent  = parent as MockTextUndoTransaction;

            Description = description;

            _state      = UndoTransactionState.Open;
            _primitives = new List <ITextUndoPrimitive>();
            MergePolicy = NullMergeUndoTransactionPolicy.Instance;
            IsReadOnly  = true;
        }
Beispiel #3
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));
            }

            if (_strongContextMapping.TryGetValue(context, out var result))
            {
                if (!keepAlive)
                {
                    _strongContextMapping.Remove(context);
                    _weakContextMapping.Add(new KeyWeakReference(context), result);
                }

                return(result);
            }

            KeyWeakReference reference = new KeyWeakReference(context);

            if (_weakContextMapping.TryGetValue(reference, out result))
            {
                if (keepAlive)
                {
                    _weakContextMapping.Remove(reference);
                    _strongContextMapping.Add(context, result);
                }

                return(result);
            }

            result = new MockTextUndoHistory(this);
            _histories.Add(result, 1);

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

            return(result);
        }