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