Example #1
0
            private IEnumerable <IOleUndoUnit> GetUndoUnits(IOleUndoManager undoManager)
            {
                IEnumOleUndoUnits undoUnitEnumerator;

                try
                {
                    // Unfortunately, EnumUndoable returns the units in oldest-first order.
                    undoManager.EnumUndoable(out undoUnitEnumerator);
                }
                catch (COMException)
                {
                    yield break;
                }

                const int BatchSize = 100;

                IOleUndoUnit[] fetchedUndoUnits = new IOleUndoUnit[BatchSize];

                while (true)
                {
                    undoUnitEnumerator.Next(BatchSize, fetchedUndoUnits, out var fetchedCount);
                    for (int i = 0; i < fetchedCount; i++)
                    {
                        yield return(fetchedUndoUnits[i]);
                    }

                    if (fetchedCount < BatchSize)
                    {
                        break;
                    }
                }
            }
Example #2
0
        /// <summary>
        /// Removes top 'count' items from given undo manager stack, returning removed undo units in a list.
        /// </summary>
        public static List <IOleUndoUnit> RemoveTopFromUndoStack(this IOleUndoManager undoManager, int count)
        {
            if (undoManager == null)
            {
                throw new ArgumentNullException("undoManager");
            }
            if (count < 0)
            {
                throw new ArgumentException("Count must be greater than or equal to zero.");
            }

            IEnumOleUndoUnits enumerator;

            undoManager.EnumUndoable(out enumerator);
            if (enumerator == null)
            {
                throw new InvalidOperationException("Undo manager seems to be incorrectly implemented.");
            }

            return(RemoveTop(undoManager, enumerator, count));
        }
Example #3
0
 public void EnumUndoable(out IEnumOleUndoUnits ppEnum)
 {
     _wrappedUndoManager.EnumUndoable(out ppEnum);
 }