//===================================================================== /// <summary> /// This is used to get information from token, content layout, and site map files open in editors /// so that current information is displayed for them in the entity references control. /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void ucEntityReferences_FileContentNeeded(object sender, FileContentNeededEventArgs e) { ContentLayoutWindow contentLayoutWindow; SiteMapEditorWindow siteMapEditorWindow; TokenEditorWindow tokenEditorWindow; foreach(IDockContent content in this.DockPanel.Documents) { contentLayoutWindow = content as ContentLayoutWindow; if(contentLayoutWindow != null) e.ContentLayoutFiles.Add(contentLayoutWindow.Filename, contentLayoutWindow.Topics); else { siteMapEditorWindow = content as SiteMapEditorWindow; if(siteMapEditorWindow != null) e.SiteMapFiles.Add(siteMapEditorWindow.Filename, siteMapEditorWindow.Topics); else { tokenEditorWindow = content as TokenEditorWindow; if(tokenEditorWindow != null) e.TokenFiles.Add(tokenEditorWindow.Filename, tokenEditorWindow.Tokens); } } } }
//===================================================================== /// <summary> /// This loads the tree view with table of contents file entries from the project /// </summary> private List<EntityReference> LoadTableOfContentsInfo() { List<ITableOfContents> tocFiles; TopicCollection contentLayout; TocEntryCollection siteMap, mergedToc; EntityReference er; bool hasSelectedItem = false; if(tableOfContents != null) return tableOfContents; tableOfContents = new List<EntityReference>(); // Get content from open file editors var args = new FileContentNeededEventArgs(FileContentNeededEvent, this); base.RaiseEvent(args); try { tocFiles = new List<ITableOfContents>(); // Load all content layout files and add them to the list foreach(var contentFile in currentProject.ContentFiles(BuildAction.ContentLayout)) { // If open in an editor, use the edited values if(!args.ContentLayoutFiles.TryGetValue(contentFile.FullPath, out contentLayout)) { contentLayout = new TopicCollection(contentFile); contentLayout.Load(); } tocFiles.Add(contentLayout); } // Load all site maps and add them to the list foreach(var contentFile in currentProject.ContentFiles(BuildAction.SiteMap)) { // If open in an editor, use the edited values if(!args.SiteMapFiles.TryGetValue(contentFile.FullPath, out siteMap)) { siteMap = new TocEntryCollection(contentFile); siteMap.Load(); } tocFiles.Add(siteMap); } tocFiles.Sort((x, y) => { ContentFile fx = x.ContentLayoutFile, fy = y.ContentLayoutFile; if(fx.SortOrder < fy.SortOrder) return -1; if(fx.SortOrder > fy.SortOrder) return 1; return String.Compare(fx.Filename, fy.Filename, StringComparison.OrdinalIgnoreCase); }); // Create the merged TOC. For the purpose of adding links, we'll include everything even topics // marked as invisible. mergedToc = new TocEntryCollection(); foreach(ITableOfContents file in tocFiles) file.GenerateTableOfContents(mergedToc, true); // Convert the TOC info to entity references foreach(var t in mergedToc) { er = new EntityReference { EntityType = EntityType.TocEntry, Id = t.Id, Label = (t.Title ?? t.Id ?? "(No title)"), ToolTip = String.Format(CultureInfo.CurrentCulture, "ID: {0}\nFile: {1}", (t.Id ?? t.Title ?? "(No ID)"), t.SourceFile), Tag = t, IsExpanded = t.IsExpanded, IsSelected = (t.IsSelected && !hasSelectedItem) }; // Only use the first selected item if(er.IsSelected) hasSelectedItem = true; tableOfContents.Add(er); if(t.Children.Count != 0) hasSelectedItem = this.AddChildTocEntries(t, er, hasSelectedItem); } } catch(Exception ex) { tableOfContents.Add(new EntityReference { EntityType = EntityType.File, Label = "Unable to load TOC info: " + ex.Message, ToolTip = "Error" }); } if(!hasSelectedItem && tableOfContents.Count != 0) tableOfContents[0].IsSelected = true; return tableOfContents; }
/// <summary> /// This loads the tree view with table of contents file entries from the project /// </summary> /// <remarks>Token information is also loaded here and passed on to the converter.</remarks> private void LoadTableOfContentsInfo() { List<ITableOfContents> tocFiles; TopicCollection contentLayout; TokenCollection tokens; tvContent.ItemsSource = null; tableOfContents = null; lblCurrentProject.Text = null; browserHistory.Clear(); historyLocation = -1; if(currentProject == null) { lblCurrentProject.Text = "None - Select a help file builder project in the Solution Explorer"; return; } // Make sure the base path is set for imported code blocks this.SetImportedCodeBasePath(); // Get content from open file editors var args = new FileContentNeededEventArgs(FileContentNeededEvent, this); base.RaiseEvent(args); lblCurrentProject.Text = currentProject.Filename; browserHistory.Clear(); historyLocation = -1; tableOfContents = new TocEntryCollection(); try { converter.MediaFiles.Clear(); // Get the image files. This information is used to resolve media link elements in the // topic files. foreach(var file in currentProject.ImagesReferences) converter.MediaFiles[file.Id] = new KeyValuePair<string, string>(file.FullPath, file.AlternateText); } catch(Exception ex) { tableOfContents.Add(new TocEntry(currentProject) { Title = "ERROR: Unable to load media info: " + ex.Message }); } try { converter.Tokens.Clear(); // Get the token files. This information is used to resolve token elements in the topic files. foreach(var file in currentProject.ContentFiles(BuildAction.Tokens).OrderBy(f => f.LinkPath)) { // If open in an editor, use the edited values if(!args.TokenFiles.TryGetValue(file.FullPath, out tokens)) { tokens = new TokenCollection(file.FullPath); tokens.Load(); } // Store the tokens as XElements so that they can be parsed inline with the topic foreach(var t in tokens) converter.Tokens.Add(t.TokenName, XElement.Parse("<token>" + t.TokenValue + "</token>")); } } catch(Exception ex) { tableOfContents.Add(new TocEntry(currentProject) { Title = "ERROR: Unable to load token info: " + ex.Message }); } try { converter.TopicTitles.Clear(); // Load the content layout files. Site maps are ignored as we don't support rendering them. tocFiles = new List<ITableOfContents>(); foreach(var contentFile in currentProject.ContentFiles(BuildAction.ContentLayout)) { // If open in an editor, use the edited values if(!args.ContentLayoutFiles.TryGetValue(contentFile.FullPath, out contentLayout)) { contentLayout = new TopicCollection(contentFile); contentLayout.Load(); } tocFiles.Add(contentLayout); } tocFiles.Sort((x, y) => { ContentFile fx = x.ContentLayoutFile, fy = y.ContentLayoutFile; if(fx.SortOrder < fy.SortOrder) return -1; if(fx.SortOrder > fy.SortOrder) return 1; return String.Compare(fx.Filename, fy.Filename, StringComparison.OrdinalIgnoreCase); }); // Create the merged TOC. For the purpose of adding links, we'll include everything even topics // marked as invisible. foreach(ITableOfContents file in tocFiles) file.GenerateTableOfContents(tableOfContents, true); // Pass the topic IDs and titles on to the converter for use in hyperlinks foreach(var t in tableOfContents.All()) if(!String.IsNullOrEmpty(t.Id)) converter.TopicTitles[t.Id] = t.LinkText; } catch(Exception ex) { tableOfContents.Add(new TocEntry(currentProject) { Title = "ERROR: Unable to load TOC info: " + ex.Message }); } if(tableOfContents.Count != 0) { foreach(var t in tableOfContents.All()) t.IsSelected = false; tableOfContents[0].IsSelected = true; } tvContent.ItemsSource = tableOfContents; }
//===================================================================== /// <summary> /// This loads the tree view with token file entries from the project /// </summary> private List<EntityReference> LoadTokenInfo() { EntityReference tokenFileEntity = null; TokenCollection tokenColl; if(tokens != null) return tokens; tokens = new List<EntityReference>(); // Get content from open file editors var args = new FileContentNeededEventArgs(FileContentNeededEvent, this); base.RaiseEvent(args); foreach(var tokenFile in currentProject.ContentFiles(BuildAction.Tokens).OrderBy(f => f.LinkPath)) try { if(File.Exists(tokenFile.FullPath)) { tokenFileEntity = new EntityReference { EntityType = EntityType.File, Id = tokenFile.FullPath, Label = Path.GetFileName(tokenFile.FullPath), ToolTip = tokenFile.FullPath }; tokens.Add(tokenFileEntity); // If open in an editor, use the edited values if(!args.TokenFiles.TryGetValue(tokenFile.FullPath, out tokenColl)) { tokenColl = new TokenCollection(tokenFile.FullPath); tokenColl.Load(); } foreach(Token t in tokenColl) tokenFileEntity.SubEntities.Add(new EntityReference { EntityType = EntityType.Token, Id = t.TokenName, Label = t.TokenName, ToolTip = t.TokenName, Tag = t }); } tokenFileEntity = null; } catch(Exception ex) { if(tokenFileEntity == null) tokens.Add(new EntityReference { EntityType = EntityType.File, Label = "Unable to load file '" + tokenFile.FullPath + "'. Reason: " + ex.Message, ToolTip = "Error" }); else tokens.Add(new EntityReference { EntityType = EntityType.File, Label = "Unable to load file: " + ex.Message, ToolTip = "Error" }); } if(tokens.Count != 0) { tokens[0].IsSelected = true; if(tokens[0].SubEntities.Count != 0) tokens[0].IsExpanded = true; } return tokens; }
//===================================================================== /// <summary> /// This loads the tree view with table of contents file entries from the project /// </summary> private List <EntityReference> LoadTableOfContentsInfo() { List <ITableOfContents> tocFiles; TopicCollection contentLayout; TocEntryCollection siteMap, mergedToc; EntityReference er; bool hasSelectedItem = false; if (tableOfContents != null) { return(tableOfContents); } tableOfContents = new List <EntityReference>(); // Get content from open file editors var args = new FileContentNeededEventArgs(FileContentNeededEvent, this); base.RaiseEvent(args); try { tocFiles = new List <ITableOfContents>(); // Load all content layout files and add them to the list foreach (var contentFile in currentProject.ContentFiles(BuildAction.ContentLayout)) { // If open in an editor, use the edited values if (!args.ContentLayoutFiles.TryGetValue(contentFile.FullPath, out contentLayout)) { contentLayout = new TopicCollection(contentFile); contentLayout.Load(); } tocFiles.Add(contentLayout); } // Load all site maps and add them to the list foreach (var contentFile in currentProject.ContentFiles(BuildAction.SiteMap)) { // If open in an editor, use the edited values if (!args.SiteMapFiles.TryGetValue(contentFile.FullPath, out siteMap)) { siteMap = new TocEntryCollection(contentFile); siteMap.Load(); } tocFiles.Add(siteMap); } tocFiles.Sort((x, y) => { ContentFile fx = x.ContentLayoutFile, fy = y.ContentLayoutFile; if (fx.SortOrder < fy.SortOrder) { return(-1); } if (fx.SortOrder > fy.SortOrder) { return(1); } return(String.Compare(fx.Filename, fy.Filename, StringComparison.OrdinalIgnoreCase)); }); // Create the merged TOC. For the purpose of adding links, we'll include everything even topics // marked as invisible. mergedToc = new TocEntryCollection(); foreach (ITableOfContents file in tocFiles) { file.GenerateTableOfContents(mergedToc, true); } // Convert the TOC info to entity references foreach (var t in mergedToc) { er = new EntityReference { EntityType = EntityType.TocEntry, Id = t.Id, Label = (t.Title ?? t.Id ?? "(No title)"), ToolTip = String.Format(CultureInfo.CurrentCulture, "ID: {0}\nFile: {1}", (t.Id ?? t.Title ?? "(No ID)"), t.SourceFile), Tag = t, IsExpanded = t.IsExpanded, IsSelected = (t.IsSelected && !hasSelectedItem) }; // Only use the first selected item if (er.IsSelected) { hasSelectedItem = true; } tableOfContents.Add(er); if (t.Children.Count != 0) { hasSelectedItem = this.AddChildTocEntries(t, er, hasSelectedItem); } } } catch (Exception ex) { tableOfContents.Add(new EntityReference { EntityType = EntityType.File, Label = "Unable to load TOC info: " + ex.Message, ToolTip = "Error" }); } if (!hasSelectedItem && tableOfContents.Count != 0) { tableOfContents[0].IsSelected = true; } return(tableOfContents); }
//===================================================================== /// <summary> /// This loads the tree view with token file entries from the project /// </summary> private List <EntityReference> LoadTokenInfo() { EntityReference tokenFileEntity = null; TokenCollection tokenColl; if (tokens != null) { return(tokens); } tokens = new List <EntityReference>(); // Get content from open file editors var args = new FileContentNeededEventArgs(FileContentNeededEvent, this); base.RaiseEvent(args); foreach (var tokenFile in currentProject.ContentFiles(BuildAction.Tokens).OrderBy(f => f.LinkPath)) { try { if (File.Exists(tokenFile.FullPath)) { tokenFileEntity = new EntityReference { EntityType = EntityType.File, Id = tokenFile.FullPath, Label = Path.GetFileName(tokenFile.FullPath), ToolTip = tokenFile.FullPath }; tokens.Add(tokenFileEntity); // If open in an editor, use the edited values if (!args.TokenFiles.TryGetValue(tokenFile.FullPath, out tokenColl)) { tokenColl = new TokenCollection(tokenFile.FullPath); tokenColl.Load(); } foreach (Token t in tokenColl) { tokenFileEntity.SubEntities.Add(new EntityReference { EntityType = EntityType.Token, Id = t.TokenName, Label = t.TokenName, ToolTip = t.TokenName, Tag = t }); } } tokenFileEntity = null; } catch (Exception ex) { if (tokenFileEntity == null) { tokens.Add(new EntityReference { EntityType = EntityType.File, Label = "Unable to load file '" + tokenFile.FullPath + "'. Reason: " + ex.Message, ToolTip = "Error" }); } else { tokens.Add(new EntityReference { EntityType = EntityType.File, Label = "Unable to load file: " + ex.Message, ToolTip = "Error" }); } } } if (tokens.Count != 0) { tokens[0].IsSelected = true; if (tokens[0].SubEntities.Count != 0) { tokens[0].IsExpanded = true; } } return(tokens); }
/// <summary> /// This loads the tree view with table of contents file entries from the project /// </summary> /// <remarks>Token information is also loaded here and passed on to the converter.</remarks> private void LoadTableOfContentsInfo() { FileItemCollection imageFiles, tokenFiles, contentLayoutFiles; List <ITableOfContents> tocFiles; TopicCollection contentLayout; TokenCollection tokens; tvContent.ItemsSource = null; tableOfContents = null; lblCurrentProject.Text = null; browserHistory.Clear(); historyLocation = -1; if (currentProject == null) { lblCurrentProject.Text = "None - Select a help file builder project in the Solution Explorer"; return; } // Make sure the base path is set for imported code blocks this.SetImportedCodeBasePath(); // Get content from open file editors var args = new FileContentNeededEventArgs(FileContentNeededEvent, this); base.RaiseEvent(args); currentProject.EnsureProjectIsCurrent(false); lblCurrentProject.Text = currentProject.Filename; browserHistory.Clear(); historyLocation = -1; tableOfContents = new TocEntryCollection(); try { converter.MediaFiles.Clear(); // Get the image files. This information is used to resolve media link elements in the // topic files. imageFiles = new FileItemCollection(currentProject, BuildAction.Image); foreach (FileItem file in imageFiles) { if (!String.IsNullOrEmpty(file.ImageId)) { converter.MediaFiles[file.ImageId] = new KeyValuePair <string, string>(file.FullPath, file.AlternateText); } } } catch (Exception ex) { tableOfContents.Add(new TocEntry(currentProject) { Title = "ERROR: Unable to load media info: " + ex.Message }); } try { converter.Tokens.Clear(); // Get the token files. This information is used to resolve token elements in the // topic files. tokenFiles = new FileItemCollection(currentProject, BuildAction.Tokens); foreach (FileItem file in tokenFiles) { // If open in an editor, use the edited values if (!args.TokenFiles.TryGetValue(file.FullPath, out tokens)) { tokens = new TokenCollection(file.FullPath); tokens.Load(); } // Store the tokens as XElements so that they can be parsed inline with the topic foreach (var t in tokens) { converter.Tokens.Add(t.TokenName, XElement.Parse("<token>" + t.TokenValue + "</token>")); } } } catch (Exception ex) { tableOfContents.Add(new TocEntry(currentProject) { Title = "ERROR: Unable to load token info: " + ex.Message }); } try { converter.TopicTitles.Clear(); // Get the content layout files. Site maps are ignored. We don't support rendering them. contentLayoutFiles = new FileItemCollection(currentProject, BuildAction.ContentLayout); tocFiles = new List <ITableOfContents>(); // Add the conceptual content layout files foreach (FileItem file in contentLayoutFiles) { // If open in an editor, use the edited values if (!args.ContentLayoutFiles.TryGetValue(file.FullPath, out contentLayout)) { contentLayout = new TopicCollection(file); contentLayout.Load(); } tocFiles.Add(contentLayout); } // Sort the files tocFiles.Sort((x, y) => { FileItem fx = x.ContentLayoutFile, fy = y.ContentLayoutFile; if (fx.SortOrder < fy.SortOrder) { return(-1); } if (fx.SortOrder > fy.SortOrder) { return(1); } return(String.Compare(fx.Name, fy.Name, StringComparison.OrdinalIgnoreCase)); }); // Create the merged TOC. For the purpose of adding links, we'll include everything // even topics marked as invisible. foreach (ITableOfContents file in tocFiles) { file.GenerateTableOfContents(tableOfContents, currentProject, true); } // Pass the topic IDs and titles on to the converter for use in hyperlinks foreach (var t in tableOfContents.All()) { if (!String.IsNullOrEmpty(t.Id)) { converter.TopicTitles[t.Id] = t.LinkText; } } } catch (Exception ex) { tableOfContents.Add(new TocEntry(currentProject) { Title = "ERROR: Unable to load TOC info: " + ex.Message }); } if (tableOfContents.Count != 0) { foreach (var t in tableOfContents.All()) { t.IsSelected = false; } tableOfContents[0].IsSelected = true; } tvContent.ItemsSource = tableOfContents; }
//===================================================================== /// <summary> /// This is used to get information from token and content layout files open in editors so that current /// information is displayed for them in the topic previewer control. /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void ucTopicPreviewer_FileContentNeeded(object sender, FileContentNeededEventArgs e) { IVsUIShell uiShell = Utility.GetServiceFromPackage<IVsUIShell, SVsUIShell>(true); IEnumWindowFrames enumFrames; IVsWindowFrame[] frames = new IVsWindowFrame[1]; object docView; uint frameCount; ContentLayoutEditorPane contentLayoutPane; TokenEditorPane tokenFilePane; if(uiShell.GetDocumentWindowEnum(out enumFrames) == VSConstants.S_OK) while(enumFrames.Next(1, frames, out frameCount) == VSConstants.S_OK && frameCount == 1) if(frames[0].GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView) == VSConstants.S_OK) { contentLayoutPane = docView as ContentLayoutEditorPane; if(contentLayoutPane != null) e.ContentLayoutFiles.Add(contentLayoutPane.Filename, contentLayoutPane.Topics); else { tokenFilePane = docView as TokenEditorPane; if(tokenFilePane != null) e.TokenFiles.Add(tokenFilePane.Filename, tokenFilePane.Tokens); } } }
//===================================================================== /// <summary> /// This is used to get information from token and content layoutfiles open in editors /// so that current information is displayed for them in the topic previewer control. /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> /// <remarks>Site maps are ignored as they aren't supported by the topic previewer</remarks> private void ucTopicPreviewer_FileContentNeeded(object sender, FileContentNeededEventArgs e) { ContentLayoutWindow contentLayoutWindow; TokenEditorWindow tokenEditorWindow; foreach(IDockContent content in this.DockPanel.Documents) { contentLayoutWindow = content as ContentLayoutWindow; if(contentLayoutWindow != null) e.ContentLayoutFiles.Add(contentLayoutWindow.Filename, contentLayoutWindow.Topics); else { tokenEditorWindow = content as TokenEditorWindow; if(tokenEditorWindow != null) e.TokenFiles.Add(tokenEditorWindow.Filename, tokenEditorWindow.Tokens); } } }