// 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;
     }
 }
        // Token: 0x06007315 RID: 29461 RVA: 0x002101D0 File Offset: 0x0020E3D0
        internal void Open(IParentUndoUnit unit)
        {
            if (!this.IsEnabled)
            {
                throw new InvalidOperationException(SR.Get("UndoServiceDisabled"));
            }
            if (unit == null)
            {
                throw new ArgumentNullException("unit");
            }
            IParentUndoUnit deepestOpenUnit = this.DeepestOpenUnit;

            if (deepestOpenUnit == unit)
            {
                throw new InvalidOperationException(SR.Get("UndoUnitCantBeOpenedTwice"));
            }
            if (deepestOpenUnit == null)
            {
                if (unit != this.LastUnit)
                {
                    this.Add(unit);
                    this.SetLastUnit(unit);
                }
                this.SetOpenedUnit(unit);
                unit.Container = this;
                return;
            }
            unit.Container = deepestOpenUnit;
            deepestOpenUnit.Open(unit);
        }
示例#3
0
        // Token: 0x060071A4 RID: 29092 RVA: 0x00207A2C File Offset: 0x00205C2C
        public virtual void Open(IParentUndoUnit newUnit)
        {
            if (newUnit == null)
            {
                throw new ArgumentNullException("newUnit");
            }
            IParentUndoUnit deepestOpenUnit = this.DeepestOpenUnit;

            if (deepestOpenUnit == null)
            {
                if (this.IsInParentUnitChain(newUnit))
                {
                    throw new InvalidOperationException(SR.Get("UndoUnitCantBeOpenedTwice"));
                }
                this._openedUnit = newUnit;
                if (newUnit != null)
                {
                    newUnit.Container = this;
                    return;
                }
            }
            else
            {
                if (newUnit != null)
                {
                    newUnit.Container = deepestOpenUnit;
                }
                deepestOpenUnit.Open(newUnit);
            }
        }
示例#4
0
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        /// <summary>
        /// Opens a new parent undo unit.
        /// </summary>
        /// <param name="newUnit">
        /// IParentUndoUnit to open
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if passed unit is null.
        /// </exception>
        public virtual void Open(IParentUndoUnit newUnit)
        {
            IParentUndoUnit deepestOpen;

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

            deepestOpen = DeepestOpenUnit;
            if (deepestOpen == null)
            {
                if (IsInParentUnitChain(newUnit))
                {
                    throw new InvalidOperationException(SR.Get(SRID.UndoUnitCantBeOpenedTwice));
                }

                _openedUnit = newUnit;
                if (newUnit != null)
                {
                    newUnit.Container = this;
                }
            }
            else
            {
                if (newUnit != null)
                {
                    newUnit.Container = deepestOpen;
                }

                deepestOpen.Open(newUnit);
            }
        }
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        /// <summary>
        /// Opens a new parent undo unit.
        /// </summary>
        /// <param name="newUnit">
        /// IParentUndoUnit to open
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if passed unit is null.
        /// </exception>
        public virtual void Open(IParentUndoUnit newUnit)
        {
            IParentUndoUnit deepestOpen;

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

            deepestOpen = DeepestOpenUnit;
            if (deepestOpen == null)
            {
                if (IsInParentUnitChain(newUnit))
                {
                    throw new InvalidOperationException(SR.Get(SRID.UndoUnitCantBeOpenedTwice));
                }

                _openedUnit = newUnit;
                if (newUnit != null)
                {
                    newUnit.Container = this;
                }
            }
            else
            {
                if (newUnit != null)
                {
                    newUnit.Container = deepestOpen;
                }

                deepestOpen.Open(newUnit);
            }
        }            
示例#6
0
        // Token: 0x060071A7 RID: 29095 RVA: 0x00207BD4 File Offset: 0x00205DD4
        public virtual void Add(IUndoUnit unit)
        {
            if (unit == null)
            {
                throw new ArgumentNullException("unit");
            }
            IParentUndoUnit deepestOpenUnit = this.DeepestOpenUnit;

            if (deepestOpenUnit != null)
            {
                deepestOpenUnit.Add(unit);
                return;
            }
            if (this.IsInParentUnitChain(unit))
            {
                throw new InvalidOperationException(SR.Get("UndoUnitCantBeAddedTwice"));
            }
            if (this.Locked)
            {
                throw new InvalidOperationException(SR.Get("UndoUnitLocked"));
            }
            if (!this.Merge(unit))
            {
                this._units.Push(unit);
                if (this.LastUnit is IParentUndoUnit)
                {
                    ((IParentUndoUnit)this.LastUnit).OnNextAdd();
                }
                this.SetLastUnit(unit);
            }
        }
 // Token: 0x0600731D RID: 29469 RVA: 0x00210794 File Offset: 0x0020E994
 internal virtual void OnNextDiscard()
 {
     if (this.UndoCount > 0)
     {
         IParentUndoUnit parentUndoUnit = (IParentUndoUnit)this.PeekUndoStack();
         parentUndoUnit.OnNextDiscard();
     }
 }
示例#8
0
        /// <summary>
        /// Called when a unit is discarded.  Unlocks the most recent unit added before the discarded one.
        /// </summary>
        internal virtual void OnNextDiscard()
        {
            if (UndoCount > 0)
            {
                IParentUndoUnit lastParent = (IParentUndoUnit)PeekUndoStack();

                lastParent.OnNextDiscard();
            }
        }
示例#9
0
        /// <summary>
        /// Opens a closed undo unit on the top of the stack.
        /// </summary>
        /// <param name="unit">
        /// IParentUndoUnit to reopen
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Thrown if:
        ///     UndoManager is disabled
        ///     another unit is already open
        ///     the given unit is locked
        ///     the given unit is not on top of the stack
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown if passed unit is null.
        /// </exception>
        internal void Reopen(IParentUndoUnit unit)
        {
            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.UndoUnitAlreadyOpen));
            }

            switch (State)
            {
            case UndoState.Normal:
            case UndoState.Redo:
            {
                if (UndoCount == 0 || PeekUndoStack() != unit)
                {
                    throw new InvalidOperationException(SR.Get(SRID.UndoUnitNotOnTopOfStack));
                }

                break;
            }

            case UndoState.Undo:
            {
                if (RedoStack.Count == 0 || (IParentUndoUnit)RedoStack.Peek() != unit)
                {
                    throw new InvalidOperationException(SR.Get(SRID.UndoUnitNotOnTopOfStack));
                }

                break;
            }

            case UndoState.Rollback:
            default:
                // should only happen if someone changes the UndoState enum or parameter validation
                Debug.Assert(false);
                break;
            }
            if (unit.Locked)
            {
                throw new InvalidOperationException(SR.Get(SRID.UndoUnitLocked));
            }

            Open(unit);
            _lastReopenedUnit = unit;
        }
示例#10
0
 // Token: 0x060071BC RID: 29116 RVA: 0x00207F14 File Offset: 0x00206114
 private bool IsInParentUnitChain(IUndoUnit unit)
 {
     if (unit is IParentUndoUnit)
     {
         IParentUndoUnit parentUndoUnit = this;
         while (parentUndoUnit != unit)
         {
             parentUndoUnit = (parentUndoUnit.Container as IParentUndoUnit);
             if (parentUndoUnit == null)
             {
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
示例#11
0
        /// <summary>
        /// Inverse of OnNextAdd().  Called when a unit previously added after this one gets discarded.
        /// </summary>
        public virtual void OnNextDiscard()
        {
            _locked = false;
            IParentUndoUnit lastParent = this;

            foreach (IUndoUnit unit in _units)
            {
                if (unit is IParentUndoUnit)
                {
                    lastParent = unit as IParentUndoUnit;
                }
            }

            if (lastParent != this)
            {
                lastParent.OnNextDiscard();
            }
        }
示例#12
0
        // Token: 0x060071AA RID: 29098 RVA: 0x00207D0C File Offset: 0x00205F0C
        public virtual void OnNextDiscard()
        {
            this._locked = false;
            IParentUndoUnit parentUndoUnit = this;

            foreach (object obj in this._units)
            {
                IUndoUnit undoUnit = (IUndoUnit)obj;
                if (undoUnit is IParentUndoUnit)
                {
                    parentUndoUnit = (undoUnit as IParentUndoUnit);
                }
            }
            if (parentUndoUnit != this)
            {
                parentUndoUnit.OnNextDiscard();
            }
        }
示例#13
0
        // Token: 0x060071AB RID: 29099 RVA: 0x00207D80 File Offset: 0x00205F80
        public virtual void Do()
        {
            IParentUndoUnit unit        = this.CreateParentUndoUnitForSelf();
            UndoManager     undoManager = this.TopContainer as UndoManager;

            if (undoManager != null && undoManager.IsEnabled)
            {
                undoManager.Open(unit);
            }
            while (this._units.Count > 0)
            {
                IUndoUnit undoUnit = this._units.Pop() as IUndoUnit;
                undoUnit.Do();
            }
            if (undoManager != null && undoManager.IsEnabled)
            {
                undoManager.Close(unit, UndoCloseAction.Commit);
            }
        }
        // Token: 0x06007316 RID: 29462 RVA: 0x00210258 File Offset: 0x0020E458
        internal void Reopen(IParentUndoUnit unit)
        {
            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("UndoUnitAlreadyOpen"));
            }
            switch (this.State)
            {
            case UndoState.Normal:
            case UndoState.Redo:
                if (this.UndoCount == 0 || this.PeekUndoStack() != unit)
                {
                    throw new InvalidOperationException(SR.Get("UndoUnitNotOnTopOfStack"));
                }
                break;

            case UndoState.Undo:
                if (this.RedoStack.Count == 0 || (IParentUndoUnit)this.RedoStack.Peek() != unit)
                {
                    throw new InvalidOperationException(SR.Get("UndoUnitNotOnTopOfStack"));
                }
                break;
            }
            if (unit.Locked)
            {
                throw new InvalidOperationException(SR.Get("UndoUnitLocked"));
            }
            this.Open(unit);
            this._lastReopenedUnit = unit;
        }
        // Token: 0x06002B4B RID: 11083 RVA: 0x000C592C File Offset: 0x000C3B2C
        public override void Do()
        {
            UndoManager     undoManager    = base.TopContainer as UndoManager;
            IParentUndoUnit parentUndoUnit = null;
            TextPointer     textPointer    = new TextPointer(this._textContainer.Start, this._cpTable, LogicalDirection.Forward);
            Table           table          = (Table)textPointer.Parent;

            this._columnWidths[this._columnIndex] -= this._resizeAmount;
            if (this._columnIndex < table.ColumnCount - 1)
            {
                this._columnWidths[this._columnIndex + 1] += this._resizeAmount;
            }
            if (undoManager != null && undoManager.IsEnabled)
            {
                parentUndoUnit = new ColumnResizeUndoUnit(textPointer, this._columnIndex, this._columnWidths, -this._resizeAmount);
                undoManager.Open(parentUndoUnit);
            }
            TextRangeEditTables.EnsureTableColumnsAreFixedSize(table, this._columnWidths);
            if (parentUndoUnit != null)
            {
                undoManager.Close(parentUndoUnit, UndoCloseAction.Commit);
            }
        }
示例#16
0
        /// <summary>
        /// Add the given parent undo unit to the undo manager, making it the OpenedUnit of the
        /// innermost open parent unit (or the undo manager itself, if no parents are open).
        /// </summary>
        /// <param name="unit">
        /// parent unit to add
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Thrown if UndoManager is disabled or passed unit is already open.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown if passed unit is null.
        /// </exception>
        internal void Open(IParentUndoUnit unit)
        {
            IParentUndoUnit deepestOpen;

            if (!IsEnabled)
            {
                throw new InvalidOperationException(SR.Get(SRID.UndoServiceDisabled));
            }

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

            deepestOpen = DeepestOpenUnit;
            if (deepestOpen == unit)
            {
                throw new InvalidOperationException(SR.Get(SRID.UndoUnitCantBeOpenedTwice));
            }

            if (deepestOpen == null)
            {
                if (unit != LastUnit)
                {
                    // Don't want to add the unit again if we're just reopening it
                    Add(unit as IUndoUnit);
                    SetLastUnit(unit as IUndoUnit);
                }
                SetOpenedUnit(unit);
                unit.Container = this;
            }
            else
            {
                unit.Container = deepestOpen;
                deepestOpen.Open(unit);
            }
        }
        /// <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);
            }
        }
示例#18
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);
            }
        }
示例#19
0
 /// <summary>
 /// current opened unit
 /// </summary>
 /// <param name="value">
 /// IParentUndoUnit to which OpenedUnit is to bet set
 /// </param>
 protected void SetOpenedUnit(IParentUndoUnit value)
 {
     _openedUnit = value;
 }
示例#20
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);
            }
        }
示例#21
0
        /// <summary>
        /// Opens a closed undo unit on the top of the stack.
        /// </summary>
        /// <param name="unit">
        /// IParentUndoUnit to reopen
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Thrown if:
        ///     UndoManager is disabled
        ///     another unit is already open
        ///     the given unit is locked
        ///     the given unit is not on top of the stack
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown if passed unit is null.
        /// </exception>
        internal void Reopen(IParentUndoUnit unit)
        {
            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.UndoUnitAlreadyOpen));
            }

            switch (State)
            {
                case UndoState.Normal :
                case UndoState.Redo :
                {
                    if (UndoCount == 0 || PeekUndoStack() != unit)
                    {
                        throw new InvalidOperationException(SR.Get(SRID.UndoUnitNotOnTopOfStack));
                    }

                    break;
                }

                case UndoState.Undo :
                {
                    if (RedoStack.Count == 0 || (IParentUndoUnit)RedoStack.Peek() != unit)
                    {
                        throw new InvalidOperationException(SR.Get(SRID.UndoUnitNotOnTopOfStack));
                    }

                    break;
                }

                case UndoState.Rollback :
                default :
                    // should only happen if someone changes the UndoState enum or parameter validation
                    Debug.Assert(false);
                    break;
            }
            if (unit.Locked)
            {
                throw new InvalidOperationException(SR.Get(SRID.UndoUnitLocked));
            }

            Open(unit);
            _lastReopenedUnit = unit;
        }
示例#22
0
        /// <summary>
        /// Add the given parent undo unit to the undo manager, making it the OpenedUnit of the
        /// innermost open parent unit (or the undo manager itself, if no parents are open).
        /// </summary>
        /// <param name="unit">
        /// parent unit to add
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Thrown if UndoManager is disabled or passed unit is already open.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown if passed unit is null.
        /// </exception>
        internal void Open(IParentUndoUnit unit)
        {
            IParentUndoUnit deepestOpen;

            if (!IsEnabled)
            {
                throw new InvalidOperationException(SR.Get(SRID.UndoServiceDisabled));
            }

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

            deepestOpen = DeepestOpenUnit;
            if (deepestOpen == unit)
            {
                throw new InvalidOperationException(SR.Get(SRID.UndoUnitCantBeOpenedTwice));
            }

            if (deepestOpen == null)
            {
                if (unit != LastUnit)
                {
                    // Don't want to add the unit again if we're just reopening it
                    Add(unit as IUndoUnit);
                    SetLastUnit(unit as IUndoUnit);
                }
                SetOpenedUnit(unit);
                unit.Container = this;
            }
            else
            {
                unit.Container = deepestOpen;
                deepestOpen.Open(unit);
            }
        }
示例#23
0
 /// <summary>
 /// current opened unit
 /// </summary>
 /// <param name="value">
 /// IParentUndoUnit to which OpenedUnit is to bet set
 /// </param>
 protected void SetOpenedUnit(IParentUndoUnit value)
 {
     _openedUnit = value;
 }
示例#24
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);
            }
        }
示例#25
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: 0x06007319 RID: 29465 RVA: 0x0021047C File Offset: 0x0020E67C
        internal void Add(IUndoUnit unit)
        {
            if (!this.IsEnabled)
            {
                throw new InvalidOperationException(SR.Get("UndoServiceDisabled"));
            }
            if (unit == null)
            {
                throw new ArgumentNullException("unit");
            }
            IParentUndoUnit deepestOpenUnit = this.DeepestOpenUnit;

            if (deepestOpenUnit != null)
            {
                deepestOpenUnit.Add(unit);
                return;
            }
            if (!(unit is IParentUndoUnit))
            {
                throw new InvalidOperationException(SR.Get("UndoNoOpenParentUnit"));
            }
            ((IParentUndoUnit)unit).Container = this;
            if (this.LastUnit is IParentUndoUnit)
            {
                ((IParentUndoUnit)this.LastUnit).OnNextAdd();
            }
            this.SetLastUnit(unit);
            if (this.State == UndoState.Normal || this.State == UndoState.Redo)
            {
                int num = this._topUndoIndex + 1;
                this._topUndoIndex = num;
                if (num == this.UndoLimit)
                {
                    this._topUndoIndex = 0;
                }
                if ((this._topUndoIndex >= this.UndoStack.Count || this.PeekUndoStack() != null) && (this.UndoLimit == -1 || this.UndoStack.Count < this.UndoLimit))
                {
                    this.UndoStack.Add(unit);
                    return;
                }
                if (this.PeekUndoStack() != null)
                {
                    num = this._bottomUndoIndex + 1;
                    this._bottomUndoIndex = num;
                    if (num == this.UndoLimit)
                    {
                        this._bottomUndoIndex = 0;
                    }
                }
                this.UndoStack[this._topUndoIndex] = unit;
                return;
            }
            else
            {
                if (this.State == UndoState.Undo)
                {
                    this.RedoStack.Push(unit);
                    return;
                }
                UndoState state = this.State;
                return;
            }
        }