Exemple #1
0
        /// <summary>
        /// Adds a unit to the undo manager without executing it
        /// </summary>
        /// <param name="unit">The UndoUnit to add</param>
        void Add(UndoUnit <T> unit)
        {
            if (IsBlocked)
            {
                throw new InvalidOperationException("Attempt to add undo operation while blocked");
            }

            if (CurrentGroup != null)
            {
                CurrentGroup.Add(unit);
            }
            else
            {
                RemoveAllRedoUnits();
                _units.Add(unit);

                // Limit undo stack size
                if (_units.Count > _maxUnits)
                {
                    // Update unmodified index
                    if (_unmodifiedPos >= 0)
                    {
                        _unmodifiedPos--;
                    }

                    // Remove
                    _units.RemoveAt(0);
                }
                else
                {
                    _currentPos++;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Execute an undo unit and add it to the manager
        /// </summary>
        /// <param name="unit">The undo unit to execute</param>
        public void Do(UndoUnit <T> unit)
        {
            // Only if not blocked
            if (IsBlocked)
            {
                throw new InvalidOperationException("Attempt to execute undo operation while blocked");
            }

            // Fire start
            if (CurrentGroup == null)
            {
                OnStartOperation();
            }

            // Remember if was modified
            bool wasModified = IsModified;

            try
            {
                // Do it
                unit.Do(_context);
                Add(unit);
            }
            finally
            {
                // End operation if not in a group
                if (CurrentGroup == null)
                {
                    OnEndOperation();
                }

                // Fire modified changed
                if (wasModified != IsModified)
                {
                    OnModifiedChanged();
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Inserts an unit to this group
 /// </summary>
 /// <param name="position">The position at which the unit should be inserted</param>
 /// <param name="unit">The UndoUnit to be inserted</param>
 public void Insert(int position, UndoUnit <T> unit)
 {
     unit.Group = this;
     _units.Insert(position, unit);
 }
Exemple #4
0
 /// <summary>
 /// Adds a unit to this group
 /// </summary>
 /// <param name="unit">The UndoUnit to be added</param>
 public void Add(UndoUnit <T> unit)
 {
     unit.Group = this;
     _units.Add(unit);
 }