Exemplo n.º 1
0
        public UndoTransactionImpl(ITextUndoHistory history, ITextUndoTransaction parent, string description)
        {
            if (history == null)
            {
                throw new ArgumentNullException("history", String.Format(CultureInfo.CurrentUICulture, "Strings.ArgumentCannotBeNull", "UndoTransactionImpl", "history"));
            }

            if (String.IsNullOrEmpty(description))
            {
                throw new ArgumentNullException("description", String.Format(CultureInfo.CurrentUICulture, "Strings.ArgumentCannotBeNull", "UndoTransactionImpl", "description"));
            }

            this.history = history as UndoHistoryImpl;

            if (this.history == null)
            {
                throw new ArgumentException("Strings.InvalidHistoryInTransaction");
            }

            this.parent = parent as UndoTransactionImpl;

            if (this.parent == null && parent != null)
            {
                throw new ArgumentException("Strings.InvalidParentInTransaction");
            }

            this.description = description;

            this.state       = UndoTransactionState.Open;
            this.primitives  = new List <ITextUndoPrimitive>();
            this.mergePolicy = NullMergeUndoTransactionPolicy.Instance;
            this.IsReadOnly  = true;
        }
Exemplo n.º 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));
            }

            this.history = history as UndoHistoryImpl;

            if (this.history == null)
            {
                throw new ArgumentException("Strings.InvalidHistoryInTransaction");
            }

            this.parent = parent as UndoTransactionImpl;

            if (this.parent == null && parent != null)
            {
                throw new ArgumentException("Strings.InvalidParentInTransaction");
            }

            this.description = description;

            this.state       = UndoTransactionState.Open;
            this.primitives  = new List <ITextUndoPrimitive>();
            this.mergePolicy = NullMergeUndoTransactionPolicy.Instance;
            this.IsReadOnly  = true;
        }
        public CatchOperationsFromHistoryForDelegatedPrimitive(UndoHistoryImpl history, DelegatedUndoPrimitiveImpl primitive, DelegatedUndoPrimitiveState state)
        {
            this.history   = history;
            this.primitive = primitive;

            primitive.State = state;
            history.ForwardToUndoOperation(primitive);
        }
Exemplo n.º 4
0
        public DelegatedUndoPrimitiveImpl(UndoHistoryImpl history, UndoTransactionImpl parent, UndoableOperationCurried operationCurried)
        {
            redoOperations = new Stack <UndoableOperationCurried>();
            undoOperations = new Stack <UndoableOperationCurried>();

            this.parent  = parent;
            this.history = history;
            this.state   = DelegatedUndoPrimitiveState.Inactive;

            undoOperations.Push(operationCurried);
        }
        /// <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("context", String.Format(CultureInfo.CurrentCulture, "Strings.ArgumentCannotBeNull", "RegisterHistory", "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);
        }