public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup == GUID_VSStandardCommandSet97) { switch ((VSStd97CmdID)prgCmds[0].cmdID) { case VSStd97CmdID.GotoRef: case VSStd97CmdID.GotoDefn: return (int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED; } } else if (pguidCmdGroup == VSStd2K) { switch ((VSStd2KCmdID)prgCmds[0].cmdID) { case VSStd2KCmdID.AUTOCOMPLETE: case VSStd2KCmdID.SHOWMEMBERLIST: case VSStd2KCmdID.COMPLETEWORD: prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_ENABLED | (int)OLECMDF.OLECMDF_SUPPORTED; return S_OK; } } return _nextTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); }
public bool IsCommandSupported(Guid commandGuid, uint commandId, out uint flags) { flags = 0; OLECMD[] cmd = new OLECMD[1]; cmd[0].cmdID = commandId; OLECMDTEXT commandText = new OLECMDTEXT(); int hr; GCHandle handle = GCHandle.Alloc(commandText, GCHandleType.Pinned); try { hr = target.QueryStatus(ref commandGuid, 1, cmd, handle.AddrOfPinnedObject()); } finally { handle.Free(); } if ((int)OleConstants.OLECMDERR_E_NOTSUPPORTED == hr) { return(false); } Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(hr); flags = cmd[0].cmdf; return(0 != (flags & (uint)OLECMDF.OLECMDF_SUPPORTED)); }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (commandFilter.QueryStatus(editorContext, pguidCmdGroup, prgCmds[0])) return VSConstants.S_OK; return Next.QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText); }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup != VsConstants.COMMANDS_GROUP_GLOBAL_GUID && pguidCmdGroup != VsConstants.COMMANDS_GROUP_SOLUTION_GUID && pguidCmdGroup != VsConstants.COMMANDS_GROUP_PROJECT_GUID) return OLECMDERR_E_UNKNOWNGROUP; if (cCmds < 1) return S_OK; var command = this[pguidCmdGroup, prgCmds[0].cmdID]; if (command == null) return OLECMDERR_E_NOTSUPPORTED; var status = command.Status; if (status == UICommandState.Disabled) prgCmds[0].cmdf = 0u; else prgCmds[0].cmdf = (uint)OLECMDF.SUPPORTED; if (status == UICommandState.Enabled) prgCmds[0].cmdf |= (uint)OLECMDF.ENABLED; else if (status == UICommandState.Hidden) prgCmds[0].cmdf |= (uint)OLECMDF.INVISIBLE; return S_OK; }
private ReSharperStatus IsReSharperEnabled() { AssertIsForeground(); // Quick exit if resharper is either uninstalled or not enabled if (!_resharperExtensionEnabled) { return(ReSharperStatus.NotInstalledOrDisabled); } if (_oleCommandTarget == null) { _oleCommandTarget = _serviceProvider.GetService <IOleCommandTarget, SUIHostCommandDispatcher>(); } var cmds = new OLECMD[1]; cmds[0].cmdID = SuspendId; cmds[0].cmdf = 0; var hr = _oleCommandTarget.QueryStatus(ReSharperCommandGroup, (uint)cmds.Length, cmds, IntPtr.Zero); if (ErrorHandler.Failed(hr)) { // In the case of an error when attempting to get the status, pretend that ReSharper isn't enabled. We also // shut down monitoring so we don't keep hitting this. FatalError.ReportWithoutCrash(Marshal.GetExceptionForHR(hr)); Shutdown(); return(ReSharperStatus.NotInstalledOrDisabled); } // When ReSharper is enabled, the ReSharper_Suspend command has the Enabled | Supported flags. When disabled, it has Invisible | Supported. return(((OLECMDF)cmds[0].cmdf).HasFlag(OLECMDF.OLECMDF_ENABLED) ? ReSharperStatus.Enabled : ReSharperStatus.Suspended); }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { var commandId = new CommandID(pguidCmdGroup, (int)prgCmds[0].cmdID); bool isSupported = false; try { isSupported = _owner._commandTarget.HandlesCommand(commandId); } catch (Exception e) { Logger.LogError(e, "Error in {0}.HandlesCommand.", _owner._commandTarget.GetType().FullName); } if (!isSupported) { if (_owner.NextCommandTarget == null) { return (int)Constants.OLECMDERR_E_NOTSUPPORTED; } else { return OleCommandTargetSpy.WrapQueryStatus(_owner, _owner.NextCommandTarget, ref pguidCmdGroup, cCmds, prgCmds, pCmdText); } } bool isEnabled = _owner._commandTarget.IsEnabled(commandId); prgCmds[0].cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED); if (isEnabled) prgCmds[0].cmdf |= (uint)(OLECMDF.OLECMDF_ENABLED); return VSConstants.S_OK; }
public static int WrapQueryStatus( IOleCommandTarget receiver, IOleCommandTarget implementer, ref System.Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, System.IntPtr pCmdText) { Debug.Assert(receiver != null); var commandId = new CommandID(pguidCmdGroup, (int)prgCmds[0].cmdID); if (LogCommand(commandId)) { Logger.LogInfo("WrapQueryStatus: => recv={0}, impl={1}, parent={2}", receiver, GetImplementerString(implementer), GetParentTargetString(implementer)); } var hr = (implementer == null) ? (int)Constants.OLECMDERR_E_NOTSUPPORTED : implementer.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); if (LogCommand(commandId)) { Logger.LogInfo("WrapQueryStatus: <= recv={0}, impl={1}, parent={2}, hr={3}, cmdf={4}", receiver, GetImplementerString(implementer), GetParentTargetString(implementer), HrToString(hr), CmdFlagsToString(prgCmds)); } return hr; }
int IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { Debug.Assert(this.sqmCommandHandler != null, "SQM handler should not be null"); // Delegate to SQM handler to see if the if commandIds are in SQM range. int result = this.sqmCommandHandler.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); Debug.Assert(result == (int)OLEConstants.OLECMDERR_E_NOTSUPPORTED || result == VSConstants.S_OK, "Unexpected return value from the generated SQM target handler"); if (!ErrorHandler.Succeeded(result)) { // Otherwise delegate to the package's default implementation. IOleCommandTarget target = this.GetService(typeof(IOleCommandTarget)) as IOleCommandTarget; if (target != null) { result = target.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); } else { result = VSConstants.OLE_E_ADVISENOTSUPPORTED; } } return result; }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup == GuidList.guidLocalRefactorCmdSet && (prgCmds[0].cmdID == PkgCmdIDList.cmdidExtractVariable || prgCmds[0].cmdID == PkgCmdIDList.cmdidExtractConstant)) { if (codeManipulator.HasExpressionSelected) prgCmds[0].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); else prgCmds[0].cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED); return VSConstants.S_OK; } if (pguidCmdGroup == GuidList.guidLocalRefactorCmdSet && (prgCmds[0].cmdID == PkgCmdIDList.cmdidAssignParameter || prgCmds[0].cmdID == PkgCmdIDList.cmdidConvertVariable)) { if (codeManipulator.HasCode) prgCmds[0].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); else prgCmds[0].cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED); return VSConstants.S_OK; } return Next.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup == VSConstants.VSStd2K && prgCmds != null) { switch (prgCmds[0].cmdID) { case (uint)VSConstants.VSStd2KCmdID.SHOWCONTEXTMENU: { prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_SUPPORTED | (uint)OLECMDF.OLECMDF_ENABLED; return VSConstants.S_OK; } case (uint)VSConstants.VSStd2KCmdID.ECMD_LEFTCLICK: { prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_SUPPORTED | (uint)OLECMDF.OLECMDF_ENABLED; return VSConstants.S_OK; } default: { return oldFilter.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); } } } else { return oldFilter.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); } }
public void FormatDocument(string filePath) { IVsUIHierarchy vsUIHierarchy = null; uint num = 0; IVsWindowFrame vsWindowFrame = null; if (!VsShellUtilities.IsDocumentOpen(this.VisualStudio.ServiceProvider, filePath, Guid.Empty, out vsUIHierarchy, out num, out vsWindowFrame)) { return; } IOleCommandTarget textView = (IOleCommandTarget)VsShellUtilities.GetTextView(vsWindowFrame); Guid gUID = typeof(VSConstants.VSStd2KCmdID).GUID; OLECMD[] oLECMDArray = new OLECMD[1]; OLECMD oLECMD = new OLECMD() { cmdID = 143 }; oLECMDArray[0] = oLECMD; OLECMD[] oLECMDArray1 = oLECMDArray; int num1 = textView.QueryStatus(ref gUID, 1, oLECMDArray1, IntPtr.Zero); Marshal.ThrowExceptionForHR(num1); if (oLECMDArray1[0].cmdf == 3) { num1 = textView.Exec(ref gUID, 143, 0, IntPtr.Zero, IntPtr.Zero); Marshal.ThrowExceptionForHR(num1); } }
public override void Apply(Workspace workspace, CancellationToken cancellationToken = default) { var visualStudioWorkspace = (VisualStudioWorkspaceImpl)workspace; if (!visualStudioWorkspace.TryAddReferenceToProject(_projectId, "*" + _assemblyIdentity.GetDisplayName())) { // We failed to add the reference, which means the project system wasn't able to bind. // We'll pop up the Add Reference dialog to let the user figure this out themselves. // This is the same approach done in CVBErrorFixApply::ApplyAddMetaReferenceFix if (visualStudioWorkspace.GetHierarchy(_projectId) is IVsUIHierarchy uiHierarchy) { var command = new OLECMD[1]; command[0].cmdID = (uint)VSConstants.VSStd2KCmdID.ADDREFERENCE; if (ErrorHandler.Succeeded(uiHierarchy.QueryStatusCommand((uint)VSConstants.VSITEMID.Root, VSConstants.VSStd2K, 1, command, IntPtr.Zero))) { if ((((OLECMDF)command[0].cmdf) & OLECMDF.OLECMDF_ENABLED) != 0) { uiHierarchy.ExecCommand((uint)VSConstants.VSITEMID.Root, VSConstants.VSStd2K, (uint)VSConstants.VSStd2KCmdID.ADDREFERENCE, 0, IntPtr.Zero, IntPtr.Zero); } } } } }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { var hr = (int)Constants.OLECMDERR_E_NOTSUPPORTED; // we want the VSConstants.VSStd97CmdID.NewWindow and the VSConstants.VSStd97CmdID.ViewCode to be handled by the // WindowPane rather than the text editor host. if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97) { if (cCmds == 1 && (prgCmds[0].cmdID == (int)VSConstants.VSStd97CmdID.NewWindow || prgCmds[0].cmdID == (int)VSConstants.VSStd97CmdID.ViewCode || prgCmds[0].cmdID == (int)VSConstants.VSStd97CmdID.ViewForm)) { var oleCommandTarget = GetService(typeof(IOleCommandTarget)) as IOleCommandTarget; if (oleCommandTarget != null) { return oleCommandTarget.QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText); } } } if (OleCommandTarget != null) { hr = OleCommandTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); } return hr; }
// hide a manu command protected int DisableCommand(ref OLECMD command) { command.cmdf = (uint)OLECMDF.OLECMDF_SUPPORTED | (uint)OLECMDF.OLECMDF_INVISIBLE; return(VSConstants.S_OK); }
private int QueryStatusImpl(Guid pguidCmdGroup, OLECMD cmd) { if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97) { Debug.Print("Query {0}-{1}", "GUID_VSStandardCommandSet97", (VSConstants.VSStd97CmdID)cmd.cmdID); } if (pguidCmdGroup == typeof(VSConstants.VSStd2KCmdID).GUID) { Debug.Print("Query {0}-{1}", "VSStd2KCmdID", (VSConstants.VSStd2KCmdID)cmd.cmdID); switch ((VSConstants.VSStd2KCmdID)cmd.cmdID) { case VSConstants.VSStd2KCmdID.SHOWMEMBERLIST: case VSConstants.VSStd2KCmdID.COMPLETEWORD: //case VSConstants.VSStd2KCmdID.PARAMINFO: //case VSConstants.VSStd2KCmdID.QUICKINFO: case VSConstants.VSStd2KCmdID.AUTOCOMPLETE: return((int)OLECMDF.OLECMDF_ENABLED | (int)OLECMDF.OLECMDF_SUPPORTED); } } else if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97) { switch ((VSConstants.VSStd97CmdID)cmd.cmdID) { case VSConstants.VSStd97CmdID.GotoDefn: case VSConstants.VSStd97CmdID.FindReferences: return((int)OLECMDF.OLECMDF_ENABLED | (int)OLECMDF.OLECMDF_SUPPORTED); } } return(VSConstants.E_FAIL); }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup.Equals(Constants.guidStandardCommandSet2K) && prgCmds[0].cmdID == (uint)VSConstants.VSStd2KCmdID.INCLUDEINPROJECT) prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_SUPPORTED | (uint)OLECMDF.OLECMDF_ENABLED; return VSConstants.S_OK; }
private OleMenuCommand GetSupportedManagePackageCommand() { // Call QueryStatus for _managePackageDialogCommand and _managePackageForSolutionDialogCommand below // to refresh the visibility of the command which is used to determine whether search results should be displayed or not. // The following API QueryStatusCommand returns S_OK if successful // int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText); // Note that both the commands belong to the commandGroup. That is, the first parameter GUID representing the cmdGroup // is the same for both the commands. Hence, it is possible to query for their status in a single call OLECMD[] cmd = new OLECMD[2]; cmd[0].cmdID = (uint)_managePackageDialogCommand.CommandID.ID; cmd[1].cmdID = (uint)_managePackageForSolutionDialogCommand.CommandID.ID; Guid guid = _managePackageDialogCommand.CommandID.Guid; int result = ((IOleCommandTarget)_provider.MenuCommandService).QueryStatus(pguidCmdGroup: ref guid, cCmds: 2u, prgCmds: cmd, pCmdText: (IntPtr)null); // At this point, if result == S_OK, the visibility of the commands are up to date and can be used confidently if (result == VSConstants.S_OK && _managePackageDialogCommand.Visible && _managePackageDialogCommand.Enabled) { return(_managePackageDialogCommand); } if (result == VSConstants.S_OK && _managePackageForSolutionDialogCommand.Visible && _managePackageForSolutionDialogCommand.Enabled) { return(_managePackageForSolutionDialogCommand); } return(null); }
int IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (_nextTarget != null) { var result = _nextTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); if (result != (int)VSConstants.S_OK) { return result; } } for (uint i = 0; i < cCmds; ++i) { if (pguidCmdGroup == typeof(VSStd2KCmdID).GUID) { ICommandHandler handler; if (pguidCmdGroup == typeof(VSStd2KCmdID).GUID && _commandHandlers.TryGetValue((VSStd2KCmdID)prgCmds[i].cmdID, out handler)) { if (_textView.TextBuffer.CheckEditAccess() && handler.IsEnabled(_textView)) { prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED); } else { prgCmds[i].cmdf = (uint)OLECMDF.OLECMDF_SUPPORTED; } } } } return VSConstants.S_OK; }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (!MarkdownEditorPackage.Options.EnableHotKeys) return _nextCommandTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); if (pguidCmdGroup != _commandGroup) return _nextCommandTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); for (int i = 0; i < cCmds; i++) { if (_commandId == prgCmds[i].cmdID) { if (!_view.Selection.IsEmpty) { prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); } else { prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_SUPPORTED; } return VSConstants.S_OK; } } return _nextCommandTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup == GuidList.CommandSetGuid && cCmds == 1) // Copy Html Markup { if (prgCmds[0].cmdID == 0x100) { Guid standard97 = VSConstants.GUID_VSStandardCommandSet97; OLECMD[] oleCmds = new OLECMD[1] { new OLECMD() { cmdID = (uint)VSConstants.VSStd97CmdID.Copy, cmdf = prgCmds[0].cmdf } }; // call into the standard handler for Copy to see if copy is available _nextCommandTargetInChain.QueryStatus(ref standard97, 1, oleCmds, IntPtr.Zero); prgCmds[0].cmdf = oleCmds[0].cmdf; return(VSConstants.S_OK); } } var result = _nextCommandTargetInChain.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); return(result); }
public void FormatDocument(string filePath) { IVsTextView vsTextView; IVsUIHierarchy uiHierarchy; uint itemID; IVsWindowFrame windowFrame; if (VsShellUtilities.IsDocumentOpen( visualStudio.ServiceProvider, filePath, Guid.Empty, out uiHierarchy, out itemID, out windowFrame)) { vsTextView = VsShellUtilities.GetTextView(windowFrame); } else { Contract.Assert(false, "Failed to get the IVsTextView, is the document open in VS?"); return; } IOleCommandTarget commandTarget = (IOleCommandTarget)vsTextView; Guid guid = typeof(VSConstants.VSStd2KCmdID).GUID; OLECMD[] commandStatus = new OLECMD[] { new OLECMD() { cmdID = (uint)VSConstants.VSStd2KCmdID.FORMATDOCUMENT } }; int hr = commandTarget.QueryStatus( ref guid, 1, commandStatus, IntPtr.Zero); Marshal.ThrowExceptionForHR(hr); if (commandStatus[0].cmdf == (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED)) { hr = commandTarget.Exec( ref guid, (uint)VSConstants.VSStd2KCmdID.FORMATDOCUMENT, 0u, IntPtr.Zero, IntPtr.Zero); Marshal.ThrowExceptionForHR(hr); } else { Contract.Assert(false, "The format command can't be executed right now, we don't expect this to happen."); } }
protected override int OnQueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { // Using just as a means that indicates that the status was invalidated and it needs to be recalculate // in response to IVsUIShell.UpdateCommandUI which is triggered for the various UI context changes this.BindCommand.RequeryCanExecute(); return base.OnQueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); }
int IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (_queryStatus != null && _cmdSet == pguidCmdGroup) for (int i = 0; i < prgCmds.Length; i++) prgCmds[i].cmdf = _queryStatus((T)prgCmds[i].cmdID); return VSConstants.S_OK; }
int IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup.Equals(Guids.guidProjectExtenderCmdSet) && prgCmds[0].cmdID == (uint)PkgCmdIDList.cmdidProjectExtender) { prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_SUPPORTED | (uint)OLECMDF.OLECMDF_INVISIBLE; return VSConstants.S_OK; } return innerTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (this.NextCommandTarget != null) { return this.NextCommandTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); } return (int)OLEConstants.OLECMDERR_E_NOTSUPPORTED; }
int IOleCommandTarget.QueryStatus(ref Guid guidGroup, uint nCmdId, OLECMD[] nCmdExcept, IntPtr pCmdText) { IOleCommandTarget oleCommandTarget = (IOleCommandTarget)this.GetService(typeof(IOleCommandTarget)); if (oleCommandTarget != null) { return oleCommandTarget.QueryStatus(ref guidGroup, nCmdId, nCmdExcept, pCmdText); } return -2147221248; }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup != PackageGuids.GuidEmmetPackageCmdSet) return NextTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); for (uint i = 0; i < cCmds; i++) prgCmds[i].cmdf = (uint)GetCommandStatus(prgCmds[i].cmdID); return VSConstants.S_OK; }
public int QueryStatus(ref Guid cmdGroup, uint cmdCount, OLECMD[] cmds, IntPtr cmdText) { if (cmdGroup != CommandGuid) return Next.QueryStatus(ref cmdGroup, cmdCount, cmds, cmdText); foreach (var cmd in cmds) cmds[0].cmdf = (uint)CanExecuteResult(cmd.cmdID); return VSConstants.S_OK; }
public CommandStatus Status(Guid group, int id) { OLECMD[] oleCmd = new OLECMD[1]; oleCmd[0].cmdID = (uint)id; oleCmd[0].cmdf = 0; int oleStatus = OleTarget.QueryStatus(ref group, 1, oleCmd, IntPtr.Zero); return OleCommand.MakeCommandStatus(oleStatus, oleCmd[0].cmdf); }
public int QueryStatus(ref Guid pguidCmdGroup, int cCmds, [In, Out] OLECMD prgCmds, [In, Out] IntPtr pCmdText) { if ((int)OLECMDID.OLECMDID_SHOWSCRIPTERROR == prgCmds.cmdID) { // Do nothing (suppress script errors) return(S_OK); } // Indicate that command is unknown. The command will then be handled by another IOleCommandTarget. return(OLECMDERR_E_UNKNOWNGROUP); }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup == typeof(EmacsCommandID).GUID && cCmds > 0 && prgCmds[0].cmdID == (uint)EmacsCommandID.BreakLine) { prgCmds[0].cmdf = (int)Microsoft.VisualStudio.OLE.Interop.Constants.MSOCMDF_ENABLED | (int)Microsoft.VisualStudio.OLE.Interop.Constants.MSOCMDF_SUPPORTED; return VSConstants.S_OK; } return this.NextCommandTarget.QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText); }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (commandFilter.QueryStatus(editorContext, pguidCmdGroup, prgCmds[0])) { prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_ENABLED | (uint)OLECMDF.OLECMDF_SUPPORTED; return VSConstants.S_OK; } return Next.QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText); }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { int hr = InternalQueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); if (hr == OLECMDERR_E_NOTSUPPORTED) { hr = OldChain.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); } return hr; }
public override int? EditFilterQueryStatus(ref OLECMD cmd, IntPtr pCmdText) { var activeView = CommonPackage.GetActiveTextView(); if (activeView != null && activeView.TextBuffer.ContentType.IsOfType(JCoreConstants.ContentType)) { cmd.cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); } else { cmd.cmdf = (uint)(OLECMDF.OLECMDF_INVISIBLE); } return VSConstants.S_OK; }
private bool IsCommandEnabled(ref Guid cmdSet, uint cmdId) { OLECMD[] cmds = new OLECMD[] { new OLECMD() { cmdID = cmdId } }; ErrorHandler.ThrowOnFailure(this.shellCmdTarget.QueryStatus(ref cmdSet, (uint)cmds.Length, cmds, IntPtr.Zero)); OLECMDF flags = (OLECMDF)cmds[0].cmdf; return((flags & OLECMDF.OLECMDF_ENABLED) == OLECMDF.OLECMDF_ENABLED); }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { for (uint i = 0; i < cCmds; i++) { prgCmds[i] = new OLECMD() { cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED) }; } return(VSConstants.S_OK); }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup != CommandGuid) return Next.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); prgCmds[0].cmdf = (uint)(CanExecute(cCmds) ? (OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED) : OLECMDF.OLECMDF_SUPPORTED); return VSConstants.S_OK; }
public CommandStatus Status(Guid group, int id) { OLECMD[] oleCmd = new OLECMD[1]; oleCmd[0].cmdID = (uint)id; oleCmd[0].cmdf = 0; int oleStatus = OleTarget.QueryStatus(ref group, 1, oleCmd, IntPtr.Zero); return(OleCommand.MakeCommandStatus(oleStatus, oleCmd[0].cmdf)); }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup != GuidList.guidSToolsCmdSet) return Next.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText); prgCmds[0].cmdf = (uint)(OLECMDF.OLECMDF_SUPPORTED); Commands.ICommand command = _commandList.Find(c => c.IsYourId(prgCmds[0].cmdID)); Debug.Assert(command != null); if (command.IsEnable(VsTextViewCreationListener.GetDTE())) { prgCmds[0].cmdf |= (uint)OLECMDF.OLECMDF_ENABLED; } return VSConstants.S_OK; }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup == VSConstants.VSStd2K) { switch ((VSConstants.VSStd2KCmdID)prgCmds[0].cmdID) { case VSConstants.VSStd2KCmdID.AUTOCOMPLETE: return VSConstants.S_OK; } } return Next.QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText); }
int IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { KeyInput ki = null; if (1 == cCmds && TryConvert(pguidCmdGroup, prgCmds[0].cmdID, pCmdText, out ki) && _buffer.CanProcess(ki)) { prgCmds[0].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); return NativeMethods.S_OK; } return _nextTarget.QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText); }
private bool RunQueryStatus(KeyInput keyInput) { var data = ToVsInforamtion(keyInput); var guid = data.Item1; var cmds = new OLECMD[1]; cmds[0] = new OLECMD { cmdID = data.Item2 }; return (ErrorHandler.Succeeded(_target.QueryStatus(ref guid, 1, cmds, data.Item3)) && cmds[0].cmdf == (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED)); }
int IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup == GuidList.guidTfsAccSwitchVS10CmdSet) { switch (prgCmds[0].cmdID) { case PkgCmdIDList.cmdidChangeAccount: case PkgCmdIDList.cmdidShowAccount: prgCmds[0].cmdf = (int)OLECMDF.OLECMDF_SUPPORTED | (int)OLECMDF.OLECMDF_ENABLED; return 0; } } return UnknownGroup; }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { foreach (var commandMapping in Commands) { int fmtindex = commandMapping.GetMatchingIndex(pguidCmdGroup, prgCmds); if (fmtindex >= 0) { prgCmds[fmtindex].cmdf = commandMapping.CommandOptions; return VSConstants.S_OK; } } return _commandChain.QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText); }
private bool NextHandlerHandlesCommand(Guid pguidCmdGroup, uint nCmdID) { OLECMD[] cmds = new OLECMD[1]; cmds[0].cmdID = nCmdID; int hr = nextCommandHandler.QueryStatus(ref pguidCmdGroup, 1, cmds, IntPtr.Zero); if (ErrorHandler.Failed(hr)) { return(false); } uint expected = (uint)OLECMDF.OLECMDF_ENABLED | (uint)OLECMDF.OLECMDF_SUPPORTED; return((cmds[0].cmdf & expected) == expected); }
private int QueryStatusImpl(Guid pguidCmdGroup, OLECMD cmd) { if (pguidCmdGroup == typeof(VSConstants.VSStd2KCmdID).GUID) { switch ((VSConstants.VSStd2KCmdID)cmd.cmdID) { case VSConstants.VSStd2KCmdID.SHOWMEMBERLIST: case VSConstants.VSStd2KCmdID.COMPLETEWORD: case VSConstants.VSStd2KCmdID.PARAMINFO: case VSConstants.VSStd2KCmdID.QUICKINFO: return((int)OLECMDF.OLECMDF_ENABLED | (int)OLECMDF.OLECMDF_SUPPORTED); } } return(VSConstants.E_FAIL); }
protected virtual int QueryStatus(ref Guid cmdGroup, ref OLECMD oleCmd, IntPtr pCmdText) { if (cmdGroup == VSConstants.VSStd2K) { switch ((VSConstants.VSStd2KCmdID)oleCmd.cmdID) { case VSConstants.VSStd2KCmdID.OUTLN_START_AUTOHIDING: case VSConstants.VSStd2KCmdID.OUTLN_STOP_HIDING_ALL: return(VSErr.OLECMDERR_E_NOTSUPPORTED); default: return(VSErr.E_FAIL);; /* Unhandled */ } } return(VSErr.E_FAIL); }
internal static int QueryStatus(this IOleCommandTarget oleCommandTarget, OleCommandData oleCommandData, out OLECMD command) { var commandGroup = oleCommandData.Group; var cmds = new OLECMD[1]; cmds[0] = new OLECMD { cmdID = oleCommandData.Id }; var result = oleCommandTarget.QueryStatus( ref commandGroup, 1, cmds, oleCommandData.VariantIn); command = cmds[0]; return(result); }
/// <summary> /// Actually run the QueryStatus command and report the result /// </summary> private bool RunQueryStatusCore(Guid commandGroup, OleCommandData oleCommandData) { var commands = new OLECMD[1]; commands[0].cmdID = oleCommandData.CommandId; var hr = _commandTarget.QueryStatus(ref commandGroup, 1, commands, oleCommandData.VariantIn); if (!ErrorHandler.Succeeded(hr)) { return(false); } // TODO: Visual Studio has slightly different behavior here IIRC. I believe it will // only cache if it's at least supported. Need to check on that var result = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); return(result == (result & commands[0].cmdf)); }
public void SectionController_IOleCommandTargetQueryStatus() { // Arrange var testSubject = this.CreateTestSubject(); IOleCommandTarget testSubjectCommandTarget = testSubject; testSubject.CommandTargets.Clear(); var command1 = new TestCommandTarget(); var command2 = new TestCommandTarget(); var command3 = new TestCommandTarget(); testSubject.CommandTargets.Add(command1); testSubject.CommandTargets.Add(command2); testSubject.CommandTargets.Add(command3); Guid group = Guid.Empty; uint cCmds = 0; OLECMD[] prgCmds = new OLECMD[0]; IntPtr pCmdText = IntPtr.Zero; // Case 1 : no commands handling the request // Act+Verify testSubjectCommandTarget.QueryStatus(ref group, cCmds, prgCmds, pCmdText).Should().Be(SectionController.CommandNotHandled); command1.QueryStatusNumberOfCalls.Should().Be(1); command2.QueryStatusNumberOfCalls.Should().Be(1); command3.QueryStatusNumberOfCalls.Should().Be(1); // Case 2 : the last command is handling the request command3.QueryStatusReturnsResult = (int)OleConstants.OLECMDERR_E_CANCELED; // Act+Verify testSubjectCommandTarget.QueryStatus(ref group, cCmds, prgCmds, pCmdText).Should().Be((int)OleConstants.OLECMDERR_E_CANCELED); command1.QueryStatusNumberOfCalls.Should().Be(2); command2.QueryStatusNumberOfCalls.Should().Be(2); command3.QueryStatusNumberOfCalls.Should().Be(2); // Case 3 : the first command is handling the request command1.QueryStatusReturnsResult = (int)OleConstants.OLECMDERR_E_DISABLED; // Act+Verify testSubjectCommandTarget.QueryStatus(ref group, cCmds, prgCmds, pCmdText).Should().Be((int)OleConstants.OLECMDERR_E_DISABLED); command1.QueryStatusNumberOfCalls.Should().Be(3); command2.QueryStatusNumberOfCalls.Should().Be(2); command3.QueryStatusNumberOfCalls.Should().Be(2); }
/// <summary> /// Helper method to query for the current status (latched, enabled, etc.) /// of the command /// </summary> /// <returns>flags representing current status</returns> private OLECMDF GetCommandStatus() { // query for the command status OLECMD cmd = new OLECMD(); cmd.cmdID = commandID; try { commandTarget.QueryStatus( CGID.MSHTML, 1, ref cmd, IntPtr.Zero); } catch { // this can throw exceptions at unexpected times such as managing // command-state when a flash-player is in the editor } // return the command flags return(cmd.cmdf); }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (pguidCmdGroup == typeof(VSConstants.VSStd2KCmdID).GUID) { for (int i = 0; i < cCmds; i++) { OLECMD cmd = prgCmds[i]; switch ((VSConstants.VSStd2KCmdID)cmd.cmdID) { case VSConstants.VSStd2KCmdID.AUTOCOMPLETE: case VSConstants.VSStd2KCmdID.SHOWMEMBERLIST: //case VSConstants.VSStd2KCmdID.COMPLETEWORD: //case VSConstants.VSStd2KCmdID.PARAMINFO: //case VSConstants.VSStd2KCmdID.QUICKINFO: prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED); return(VSConstants.S_OK); } } } return(m_nextCommandHandler.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText)); }
/// <summary> /// Run the KeyInput value through QueryStatus. Returns true if the QueryStatus call /// indicated the command was supported /// </summary> private bool RunQueryStatus(KeyInput keyInput) { OleCommandData data; Guid commandGroup; Assert.IsTrue(OleCommandUtil.TryConvert(keyInput, out commandGroup, out data)); try { var cmds = new OLECMD[1]; cmds[0] = new OLECMD { cmdID = data.CommandId }; return (ErrorHandler.Succeeded(_target.QueryStatus(ref commandGroup, 1, cmds, data.VariantIn)) && cmds[0].cmdf == (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED)); } finally { OleCommandData.Release(ref data); } }
/// <summary> /// Checks if a command is enabled and supported. /// </summary> public static async Task <bool> IsAvailableAsync(this CommandID cmd) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IOleCommandTarget cs = await VS.GetRequiredServiceAsync <SUIHostCommandDispatcher, IOleCommandTarget>(); Guid guid = cmd.Guid; OLECMD[]? cmds = new OLECMD[1]; cmds[0].cmdID = (uint)cmd.ID; cmds[0].cmdf = 0; int hr = cs.QueryStatus(ref guid, (uint)cmds.Length, cmds, IntPtr.Zero); if (ErrorHandler.Succeeded(hr)) { if (((OLECMDF)cmds[0].cmdf).HasFlag(OLECMDF.OLECMDF_ENABLED)) { return(true); } } return(false); }
/// <summary> /// Unused /// </summary> /// <param name="pguidCmdGroup"></param> /// <param name="cCmds"></param> /// <param name="prgCmds"></param> /// <param name="pCmdText"></param> /// <returns></returns> public int QueryStatus(IntPtr pguidCmdGroup, uint cCmds, ref OLECMD prgCmds, IntPtr pCmdText) { return(0); }
/// <summary> /// Returns true if ReSharper is installed, enabled, and not suspended. /// </summary> private async ValueTask <ReSharperStatus> IsReSharperRunningAsync(CancellationToken cancellationToken) { // Quick exit if resharper is either uninstalled or not enabled if (!_resharperExtensionInstalledAndEnabled) { return(ReSharperStatus.NotInstalledOrDisabled); } await EnsureOleCommandTargetAsync().ConfigureAwait(false); // poll until either suspend or resume botton is available, or until operation is canceled while (true) { cancellationToken.ThrowIfCancellationRequested(); var suspendFlag = await QueryStatusAsync(SuspendId).ConfigureAwait(false); // In the case of an error when attempting to get the status, pretend that ReSharper isn't enabled. We also // shut down monitoring so we don't keep hitting this. if (suspendFlag == 0) { return(ReSharperStatus.NotInstalledOrDisabled); } var resumeFlag = await QueryStatusAsync(ResumeId).ConfigureAwait(false); if (resumeFlag == 0) { return(ReSharperStatus.NotInstalledOrDisabled); } // When ReSharper is running, the ReSharper_Suspend command is Enabled and not Invisible if (suspendFlag.HasFlag(OLECMDF.OLECMDF_ENABLED) && !suspendFlag.HasFlag(OLECMDF.OLECMDF_INVISIBLE)) { return(ReSharperStatus.Enabled); } // When ReSharper is suspended, the ReSharper_Resume command is Enabled and not Invisible if (resumeFlag.HasFlag(OLECMDF.OLECMDF_ENABLED) && !resumeFlag.HasFlag(OLECMDF.OLECMDF_INVISIBLE)) { return(ReSharperStatus.Suspended); } // ReSharper has not finished initializing, so try again later await Task.Delay(TimeSpan.FromSeconds(2), cancellationToken).ConfigureAwait(false); } async Task <OLECMDF> QueryStatusAsync(uint cmdId) { var cmds = new OLECMD[1]; cmds[0].cmdID = cmdId; cmds[0].cmdf = 0; await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var hr = _oleCommandTarget.QueryStatus(ReSharperCommandGroup, (uint)cmds.Length, cmds, IntPtr.Zero); if (ErrorHandler.Failed(hr)) { FatalError.ReportWithoutCrash(Marshal.GetExceptionForHR(hr)); await ShutdownAsync().ConfigureAwait(false); return(0); } return((OLECMDF)cmds[0].cmdf); } async Task EnsureOleCommandTargetAsync() { if (_oleCommandTarget != null) { return; } await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); _oleCommandTarget = _serviceProvider.GetService <SUIHostCommandDispatcher, IOleCommandTarget>(); } }
public bool QueryStatus(GherkinEditorContext editorContext, Guid pguidCmdGroup, OLECMD prgCmd) { if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97) { var vsStd97CmdId = (VSConstants.VSStd97CmdID)prgCmd.cmdID; #if TRACE_VS_COMMANDS tracer.Trace("QueryStatus/VSStd97CmdID:{0}", this, vsStd97CmdId); #endif switch (vsStd97CmdId) { case VSConstants.VSStd97CmdID.GotoDefn: if (goToStepDefinitionCommand.CanGoToDefinition(editorContext)) { return(true); } break; } } else if (pguidCmdGroup == VSConstants.VSStd2K) { var vsStd2KCmdId = (VSConstants.VSStd2KCmdID)prgCmd.cmdID; #if TRACE_VS_COMMANDS tracer.Trace("QueryStatus/VSStd2KCmdID:{0}", this, vsStd2KCmdId); #endif switch (vsStd2KCmdId) { case VSConstants.VSStd2KCmdID.COMMENT_BLOCK: case VSConstants.VSStd2KCmdID.COMMENTBLOCK: case VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK: case VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK: case VSConstants.VSStd2KCmdID.RENAME: return(true); } } else if (pguidCmdGroup == GuidList.guidSpecFlowCmdSet) { var specFlowCmdSet = (SpecFlowCmdSet)prgCmd.cmdID; #if TRACE_VS_COMMANDS tracer.Trace("QueryStatus/SpecFlowCmdSet:{0}", this, specFlowCmdSet); #endif switch (specFlowCmdSet) { case SpecFlowCmdSet.RunScenarios: case SpecFlowCmdSet.DebugScenarios: return(true); } } else if (pguidCmdGroup == ReSharperCommandGroups.CommandGroup) { var reSharperCmd = (ReSharperCommand)prgCmd.cmdID; #if TRACE_VS_COMMANDS tracer.Trace("QueryStatus/ReSharperCommand:{0}", this, reSharperCmd); #endif switch (reSharperCmd) { case ReSharperCommand.GotoDeclaration: if (goToStepDefinitionCommand.CanGoToDefinition(editorContext)) { return(true); } break; case ReSharperCommand.LineComment: return(true); case ReSharperCommand.UnitTestRunContext: case ReSharperCommand.UnitTestDebugContext: return(true); } } #if TRACE_VS_COMMANDS else { tracer.Trace("QueryStatus/Other:{0} / {1}", this, pguidCmdGroup, prgCmd.cmdID); } #endif return(false); }
public void TestSccMenuCommands() { int result = 0; Guid badGuid = new Guid(); Guid guidCmdGroup = GuidList.guidSccProviderCmdSet; OLECMD[] cmdAddToScc = new OLECMD[1]; cmdAddToScc[0].cmdID = CommandId.icmdAddToSourceControl; OLECMD[] cmdCheckin = new OLECMD[1]; cmdCheckin[0].cmdID = CommandId.icmdCheckin; OLECMD[] cmdCheckout = new OLECMD[1]; cmdCheckout[0].cmdID = CommandId.icmdCheckout; OLECMD[] cmdUseSccOffline = new OLECMD[1]; cmdUseSccOffline[0].cmdID = CommandId.icmdUseSccOffline; OLECMD[] cmdViewToolWindow = new OLECMD[1]; cmdViewToolWindow[0].cmdID = CommandId.icmdViewToolWindow; OLECMD[] cmdToolWindowToolbarCommand = new OLECMD[1]; cmdToolWindowToolbarCommand[0].cmdID = CommandId.icmdToolWindowToolbarCommand; OLECMD[] cmdUnsupported = new OLECMD[1]; cmdUnsupported[0].cmdID = 0; // Initialize the provider, etc SccProviderService target = GetSccProviderServiceInstance; // Mock a service implementing IVsMonitorSelection BaseMock monitorSelection = MockIVsMonitorSelectionFactory.GetMonSel(); serviceProvider.AddService(typeof(IVsMonitorSelection), monitorSelection, true); // Commands that don't belong to our package should not be supported result = _sccProvider.QueryStatus(ref badGuid, 1, cmdAddToScc, IntPtr.Zero); Assert.AreEqual((int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED, result); // The command should be invisible when there is no solution VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdAddToScc); // Activate the provider and test the result target.SetActive(); Assert.AreEqual(true, target.Active, "Microsoft.Samples.VisualStudio.SourceControlIntegration.SccProvider.SccProviderService.Active was not reported correctly."); // The commands should be invisible when there is no solution VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdUseSccOffline); // Commands that don't belong to our package should not be supported result = _sccProvider.QueryStatus(ref guidCmdGroup, 1, cmdUnsupported, IntPtr.Zero); Assert.AreEqual((int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED, result); // Deactivate the provider and test the result target.SetInactive(); Assert.AreEqual(false, target.Active, "Microsoft.Samples.VisualStudio.SourceControlIntegration.SccProvider.SccProviderService.Active was not reported correctly."); // Create a solution solution.SolutionFile = Path.GetTempFileName(); MockIVsProject project = new MockIVsProject(Path.GetTempFileName()); project.AddItem(Path.GetTempFileName()); solution.AddProject(project); // The commands should be invisible when the provider is not active VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdUseSccOffline); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdViewToolWindow); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE, cmdToolWindowToolbarCommand); // Activate the provider and test the result target.SetActive(); Assert.AreEqual(true, target.Active, "Microsoft.Samples.VisualStudio.SourceControlIntegration.SccProvider.SccProviderService.Active was not reported correctly."); // The command should be visible but disabled now, except the toolwindow ones VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdViewToolWindow); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdToolWindowToolbarCommand); // Set selection to solution node VSITEMSELECTION selSolutionRoot; selSolutionRoot.pHier = _solution as IVsHierarchy; selSolutionRoot.itemid = VSConstants.VSITEMID_ROOT; monitorSelection["Selection"] = new VSITEMSELECTION[] { selSolutionRoot }; // The add command should be available, rest should be disabled VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline); // Still solution hierarchy, but other way selSolutionRoot.pHier = null; selSolutionRoot.itemid = VSConstants.VSITEMID_ROOT; monitorSelection["Selection"] = new VSITEMSELECTION[] { selSolutionRoot }; // The add command should be available, rest should be disabled VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline); // Set selection to project node VSITEMSELECTION selProjectRoot; selProjectRoot.pHier = project as IVsHierarchy; selProjectRoot.itemid = VSConstants.VSITEMID_ROOT; monitorSelection["Selection"] = new VSITEMSELECTION[] { selProjectRoot }; // The add command should be available, rest should be disabled VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline); // Set selection to project item VSITEMSELECTION selProjectItem; selProjectItem.pHier = project as IVsHierarchy; selProjectItem.itemid = 0; monitorSelection["Selection"] = new VSITEMSELECTION[] { selProjectItem }; // The add command should be available, rest should be disabled VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline); // Set selection to project and item node and add project to scc monitorSelection["Selection"] = new VSITEMSELECTION[] { selProjectRoot, selProjectItem }; VerifyCommandExecution(cmdAddToScc); // The add command and checkin should be disabled, rest should be available now VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdUseSccOffline); // Checkout the project VerifyCommandExecution(cmdCheckout); // The add command and checkout should be disabled, rest should be available now VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdUseSccOffline); // Select the solution monitorSelection["Selection"] = new VSITEMSELECTION[] { selSolutionRoot }; // The checkout and offline should be disabled, rest should be available now VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline); // Checkin the project VerifyCommandExecution(cmdCheckin); // The add command and checkout should be enabled, rest should be disabled VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline); // Add the solution to scc VerifyCommandExecution(cmdAddToScc); // The add command and checkin should be disabled, rest should be available now VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdUseSccOffline); // Select the solution and project monitorSelection["Selection"] = new VSITEMSELECTION[] { selSolutionRoot, selProjectRoot }; // Take the project and solution offline VerifyCommandExecution(cmdUseSccOffline); // The offline command should be latched VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_LATCHED, cmdUseSccOffline); // Select the solution only monitorSelection["Selection"] = new VSITEMSELECTION[] { selSolutionRoot }; // Take the solution online VerifyCommandExecution(cmdUseSccOffline); // The offline command should be normal again VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdUseSccOffline); // Select the solution and project monitorSelection["Selection"] = new VSITEMSELECTION[] { selSolutionRoot, selProjectRoot }; // The offline command should be disabled for mixed selection VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdUseSccOffline); // Add a new item to the project project.AddItem(Path.GetTempFileName()); // Select the new item selProjectItem.pHier = project as IVsHierarchy; selProjectItem.itemid = 1; monitorSelection["Selection"] = new VSITEMSELECTION[] { selProjectItem }; // The add command and checkout should be disabled, rest should be available now VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_LATCHED, cmdUseSccOffline); // Checkin the new file (this should do an add) VerifyCommandExecution(cmdCheckin); // The add command and checkout should be disabled, rest should be available now VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdAddToScc); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED, cmdCheckin); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED, cmdCheckout); VerifyCommandStatus(OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_LATCHED, cmdUseSccOffline); }
/// <summary> /// Enables a command to hook into our edit filter for Python text buffers. /// /// Called with the OLECMD object for the command being processed. Returns null /// if the command does not want to handle this message or the HRESULT that /// should be returned from the QueryStatus call. /// </summary> public virtual int?EditFilterQueryStatus(ref OLECMD cmd, IntPtr pCmdText) { return(null); }
public CommandResult ExecCommand(System.ComponentModel.Design.CommandID command, bool verifyEnabled, object argument) { if (command == null) { throw new ArgumentNullException("command"); } // TODO: Assert that we are in the UI thread IOleCommandTarget dispatcher = CommandDispatcher; if (dispatcher == null) { return(new CommandResult(false)); } Guid g = command.Guid; if (verifyEnabled) { OLECMD[] cmd = new OLECMD[1]; cmd[0].cmdID = unchecked ((uint)command.ID); if (VSErr.S_OK != dispatcher.QueryStatus(ref g, 1, cmd, IntPtr.Zero)) { return(new CommandResult(false)); } OLECMDF flags = (OLECMDF)cmd[0].cmdf; if ((flags & OLECMDF.OLECMDF_SUPPORTED) == (OLECMDF)0) { return(new CommandResult(false)); // Not supported } if ((flags & OLECMDF.OLECMDF_ENABLED) == (OLECMDF)0) { return(new CommandResult(false)); // Not enabled } } IntPtr vIn = IntPtr.Zero; IntPtr vOut = IntPtr.Zero; try { vOut = Marshal.AllocCoTaskMem(128); NativeMethods.VariantInit(vOut); if (argument != null) { vIn = Marshal.AllocCoTaskMem(128); Marshal.GetNativeVariantForObject(argument, vIn); } bool ok = VSErr.Succeeded(dispatcher.Exec(ref g, unchecked ((uint)command.ID), (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, IntPtr.Zero, IntPtr.Zero)); return(new CommandResult(ok, Marshal.GetObjectForNativeVariant(vOut))); } finally { if (vIn != IntPtr.Zero) { NativeMethods.VariantClear(vIn); Marshal.FreeCoTaskMem(vIn); } if (vOut != IntPtr.Zero) { NativeMethods.VariantClear(vOut); Marshal.FreeCoTaskMem(vOut); } } }