/// <summary> /// Converts OLE result and command status to CommandStatus /// </summary> /// <param name="oleResult">OLE result</param> /// <param name="oleCommandFlags">OLE command state flags</param> /// <returns>Command status</returns> public static CommandStatus MakeCommandStatus(int oleResult, uint oleCommandFlags) { CommandStatus cs = CommandStatus.NotSupported; OLECMDF oleFlags = (OLECMDF)oleCommandFlags; if (oleResult != (int)Constants.OLECMDERR_E_NOTSUPPORTED) { if ((oleFlags & OLECMDF.OLECMDF_SUPPORTED) == OLECMDF.OLECMDF_SUPPORTED) { cs |= CommandStatus.Supported; } if ((oleFlags & OLECMDF.OLECMDF_ENABLED) == OLECMDF.OLECMDF_ENABLED) { cs |= CommandStatus.Enabled; } if ((oleFlags & OLECMDF.OLECMDF_INVISIBLE) == OLECMDF.OLECMDF_INVISIBLE) { cs |= CommandStatus.Invisible; } if ((oleFlags & OLECMDF.OLECMDF_LATCHED) == OLECMDF.OLECMDF_LATCHED) { cs |= CommandStatus.Latched; } } return(cs); }
public CommandMapping(Guid commandGroup, int commandId, OLECMDF commandOptions, Func <CommandBase> commandCreator) { _commandGroup = commandGroup; _commandId = (uint)commandId; _commandOptions = (uint)commandOptions; _commandCreator = commandCreator; }
public void UpdateFlags(ref OLECMDF cmdf) { if (Enabled) { cmdf |= OLECMDF.OLECMDF_ENABLED; } if (Checked) { cmdf |= OLECMDF.OLECMDF_LATCHED; } if (Ninched) { cmdf |= OLECMDF.OLECMDF_NINCHED; } if (!Visible) { cmdf |= OLECMDF.OLECMDF_INVISIBLE | OLECMDF.OLECMDF_DEFHIDEONCTXTMENU; } if (HideOnContextMenu) { cmdf |= OLECMDF.OLECMDF_DEFHIDEONCTXTMENU; } }
public int QueryStatus(AnkhContext context, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if (context == null) { throw new ArgumentNullException("context"); } else if (cCmds != 1 || prgCmds == null) { return(-1); } TextQueryType textQuery = TextQueryType.None; if (pCmdText != IntPtr.Zero) { // VS Want's some text from us for either the statusbar or the command text OLECMDTEXTF textType = GetFlags(pCmdText); switch (textType) { case OLECMDTEXTF.OLECMDTEXTF_NAME: textQuery = TextQueryType.Name; break; case OLECMDTEXTF.OLECMDTEXTF_STATUS: textQuery = TextQueryType.Status; break; } } CommandUpdateEventArgs updateArgs = new CommandUpdateEventArgs((AnkhCommand)prgCmds[0].cmdID, context, textQuery); OLECMDF cmdf = OLECMDF.OLECMDF_SUPPORTED; if (PerformUpdate(updateArgs.Command, updateArgs)) { updateArgs.UpdateFlags(ref cmdf); } if (updateArgs.DynamicMenuEnd) { return(VSErr.OLECMDERR_E_NOTSUPPORTED); } if (textQuery != TextQueryType.None && !string.IsNullOrEmpty(updateArgs.Text)) { SetText(pCmdText, updateArgs.Text); } if (_customizeMode && updateArgs.Command != AnkhCommand.ForceUIShow) { prgCmds[0].cmdf = (uint)(cmdf & ~OLECMDF.OLECMDF_INVISIBLE); } else { prgCmds[0].cmdf = (uint)cmdf; } return(0); // S_OK }
int IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { OLECMDF cmdf = OLECMDF.OLECMDF_SUPPORTED; string label; if (TryParseBranchName(prgCmds[0].cmdID, out label)) { VsShellUtilities.SetOleCmdText(pCmdText, label); // SetOleCmdText(pCmdText, label); cmdf |= OLECMDF.OLECMDF_ENABLED; if (string.Equals(label, StatusBarService.BranchName, StringComparison.OrdinalIgnoreCase)) { cmdf |= OLECMDF.OLECMDF_LATCHED; } prgCmds[0].cmdf = (uint)(cmdf); return(VSConstants.S_OK); } else if (TryParseRepositoryCommand(prgCmds[0].cmdID, out label) || TryParseBranchCommand(prgCmds[0].cmdID, out label)) { VsShellUtilities.SetOleCmdText(pCmdText, label); //SetOleCmdText(pCmdText, label); cmdf |= OLECMDF.OLECMDF_ENABLED; prgCmds[0].cmdf = (uint)(cmdf); return(VSConstants.S_OK); } else { return((int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED)); } //throw new NotImplementedException(); }
public int GetMarkerCommandInfo(IVsTextMarker pMarker, int iItem, string[] pbstrText, uint[] pcmdf) { if (commands != null) { try { const OLECMDF OLECMDF_ENABLE = (OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED); if (iItem == (int)MarkerCommandValues.mcvBodyDoubleClickCommand && pcmdf != null) { pcmdf[0] = (uint)OLECMDF_ENABLE; } else if (iItem >= (int)MarkerCommandValues.mcvFirstContextMenuCommand && iItem <= (int)MarkerCommandValues.mcvLastContextMenuCommand && pbstrText != null && pcmdf != null) { int item = iItem - (int)MarkerCommandValues.mcvFirstContextMenuCommand; ITaskMenuItem[] menuItems = commands.GetMenuItems(null); if (menuItems != null && item < menuItems.Length) { ITaskMenuItem menuItem = menuItems[item]; if (menuItem != null && menuItem.Kind != TaskMenuKind.Submenu) { pbstrText[0] = menuItem.Caption; if (commands.IsEnabled(menuItems[item])) { pcmdf[0] = (uint)OLECMDF_ENABLE; if (menuItem.Kind == TaskMenuKind.Checkable) { if (commands.IsChecked(menuItems[item])) { pcmdf[0] |= (uint)(OLECMDF_ENABLE | OLECMDF.OLECMDF_LATCHED); } else { pcmdf[0] |= (uint)(OLECMDF_ENABLE | OLECMDF.OLECMDF_NINCHED); } } } else { pcmdf[0] = (uint)OLECMDF.OLECMDF_SUPPORTED; } } } } return(0); } catch { // communication to msbuild task may be broken, need to catch all errors return(VSConstants.E_NOTIMPL); } } else { return(VSConstants.E_NOTIMPL); } }
/// <summary> ///A test for menu command status ///</summary> void VerifyCommandStatus(OLECMDF expectedStatus, OLECMD[] command) { Guid guidCmdGroup = GuidList.guidSccProviderCmdSet; int result = _sccProvider.QueryStatus(ref guidCmdGroup, 1, command, IntPtr.Zero); Assert.AreEqual(VSConstants.S_OK, result); Debug.Assert((uint)(expectedStatus) == command[0].cmdf); Assert.AreEqual((uint)(expectedStatus), command[0].cmdf); }
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); }
/// <summary> /// QueryStatus called for each command when the extension initialises. /// </summary> /// <param name="commandGroupGuid">The Command group Guid.</param> /// <param name="commands">The commands array. Passing the array is necessary, because otherwise command flags do not apply to the original instance. </param> /// <param name="commandFlags">The command flags.</param> /// <param name="commandText">the command text.</param> /// <returns> /// integer indicating whether the command is supported. /// </returns> private int QueryCommandStatus(Guid commandGroupGuid, OLECMD[] commands, OLECMDF commandFlags, IntPtr commandText) { // Process Blinkbox Commands switch (commands[0].cmdID) { case Blinkbox.CommandIds.BlinkboxDeployId: if (GitBash.Exists && this.DeployProjectAvailable()) { commandFlags |= OLECMDF.OLECMDF_ENABLED; } break; case Blinkbox.CommandIds.BlinkboxCommitAndDeployId: if (GitBash.Exists && this.sccService.IsSolutionGitControlled && this.DeployProjectAvailable()) { commandFlags |= OLECMDF.OLECMDF_ENABLED; } break; case Blinkbox.CommandIds.GitTfsCheckinButtonId: case Blinkbox.CommandIds.GitTfsGetLatestButtonId: case Blinkbox.CommandIds.GitTfsCleanWorkspacesButtonId: case Blinkbox.CommandIds.GitTfsMenu: case Blinkbox.CommandIds.GitTfsMenuGroup: // Disable controls if git-tfs is not found. if (this.IsSolutionGitTfsControlled() && this.sccService.IsSolutionGitControlled) { commandFlags |= OLECMDF.OLECMDF_ENABLED; } else { commandFlags &= ~OLECMDF.OLECMDF_ENABLED; } var menuOption = GitTfs.MenuOptions.FirstOrDefault(x => x.CommandId == commands[0].cmdID); if (menuOption != null) { // If its a menu option set the text. this.basicSccProvider.SetOleCmdText(commandText, menuOption.Name); } break; default: // Not one of our commands - return return((int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED); } // command handled here commands[0].cmdf = (uint)commandFlags; return(VSConstants.S_OK); }
OLECMDF QueryStatus_icmdHgAddSelected() { OLECMDF cmdf = OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE; long stateMask = (long)HGLib.HGFileStatus.scsUncontrolled | (long)HGLib.HGFileStatus.scsIgnored; if (!Configuration.Global.EnableContextSearch || FindSelectedFirstMask(false, stateMask)) { cmdf = OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED; } return(cmdf); }
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { if ((prgCmds == null)) { return(VSErr.E_INVALIDARG); } System.Diagnostics.Debug.Assert(cCmds == 1, "Multiple commands"); // Should never happen in VS CommandID cd = new CommandID(pguidCmdGroup, unchecked ((int)prgCmds[0].cmdID)); List <CommandData> items; if (!_data.TryGetValue(cd, out items)) { return(VSErr.OLECMDERR_E_NOTSUPPORTED); } foreach (CommandData d in items) { if (!d.Control.ContainsFocus) { continue; } CommandUpdateEventArgs ee = new CommandUpdateEventArgs((AnkhCommand)cd.ID, GetService <AnkhContext>()); if (d.UpdateHandler != null) { d.UpdateHandler(d.Control, ee); } if (ee.DynamicMenuEnd) { return(VSErr.OLECMDERR_E_NOTSUPPORTED); } OLECMDF cmdf = OLECMDF.OLECMDF_SUPPORTED; ee.UpdateFlags(ref cmdf); prgCmds[0].cmdf = (uint)cmdf; return(VSErr.S_OK); } return(VSErr.OLECMDERR_E_NOTSUPPORTED); }
OLECMDF QueryStatus_icmdHgRevert() { OLECMDF cmdf = OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE; long stateMask = (long)HGLib.HGFileStatus.scsAdded | (long)HGLib.HGFileStatus.scsCopied | (long)HGLib.HGFileStatus.scsModified | (long)HGLib.HGFileStatus.scsRenamed | (long)HGLib.HGFileStatus.scsRemoved; if (!Configuration.Global.EnableContextSearch || FindSelectedFirstMask(false, stateMask)) { cmdf = OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED; } return(cmdf); }
private OLECMDF GetVsStatus(CommandStatus commandStatus) { OLECMDF ret = 0; if (commandStatus.HasFlag(CommandStatus.Supported)) { ret |= OLECMDF.OLECMDF_SUPPORTED; } if (commandStatus.HasFlag(CommandStatus.Enabled)) { ret |= OLECMDF.OLECMDF_ENABLED; } if (commandStatus.HasFlag(CommandStatus.Invisible)) { ret |= OLECMDF.OLECMDF_INVISIBLE; } return(ret); }
/// <summary> /// Called from VS to see what commands we support. /// </summary> int IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { bool any = false; for (int i = 0; i < cCmds; ++i) { OLECMDF f = QueryStatus(pguidCmdGroup, prgCmds[i].cmdID); if ((f & OLECMDF.OLECMDF_SUPPORTED) != 0) { prgCmds[i].cmdf = (uint)f; any = true; } } if (any) { return(VSConstants.S_OK); } return(_next.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText)); }
public int QueryStatus(ref Guid guidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { Debug.Assert(cCmds == 1, "Multiple commands"); Debug.Assert(prgCmds != null, "NULL argument"); if ((prgCmds == null)) { return(VSConstants.E_INVALIDARG); } for (int i = 0; i < cCmds; i++) { OLECMDF cmdf = OLECMDF.OLECMDF_SUPPORTED; var command = prgCmds[i]; switch (command.cmdID) { case Command1.CommandId: if (Command1.Instance != null && Command1.Instance.IsAvailable()) { cmdf |= OLECMDF.OLECMDF_ENABLED; } else { cmdf |= OLECMDF.OLECMDF_INVISIBLE; } prgCmds[i].cmdf = (uint)cmdf; break; case SpikeWindowCommand.CommandId: //cmdf |= OLECMDF.OLECMDF_INVISIBLE; //prgCmds[i].cmdf = (uint)cmdf; break; default: break; } } return(VSConstants.S_OK); }
protected override bool TryQueryStatus(Guid commandGroup, uint commandId, ref OLECMDF commandFlags) { if (commandGroup == VsMenus.guidStandardCommandSet97) { switch (commandId) { case (uint)VSConstants.VSStd97CmdID.FindReferences: if (IsFindAllReferencesSupported()) { commandFlags = OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED; } else { commandFlags = OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE; } return(true); } } return(false); }
/// <summary> /// The VS shell calls this function to know if a menu item should be visible and /// if it should be enabled/disabled. /// This is called only when the package is active. /// </summary> /// <param name="guidCmdGroup">Guid describing which set of commands the current command(s) belong to</param> /// <param name="cCmds">Number of commands for which status are being asked</param> /// <param name="prgCmds">Information for each command</param> /// <param name="pCmdText">Used to dynamically change the command text</param> /// <returns>HRESULT</returns> public int QueryStatus(ref Guid guidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { // Filter out commands that are not defined by this package if (guidCmdGroup != new Guid("{00000000-0000-0000-0000-000000000000}")) { return((int)(Constants.OLECMDERR_E_NOTSUPPORTED)); } if (cCmds == 0 || prgCmds == null || prgCmds.Length == 0 || cCmds != prgCmds.Length) { return(VSConstants.E_INVALIDARG); } // Show and enable all commands. OLECMDF cmdf = OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED; for (int i = 0; i < cCmds; i++) { prgCmds[i].cmdf = (uint)cmdf; } return(VSConstants.S_OK); }
int IOleCommandTarget.QueryStatus(ref Guid guidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { Debug.Assert(cCmds == 1, "Multiple commands"); Debug.Assert(prgCmds != null, "NULL argument"); if ((prgCmds == null)) { return(VSConstants.E_INVALIDARG); } // Filter out commands that are not defined by this package if (guidCmdGroup != GuidList.guidSccProviderCmdSet) { return((int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED)); } OLECMDF cmdf = OLECMDF.OLECMDF_SUPPORTED; // All source control commands needs to be hidden and disabled when the provider is not active if (!sccService.Active) { cmdf = cmdf | OLECMDF.OLECMDF_INVISIBLE; cmdf = cmdf & ~(OLECMDF.OLECMDF_ENABLED); prgCmds[0].cmdf = (uint)cmdf; return(VSConstants.S_OK); } // Call hook to query additional commands first. var result = Blinkbox.Events.BlinkboxSccHooks.QueryCommandStatus(guidCmdGroup, prgCmds, cmdf, pCmdText); if (result != (int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED) { // Handled in the hook return(result); } // Process our Commands switch (prgCmds[0].cmdID) { case CommandId.imnuGitSourceControlMenu: OLECMDTEXT cmdtxtStructure = (OLECMDTEXT)Marshal.PtrToStructure(pCmdText, typeof(OLECMDTEXT)); if (cmdtxtStructure.cmdtextf == (uint)OLECMDTEXTF.OLECMDTEXTF_NAME) { var branchName = sccService.CurrentBranchName; string menuText = string.IsNullOrEmpty(branchName) ? "Git" : "Git (" + branchName + ")"; SetOleCmdText(pCmdText, menuText); } break; case CommandId.icmdSccCommandGitBash: if (GitBash.Exists) { cmdf |= OLECMDF.OLECMDF_ENABLED; } break; case CommandId.icmdSccCommandGitExtension: var gitExtensionPath = GitSccOptions.Current.GitExtensionPath; if (!string.IsNullOrEmpty(gitExtensionPath) && File.Exists(gitExtensionPath) && GitSccOptions.Current.NotExpandGitExtensions) { cmdf |= OLECMDF.OLECMDF_ENABLED; } else { cmdf |= OLECMDF.OLECMDF_INVISIBLE; } break; case CommandId.icmdSccCommandGitTortoise: var tortoiseGitPath = GitSccOptions.Current.TortoiseGitPath; if (!string.IsNullOrEmpty(tortoiseGitPath) && File.Exists(tortoiseGitPath) && GitSccOptions.Current.NotExpandTortoiseGit) { cmdf |= OLECMDF.OLECMDF_ENABLED; } else { cmdf |= OLECMDF.OLECMDF_INVISIBLE; } break; case CommandId.icmdSccCommandUndo: case CommandId.icmdSccCommandCompare: if (GitBash.Exists && sccService.CanCompareSelectedFile) { cmdf |= OLECMDF.OLECMDF_ENABLED; } break; case CommandId.icmdSccCommandEditIgnore: if (sccService.IsSolutionGitControlled) { cmdf |= OLECMDF.OLECMDF_ENABLED; } break; case CommandId.icmdSccCommandHistory: case CommandId.icmdSccCommandPendingChanges: case CommandId.icmdPendingChangesAmend: case CommandId.icmdPendingChangesCommit: case CommandId.icmdPendingChangesCommitToBranch: if (GitBash.Exists && sccService.IsSolutionGitControlled) { cmdf |= OLECMDF.OLECMDF_ENABLED; } break; case CommandId.icmdSccCommandAbout: case CommandId.icmdSccCommandRefresh: //if (sccService.IsSolutionGitControlled) cmdf |= OLECMDF.OLECMDF_ENABLED; break; case CommandId.icmdSccCommandInit: if (!sccService.IsSolutionGitControlled) { cmdf |= OLECMDF.OLECMDF_ENABLED; } else { cmdf |= OLECMDF.OLECMDF_INVISIBLE; } break; default: var gitExtPath = GitSccOptions.Current.GitExtensionPath; var torGitPath = GitSccOptions.Current.TortoiseGitPath; if (prgCmds[0].cmdID >= CommandId.icmdGitExtCommand1 && prgCmds[0].cmdID < CommandId.icmdGitExtCommand1 + GitToolCommands.GitExtCommands.Count && !string.IsNullOrEmpty(gitExtPath) && File.Exists(gitExtPath) && !GitSccOptions.Current.NotExpandGitExtensions) { int idx = (int)prgCmds[0].cmdID - CommandId.icmdGitExtCommand1; SetOleCmdText(pCmdText, GitToolCommands.GitExtCommands[idx].Name); cmdf |= OLECMDF.OLECMDF_ENABLED; break; } else if (prgCmds[0].cmdID >= CommandId.icmdGitTorCommand1 && prgCmds[0].cmdID < CommandId.icmdGitTorCommand1 + GitToolCommands.GitTorCommands.Count && !string.IsNullOrEmpty(torGitPath) && File.Exists(torGitPath) && !GitSccOptions.Current.NotExpandTortoiseGit) { int idx = (int)prgCmds[0].cmdID - CommandId.icmdGitTorCommand1; SetOleCmdText(pCmdText, GitToolCommands.GitTorCommands[idx].Name); cmdf |= OLECMDF.OLECMDF_ENABLED; break; } else { return((int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED)); } } prgCmds[0].cmdf = (uint)(cmdf); return(VSConstants.S_OK); }
public bool QueryCommandStatus(Guid guidCmdGroup, uint commandId, IntPtr commandText, out OLECMDF commandStatus) { commandStatus = new OLECommandFlags(); if (guidCmdGroup == VSConstants.VSStd2K) { switch ((VSConstants.VSStd2KCmdID)commandId) { case VSConstants.VSStd2KCmdID.FORMATDOCUMENT: if (this.CanFormatDocument()) { commandStatus = OLECommandFlags.OLECMDF_ENABLED | OLECommandFlags.OLECMDF_SUPPORTED; return true; } break; case VSConstants.VSStd2KCmdID.FORMATSELECTION: if (this.CanFormatSelection()) { commandStatus = OLECommandFlags.OLECMDF_SUPPORTED; if (!this.textView.Selection.IsEmpty) { commandStatus |= OLECommandFlags.OLECMDF_ENABLED; } return true; } break; } } return false; }
/// <summary> /// The shell call this function to know if a menu item should be visible and /// if it should be enabled/disabled. /// Note that this function will only be called when an instance of this editor /// is open. /// </summary> /// <param name="guidCmdGroup">Guid describing which set of command the current command(s) belong to</param> /// <param name="cCmds">Number of command which status are being asked for</param> /// <param name="prgCmds">Information for each command</param> /// <param name="pCmdText">Used to dynamically change the command text</param> /// <returns>HRESULT</returns> public int QueryStatus(ref Guid guidCmdGroup, uint cCmds, OLECMD[] prgCmds, System.IntPtr pCmdText) { Debug.Assert(cCmds == 1, "Multiple commands"); Debug.Assert(prgCmds != null, "NULL argument"); if ((prgCmds == null)) { return(VSConstants.E_INVALIDARG); } // Filter out commands that are not defined by this package if (guidCmdGroup != GuidList.guidSccProviderCmdSet) { return((int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED));; } OLECMDF cmdf = OLECMDF.OLECMDF_SUPPORTED; // All source control commands needs to be hidden and disabled when the provider is not active if (!sccService.Active) { cmdf = OLECMDF.OLECMDF_INVISIBLE; prgCmds[0].cmdf = (uint)cmdf; return(VSConstants.S_OK); } // Process our Commands switch (prgCmds[0].cmdID) { case CommandId.icmdHgStatus: cmdf = QueryStatus_icmdHgStatus(); break; case CommandId.icmdHgCommitRoot: cmdf = QueryStatus_icmdHgCommitRoot(); break; case CommandId.icmdHgCommitSelected: cmdf = QueryStatus_icmdHgCommitSelected(); break; case CommandId.icmdHgHistoryRoot: cmdf = QueryStatus_icmdHgHistoryRoot(); break; case CommandId.icmdHgHistorySelected: cmdf = QueryStatus_icmdHgHistorySelected(); break; case CommandId.icmdHgSynchronize: cmdf = QueryStatus_icmdHgSynchronize(); break; case CommandId.icmdHgUpdateToRevision: cmdf = QueryStatus_icmdHgUpdateToRevision(); break; case CommandId.icmdHgDiff: cmdf = QueryStatus_icmdHgDiff(); break; case CommandId.icmdHgRevert: cmdf = QueryStatus_icmdHgRevert(); break; case CommandId.icmdHgAnnotate: cmdf = QueryStatus_icmdHgAnnotate(); break; case CommandId.icmdHgAddSelected: cmdf = QueryStatus_icmdHgAddSelected(); break; case CommandId.icmdViewToolWindow: case CommandId.icmdToolWindowToolbarCommand: // These commmands are always enabled when the provider is active cmdf = OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED;; break; default: return((int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED)); } prgCmds[0].cmdf = (uint)cmdf; return(VSConstants.S_OK); }
public bool QueryCommandStatus(Guid guidCmdGroup, uint commandId, IntPtr commandText, out OLECMDF commandStatus) { commandStatus = new OLECommandFlags(); if (guidCmdGroup == VSConstants.VSStd2K) { switch ((VSConstants.VSStd2KCmdID)commandId) { case VSConstants.VSStd2KCmdID.FORMATDOCUMENT: if (this.CanFormatDocument()) { commandStatus = OLECommandFlags.OLECMDF_ENABLED | OLECommandFlags.OLECMDF_SUPPORTED; return(true); } break; case VSConstants.VSStd2KCmdID.FORMATSELECTION: if (this.CanFormatSelection()) { commandStatus = OLECommandFlags.OLECMDF_SUPPORTED; if (!this.textView.Selection.IsEmpty) { commandStatus |= OLECommandFlags.OLECMDF_ENABLED; } return(true); } break; } } return(false); }
public void UpdateFlags(ref OLECMDF cmdf) { if (Enabled) cmdf |= OLECMDF.OLECMDF_ENABLED; if (Checked) cmdf |= OLECMDF.OLECMDF_LATCHED; if (Ninched) cmdf |= OLECMDF.OLECMDF_NINCHED; if (!Visible) cmdf |= OLECMDF.OLECMDF_INVISIBLE; if (HideOnContextMenu) cmdf |= OLECMDF.OLECMDF_DEFHIDEONCTXTMENU; }
protected override bool TryQueryStatus(Guid commandGroup, uint commandId, ref OLECMDF commandFlags) { if (commandGroup == VsMenus.guidStandardCommandSet97) { switch (commandId) { case (uint)VSConstants.VSStd97CmdID.FindReferences: if (IsFindAllReferencesSupported()) { commandFlags = OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED; } else { commandFlags = OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_INVISIBLE; } return true; } } return false; }
protected virtual bool TryQueryStatus(Guid commandGroup, uint commandId, ref OLECMDF commandFlags) => false;
protected virtual bool TryQueryStatus(Guid commandGroup, uint commandId, ref OLECMDF commandFlags) { return false; }
protected virtual bool SupportsVSStd97Command(uint commandID, ref OLECMDF status) { return(false); }
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); } } }
internal static bool QueryStatus(this IOleCommandTarget oleCommandTarget, OleCommandData oleCommandData, OLECMDF status) { OLECMD command; var hr = QueryStatus(oleCommandTarget, oleCommandData, out command); if (hr != VSConstants.S_OK) { return(false); } var ret = (OLECMDF)command.cmdf; return(status == (ret & status)); }
public CommandMapping(Guid commandGroup, int commandId, OLECMDF commandOptions, Func<CommandBase> commandCreator) { _commandGroup = commandGroup; _commandId = (uint)commandId; _commandOptions = (uint)commandOptions; _commandCreator = commandCreator; }
/// <summary> /// The shell call this function to know if a menu item should be visible and /// if it should be enabled/disabled. /// Note that this function will only be called when an instance of this editor is open. /// </summary> /// <param name="pguidCmdGroup">Guid describing which set of command the current command(s) belong to.</param> /// <param name="cCmds">Number of command which status are being asked for.</param> /// <param name="prgCmds">Information for each command.</param> /// <param name="pCmdText">Used to dynamically change the command text.</param> /// <returns>S_OK if the method succeeds.</returns> public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { // validate parameters if (prgCmds == null || cCmds != 1) { return(VSConstants.E_INVALIDARG); } OLECMDF cmdf = OLECMDF.OLECMDF_SUPPORTED; if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97) { // Process standard Commands switch (prgCmds[0].cmdID) { case (uint)VSConstants.VSStd97CmdID.SelectAll: { // Always enabled cmdf = OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED; break; } case (uint)VSConstants.VSStd97CmdID.Copy: case (uint)VSConstants.VSStd97CmdID.Cut: { // Enable if something is selected //if (editorControl.SelectionLength > 0) //{ // cmdf |= OLECMDF.OLECMDF_ENABLED; //} break; } case (uint)VSConstants.VSStd97CmdID.Paste: { // Enable if clipboard has content we can paste //if (editorControl.CanPaste(DataFormats.GetFormat(DataFormats.Text))) //{ // cmdf |= OLECMDF.OLECMDF_ENABLED; //} break; } case (uint)VSConstants.VSStd97CmdID.Redo: { // Enable if actions that have occurred within the RichTextBox // can be reapplied //if (editorControl.CanRedo) //{ // cmdf |= OLECMDF.OLECMDF_ENABLED; //} break; } case (uint)VSConstants.VSStd97CmdID.Undo: { //if (editorControl.CanUndo) //{ // cmdf |= OLECMDF.OLECMDF_ENABLED; //} break; } default: { return((int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED)); } } } else if (pguidCmdGroup == ConstCollection.guidEditorCmdSet) { // Process our Commands switch (prgCmds[0].cmdID) { // if we had commands specific to our editor, they would be processed here default: { return((int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED)); } } } else { return((int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED));; } prgCmds[0].cmdf = (uint)cmdf; return(VSConstants.S_OK); }
/// <summary> /// The shell call this function to know if a menu item should be visible and /// if it should be enabled/disabled. /// Note that this function will only be called when an instance of this editor /// is open. /// </summary> /// <param name="guidCmdGroup">Guid describing which set of command the current command(s) belong to</param> /// <param name="cCmds">Number of command which status are being asked for</param> /// <param name="prgCmds">Information for each command</param> /// <param name="pCmdText">Used to dynamically change the command text</param> /// <returns>HRESULT</returns> public int QueryStatus(ref Guid guidCmdGroup, uint cCmds, OLECMD[] prgCmds, System.IntPtr pCmdText) { Trace.WriteLineIf(_commandTraceSwitch.TraceVerbose, "VS2P4Package.QueryStatus(guid) entered"); //Stopwatch stopwatch = new Stopwatch(); //stopwatch.Start(); Debug.Assert(cCmds == 1, "Multiple commands"); Debug.Assert(prgCmds != null, "NULL argument"); // Filter out commands that are not defined by this package if (guidCmdGroup != GuidList.guidVS2P4CmdSet) { return((int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED));; } OLECMDF cmdf = OLECMDF.OLECMDF_SUPPORTED; // All source control commands needs to be hidden and disabled when the provider is not active Trace.WriteLineIf(_commandTraceSwitch.TraceVerbose, "VS2P4Package.QueryStatus(guid) checking for provider active"); if (!_sccService.IsActive) { cmdf = cmdf | OLECMDF.OLECMDF_INVISIBLE; cmdf = cmdf & ~(OLECMDF.OLECMDF_ENABLED); prgCmds[0].cmdf = (uint)cmdf; Trace.WriteLineIf(_commandTraceSwitch.TraceVerbose, "VS2P4Package.QueryStatus(guid): provider not active"); return(VSConstants.S_OK); } Trace.WriteLineIf(_commandTraceSwitch.TraceVerbose, String.Format("VS2P4Package.QueryStatus(guid) prgCmds[0].cmdID = {0}", prgCmds[0].cmdID.ToString())); // Process our Commands switch (prgCmds[0].cmdID) { case CommandId.icmdCheckout: cmdf |= QueryStatus_icmdCheckout(); break; case CommandId.icmdMarkForAdd: cmdf |= QueryStatus_icmdMarkForAdd(); break; case CommandId.icmdRevertIfUnchanged: cmdf |= QueryStatus_icmdRevertIfUnchanged(); break; case CommandId.icmdRevert: cmdf |= QueryStatus_icmdRevert(); break; case CommandId.icmdGetLatestRevison: cmdf |= QueryStatus_icmdGetLatestRevison(); break; case CommandId.icmdRevisionHistory: cmdf |= QueryStatus_icmdRevisionHistory(); break; case CommandId.icmdDiff: cmdf |= QueryStatus_icmdDiff(); break; case CommandId.icmdTimeLapse: cmdf |= QueryStatus_icmdTimeLapse(); break; case CommandId.icmdRefresh: cmdf |= QueryStatus_icmdRefresh(); break; default: return((int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED)); } Trace.WriteLineIf(_commandTraceSwitch.TraceVerbose, String.Format("VS2P4Package.QueryStatus(guid) cmdF = {0}", cmdf.ToString())); prgCmds[0].cmdf = (uint)cmdf; //stopwatch.Stop(); //if (stopwatch.ElapsedTicks > 10) //{ // Log.Debug(String.Format("QueryStatus() took {0} msec", stopwatch.ElapsedMilliseconds)); //} Trace.WriteLineIf(_commandTraceSwitch.TraceVerbose, "VS2P4Package.QueryStatus(guid) completed"); return(VSConstants.S_OK); }
/// <summary> /// The shell call this function to know if a menu item should be visible and /// if it should be enabled/disabled. /// Note that this function will only be called when an instance of this editor /// is open. /// </summary> /// <param name="guidCmdGroup">Guid describing which set of command the current command(s) belong to</param> /// <param name="cCmds">Number of command which status are being asked for</param> /// <param name="prgCmds">Information for each command</param> /// <param name="pCmdText">Used to dynamically change the command text</param> /// <returns>HRESULT</returns> public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, System.IntPtr pCmdText) { Debug.Assert(cCmds == 1, "Multiple commands"); Debug.Assert(prgCmds != null, "NULL argument"); if ((prgCmds == null)) { return(VSConstants.E_INVALIDARG); } OLECMDF cmdf = OLECMDF.OLECMDF_SUPPORTED; if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97) { // Process standard Commands switch (prgCmds[0].cmdID) { case (uint)VSStd97CmdID.SelectAll: { // Always enabled cmdf = OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED; break; } case (uint)VSStd97CmdID.Copy: /*case (uint)VSStd97CmdID.Cut: * { * // Enable if something is selected * if (textBox1.SelectionLength > 0) * cmdf |= OLECMDF.OLECMDF_ENABLED; * break; * } * case (uint)VSStd97CmdID.Paste: * { * // Enable if clipboard has content we can paste * if (textBox1.CanPaste(DataFormats.GetFormat(DataFormats.Text))) * cmdf |= OLECMDF.OLECMDF_ENABLED; * break; * } * case (uint)VSStd97CmdID.Redo: * { * if (textBox1.CanRedo) * cmdf |= OLECMDF.OLECMDF_ENABLED; * break; * } * case (uint)VSStd97CmdID.Undo: * { * if (textBox1.CanUndo) * cmdf |= OLECMDF.OLECMDF_ENABLED; * break; * }*/ default: return((int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED)); } } else if (pguidCmdGroup == GuidList.guidTableEditorTestCmdSet) { // Process our Commands switch (prgCmds[0].cmdID) { // if we had commands specific to our editor, they would be processed here default: return((int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED)); } } else { return((int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED)); }; prgCmds[0].cmdf = (uint)cmdf; return(VSConstants.S_OK); }
int IOleCommandTarget.QueryStatus(ref Guid guidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) { Debug.Assert(cCmds == 1, "Multiple commands"); Debug.Assert(prgCmds != null, "NULL argument"); if ((prgCmds == null)) { return(VSConstants.E_INVALIDARG); } // Filter out commands that are not defined by this package if (guidCmdGroup != GuidList.guidVsGitToolsPackageCmdSet) { return((int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED)); } OLECMDF cmdf = OLECMDF.OLECMDF_SUPPORTED; //cmdf = cmdf | OLECMDF.OLECMDF_INVISIBLE; cmdf = cmdf & ~(OLECMDF.OLECMDF_ENABLED); // Process our Commands switch (prgCmds[0].cmdID) { case PkgCmdIDList.icmdSccCommandGitBash: if (GitBash.Exists) { cmdf |= OLECMDF.OLECMDF_ENABLED; } break; case PkgCmdIDList.icmdSccCommandGitExtension: var gitExtensionPath = GitSccOptions.Current.GitExtensionPath; if (!string.IsNullOrEmpty(gitExtensionPath) && File.Exists(gitExtensionPath)) { cmdf |= OLECMDF.OLECMDF_ENABLED; } break; case PkgCmdIDList.icmdSccCommandGitTortoise: var tortoiseGitPath = GitSccOptions.Current.TortoiseGitPath; if (!string.IsNullOrEmpty(tortoiseGitPath) && File.Exists(tortoiseGitPath)) { cmdf |= OLECMDF.OLECMDF_ENABLED; } break; case PkgCmdIDList.icmdSccCommandEditIgnore: if (IsSolutionGitControlled) { cmdf |= OLECMDF.OLECMDF_ENABLED; } else { cmdf = cmdf | OLECMDF.OLECMDF_INVISIBLE; } break; case PkgCmdIDList.icmdSccCommandHistory: case PkgCmdIDList.icmdSccCommandPendingChanges: case PkgCmdIDList.icmdPendingChangesAmend: case PkgCmdIDList.icmdPendingChangesCommit: case PkgCmdIDList.icmdPendingChangesCommitToBranch: if (GitBash.Exists && IsSolutionGitControlled) { cmdf |= OLECMDF.OLECMDF_ENABLED; } else { cmdf = cmdf | OLECMDF.OLECMDF_INVISIBLE; } break; case PkgCmdIDList.icmdSccCommandAbout: case PkgCmdIDList.icmdPendingChangesRefresh: case PkgCmdIDList.icmdPendingChangesSettings: cmdf |= OLECMDF.OLECMDF_ENABLED; break; case PkgCmdIDList.icmdSccCommandInit: if (repository != null && !IsSolutionGitControlled) { cmdf |= OLECMDF.OLECMDF_ENABLED; } else { //cmdf = cmdf & ~(OLECMDF.OLECMDF_ENABLED); cmdf = cmdf | OLECMDF.OLECMDF_INVISIBLE; } break; default: var gitExtPath = GitSccOptions.Current.GitExtensionPath; var torGitPath = GitSccOptions.Current.TortoiseGitPath; if (prgCmds[0].cmdID >= PkgCmdIDList.icmdGitExtCommand1 && prgCmds[0].cmdID < PkgCmdIDList.icmdGitExtCommand1 + GitToolCommands.GitExtCommands.Count && !string.IsNullOrEmpty(gitExtPath) && File.Exists(gitExtPath)) { int idx = (int)prgCmds[0].cmdID - PkgCmdIDList.icmdGitExtCommand1; SetOleCmdText(pCmdText, GitToolCommands.GitExtCommands[idx].Name); cmdf |= OLECMDF.OLECMDF_ENABLED; break; } else if (prgCmds[0].cmdID >= PkgCmdIDList.icmdGitTorCommand1 && prgCmds[0].cmdID < PkgCmdIDList.icmdGitTorCommand1 + GitToolCommands.GitTorCommands.Count && !string.IsNullOrEmpty(torGitPath) && File.Exists(torGitPath)) { int idx = (int)prgCmds[0].cmdID - PkgCmdIDList.icmdGitTorCommand1; SetOleCmdText(pCmdText, GitToolCommands.GitTorCommands[idx].Name); cmdf |= OLECMDF.OLECMDF_ENABLED; break; } else { return((int)(Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED)); } } prgCmds[0].cmdf = (uint)(cmdf); return(VSConstants.S_OK); }