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); } // 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 PackageIds.cmdIdAddProjectToSCC: if (SolutionExtensions.CanAddSelectedProjectToGitRepoitory() && sccService.Active) { cmdf |= OLECMDF.OLECMDF_ENABLED; } else { cmdf |= OLECMDF.OLECMDF_INVISIBLE; } 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; if (sccService.CanCompareSelectedFile) { cmdf |= OLECMDF.OLECMDF_ENABLED; } break; case CommandId.icmdSccCommandEditIgnore: if (sccService.IsSolutionGitControlled) { cmdf |= OLECMDF.OLECMDF_ENABLED; } break; case CommandId.cmdidGitIgnoreSubMenuCommandUpdate: 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; if (sccService.IsSolutionGitControlled) { cmdf |= OLECMDF.OLECMDF_ENABLED; } break; 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; case CommandId.icmdPendingChangesSettings: cmdf |= OLECMDF.OLECMDF_ENABLED; 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 if (prgCmds[0].cmdID >= CommandId.icmdGitIgnoreCommand1 && //prgCmds[0].cmdID < CommandId.icmdGitIgnoreCommand1 + GitToolCommands.IgnoreCommands.Count) //{ // int idx = (int)prgCmds[0].cmdID - CommandId.icmdGitTorCommand1; // SetOleCmdText(pCmdText, GitToolCommands.IgnoreCommands[idx]); // 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); }