//===================================================================== /// <summary> /// This loads the tree view with image file entries from the project /// </summary> private void LoadImageInfo() { TreeNode node; tvEntities.ImageList = ilImages; tvEntities.Nodes.Clear(); if (images == null) { images = new ImageReferenceCollection(currentProject); } foreach (ImageReference ir in images) { if (!String.IsNullOrEmpty(ir.Id)) { node = tvEntities.Nodes.Add(ir.DisplayTitle); node.Name = ir.Id; node.Tag = ir; node.ImageIndex = node.SelectedImageIndex = (int)EntityType.Images; } } txtFindName.Enabled = true; tvEntities.Enabled = true; }
private void menuItemOpenImage_Click(object sender, EventArgs e) { openFileDialog1.Filter = Resources.ImageFormatFilter; openFileDialog1.FileName = ""; if (openFileDialog1.ShowDialog(this) == DialogResult.OK) { LoadNewImageFile(openFileDialog1.FileName); if (pictureBox1.Image != null) { addBookmarkToolStripMenuItem.Enabled = true; } if (_imageReferenceCollection != null) { return; } _imageReferenceCollection = new ImageReferenceCollection(new List <int>(), _imageLoaderService); var currentImage = _imageReferenceCollection.SetCurrentImage(openFileDialog1.FileName); _dataReady = true; if (_imageLoaderService.ImageReferenceList == null) { _imageLoaderService.CreateFromOpenSingleImage(currentImage); } } }
private void SetImageReferenceCollection() { bool randomizeImageCollection = _applicationSettingsService.Settings.AutoRandomizeCollection; if (!_imageLoaderService.IsRunningImport && _imageLoaderService.ImageReferenceList != null) { _imageReferenceCollection = _imageLoaderService.GenerateImageReferenceCollection(randomizeImageCollection); _dataReady = true; } }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="project">The project from which to load the settings</param> public ConceptualContentSettings(SandcastleProject project) { imageFiles = new ImageReferenceCollection(project); codeSnippetFiles = new FileItemCollection(project, BuildAction.CodeSnippets); tokenFiles = new FileItemCollection(project, BuildAction.Tokens); contentLayoutFiles = new FileItemCollection(project, BuildAction.ContentLayout); topics = new Collection<TopicCollection>(); foreach(FileItem file in contentLayoutFiles) topics.Add(new TopicCollection(file)); }
public void SetImages(ImageReferenceCollection collection) { if (cic == collection) return; if (cic != null) cic.CollectionChanged -= ComicImageCollection_CollectionChanged; cic = collection; if (cic != null) { cic.CollectionChanged += ComicImageCollection_CollectionChanged; ComicImageCollection_CollectionChanged(cic, new System.Collections.Specialized.NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction.Reset)); } }
public void SetImages(ImageReferenceCollection images) { if (_images != images) { if (_images != null) _images.CollectionChanged -= Images_CollectionChanged; _images = images; if (images != null) { images.CollectionChanged += Images_CollectionChanged; Images_CollectionChanged(images, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } } }
public void SetImages(ImageReferenceCollection images) { if (_images != images) { if (_images != null) { _images.CollectionChanged -= Images_CollectionChanged; } _images = images; if (images != null) { images.CollectionChanged += Images_CollectionChanged; Images_CollectionChanged(images, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } } }
public void SetImages(ImageReferenceCollection collection) { if (cic == collection) { return; } if (cic != null) { cic.CollectionChanged -= ComicImageCollection_CollectionChanged; } cic = collection; if (cic != null) { cic.CollectionChanged += ComicImageCollection_CollectionChanged; ComicImageCollection_CollectionChanged(cic, new System.Collections.Specialized.NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction.Reset)); } }
public void SetImages(ImageReferenceCollection value) { if (_images == value) return; if (_images != null) { _images.CollectionChanged -= Images_CollectionChanged; _images.CollectionItemPropertyChanged -= Images_CollectionItemPropertyChanged; } _images = value; if (value != null) { value.CollectionChanged += Images_CollectionChanged; value.CollectionItemPropertyChanged += Images_CollectionItemPropertyChanged; Images_CollectionChanged(value, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } }
public void SetImages(ImageReferenceCollection value) { if (_images == value) { return; } if (_images != null) { _images.CollectionChanged -= Images_CollectionChanged; _images.CollectionItemPropertyChanged -= Images_CollectionItemPropertyChanged; } _images = value; if (value != null) { value.CollectionChanged += Images_CollectionChanged; value.CollectionItemPropertyChanged += Images_CollectionItemPropertyChanged; Images_CollectionChanged(value, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } }
//===================================================================== /// <summary> /// This loads the tree view with image file entries from the project /// </summary> private List <EntityReference> LoadImageInfo() { ImageReferenceCollection imagesRefs; if (images != null) { return(images); } images = new List <EntityReference>(); currentProject.EnsureProjectIsCurrent(false); imagesRefs = new ImageReferenceCollection(currentProject); foreach (ImageReference ir in imagesRefs) { if (!String.IsNullOrEmpty(ir.Id)) { images.Add(new EntityReference { EntityType = EntityType.Image, Id = ir.Id, Label = ir.DisplayTitle, ToolTip = String.Format(CultureInfo.CurrentCulture, "ID: {0}\nFile: {1}", ir.Id, ir.FullPath), Tag = ir }); } } if (images.Count != 0) { images[0].IsSelected = true; } return(images); }
/// <summary> /// Refresh the currently displayed entity information /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void tsbRefresh_Click(object sender, EventArgs e) { switch ((EntityType)cboContentType.SelectedIndex) { case EntityType.Tokens: tokenFiles = null; break; case EntityType.Images: images = null; break; case EntityType.CodeSnippets: codeSnippetFiles = null; break; default: codeEntities = null; break; } tvEntities.Nodes.Clear(); this.cboContentType_SelectedIndexChanged(sender, e); }
protected virtual void Dispose(bool disposing) { if (disposing) { using (EnterUndirtiableSection()) { if (_images != null) { _images.Clear(); _images.Dispose(); _images = null; } if (_bookmarks != null) { _bookmarks.Clear(); _bookmarks.Dispose(); _bookmarks = null; } Thumbnail = null; Title = Author = string.Empty; IsDirty = false; } } }
//===================================================================== /// <summary> /// This loads the tree view with image file entries from the project /// </summary> private void LoadImageInfo() { TreeNode node; tvEntities.ImageList = ilImages; tvEntities.Nodes.Clear(); if(images == null) images = new ImageReferenceCollection(currentProject); foreach(ImageReference ir in images) if(!String.IsNullOrEmpty(ir.Id)) { node = tvEntities.Nodes.Add(ir.DisplayTitle); node.Name = ir.Id; node.Tag = ir; node.ImageIndex = node.SelectedImageIndex = (int)EntityType.Images; } txtFindName.Enabled = true; tvEntities.Enabled = true; }
//===================================================================== /// <summary> /// This loads the tree view with image file entries from the project /// </summary> private List<EntityReference> LoadImageInfo() { ImageReferenceCollection imagesRefs; if(images != null) return images; images = new List<EntityReference>(); currentProject.EnsureProjectIsCurrent(false); imagesRefs = new ImageReferenceCollection(currentProject); foreach(ImageReference ir in imagesRefs) if(!String.IsNullOrEmpty(ir.Id)) images.Add(new EntityReference { EntityType = EntityType.Image, Id = ir.Id, Label = ir.DisplayTitle, ToolTip = String.Format(CultureInfo.CurrentCulture, "ID: {0}\nFile: {1}", ir.Id, ir.FullPath), Tag = ir }); if(images.Count != 0) images[0].IsSelected = true; return images; }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="source">The source path containing the HTML files</param> /// <param name="dest">The destination path for the MAML topics and /// supporting files</param> /// <param name="createCompanion">True to create companion files for /// all topic files or false to not create them.</param> /// <param name="moveIntroText">If true, move text before the first section into an introduction element. /// If false, insert a place holder introduction element.</param> public HtmlToMaml(string source, string dest, bool createCompanion, bool moveIntroText) { XPathDocument rulesFile; XPathNavigator navRules; StringBuilder sb; string name; sourcePath = source; destPath = dest; createCompanionFile = createCompanion; replaceIntro = moveIntroText; pathProvider = this; if(sourcePath.EndsWith("\\", StringComparison.Ordinal)) sourcePath = sourcePath.Substring(0, sourcePath.Length - 1); if(destPath.EndsWith("\\", StringComparison.Ordinal)) destPath = destPath.Substring(0, destPath.Length - 1); sourcePath = Path.GetFullPath(sourcePath); destPath = Path.GetFullPath(destPath); topics = new TopicCollection(); images = new ImageReferenceCollection(); topicDictionary = new Dictionary<FilePath, Topic>(); imageDictionary = new Dictionary<FilePath, ImageReference>(); conversionRules = new Dictionary<string, TagOptions>(); markupSections = new List<string>(); entities = new Dictionary<string, string>(); tokens = new Dictionary<string, string>(); // Load the conversion rules rulesFile = new XPathDocument(Path.Combine(Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location), "ConversionRules.xml")); navRules = rulesFile.CreateNavigator(); XPathNavigator bodyExpr = navRules.SelectSingleNode("//BodyExtract"); if(bodyExpr != null) FileParser.BodyExtractExpression = bodyExpr.GetAttribute( "expression", string.Empty); // Add the tags we will handle internally conversionRules.Add("a", null); conversionRules.Add("code", null); conversionRules.Add("h1", null); conversionRules.Add("h2", null); conversionRules.Add("h3", null); conversionRules.Add("h4", null); conversionRules.Add("h5", null); conversionRules.Add("h6", null); conversionRules.Add("img", null); conversionRules.Add("see", null); // Get the rules to process sb = new StringBuilder(); foreach(XPathNavigator nav in navRules.Select("//Entities/Entity")) entities.Add(nav.GetAttribute("name", String.Empty), nav.GetAttribute("value", String.Empty)); foreach(XPathNavigator nav in navRules.Select("//MarkupWrapper/Tag")) { if(sb.Length != 0) sb.Append("|"); name = nav.GetAttribute("name", String.Empty).ToLower( CultureInfo.InvariantCulture); conversionRules.Add(name, null); sb.Append(name); } name = sb.ToString(); sb.Insert(0, @"<\s*("); sb.Append(@")[^>]*?>.*?<\s*/\s*(\1)[^>]*?>|<\s*("); sb.Append(name); sb.Append(@")\s*?((\s|/)[^>]*?)?>"); reMarkupWrapper = new Regex(sb.ToString(), RegexOptions.IgnoreCase | RegexOptions.Singleline); reReplaceMarker= new Regex("\xFF"); matchMarkupWrapper = new MatchEvaluator(OnMatchMarkupWrapper); matchMarker = new MatchEvaluator(OnMatchMarker); sb.Remove(0, sb.Length); foreach(XPathNavigator nav in navRules.Select("//Remove/Tag")) { if(sb.Length != 0) sb.Append("|"); name = nav.GetAttribute("name", String.Empty).ToLower( CultureInfo.InvariantCulture); conversionRules.Add(name, null); sb.Append(name); } sb.Insert(0, @"<\s*/?\s*("); sb.Append(@")\s*?((\s|/)[^>]*?)?>"); reRemoveTag = new Regex(sb.ToString(), RegexOptions.IgnoreCase | RegexOptions.Singleline); sb.Remove(0, sb.Length); foreach(XPathNavigator nav in navRules.Select("//Replace/Tag")) { if(sb.Length != 0) sb.Append("|"); name = nav.GetAttribute("name", String.Empty).ToLower( CultureInfo.InvariantCulture); conversionRules.Add(name, new TagOptions(nav)); sb.Append(name); } sb.Insert(0, @"<\s*(?<Closing>/?)\s*(?<Tag>"); sb.Append(@")\s*(?<Attributes>(\s|/)[^>]*?)?>"); reReplaceTag = new Regex(sb.ToString(), RegexOptions.IgnoreCase | RegexOptions.Singleline); matchReplace = new MatchEvaluator(OnMatchReplace); matchCode = new MatchEvaluator(OnMatchCode); matchSee = new MatchEvaluator(OnMatchSee); matchAnchor = new MatchEvaluator(OnMatchAnchor); matchImage = new MatchEvaluator(OnMatchImage); matchHeading = new MatchEvaluator(OnMatchHeading); matchIntroduction = new MatchEvaluator(OnMatchIntroduction); matchEntity = new MatchEvaluator(OnMatchEntity); matchToken = new MatchEvaluator(OnMatchToken); }
/// <summary> /// This method can be used by plug-ins to merge content from another Sandcastle Help File Builder /// project file. /// </summary> /// <param name="project">The project file from which to merge content</param> /// <remarks>Auto-generated content can be added to a temporary SHFB project and then added to the /// current project's content at build time using this method. Such content cannot always be added to /// the project being built as it may alter the underlying MSBuild project which is not wanted.</remarks> public void MergeContentFrom(SandcastleProject project) { var otherImageFiles = new ImageReferenceCollection(project); var otherCodeSnippetFiles = new FileItemCollection(project, BuildAction.CodeSnippets); var otherTokenFiles = new FileItemCollection(project, BuildAction.Tokens); var otherContentLayoutFiles = new FileItemCollection(project, BuildAction.ContentLayout); foreach(var image in otherImageFiles) imageFiles.Add(image); foreach(var snippets in otherCodeSnippetFiles) codeSnippetFiles.Add(snippets); foreach(var tokens in otherTokenFiles) tokenFiles.Add(tokens); foreach(FileItem file in otherContentLayoutFiles) topics.Add(new TopicCollection(file)); }
/// <summary> /// Refresh the currently displayed entity information /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void tsbRefresh_Click(object sender, EventArgs e) { switch((EntityType)cboContentType.SelectedIndex) { case EntityType.Tokens: tokenFiles = null; break; case EntityType.Images: images = null; break; case EntityType.CodeSnippets: codeSnippetFiles = null; break; default: codeEntities = null; break; } tvEntities.Nodes.Clear(); this.cboContentType_SelectedIndexChanged(sender, e); }
/// <summary> /// Import image file information from a media content file. /// </summary> /// <param name="filename">The media content filename</param> private void ImportMediaFile(string filename) { List<string> filesSeen = new List<string>(); ImageReferenceCollection images; XPathDocument media; XPathNavigator navMedia, file, altText; FileItem fileItem; string guid, id, path, newName; int uniqueId; images = new ImageReferenceCollection(base.Project); media = new XPathDocument(filename); navMedia = media.CreateNavigator(); foreach(XPathNavigator item in navMedia.Select("//item")) { guid = null; file = altText = null; id = item.GetAttribute("id", String.Empty); file = item.SelectSingleNode("image/@file"); altText = item.SelectSingleNode("image/altText"); if(!String.IsNullOrEmpty(id)) guid = id.Trim(); if(!String.IsNullOrEmpty(guid) && images.FindId(guid) == null && file != null && !String.IsNullOrEmpty(file.Value)) { path = newName = file.Value; // If relative, get the full path. If no path, assume // Help\Art as the default. if(String.IsNullOrEmpty(Path.GetDirectoryName(path))) { path = Path.Combine(@"Help\Art", path); newName = path.Substring(5); } if(Path.IsPathRooted(path)) newName = Path.GetFileName(path); else path = Path.GetFullPath(Path.Combine(base.OldFolder, path)); // It's possible that two entries share the same file // so we'll need to create a new copy as in SHFB, the // settings are managed via the project explorer and each // file is unique. uniqueId = 1; while(filesSeen.Contains(newName)) { newName = Path.Combine(Path.GetDirectoryName(newName), Path.GetFileNameWithoutExtension(newName) + uniqueId.ToString(CultureInfo.InvariantCulture) + Path.GetExtension(newName)); uniqueId++; } filesSeen.Add(newName); fileItem = project.AddFileToProject(path, Path.Combine(base.ProjectFolder, newName)); fileItem.BuildAction = BuildAction.Image; fileItem.ImageId = guid; if(altText != null) fileItem.AlternateText = altText.Value; } } }
/// <summary> /// Import image file information from an existing MAML media content /// file. /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void miImportMediaFile_Click(object sender, EventArgs e) { List<string> filesSeen = new List<string>(); ImageReferenceCollection images; XPathDocument media; XPathNavigator navMedia, file, altText; FileItem fileItem; TreeNode parent = tvProjectFiles.SelectedNode; NodeData nodeData; string guid, id, path, destPath, newName; int uniqueId; using(OpenFileDialog dlg = new OpenFileDialog()) { dlg.Title = "Select the MAML media content file"; dlg.Filter = "MAML media content files (*.xml)|*.xml|" + "All Files (*.*)|*.*"; dlg.InitialDirectory = Directory.GetCurrentDirectory(); dlg.DefaultExt = "xml"; // If selected, add the new images from the media file. Images // with an ID that is already in the collection are ignored. if(dlg.ShowDialog() == DialogResult.OK) { if(parent == null || parent == tvProjectFiles.Nodes[0]) destPath = Path.GetDirectoryName(currentProject.Filename); else { nodeData = (NodeData)parent.Tag; if(nodeData.BuildAction == BuildAction.DocumentationSource || nodeData.BuildAction == BuildAction.ReferenceItem) destPath = Path.GetDirectoryName(currentProject.Filename); else if(nodeData.BuildAction == BuildAction.Folder) destPath = ((FileItem)nodeData.Item).Include; else destPath = Path.GetDirectoryName( ((FileItem)nodeData.Item).Include); } try { Cursor.Current = Cursors.WaitCursor; images = new ImageReferenceCollection(currentProject); media = new XPathDocument(dlg.FileName); navMedia = media.CreateNavigator(); foreach(XPathNavigator item in navMedia.Select("//item")) { guid = null; file = altText = null; id = item.GetAttribute("id", String.Empty); file = item.SelectSingleNode("image/@file"); altText = item.SelectSingleNode("image/altText"); if(!String.IsNullOrEmpty(id)) guid = id.Trim(); if(!String.IsNullOrEmpty(guid) && images.FindId(guid) == null && file != null && !String.IsNullOrEmpty(file.Value)) { path = newName = file.Value; // If relative, get the full path if(!Path.IsPathRooted(path)) path = Path.GetFullPath(Path.Combine( Path.GetDirectoryName(dlg.FileName), path)); // It's possible that two entries share the // same file so we'll need to create a new copy // as in SHFB, the settings are managed via the // project explorer and each file is unique. uniqueId = 1; while(filesSeen.Contains(newName)) { newName = Path.Combine(Path.GetDirectoryName(newName), Path.GetFileNameWithoutExtension(newName) + uniqueId.ToString(CultureInfo.InvariantCulture) + Path.GetExtension(newName)); uniqueId++; } filesSeen.Add(newName); fileItem = currentProject.AddFileToProject(path, Path.Combine(destPath, Path.GetFileName(newName))); fileItem.BuildAction = BuildAction.Image; fileItem.ImageId = guid; if(altText != null) fileItem.AlternateText = altText.Value; } } // If existing items were found, we will have changed // their build action to Image so reload the tree to // ensure that the change is reflected there. this.LoadProject(); } finally { Cursor.Current = Cursors.Default; } } } }
/// <summary> /// Import image file information from a media content file. /// </summary> /// <param name="filename">The media content filename</param> private void ImportMediaFile(string filename) { List <string> filesSeen = new List <string>(); ImageReferenceCollection images; XPathDocument media; XPathNavigator navMedia, file, altText; FileItem fileItem; string guid, id, path, newName; int uniqueId; images = new ImageReferenceCollection(base.Project); media = new XPathDocument(filename); navMedia = media.CreateNavigator(); foreach (XPathNavigator item in navMedia.Select("//item")) { guid = null; file = altText = null; id = item.GetAttribute("id", String.Empty); file = item.SelectSingleNode("image/@file"); altText = item.SelectSingleNode("image/altText"); if (!String.IsNullOrEmpty(id)) { guid = id.Trim(); } if (!String.IsNullOrEmpty(guid) && images.FindId(guid) == null && file != null && !String.IsNullOrEmpty(file.Value)) { path = newName = file.Value; // If relative, get the full path. If no path, assume Help\Art as the default if (String.IsNullOrEmpty(Path.GetDirectoryName(path))) { path = Path.Combine(@"Help\Art", path); newName = path.Substring(5); } if (Path.IsPathRooted(path)) { newName = Path.GetFileName(path); } else { path = Path.GetFullPath(Path.Combine(base.OldFolder, path)); } // It's possible that two entries share the same file so we'll need to create a new copy as // in SHFB, the settings are managed via the project explorer and each file is unique. uniqueId = 1; while (filesSeen.Contains(newName)) { newName = Path.Combine(Path.GetDirectoryName(newName), Path.GetFileNameWithoutExtension(newName) + uniqueId.ToString(CultureInfo.InvariantCulture) + Path.GetExtension(newName)); uniqueId++; } filesSeen.Add(newName); fileItem = project.AddFileToProject(path, Path.Combine(base.ProjectFolder, newName)); fileItem.BuildAction = BuildAction.Image; fileItem.ImageId = guid; if (altText != null) { fileItem.AlternateText = altText.Value; } } } }