using System; using System.Collections; using System.IO; using HtmlHelp.ChmDecoding; namespace HtmlHelp { /// /// The class Category implements methods/properties for handling an information category /// /// Note: Information types and categories allow users to filter help contents. /// They are only supported if using sitemap TOC and/or sitemap Index. public class Category { private string _name = ""; private string _description = ""; private ArrayList _infoTypes = null; private int _referenceCount = 1; /// /// Standard constructor /// public Category() : this("","") { } /// /// Standard constructor /// /// name of the category /// description public Category(string name, string description) : this(name, description, new ArrayList()) { } /// /// Standard constructor /// /// name of the category /// description /// Arraylist of InformationType instances which applies to this category public Category(string name, string description, ArrayList linkedInformationTypes) { _name = name; _description = description; _infoTypes = linkedInformationTypes; } #region Data dumping /// /// Dump the class data to a binary writer /// /// writer to write the data internal void Dump(ref BinaryWriter writer) { writer.Write( _name ); writer.Write( _description ); writer.Write( _infoTypes.Count ); for(int i=0; i<_infoTypes.Count;i++) { InformationType curType = _infoTypes[i] as InformationType; writer.Write( curType.Name ); } } /// /// Reads the object data from a dump store /// /// reader to read the data /// current CHMFile instance which reads from dump internal void ReadDump(ref BinaryReader reader, CHMFile chmFile) { _name = reader.ReadString(); _description = reader.ReadString(); int nCnt = reader.ReadInt32(); for(int i=0; i /// Merges the lineked information types from cat into this instance /// /// category instance internal void MergeInfoTypes(Category cat) { if(cat!=null) { if(cat.InformationTypes.Count > 0) { for(int i=0;i /// Gets/Sets the reference count of this information type instance /// internal int ReferenceCount { get { return _referenceCount; } set { _referenceCount = value; } } /// /// Gets/Sets the name of the information type /// public string Name { get { return _name; } set { _name = value; } } /// /// Gets/Sets the description of the information type /// public string Description { get { return _description; } set { _name = value; } } /// /// Gets an ArrayList with the linked Information types /// public ArrayList InformationTypes { get { return _infoTypes; } } /// /// Adds a new information type to the category /// /// public void AddInformationType(InformationType type) { _infoTypes.Add(type); } /// /// Removes an information type from the category /// /// public void RemoveInformationType(InformationType type) { _infoTypes.Remove(type); } /// /// Checks if the category contains an information type /// /// information type instance to check /// Return true if the information type is part of this category public bool ContainsInformationType(InformationType type) { return _infoTypes.Contains(type); } /// /// Checks if the category contains an information type /// /// name of the information type /// Return true if the information type is part of this category public bool ContainsInformationType(string name) { for(int i=0;i<_infoTypes.Count;i++) { InformationType curType = _infoTypes[i] as InformationType; if(curType.Name == name) return true; } return false; } } }