2 using System.Collections;
5 using HtmlHelp.ChmDecoding;
10 /// The class <c>Category</c> implements methods/properties for handling an information category
12 /// <remarks>Note: Information types and categories allow users to filter help contents.
13 /// They are only supported if using sitemap TOC and/or sitemap Index.</remarks>
16 private string _name = "";
17 private string _description = "";
18 private ArrayList _infoTypes = null;
19 private int _referenceCount = 1;
22 /// Standard constructor
24 public Category() : this("","")
29 /// Standard constructor
31 /// <param name="name">name of the category</param>
32 /// <param name="description">description</param>
33 public Category(string name, string description) : this(name, description, new ArrayList())
37 /// Standard constructor
39 /// <param name="name">name of the category</param>
40 /// <param name="description">description</param>
41 /// <param name="linkedInformationTypes">Arraylist of InformationType instances which applies to this category</param>
42 public Category(string name, string description, ArrayList linkedInformationTypes)
45 _description = description;
46 _infoTypes = linkedInformationTypes;
51 /// Dump the class data to a binary writer
53 /// <param name="writer">writer to write the data</param>
54 internal void Dump(ref BinaryWriter writer)
56 writer.Write( _name );
57 writer.Write( _description );
59 writer.Write( _infoTypes.Count );
61 for(int i=0; i<_infoTypes.Count;i++)
63 InformationType curType = _infoTypes[i] as InformationType;
64 writer.Write( curType.Name );
70 /// Reads the object data from a dump store
72 /// <param name="reader">reader to read the data</param>
73 /// <param name="chmFile">current CHMFile instance which reads from dump</param>
74 internal void ReadDump(ref BinaryReader reader, CHMFile chmFile)
76 _name = reader.ReadString();
77 _description = reader.ReadString();
79 int nCnt = reader.ReadInt32();
81 for(int i=0; i<nCnt; i++)
83 string sITName = reader.ReadString();
85 InformationType linkedType = chmFile.GetInformationType( sITName );
87 if(linkedType != null)
89 linkedType.SetCategoryFlag(true);
90 _infoTypes.Add(linkedType);
97 /// Merges the lineked information types from cat into this instance
99 /// <param name="cat">category instance</param>
100 internal void MergeInfoTypes(Category cat)
104 if(cat.InformationTypes.Count > 0)
106 for(int i=0;i<cat.InformationTypes.Count;i++)
108 InformationType curType = cat.InformationTypes[i] as InformationType;
110 if(!ContainsInformationType(curType.Name))
112 curType.SetCategoryFlag(true);
113 _infoTypes.Add(curType);
121 /// Gets/Sets the reference count of this information type instance
123 internal int ReferenceCount
125 get { return _referenceCount; }
126 set { _referenceCount = value; }
130 /// Gets/Sets the name of the information type
134 get { return _name; }
135 set { _name = value; }
139 /// Gets/Sets the description of the information type
141 public string Description
143 get { return _description; }
144 set { _name = value; }
148 /// Gets an ArrayList with the linked Information types
150 public ArrayList InformationTypes
152 get { return _infoTypes; }
156 /// Adds a new information type to the category
158 /// <param name="type"></param>
159 public void AddInformationType(InformationType type)
161 _infoTypes.Add(type);
165 /// Removes an information type from the category
167 /// <param name="type"></param>
168 public void RemoveInformationType(InformationType type)
170 _infoTypes.Remove(type);
174 /// Checks if the category contains an information type
176 /// <param name="type">information type instance to check</param>
177 /// <returns>Return true if the information type is part of this category</returns>
178 public bool ContainsInformationType(InformationType type)
180 return _infoTypes.Contains(type);
184 /// Checks if the category contains an information type
186 /// <param name="name">name of the information type</param>
187 /// <returns>Return true if the information type is part of this category</returns>
188 public bool ContainsInformationType(string name)
190 for(int i=0;i<_infoTypes.Count;i++)
192 InformationType curType = _infoTypes[i] as InformationType;
194 if(curType.Name == name)