4 using System.Collections;
6 using HtmlHelp.ChmDecoding;
11 /// The class <c>IndexItem</c> implements an help-index item
13 public sealed class IndexItem : IComparable
16 /// Internal member storing the keyword
18 private string _keyWord = "";
20 /// Internal member storing all associated information type strings
22 private ArrayList _infoTypeStrings = new ArrayList();
24 /// Internal member storing the flag if this is a see-also keyword
26 private bool _isSeeAlso = false;
28 /// Internal member storing the indent of the keyword
30 private int _indent = 0;
32 /// Internal member storing the last index of the keyword in the seperated list
34 private int _charIndex = 0;
36 /// Internal member storing the entry index
38 private int _entryIndex = 0;
40 /// Internal member storing an array of see-also values
42 private string[] _seeAlso = new string[0];
44 /// Internal member storing an array of topic offsets
46 private int[] _nTopics = new int[0];
48 /// Internal member storing the topics
50 private ArrayList _Topics = null;
52 /// Associated CHMFile instance
54 private CHMFile _chmFile = null;
56 /// Internal flag specifying the chm file path
58 private string _chmFileName = "";
61 /// Constructor of the class
63 /// <param name="chmFile">associated CHMFile instance</param>
64 /// <param name="keyWord">keyword</param>
65 /// <param name="isSeeAlso">true if it is a see-also keyword</param>
66 /// <param name="indent">indent of the entry</param>
67 /// <param name="charIndex">char index of the last keyword in the separated list</param>
68 /// <param name="entryIndex">index of the entry</param>
69 /// <param name="seeAlsoValues">string array with see-also values</param>
70 /// <param name="topicOffsets">integer array with topic offsets</param>
71 internal IndexItem(CHMFile chmFile, string keyWord, bool isSeeAlso, int indent, int charIndex, int entryIndex, string[] seeAlsoValues, int[] topicOffsets)
74 _chmFileName = _chmFile.ChmFilePath;
76 _isSeeAlso = isSeeAlso;
78 _charIndex = charIndex;
79 _entryIndex = entryIndex;
80 _seeAlso = seeAlsoValues;
81 _nTopics = topicOffsets;
85 /// Standard constructor
93 /// Dump the class data to a binary writer
95 /// <param name="writer">writer to write the data</param>
96 /// <param name="writeFileName">true if the chm filename should be written</param>
97 internal void Dump(ref BinaryWriter writer, bool writeFileName)
101 writer.Write(_keyWord);
102 writer.Write(_isSeeAlso);
103 writer.Write(_indent);
106 writer.Write(_chmFileName);
108 writer.Write(_infoTypeStrings.Count);
110 for(i=0; i<_infoTypeStrings.Count; i++)
111 writer.Write( (_infoTypeStrings[i]).ToString() );
113 writer.Write(_seeAlso.Length);
115 for(i=0; i<_seeAlso.Length; i++)
117 if(_seeAlso[i] == null)
120 writer.Write( _seeAlso[i] );
123 writer.Write(Topics.Count);
125 for(i=0; i<Topics.Count; i++)
127 IndexTopic topic = ((IndexTopic)(Topics[i]));
128 topic.Dump(ref writer);
133 /// Dump the class data to a binary writer
135 /// <param name="writer">writer to write the data</param>
136 internal void Dump(ref BinaryWriter writer)
138 Dump(ref writer, false);
142 /// Reads the object data from a dump store
144 /// <param name="reader">reader to read the data</param>
145 /// <param name="filesList">filelist from helpsystem</param>
146 internal bool ReadDump(ref BinaryReader reader, ArrayList filesList)
149 _keyWord = reader.ReadString();
150 _isSeeAlso = reader.ReadBoolean();
151 _indent = reader.ReadInt32();
152 _chmFileName = reader.ReadString();
154 foreach(CHMFile curFile in filesList)
156 if(curFile.ChmFilePath == _chmFileName)
166 int nCnt = reader.ReadInt32();
168 for(i=0; i<nCnt; i++)
170 string sIT = reader.ReadString();
171 _infoTypeStrings.Add(sIT);
174 nCnt = reader.ReadInt32();
176 _seeAlso = new string[nCnt];
178 for(i=0; i<nCnt; i++)
180 _seeAlso[i] = reader.ReadString();
183 nCnt = reader.ReadInt32();
185 for(i=0; i<nCnt; i++)
187 IndexTopic topic = new IndexTopic("","","","");
188 topic.SetChmInfo( _chmFile.CompileFile, _chmFile.ChmFilePath);
189 topic.AssociatedFile = _chmFile;
190 topic.ReadDump(ref reader);
199 /// Reads the object data from a dump store
201 /// <param name="reader">reader to read the data</param>
202 internal void ReadDump(ref BinaryReader reader)
205 _keyWord = reader.ReadString();
206 _isSeeAlso = reader.ReadBoolean();
207 _indent = reader.ReadInt32();
209 int nCnt = reader.ReadInt32();
211 for(i=0; i<nCnt; i++)
213 string sIT = reader.ReadString();
214 _infoTypeStrings.Add(sIT);
217 nCnt = reader.ReadInt32();
219 _seeAlso = new string[nCnt];
221 for(i=0; i<nCnt; i++)
223 _seeAlso[i] = reader.ReadString();
226 nCnt = reader.ReadInt32();
228 for(i=0; i<nCnt; i++)
230 IndexTopic topic = new IndexTopic("","","","");
231 topic.AssociatedFile = _chmFile;
232 topic.SetChmInfo( _chmFile.CompileFile, _chmFile.ChmFilePath);
233 topic.ReadDump(ref reader);
240 /// Implements the compareto method which allows sorting.
242 /// <param name="obj">object to compare to</param>
243 /// <returns>See <see cref="System.IComparable">IComparable.CompareTo()</see></returns>
244 public int CompareTo(object obj)
246 if( obj.GetType() == this.GetType() )
248 IndexItem cmp = (IndexItem)obj;
250 return this.KeyWordPath.CompareTo( cmp.KeyWordPath );
257 /// Gets/Sets the associated CHMFile instance
259 internal CHMFile ChmFile
261 get { return _chmFile; }
262 set { _chmFile = value; }
266 /// Gets the ArrayList which holds all information types/categories this item is associated
268 internal ArrayList InfoTypeStrings
270 get { return _infoTypeStrings; }
274 /// Adds a see-also string to the index item and marks it as see also item
276 /// <param name="seeAlsoString">see also string to add</param>
277 internal void AddSeeAlso(string seeAlsoString)
279 string[] seeAlso = new string[ _seeAlso.Length +1 ];
280 for(int i=0; i<_seeAlso.Length; i++)
281 seeAlso[i] = _seeAlso[i];
283 seeAlso[_seeAlso.Length] = seeAlsoString;
289 /// Gets/Sets the full keyword-path of this item ( ", " separated list)
291 public string KeyWordPath
293 get { return _keyWord; }
294 set { _keyWord = value; }
298 /// Gets the keyword of this item
300 public string KeyWord
304 return _keyWord.Substring(_charIndex, _keyWord.Length-_charIndex);
309 /// Gets the keyword of this item with prefixing indent spaces
311 public string IndentKeyWord
315 string sKW = this.KeyWord;
316 StringBuilder sb = new StringBuilder("",this.Indent*3 + sKW.Length);
317 for(int i=0; i<this.Indent; i++)
320 return sb.ToString();
325 /// Gets/Sets the see-also flag of this item
327 public bool IsSeeAlso
329 get { return _isSeeAlso; }
330 set { _isSeeAlso = value; }
334 /// Gets/Sets the listbox indent for this item
338 get { return _indent; }
339 set { _indent = value; }
343 /// Gets/Sets the character index of an indent keyword
347 get { return _charIndex; }
348 set { _charIndex = value; }
352 /// Gets the see-also values of this item
354 public string[] SeeAlso
356 get { return _seeAlso; }
360 /// Gets an array with the associated topics
362 public ArrayList Topics
366 if( _Topics == null )
370 _Topics = new ArrayList();
374 if( (_chmFile != null) && (_chmFile.TopicsFile != null) )
376 _Topics = new ArrayList();
378 for(int i=0; i<_nTopics.Length; i++)
380 IndexTopic newTopic = IndexTopic.FromTopicEntry((TopicEntry)_chmFile.TopicsFile.TopicTable[ _nTopics[i] ]);
381 newTopic.AssociatedFile = _chmFile;
382 _Topics.Add( newTopic );
387 _Topics = new ArrayList();