[devmgr]
[reactos.git] / irc / TechBot / CHMLibrary / Category.cs
1 using System;
2 using System.Collections;
3 using System.IO;
4
5 using HtmlHelp.ChmDecoding;
6
7 namespace HtmlHelp
8 {
9 /// <summary>
10 /// The class <c>Category</c> implements methods/properties for handling an information category
11 /// </summary>
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>
14 public class Category
15 {
16 private string _name = "";
17 private string _description = "";
18 private ArrayList _infoTypes = null;
19 private int _referenceCount = 1;
20
21 /// <summary>
22 /// Standard constructor
23 /// </summary>
24 public Category() : this("","")
25 {
26 }
27
28 /// <summary>
29 /// Standard constructor
30 /// </summary>
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())
34 {
35 }
36 /// <summary>
37 /// Standard constructor
38 /// </summary>
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)
43 {
44 _name = name;
45 _description = description;
46 _infoTypes = linkedInformationTypes;
47 }
48
49 #region Data dumping
50 /// <summary>
51 /// Dump the class data to a binary writer
52 /// </summary>
53 /// <param name="writer">writer to write the data</param>
54 internal void Dump(ref BinaryWriter writer)
55 {
56 writer.Write( _name );
57 writer.Write( _description );
58
59 writer.Write( _infoTypes.Count );
60
61 for(int i=0; i<_infoTypes.Count;i++)
62 {
63 InformationType curType = _infoTypes[i] as InformationType;
64 writer.Write( curType.Name );
65 }
66
67 }
68
69 /// <summary>
70 /// Reads the object data from a dump store
71 /// </summary>
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)
75 {
76 _name = reader.ReadString();
77 _description = reader.ReadString();
78
79 int nCnt = reader.ReadInt32();
80
81 for(int i=0; i<nCnt; i++)
82 {
83 string sITName = reader.ReadString();
84
85 InformationType linkedType = chmFile.GetInformationType( sITName );
86
87 if(linkedType != null)
88 {
89 linkedType.SetCategoryFlag(true);
90 _infoTypes.Add(linkedType);
91 }
92 }
93 }
94 #endregion
95
96 /// <summary>
97 /// Merges the lineked information types from cat into this instance
98 /// </summary>
99 /// <param name="cat">category instance</param>
100 internal void MergeInfoTypes(Category cat)
101 {
102 if(cat!=null)
103 {
104 if(cat.InformationTypes.Count > 0)
105 {
106 for(int i=0;i<cat.InformationTypes.Count;i++)
107 {
108 InformationType curType = cat.InformationTypes[i] as InformationType;
109
110 if(!ContainsInformationType(curType.Name))
111 {
112 curType.SetCategoryFlag(true);
113 _infoTypes.Add(curType);
114 }
115 }
116 }
117 }
118 }
119
120 /// <summary>
121 /// Gets/Sets the reference count of this information type instance
122 /// </summary>
123 internal int ReferenceCount
124 {
125 get { return _referenceCount; }
126 set { _referenceCount = value; }
127 }
128
129 /// <summary>
130 /// Gets/Sets the name of the information type
131 /// </summary>
132 public string Name
133 {
134 get { return _name; }
135 set { _name = value; }
136 }
137
138 /// <summary>
139 /// Gets/Sets the description of the information type
140 /// </summary>
141 public string Description
142 {
143 get { return _description; }
144 set { _name = value; }
145 }
146
147 /// <summary>
148 /// Gets an ArrayList with the linked Information types
149 /// </summary>
150 public ArrayList InformationTypes
151 {
152 get { return _infoTypes; }
153 }
154
155 /// <summary>
156 /// Adds a new information type to the category
157 /// </summary>
158 /// <param name="type"></param>
159 public void AddInformationType(InformationType type)
160 {
161 _infoTypes.Add(type);
162 }
163
164 /// <summary>
165 /// Removes an information type from the category
166 /// </summary>
167 /// <param name="type"></param>
168 public void RemoveInformationType(InformationType type)
169 {
170 _infoTypes.Remove(type);
171 }
172
173 /// <summary>
174 /// Checks if the category contains an information type
175 /// </summary>
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)
179 {
180 return _infoTypes.Contains(type);
181 }
182
183 /// <summary>
184 /// Checks if the category contains an information type
185 /// </summary>
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)
189 {
190 for(int i=0;i<_infoTypes.Count;i++)
191 {
192 InformationType curType = _infoTypes[i] as InformationType;
193
194 if(curType.Name == name)
195 return true;
196 }
197
198 return false;
199 }
200 }
201 }