//===================================================================== /// <summary> /// This is overridden to create the project node /// </summary> /// <returns>A project node</returns> protected override ProjectNode CreateProject() { ProjectPackage package = (ProjectPackage)this.Package; SandcastleBuilderProjectNode project = new SandcastleBuilderProjectNode(package); project.SetSite((IOleServiceProvider)((IServiceProvider)package).GetService(typeof(IOleServiceProvider))); return(project); }
//===================================================================== /// <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; }
/// <summary> /// View the last build HTML Help 1 file, MS Help 2 file, MS Help Viewer, or website Index.aspx page /// </summary> /// <param name="projectNode">The project node for which to open the help file</param> internal void ViewBuiltHelpFile(SandcastleBuilderProjectNode projectNode) { if (projectNode != null) { SandcastleProject project = projectNode.SandcastleProject; if (project == null) { return; } if ((project.HelpFileFormat & HelpFileFormats.HtmlHelp1) != 0) { this.ViewBuiltHelpFile(project, PkgCmdIDList.ViewHtmlHelp); } else if ((project.HelpFileFormat & HelpFileFormats.MSHelp2) != 0) { this.ViewBuiltHelpFile(project, PkgCmdIDList.ViewHxSHelp); } else if ((project.HelpFileFormat & HelpFileFormats.OpenXml) != 0) { this.ViewBuiltHelpFile(project, PkgCmdIDList.ViewDocxHelp); } else if ((project.HelpFileFormat & HelpFileFormats.Website) != 0) { Utility.OpenUrl(projectNode.StartWebServerInstance()); } else { // This format opens a modal dialog box so we'll use it last if nothing else is // selected. var options = this.GeneralOptions; if (options != null) { using (LaunchMSHelpViewerDlg dlg = new LaunchMSHelpViewerDlg(project, options.MSHelpViewerPath)) { dlg.ShowDialog(); } } } } }
/// <summary> /// Monitor for changes to the active project and notify the entity references user control when a /// new SHFB project is selected as the active project. /// </summary> /// <param name="pHierOld">The hierarchy for the previously selected item</param> /// <param name="itemidOld">Project item identifier for the previously selected item</param> /// <param name="pMISOld">Interface for previous multi-selection items</param> /// <param name="pSCOld">Interface for the previous selection container</param> /// <param name="pHierNew">The hierarchy for the new selection</param> /// <param name="itemidNew">Project item identifier for the new selection</param> /// <param name="pMISNew">Interface for new multi-selection items</param> /// <param name="pSCNew">Interface for the new selection container</param> /// <returns></returns> int IVsSelectionEvents.OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew) { ThreadHelper.ThrowIfNotOnUIThread(); SandcastleProject shfbProject = null; EntityReferencesControl ucEntityReferences; object project; if (pHierOld == null || !pHierOld.Equals(pHierNew)) { ucEntityReferences = base.Content as EntityReferencesControl; if (ucEntityReferences != null) { if (pHierNew != null) { ErrorHandler.ThrowOnFailure(pHierNew.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out project)); EnvDTE.Project envDTEProject = project as EnvDTE.Project; if (envDTEProject != null) { SandcastleBuilderProjectNode projectNode = envDTEProject.Object as SandcastleBuilderProjectNode; if (projectNode != null) { shfbProject = projectNode.SandcastleProject; } } } // We'll keep the existing reference unless it changes or the project is closed if ((shfbProject == null && pHierNew == null) || (shfbProject != null && (ucEntityReferences.CurrentProject == null || ucEntityReferences.CurrentProject.Filename != shfbProject.Filename))) { ucEntityReferences.CurrentProject = shfbProject; } } } return(VSConstants.S_OK); }
/// <summary> /// View the last built help output /// </summary> /// <param name="projectNode">The project node for which to open the help file</param> internal void ViewBuiltHelpFile(SandcastleBuilderProjectNode projectNode) { if (projectNode != null) { SandcastleProject project = projectNode.SandcastleProject; if (project == null) { return; } #pragma warning disable VSTHRD010 if ((project.HelpFileFormat & HelpFileFormats.HtmlHelp1) != 0) { ViewBuiltHelpFile(project, PkgCmdIDList.ViewHtmlHelp); } else if ((project.HelpFileFormat & HelpFileFormats.OpenXml) != 0) { ViewBuiltHelpFile(project, PkgCmdIDList.ViewDocxHelp); } else if ((project.HelpFileFormat & HelpFileFormats.Markdown) != 0) { ViewBuiltHelpFile(project, 0); } else if ((project.HelpFileFormat & HelpFileFormats.Website) != 0) { Utility.OpenUrl(projectNode.StartWebServerInstance()); } else { // This format opens a modal dialog box so we'll use it last if nothing else // is selected. var options = this.GeneralOptions; if (options != null) { var dlg = new LaunchMSHelpViewerDlg(project, options.MSHelpViewerPath); dlg.ShowModalDialog(); } } #pragma warning restore VSTHRD010 } }