// Token: 0x06007318 RID: 29464 RVA: 0x00210348 File Offset: 0x0020E548
 internal void Close(IParentUndoUnit unit, UndoCloseAction closeAction)
 {
     if (!this.IsEnabled)
     {
         throw new InvalidOperationException(SR.Get("UndoServiceDisabled"));
     }
     if (unit == null)
     {
         throw new ArgumentNullException("unit");
     }
     if (this.OpenedUnit == null)
     {
         throw new InvalidOperationException(SR.Get("UndoNoOpenUnit"));
     }
     if (this.OpenedUnit != unit)
     {
         IParentUndoUnit openedUnit = this.OpenedUnit;
         while (openedUnit.OpenedUnit != null && openedUnit.OpenedUnit != unit)
         {
             openedUnit = openedUnit.OpenedUnit;
         }
         if (openedUnit.OpenedUnit == null)
         {
             throw new ArgumentException(SR.Get("UndoUnitNotFound"), "unit");
         }
         openedUnit.Close(closeAction);
         return;
     }
     else
     {
         if (closeAction != UndoCloseAction.Commit)
         {
             this.SetState(UndoState.Rollback);
             if (unit.OpenedUnit != null)
             {
                 unit.Close(closeAction);
             }
             if (closeAction == UndoCloseAction.Rollback)
             {
                 unit.Do();
             }
             this.PopUndoStack();
             this.SetOpenedUnit(null);
             this.OnNextDiscard();
             this.SetLastUnit((this._topUndoIndex == -1) ? null : this.PeekUndoStack());
             this.SetState(UndoState.Normal);
             return;
         }
         if (unit.OpenedUnit != null)
         {
             unit.Close(UndoCloseAction.Commit);
         }
         if (this.State != UndoState.Redo && this.State != UndoState.Undo && this.RedoStack.Count > 0)
         {
             this.RedoStack.Clear();
         }
         this.SetOpenedUnit(null);
         return;
     }
 }
Exemplo n.º 2
0
        // Close the text parent undo unit
        private void CloseTextParentUndoUnit(TextParentUndoUnit textParentUndoUnit, UndoCloseAction undoCloseAction)
        {
            if (textParentUndoUnit != null)
            {
                UndoManager undoManager = UndoManager.GetUndoManager(this.TextContainer.Parent);

                // Close the text parent undo unit
                undoManager.Close(textParentUndoUnit, undoCloseAction);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Closes an open child parent unit, adding it to the containing unit's undo stack if committed.
        /// </summary>
        /// <param name="unit">
        /// IParentUndoUnit to close.  If NULL, this unit's OpenedUnit is closed.
        /// </param>
        /// <param name="closeAction">
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Thrown if:
        ///     UndoManager is disabled
        ///     no undo unit is currently open
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown if unit is null
        /// </exception>
        internal void Close(IParentUndoUnit unit, UndoCloseAction closeAction)
        {
            if (!IsEnabled)
            {
                throw new InvalidOperationException(SR.Get(SRID.UndoServiceDisabled));
            }

            if (unit == null)
            {
                throw new ArgumentNullException("unit");
            }

            if (OpenedUnit == null)
            {
                throw new InvalidOperationException(SR.Get(SRID.UndoNoOpenUnit));
            }

            // find the parent of the given unit
            if (OpenedUnit != unit)
            {
                IParentUndoUnit closeParent;

                closeParent = OpenedUnit;

                while (closeParent.OpenedUnit != null && closeParent.OpenedUnit != unit)
                {
                    closeParent = closeParent.OpenedUnit;
                }

                if (closeParent.OpenedUnit == null)
                {
                    throw new ArgumentException(SR.Get(SRID.UndoUnitNotFound), "unit");
                }

                closeParent.Close(closeAction);
                return;
            }

            //
            // Close our open unit
            //
            if (closeAction != UndoCloseAction.Commit)
            {
                // discard unit
                SetState(UndoState.Rollback);
                if (unit.OpenedUnit != null)
                {
                    unit.Close(closeAction);
                }

                if (closeAction == UndoCloseAction.Rollback)
                {
                    unit.Do();
                }

                PopUndoStack();

                SetOpenedUnit(null);
                OnNextDiscard();
                SetLastUnit(_topUndoIndex == -1 ? null : PeekUndoStack()); // can be null, which is fine
                SetState(UndoState.Normal);
            }
            else
            {
                // commit unit
                if (unit.OpenedUnit != null)
                {
                    unit.Close(UndoCloseAction.Commit);
                }

                // flush redo stack
                if (State != UndoState.Redo && State != UndoState.Undo && RedoStack.Count > 0)
                {
                    RedoStack.Clear();
                }

                SetOpenedUnit(null);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Closes the current open unit, adding it to the containing unit's undo stack if committed.
 /// </summary>
 internal void Close(UndoCloseAction closeAction)
 {
     Close(OpenedUnit, closeAction);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Closes an open child parent unit, adding it to the containing unit's undo stack if committed.
        /// </summary>
        /// <param name="unit">
        /// IParentUndoUnit to close.  If NULL, this unit's OpenedUnit is closed.
        /// </param>
        /// <param name="closeAction">
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Thrown if:
        ///     UndoManager is disabled
        ///     no undo unit is currently open
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown if unit is null
        /// </exception>
        internal void Close(IParentUndoUnit unit, UndoCloseAction closeAction)
        {
            if (!IsEnabled)
            {
                throw new InvalidOperationException(SR.Get(SRID.UndoServiceDisabled));
            }

            if (unit == null)
            {
                throw new ArgumentNullException("unit");
            }

            if (OpenedUnit == null)
            {
                throw new InvalidOperationException(SR.Get(SRID.UndoNoOpenUnit));
            }

            // find the parent of the given unit
            if (OpenedUnit != unit)
            {
                IParentUndoUnit closeParent;

                closeParent = OpenedUnit;

                while (closeParent.OpenedUnit != null && closeParent.OpenedUnit != unit)
                {
                    closeParent = closeParent.OpenedUnit;
                }

                if (closeParent.OpenedUnit == null)
                {
                    throw new ArgumentException(SR.Get(SRID.UndoUnitNotFound), "unit");
                }

                closeParent.Close(closeAction);
                return;
            }

            //
            // Close our open unit
            //
            if (closeAction != UndoCloseAction.Commit)
            {
                // discard unit
                SetState(UndoState.Rollback);
                if (unit.OpenedUnit != null)
                {
                    unit.Close(closeAction);
                }

                if (closeAction == UndoCloseAction.Rollback)
                {
                    unit.Do();
                }

                PopUndoStack();

                SetOpenedUnit(null);
                OnNextDiscard();
                SetLastUnit(_topUndoIndex == -1 ? null : PeekUndoStack()); // can be null, which is fine
                SetState(UndoState.Normal);
            }
            else
            {
                // commit unit
                if (unit.OpenedUnit != null)
                {
                    unit.Close(UndoCloseAction.Commit);
                }

                // flush redo stack
                if (State != UndoState.Redo && State != UndoState.Undo && RedoStack.Count > 0)
                {
                    RedoStack.Clear();
                }

                SetOpenedUnit(null);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Closes the current open unit, adding it to the containing unit's undo stack if committed.
 /// </summary>
 internal void Close(UndoCloseAction closeAction)
 {
     Close(OpenedUnit, closeAction);
 }
Exemplo n.º 7
0
        // Token: 0x060071A6 RID: 29094 RVA: 0x00207A9C File Offset: 0x00205C9C
        public virtual void Close(IParentUndoUnit unit, UndoCloseAction closeAction)
        {
            if (unit == null)
            {
                throw new ArgumentNullException("unit");
            }
            if (this.OpenedUnit == null)
            {
                throw new InvalidOperationException(SR.Get("UndoNoOpenUnit"));
            }
            if (this.OpenedUnit != unit)
            {
                IParentUndoUnit parentUndoUnit = this;
                while (parentUndoUnit.OpenedUnit != null && parentUndoUnit.OpenedUnit != unit)
                {
                    parentUndoUnit = parentUndoUnit.OpenedUnit;
                }
                if (parentUndoUnit.OpenedUnit == null)
                {
                    throw new ArgumentException(SR.Get("UndoUnitNotFound"), "unit");
                }
                if (parentUndoUnit != this)
                {
                    parentUndoUnit.Close(closeAction);
                    return;
                }
            }
            UndoManager undoManager = this.TopContainer as UndoManager;

            if (closeAction != UndoCloseAction.Commit)
            {
                if (undoManager != null)
                {
                    undoManager.IsEnabled = false;
                }
                if (this.OpenedUnit.OpenedUnit != null)
                {
                    this.OpenedUnit.Close(closeAction);
                }
                if (closeAction == UndoCloseAction.Rollback)
                {
                    this.OpenedUnit.Do();
                }
                this._openedUnit = null;
                if (this.TopContainer is UndoManager)
                {
                    ((UndoManager)this.TopContainer).OnNextDiscard();
                }
                else
                {
                    ((IParentUndoUnit)this.TopContainer).OnNextDiscard();
                }
                if (undoManager != null)
                {
                    undoManager.IsEnabled = true;
                    return;
                }
            }
            else
            {
                if (this.OpenedUnit.OpenedUnit != null)
                {
                    this.OpenedUnit.Close(UndoCloseAction.Commit);
                }
                IParentUndoUnit openedUnit = this.OpenedUnit;
                this._openedUnit = null;
                this.Add(openedUnit);
                this.SetLastUnit(openedUnit);
            }
        }
Exemplo n.º 8
0
 // Token: 0x060071A5 RID: 29093 RVA: 0x00207A8D File Offset: 0x00205C8D
 public virtual void Close(UndoCloseAction closeAction)
 {
     this.Close(this.OpenedUnit, closeAction);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Closes an open child parent unit, adding it to the containing unit's undo stack if committed.
        /// </summary>
        /// <param name="unit">
        /// IParentUndoUnit to close.  If NULL, this unit's OpenedUnit is closed.
        /// </param>
        /// <param name="closeAction">
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Thrown if no undo unit is currently open
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown if unit is null
        /// </exception>
        public virtual void Close(IParentUndoUnit unit, UndoCloseAction closeAction)
        {
            UndoManager undoManager;

            if (unit == null)
            {
                throw new ArgumentNullException("unit");
            }

            if (OpenedUnit == null)
            {
                throw new InvalidOperationException(SR.Get(SRID.UndoNoOpenUnit));
            }

            // find the parent of the given unit
            if (OpenedUnit != unit)
            {
                IParentUndoUnit closeParent;

                closeParent = this;
                while (closeParent.OpenedUnit != null && closeParent.OpenedUnit != unit)
                {
                    closeParent = closeParent.OpenedUnit;
                }

                if (closeParent.OpenedUnit == null)
                {
                    throw new ArgumentException(SR.Get(SRID.UndoUnitNotFound), "unit");
                }

                if (closeParent != this)
                {
                    closeParent.Close(closeAction);
                    return;
                }
            }

            //
            // Close our open unit
            //

            // Get the undo manager
            undoManager = TopContainer as UndoManager;

            if (closeAction != UndoCloseAction.Commit)
            {
                // discard unit
                if (undoManager != null)
                {
                    undoManager.IsEnabled = false;
                }

                if (OpenedUnit.OpenedUnit != null)
                {
                    OpenedUnit.Close(closeAction);
                }

                if (closeAction == UndoCloseAction.Rollback)
                {
                    ((IParentUndoUnit)OpenedUnit).Do();
                }

                _openedUnit = null;

                // unlock previous unit(s)
                if (TopContainer is UndoManager)
                {
                    ((UndoManager)TopContainer).OnNextDiscard();
                }
                else
                {
                    ((IParentUndoUnit)TopContainer).OnNextDiscard();
                }

                if (undoManager != null)
                {
                    undoManager.IsEnabled = true;
                }
            }
            else
            {
                // commit unit
                if (OpenedUnit.OpenedUnit != null)
                {
                    OpenedUnit.Close(UndoCloseAction.Commit);
                }

                IParentUndoUnit openedUnit = OpenedUnit;
                _openedUnit = null;
                Add(openedUnit);
                SetLastUnit(openedUnit);
            }
        }
 // Token: 0x06007317 RID: 29463 RVA: 0x00210339 File Offset: 0x0020E539
 internal void Close(UndoCloseAction closeAction)
 {
     this.Close(this.OpenedUnit, closeAction);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Closes the current open unit, adding it to the containing unit's undo stack if committed.
 /// </summary>
 public virtual void Close(UndoCloseAction closeAction)
 {
     Close(OpenedUnit, closeAction);
 }
Exemplo n.º 12
0
        // Closes an opened composition unit and adding it to the containing unit's undo stack.
        private void CloseCompositionUndoUnit(UndoCloseAction undoCloseAction, ITextPointer compositionEnd)
        {
            UndoManager undoManager;
            DependencyObject parent;

            parent = _editor.TextContainer.Parent;
            undoManager = UndoManager.GetUndoManager(parent);

            if (undoManager != null && undoManager.IsEnabled && undoManager.OpenedUnit != null)
            {
                if (_compositionUndoUnit != null)
                {
                    // Closes an opened composition unit and commit it to add the composition
                    // undo unit into the containing unit's undo stack.
                    if (undoCloseAction == UndoCloseAction.Commit)
                    {
                        _compositionUndoUnit.RecordRedoSelectionState(compositionEnd, compositionEnd);
                    }
                    undoManager.Close(_compositionUndoUnit, undoCloseAction);
                }
            }
            else
            {
                _compositionUndoUnit = null;
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Closes an open child parent unit, adding it to the containing unit's undo stack if committed.
        /// </summary>
        /// <param name="unit">
        /// IParentUndoUnit to close.  If NULL, this unit's OpenedUnit is closed.
        /// </param>
        /// <param name="closeAction">
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Thrown if no undo unit is currently open
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown if unit is null
        /// </exception>
        public virtual void Close(IParentUndoUnit unit, UndoCloseAction closeAction)
        {
            UndoManager undoManager;

            if (unit == null)
            {
                throw new ArgumentNullException("unit");
            }

            if (OpenedUnit == null)
            {
                throw new InvalidOperationException(SR.Get(SRID.UndoNoOpenUnit));
            }

            // find the parent of the given unit
            if (OpenedUnit != unit)
            {
                IParentUndoUnit closeParent;

                closeParent = this;
                while (closeParent.OpenedUnit != null && closeParent.OpenedUnit != unit)
                {
                    closeParent = closeParent.OpenedUnit;
                }

                if (closeParent.OpenedUnit == null)
                {
                    throw new ArgumentException(SR.Get(SRID.UndoUnitNotFound), "unit");
                }

                if (closeParent != this)
                {
                    closeParent.Close(closeAction);
                    return;
                }
            }

            //
            // Close our open unit
            //

            // Get the undo manager
            undoManager = TopContainer as UndoManager;

            if (closeAction != UndoCloseAction.Commit)
            {
                // discard unit
                if (undoManager != null)
                {
                    undoManager.IsEnabled = false;
                }

                if (OpenedUnit.OpenedUnit != null)
                {
                    OpenedUnit.Close(closeAction);
                }

                if (closeAction == UndoCloseAction.Rollback)
                {
                    ((IParentUndoUnit)OpenedUnit).Do();
                }

                _openedUnit = null;

                // unlock previous unit(s)
                if (TopContainer is UndoManager)
                {
                    ((UndoManager)TopContainer).OnNextDiscard();
                }
                else
                {
                    ((IParentUndoUnit)TopContainer).OnNextDiscard();
                }

                if (undoManager != null)
                {
                    undoManager.IsEnabled = true;
                }
            }
            else
            {
                // commit unit
                if (OpenedUnit.OpenedUnit != null)
                {
                    OpenedUnit.Close(UndoCloseAction.Commit);
                }

                IParentUndoUnit openedUnit = OpenedUnit;
                _openedUnit = null;
                Add(openedUnit);
                SetLastUnit(openedUnit);
            }
        }
Exemplo n.º 14
0
 /// <summary>
 /// Closes the current open unit, adding it to the containing unit's undo stack if committed.
 /// </summary>
 public virtual void Close(UndoCloseAction closeAction)
 {
     Close(OpenedUnit, closeAction);
 }
Exemplo n.º 15
0
        /// <summary> 
        /// The helper for typing undo unit megring.
        /// Supposed to be called at the end of typing block - 
        /// after all changes are done. 
        /// Assumes that OpenTypingUndoUnit method was called
        /// in the beginning of this sequence. 
        /// </summary>
        private static void CloseTypingUndoUnit(TextEditor This, UndoCloseAction closeAction)
        {
            UndoManager undoManager = This._GetUndoManager(); 

            if (undoManager != null && undoManager.IsEnabled) 
            { 
                if (This._typingUndoUnit != null && undoManager.LastUnit == This._typingUndoUnit && !This._typingUndoUnit.Locked)
                { 
                    if (This._typingUndoUnit is TextParentUndoUnit)
                    {
                        ((TextParentUndoUnit)This._typingUndoUnit).RecordRedoSelectionState();
                    } 
                    undoManager.Close(This._typingUndoUnit, closeAction);
                } 
            } 
            else
            { 
                This._typingUndoUnit = null;
            }
        }