public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97) { for (int i = 0; i < cCmds; i++) { switch ((VSConstants.VSStd97CmdID)prgCmds[i].cmdID) { case VSConstants.VSStd97CmdID.GotoDefn: prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); return(VSConstants.S_OK); } } } else if (pguidCmdGroup == VSConstants.VsStd12) { for (int i = 0; i < cCmds; i++) { switch ((VSConstants.VSStd12CmdID)prgCmds[i].cmdID) { case VSConstants.VSStd12CmdID.PeekDefinition: var canPeek = _peekBroker.CanTriggerPeekSession( _textView, PredefinedPeekRelationships.Definitions.Name, filename => false ); prgCmds[i].cmdf = (uint)OLECMDF.OLECMDF_SUPPORTED; prgCmds[0].cmdf |= (uint)(canPeek == true ? OLECMDF.OLECMDF_ENABLED : OLECMDF.OLECMDF_INVISIBLE); return(VSConstants.S_OK); } } } return(Next.QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText)); }
/// <summary> /// Called from VS to see what commands we support. /// </summary> public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97) { for (int i = 0; i < cCmds; i++) { switch ((VSConstants.VSStd97CmdID)prgCmds[i].cmdID) { case VSConstants.VSStd97CmdID.GotoDefn: prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); break; case VSConstants.VSStd97CmdID.FindReferences: prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); break; } } } else if (pguidCmdGroup == VSConstants.VsStd12) { for (int i = 0; i < cCmds; i++) { switch ((VSConstants.VSStd12CmdID)prgCmds[i].cmdID) { case VSConstants.VSStd12CmdID.PeekDefinition: // Since our provider supports standalone files, // the predicate isn't invoked but it needs to be non null. var canPeek = _peekBroker?.CanTriggerPeekSession( _textView, PredefinedPeekRelationships.Definitions.Name, isStandaloneFilePredicate: (string filename) => false ); prgCmds[i].cmdf = (uint)OLECMDF.OLECMDF_SUPPORTED; prgCmds[0].cmdf |= (uint)(canPeek == true ? OLECMDF.OLECMDF_ENABLED : OLECMDF.OLECMDF_INVISIBLE); break; } } } else if (pguidCmdGroup == GuidList.guidPythonToolsCmdSet) { for (int i = 0; i < cCmds; i++) { switch (prgCmds[i].cmdID) { case PkgCmdIDList.cmdidRefactorRenameIntegratedShell: // C# provides the refactor context menu for the main VS command outside // of the integrated shell. In the integrated shell we provide our own // command for it so these still show up. prgCmds[i].cmdf = CommandDisabledAndHidden; break; case PkgCmdIDList.cmdidExtractMethodIntegratedShell: // C# provides the refactor context menu for the main VS command outside // of the integrated shell. In the integrated shell we provide our own // command for it so these still show up. prgCmds[i].cmdf = CommandDisabledAndHidden; break; case CommonConstants.StartDebuggingCmdId: case CommonConstants.StartWithoutDebuggingCmdId: // Don't enable the command when the file is null or doesn't exist, // which can happen in the diff window. if (File.Exists(_textView.GetFilePath())) { prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); } else { prgCmds[i].cmdf = CommandDisabledAndHidden; } return(VSConstants.S_OK); default: lock (PythonToolsPackage.CommandsLock) { foreach (var command in PythonToolsPackage.Commands.Keys) { if (command.CommandId == prgCmds[i].cmdID) { int?res = command.EditFilterQueryStatus(ref prgCmds[i], pCmdText); if (res != null) { return(res.Value); } } } } break; } } } else if (pguidCmdGroup == CommonConstants.Std2KCmdGroupGuid) { for (int i = 0; i < cCmds; i++) { switch ((VSConstants.VSStd2KCmdID)prgCmds[i].cmdID) { case VSConstants.VSStd2KCmdID.FORMATDOCUMENT: case VSConstants.VSStd2KCmdID.FORMATSELECTION: case VSConstants.VSStd2KCmdID.SHOWMEMBERLIST: case VSConstants.VSStd2KCmdID.COMPLETEWORD: case VSConstants.VSStd2KCmdID.QUICKINFO: case VSConstants.VSStd2KCmdID.PARAMINFO: prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); break; case VSConstants.VSStd2KCmdID.OUTLN_STOP_HIDING_ALL: if (_textView.GetOutliningTagger()?.Enabled == true) { prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); } break; case VSConstants.VSStd2KCmdID.OUTLN_START_AUTOHIDING: if (_textView.GetOutliningTagger()?.Enabled == false) { prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); } break; case VSConstants.VSStd2KCmdID.COMMENT_BLOCK: case VSConstants.VSStd2KCmdID.COMMENTBLOCK: case VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK: case VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK: prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); break; case VSConstants.VSStd2KCmdID.EXTRACTMETHOD: QueryStatusExtractMethod(prgCmds, i); break; case VSConstants.VSStd2KCmdID.RENAME: QueryStatusRename(prgCmds, i); break; } } } if (prgCmds.All(f => f.cmdf != 0)) { return(VSConstants.S_OK); } return(_next.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText)); }