//===================================================================== /// <summary> /// This is used to set the state of a menu command on the View Help menu /// </summary> /// <param name="command">The command object</param> /// <param name="format">The help file format</param> private static void SetViewHelpCommandState(OleMenuCommand command, HelpFileFormats?format) { ThreadHelper.ThrowIfNotOnUIThread(); Array activeProjects = null; DTE dte = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(DTE)) as DTE; bool visible = false, enabled = false; if (dte != null) { Solution s = dte.Solution; // Hide the menu option if a SHFB project is not loaded if (s != null) { #pragma warning disable VSTHRD010 visible = s.Projects.Cast <Project>().Any( p => p.UniqueName.EndsWith(".shfbproj", StringComparison.OrdinalIgnoreCase)); #pragma warning restore VSTHRD010 // Check the active project for the specified help format if visible if (visible) { try { activeProjects = dte.ActiveSolutionProjects as Array; } catch { // The above can throw an exception while the project is loading which // we should ignore. } if (activeProjects != null && activeProjects.Length > 0) { Project p = activeProjects.GetValue(0) as Project; if (p != null && p.Object != null && p.UniqueName.EndsWith(".shfbproj", StringComparison.OrdinalIgnoreCase)) { SandcastleBuilderProjectNode pn = (SandcastleBuilderProjectNode)p.Object; string projectHelpFormat = (pn.GetProjectProperty("HelpFileFormat") ?? HelpFileFormats.HtmlHelp1.ToString()); enabled = (!pn.BuildInProgress && (format == null || projectHelpFormat.IndexOf( format.ToString(), StringComparison.OrdinalIgnoreCase) != -1)); } } } } } command.Visible = visible; command.Enabled = enabled; }
//===================================================================== /// <summary> /// This is used to set the state of a menu command on the View Help menu /// </summary> /// <param name="command">The command object</param> /// <param name="format">The help file format</param> private static void SetViewHelpCommandState(OleMenuCommand command, HelpFileFormats?format) { Array activeProjects = null; DTE dte = Utility.GetServiceFromPackage <DTE, DTE>(false); bool visible = false, enabled = false; if (dte != null) { Solution s = dte.Solution; // Hide the menu option if a SHFB project is not loaded if (s != null) { visible = s.Projects.Cast <Project>().Any( p => p.UniqueName.EndsWith(".shfbproj", StringComparison.OrdinalIgnoreCase)); // Check the active project for the specified help format if visible if (visible) { try { activeProjects = dte.ActiveSolutionProjects as Array; } catch { // The above can throw an exception while the project is loading which // we should ignore. } if (activeProjects != null && activeProjects.Length > 0) { Project p = activeProjects.GetValue(0) as Project; if (p != null && p.Object != null && p.UniqueName.EndsWith(".shfbproj", StringComparison.OrdinalIgnoreCase)) { SandcastleBuilderProjectNode pn = (SandcastleBuilderProjectNode)p.Object; string projectHelpFormat = (pn.GetProjectProperty("HelpFileFormat") ?? HelpFileFormats.HtmlHelp1.ToString()); enabled = (!pn.BuildInProgress && (format == null || projectHelpFormat.IndexOf( format.ToString(), StringComparison.OrdinalIgnoreCase) != -1)); } } } } } command.Visible = visible; command.Enabled = enabled; }