コード例 #1
0
ファイル: UndoStack.cs プロジェクト: polytronicgr/netrix
        public List <IUndoObject> GetUndoHistory()
        {
            int i = 0;

            Interop.IOleUndoUnit      unit;
            Interop.IEnumOleUndoUnits undoUnits = null;
            undoUnits = ((Interop.IOleUndoManager)_undoManager).EnumUndoable();
            System.Collections.Generic.List <UndoUnit> undos = new List <UndoUnit>();
            if (undoUnits != null)
            {
                undoUnits.Reset();
                try
                {
                    while (i == 0)
                    {
                        undoUnits.Next(1, out unit, out i);
                        if (undoUnits == null || i == 0)
                        {
                            break;
                        }
                        undos.Add(new UndoUnit(unit, ((Interop.IOleUndoManager)_undoManager)));
                        i = 0;
                    }
                }
                catch
                {
                }
            }
            return(undos);
        }
コード例 #2
0
        private void Pack(Interop.IEnumOleUndoUnits enumerator)
        {
            enumerator.Reset();
            Interop.IOleUndoUnit[] units = new Interop.IOleUndoUnit[(uint)_startIndex];
            _undoUnits = new Interop.IOleUndoUnit[(uint)_numUndos];
            //IntPtr j1 = IntPtr.Zero;
            Interop.IOleUndoUnit unit;
            int i1 = 0;

            for (int k = 0; k < _startIndex; k++)
            {
                enumerator.Next(1, out unit, out i1);
                units[k] = unit; // (Interop.IOleUndoUnit)Marshal.GetObjectForIUnknown(unit);
                //Marshal.Release(unit);
            }
            for (int i2 = 0; i2 < _numUndos; i2++)
            {
                enumerator.Next(1, out unit, out i1);
                _undoUnits[i2] = unit; // (Interop.IOleUndoUnit)Marshal.GetObjectForIUnknown(unit);
                //Marshal.Release(unit);
            }
            undoManager.DiscardFrom(null);
            for (int j2 = 0; j2 < _startIndex; j2++)
            {
                if (units[j2] == null)
                {
                    continue;
                }
                undoManager.Add(units[j2]);
            }
            undoManager.Add(this);
        }
コード例 #3
0
 public void Open()
 {
     try
     {
         Interop.IEnumOleUndoUnits units = null;
         if (_type == BatchedUndoType.Undo)
         {
             undoManager.Enable(true);
             units = undoManager.EnumUndoable();
             if (units != null)
             {
                 _startIndex = CountUndos(units);
             }
         }
         else
         {
             undoManager.Enable(true);
             units = undoManager.EnumRedoable();
             if (units != null)
             {
                 _startIndex = CountUndos(units);
             }
         }
     }
     catch
     {
         _startIndex = 0; // restart in case of error
     }
 }
コード例 #4
0
        /// <summary>
        /// Counts number of undo operations.
        /// </summary>
        /// <param name="enumerator"></param>
        /// <returns>Number of undo operations.</returns>
        private int CountUndos(Interop.IEnumOleUndoUnits enumerator)
        {
            int j = 0;
            int i = 0;

            //IntPtr k = IntPtr.Zero;
            Interop.IOleUndoUnit unit;
            if (enumerator == null)
            {
                return(0);
            }
            try
            {
                enumerator.Reset();
            }
            catch
            {
                return(0);
            }
            try
            {
                while (i == 0)
                {
                    enumerator.Next(1, out unit, out i);
                    if (unit != null)
                    {
                        if (unit is BatchedUndoUnit)
                        {
                            // packed steps
                        }
                        else
                        {
                            Marshal.ReleaseComObject(unit);
                        }
                    }
                    if (enumerator == null || i == 0)
                    {
                        break;
                    }
                    i = 0;
                    j++;
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message, "UNDO->COUNTUNDOS->ERROR");
            }
            finally
            {
                enumerator.Reset();
            }
            return(j);
        }
コード例 #5
0
ファイル: UndoStack.cs プロジェクト: polytronicgr/netrix
 public void Open()
 {
     ((Interop.IOleUndoManager)_undoManager).Enable(true);
     _undoUnits = ((Interop.IOleUndoManager)_undoManager).EnumUndoable();
     if (_undoUnits != null)
     {
         _startIndex = CountUndos();
     }
     else
     {
         _startIndex = 0;
     }
 }
コード例 #6
0
ファイル: UndoStack.cs プロジェクト: polytronicgr/netrix
 public void Close()
 {
     try
     {
         int i = 0;
         _undoUnits = ((Interop.IOleUndoManager)_undoManager).EnumUndoable();
         i          = CountUndos();
         _numUndos  = Math.Max(0, i - _startIndex);
         PackThis();
     }
     catch
     {
     }
 }
コード例 #7
0
        /// <summary>
        /// Returns the collection of Undo/Redo objects available.
        /// </summary>
        /// <remarks>
        /// The current type of unit object decided whether this method returns the Undo or Redo history.
        /// The collections consists of <see cref="UndoObject"/> objects, which implement <see cref="IUndoObject"/>.
        /// These objects may have information about subobjects, which the undo manager creates if the user
        /// requests packed undo sequences.
        /// </remarks>
        /// <seealso cref="NumChildUndos"/>
        /// <seealso cref="HasChildUndos"/>
        /// <seealso cref="UndoObject"/>
        /// <seealso cref="Type"/>
        /// <returns>Returns a collection of objects of type <see cref="IUndoObject"/>.</returns>
        public System.Collections.Generic.List <IUndoObject> GetUndoHistory()
        {
            int i = 0;

            //IntPtr k = IntPtr.Zero;
            Interop.IOleUndoUnit      unit;
            Interop.IEnumOleUndoUnits undoUnits = null;
            if (_type == BatchedUndoType.Undo)
            {
                undoUnits = ((HtmlEditor)_editor).UndoManager.EnumUndoable();
            }
            else
            {
                undoUnits = ((HtmlEditor)_editor).UndoManager.EnumRedoable();
            }
            System.Collections.Generic.List <IUndoObject> undos = new System.Collections.Generic.List <IUndoObject>();
            if (undoUnits != null)
            {
                undoUnits.Reset();
                try
                {
                    while (i == 0)
                    {
                        undoUnits.Next(1, out unit, out i);
                        if (undoUnits == null || i == 0)
                        {
                            break;
                        }                        //Interop.IOleUndoUnit unit = (Interop.IOleUndoUnit) Marshal.GetObjectForIUnknown(k);
                        string s;
                        unit.GetDescription(out s);
                        UndoUnit managedUndo = null;
                        if (unit is UndoUnit)
                        {
                            managedUndo = (UndoUnit)unit;
                        }
                        else
                        {
                            managedUndo = new UndoUnit(unit, ((HtmlEditor)_editor).UndoManager);
                        }
                        UndoObject wrappedObject = new UndoObject(s, managedUndo, ((HtmlEditor)_editor).UndoManager);
                        undos.Add(wrappedObject);
                        i = 0;
                    }
                }
                catch
                {
                }
            }
            return(undos);
        }