//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="project">The project from which to load the settings</param> public ConceptualContentSettings(SandcastleProject project) { imageFiles = project.ImagesReferences.ToList(); codeSnippetFiles = project.ContentFiles(BuildAction.CodeSnippets).OrderBy(f => f.LinkPath).ToList(); tokenFiles = project.ContentFiles(BuildAction.Tokens).OrderBy(f => f.LinkPath).ToList(); contentLayoutFiles = project.ContentFiles(BuildAction.ContentLayout).ToList(); topics = project.ContentFiles(BuildAction.ContentLayout).Select(file => new TopicCollection(file)).ToList(); }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="project">The project from which to load the settings</param> public ConceptualContentSettings(SandcastleProject project) { if (project == null) { throw new ArgumentNullException(nameof(project)); } this.ImageFiles = project.ImagesReferences.ToList(); this.CodeSnippetFiles = project.ContentFiles(BuildAction.CodeSnippets).OrderBy(f => f.LinkPath).ToList(); this.TokenFiles = project.ContentFiles(BuildAction.Tokens).OrderBy(f => f.LinkPath).ToList(); this.ContentLayoutFiles = project.ContentFiles(BuildAction.ContentLayout).ToList(); this.Topics = project.ContentFiles(BuildAction.ContentLayout).Select(file => new TopicCollection(file)).ToList(); }
//===================================================================== /// <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() { 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; }