Exemplo n.º 1
0
        /// <summary>
        /// IOleUndoUnit member - called when user selects to undo/redo an action
        /// </summary>
        public void Do(IOleUndoManager pUndoManager)
        {
            // do all PrependUnits
            List <IOleUndoUnit> prepunits = HandleUnits(PrependUnits, pUndoManager);

            if (isUndo)
            {
                Undo();
            }
            else
            {
                Redo();
            }

            // do all AppendUnits
            List <IOleUndoUnit> appunits = HandleUnits(AppendUnits, pUndoManager);

            this.AppendUnits.Clear();
            this.PrependUnits.Clear();

            this.AppendUnits.AddRange(appunits);
            this.PrependUnits.AddRange(prepunits);

            // add this to the opposite stack
            pUndoManager.Add(this);

            // undo unit becomes redo unit
            isUndo = !isUndo;
        }
Exemplo n.º 2
0
 protected virtual int Do(IOleUndoManager oleUndoManager)
 {
     try
     {
         if (unitState == UndoUnitState.Undoing)
         {
             UndoAction();
         }
         else
         {
             RedoAction();
         }
         unitState = (unitState == UndoUnitState.Undoing) ? UndoUnitState.Redoing : UndoUnitState.Undoing;
         if (oleUndoManager != null)
         {
             oleUndoManager.Add(this);
         }
         return(VSConstants.S_OK);
     }
     catch (COMException e)
     {
         return(e.ErrorCode);
     }
     catch
     {
         return(VSConstants.E_ABORT);
     }
     finally
     {
     }
 }
Exemplo n.º 3
0
        private bool TryUninstallAndAddRedoAction(
            string source,
            string packageName,
            string versionOpt,
            bool includePrerelease,
            EnvDTE.DTE dte,
            EnvDTE.Project dteProject,
            IOleUndoManager undoManager
            )
        {
            var uninstalled = TryUninstallPackage(packageName, dte, dteProject);

            if (uninstalled)
            {
                // if the install succeeded, then add an uninstall item to the undo manager.
                undoManager?.Add(
                    new InstallPackageUndoUnit(
                        this,
                        source,
                        packageName,
                        versionOpt,
                        includePrerelease,
                        dte,
                        dteProject,
                        undoManager
                        )
                    );
            }

            return(uninstalled);
        }
Exemplo n.º 4
0
 /// <summary>
 ///     Close the current undo scope.  This will add the current ParentUndoUnit to the wrapped IOleUndoManager.
 /// </summary>
 public void CloseParentUndoScope()
 {
     if (_parentUndoUnit != null)
     {
         _wrappedUndoManager.Add(_parentUndoUnit);
         _parentUndoUnit = null;
     }
 }
Exemplo n.º 5
0
        public virtual void Do(IOleUndoManager undoManager)
        {
            if (undoManager != null)
                undoManager.Add(this);

            if (Undo)
                HandleUndo();
            else
                HandleRedo();

            //invert the undo state
            Undo = !Undo;
        }
Exemplo n.º 6
0
        public virtual void Do(IOleUndoManager undoManager)
        {
            if (undoManager != null)
            {
                undoManager.Add(this);
            }

            if (Undo)
            {
                HandleUndo();
            }
            else
            {
                HandleRedo();
            }

            //invert the undo state
            Undo = !Undo;
        }
Exemplo n.º 7
0
        private async Task <bool> TryUninstallAndAddRedoActionAsync(
            string source, string packageName, string?version, bool includePrerelease,
            Guid projectGuid, EnvDTE.DTE dte, EnvDTE.Project dteProject, IOleUndoManager undoManager,
            IProgressTracker progressTracker, CancellationToken cancellationToken)
        {
            var uninstalled = await TryUninstallPackageAsync(
                packageName, projectGuid, dte, dteProject, progressTracker, cancellationToken).ConfigureAwait(false);

            if (uninstalled)
            {
                // if the install succeeded, then add an uninstall item to the undo manager.
                await this.ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                undoManager?.Add(new InstallPackageUndoUnit(
                                     this, source, packageName,
                                     version, includePrerelease,
                                     projectGuid, dte, dteProject, undoManager));
            }

            return(uninstalled);
        }
Exemplo n.º 8
0
 // Undoing this instance simply adds it to the Redo stack.
 public override void Do(IOleUndoManager pUndoManager)
 {
     _undoManager.Add(this);
 }
Exemplo n.º 9
0
        private static List <IOleUndoUnit> RemoveTop(IOleUndoManager undoManager, IEnumOleUndoUnits enumerator, int count)
        {
            List <IOleUndoUnit> backupList = new List <IOleUndoUnit>();
            List <IOleUndoUnit> returnList = new List <IOleUndoUnit>();
            int hr;

            if (count > 0)
            {
                uint returned = 1;

                // backup all existing undo units
                while (returned > 0)
                {
                    IOleUndoUnit[] units = new IOleUndoUnit[10];

                    hr = enumerator.Next((uint)units.Length, units, out returned);
                    Marshal.ThrowExceptionForHR(hr);

                    if (returned == 10)
                    {
                        backupList.AddRange(units);
                    }
                    else if (returned > 0)
                    {
                        for (int i = 0; i < returned; i++)
                        {
                            backupList.Add(units[i]);
                        }
                    }
                }

                // put units back except those which should be removed
                if (backupList.Count > 0)
                {
                    PoisonPillUndoUnit pill = new PoisonPillUndoUnit();
                    undoManager.Add(pill);

                    // clear stack
                    undoManager.DiscardFrom(pill);

                    // add units back
                    for (int i = 0; i < backupList.Count - count; i++)
                    {
                        undoManager.Add(backupList[i]);
                    }

                    // return top "count" units or less, if there's not enough
                    if (count <= backupList.Count)
                    {
                        returnList = backupList.GetRange(backupList.Count - count, count);
                    }
                    else
                    {
                        returnList = backupList;
                    }
                }
            }

            returnList.Reverse();
            return(returnList);
        }