Exemplo n.º 1
0
        /// <summary>
        /// Provides a first chance to handle any command that MSOLE.IOleCommandTarget.QueryStatus
        /// informed the shell to pass to this window. Implements IOleCommandTarget.Exec
        /// </summary>
        protected int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            int  hr      = 0;
            bool handled = true;

            // Only handle commands from the Office 97 Command Set (aka VSStandardCommandSet97).
            if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)
            {
                // Default to a not-supported status.
                hr = (int)MSOLE.Constants.OLECMDERR_E_NOTSUPPORTED;
                MSOLE.IOleCommandTarget forwardTo = myTextBox as MSOLE.IOleCommandTarget;
                if (forwardTo != null)
                {
                    hr = forwardTo.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
                    // We enabled the command, so we say we handled it regardless of the further conditions
                    if (hr != (int)MSOLE.Constants.OLECMDERR_E_NOTSUPPORTED && hr != (int)MSOLE.Constants.OLECMDERR_E_UNKNOWNGROUP)
                    {
                        hr = VSConstants.S_OK;
                    }
                    else
                    {
                        handled = false;
                    }
                }
                else
                {
                    // If the command is from our command set, but not explicitly handled, inform the shell
                    // that we didn't handle the command.
                    handled = false;
                    hr      = (int)MSOLE.Constants.OLECMDERR_E_NOTSUPPORTED;
                }
            }
            // The command is from an unknown group.
            else
            {
                handled = false;
                hr      = (int)MSOLE.Constants.OLECMDERR_E_UNKNOWNGROUP;
            }

            if (!handled)
            {
                Debug.Assert(ErrorHandler.Failed(hr));
                ModelingDocData docData = CurrentDocument;
                Microsoft.VisualStudio.Modeling.Shell.UndoManager undoManager;
                MSOLE.IOleCommandTarget forwardTo;
                if ((docData != null &&
                     null != (undoManager = docData.UndoManager) &&
                     null != (forwardTo = undoManager.VSUndoManager as MSOLE.IOleCommandTarget)) ||
                    null != (forwardTo = GetService(typeof(MSOLE.IOleCommandTarget)) as MSOLE.IOleCommandTarget))
                {
                    // If the command wasn't handled already, give the undo manager a chance to handle the command.
                    hr = forwardTo.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
                }
            }
            return(hr);
        }
Exemplo n.º 2
0
        public int HandleCommand(IWpfTextView textView, OleInterop.IOleCommandTarget commandTarget)
        {
            Guid cmdGroup = VSConstants.VSStd2K;

            // Execute FormatSelection or FormatDocument depending on current state of selected code
            uint cmdID = IsCursorOnly(textView) ? (uint)VSConstants.VSStd2KCmdID.FORMATDOCUMENT : (uint)VSConstants.VSStd2KCmdID.FORMATSELECTION;

            commandTarget.Exec(ref cmdGroup, cmdID, (uint)OleInterop.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, IntPtr.Zero, IntPtr.Zero);

            return(VSConstants.S_OK);
        }
        protected virtual void RefreshMsTestWindow()
        {
            //refreshCmdGuid,cmdID is the command id of refresh command.
            Guid refreshCmdGuid = new Guid("{B85579AA-8BE0-4C4F-A850-90902B317571}");

            VSOLE.IOleCommandTarget cmdTarget = Package.GetGlobalService(typeof(SUIHostCommandDispatcher)) as VSOLE.IOleCommandTarget;
            const uint cmdID = 13109;

            if (cmdTarget != null)
            {
                cmdTarget.Exec(ref refreshCmdGuid, cmdID, (uint)VSOLE.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, IntPtr.Zero, IntPtr.Zero);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Provides a first chance to tell the shell that this window is capable
        /// of handling certain commands. Implements IOleCommandTarget.QueryStatus
        /// </summary>
        protected int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, MSOLE.OLECMD[] prgCmds, IntPtr pCmdText)
        {
            int  hr      = VSConstants.S_OK;
            bool handled = true;

            if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97)               // Only handle commands from the Office 97
            // Command Set (aka VSStandardCommandSet97).
            {
                MSOLE.IOleCommandTarget forwardTo = myTextBox as MSOLE.IOleCommandTarget;
                if (forwardTo != null)
                {
                    hr      = forwardTo.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
                    handled = hr != (int)MSOLE.Constants.OLECMDERR_E_NOTSUPPORTED && hr != (int)MSOLE.Constants.OLECMDERR_E_UNKNOWNGROUP;
                }
                else
                {
                    // Inform the shell that we don't support any other commands.
                    hr      = (int)MSOLE.Constants.OLECMDERR_E_NOTSUPPORTED;
                    handled = false;
                }
            }
            else
            {
                // Inform the shell that we don't recognize this command group.
                handled = false;
                hr      = (int)MSOLE.Constants.OLECMDERR_E_UNKNOWNGROUP;
            }
            if (!handled)
            {
                Debug.Assert(ErrorHandler.Failed(hr));
                ModelingDocData docData = CurrentDocument;
                Microsoft.VisualStudio.Modeling.Shell.UndoManager undoManager;
                MSOLE.IOleCommandTarget forwardTo;
                if ((docData != null &&
                     null != (undoManager = docData.UndoManager) &&
                     null != (forwardTo = undoManager.VSUndoManager as MSOLE.IOleCommandTarget)) ||
                    null != (forwardTo = GetService(typeof(MSOLE.IOleCommandTarget)) as MSOLE.IOleCommandTarget))
                {
                    // If the command wasn't handled already, forward it to the undo manager.
                    hr = forwardTo.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
                }
                else
                {
                    hr = (int)MSOLE.Constants.MSOCMDERR_E_NOTSUPPORTED;
                }
            }
            return(hr);
        }
Exemplo n.º 5
0
        public int HandleCommand(IWpfTextView textView, IClassifier classifier, OleInterop.IOleCommandTarget commandTarget, IEditorOperations editorOperations)
        {
            Guid cmdGroup = VSConstants.VSStd2K;

            // Is anything selected? (Or just a cursor)
            bool cursorOnly = IsCursorOnly(textView);

            // Execute Comment or Uncomment depending on current state of selected code
            uint cmdID = IsAllCommented(textView, classifier) ? (uint)VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK : (uint)VSConstants.VSStd2KCmdID.COMMENT_BLOCK;
            int  hr    = commandTarget.Exec(ref cmdGroup, cmdID, (uint)OleInterop.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, IntPtr.Zero, IntPtr.Zero);

            if (cursorOnly)
            {
                // Move caret down one line
                editorOperations.MoveLineDown(extendSelection: false);
            }

            return(VSConstants.S_OK);
        }
Exemplo n.º 6
0
 public override void ShowContextMenu(int menuId, Guid groupGuid, Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget target, int x, int y)
 {
     base.ShowContextMenu(menuId, groupGuid, target, x, y);
 }
Exemplo n.º 7
0
 public int RemoveCommandFilter(Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget pCmdTarg)
 {
     this.installedFilter = null;
     return(VSConstants.S_OK);
 }
Exemplo n.º 8
0
        public static int HandleCommand(IWpfTextView textView, IClassifier classifier, OleInterop.IOleCommandTarget commandTarget, IEditorOperations editorOperations)
        {
            // TODO: Handle UNDO management. This should occur as a single undo-able transaction in the Undo history
            editorOperations.MoveToEndOfLine(false);
            editorOperations.Delete();
            editorOperations.DeleteHorizontalWhiteSpace();

            return(VSConstants.S_OK);
        }
Exemplo n.º 9
0
 public int HandleCommand(IWpfTextView textView, OleInterop.IOleCommandTarget commandTarget, IEditorOperations editorOperations)
 {
     return(textView.MoveMemberDown(commandTarget, editorOperations));
 }