2 using System.Diagnostics;
3 using System.Collections;
4 using HtmlHelp.ChmDecoding;
9 /// The class <c>TableOfContents</c> holds the TOC of the htmlhelp system class.
11 public class TableOfContents
13 private ArrayList _toc = new ArrayList();
16 /// Standard constructor
18 public TableOfContents()
23 /// Constructor of the class
25 /// <param name="toc"></param>
26 public TableOfContents(ArrayList toc)
32 /// Gets the internal stored table of contents
40 /// Clears the current toc
49 /// Gets the number of topics in the toc
51 /// <returns>Returns the number of topics in the toc</returns>
61 /// Merges the <c>arrToC</c> list to the one in this instance
63 /// <param name="arrToC">the toc list which should be merged with the current one</param>
64 internal void MergeToC( ArrayList arrToC )
67 _toc = new ArrayList();
69 MergeToC(_toc, arrToC, null);
73 /// Merges the <c>arrToC</c> list to the one in this instance (called if merged files
74 /// were found in a CHM)
76 /// <param name="arrToC">the toc list which should be merged with the current one</param>
77 /// <param name="openFiles">An arraylist of CHMFile instances.</param>
78 internal void MergeToC( ArrayList arrToC, ArrayList openFiles )
81 _toc = new ArrayList();
82 MergeToC(_toc, arrToC, openFiles);
86 /// Internal method for recursive toc merging
88 /// <param name="globalLevel">level of global toc</param>
89 /// <param name="localLevel">level of local toc</param>
90 /// <param name="openFiles">An arraylist of CHMFile instances.</param>
91 private void MergeToC( ArrayList globalLevel, ArrayList localLevel, ArrayList openFiles )
93 foreach( TOCItem curItem in localLevel)
95 // if it is a part of the merged-links, we have to do nothing,
96 // because the method HtmlHelpSystem.RecalculateMergeLinks() has already
97 // placed this item at its correct position.
98 if(!IsMergedItem(curItem.Name, curItem.Local, openFiles))
100 TOCItem globalItem = ContainsToC(globalLevel, curItem.Name);
101 if(globalItem == null)
103 // the global toc doesn't have a topic with this name
104 // so we need to add the complete toc node to the global toc
106 globalLevel.Add( curItem );
110 // the global toc contains the current topic
111 // advance to the next level
113 if( (globalItem.Local.Length <= 0) && (curItem.Local.Length > 0) )
115 // set the associated url
116 globalItem.Local = curItem.Local;
117 globalItem.ChmFile = curItem.ChmFile;
120 MergeToC(globalItem.Children, curItem.Children);
127 /// Checks if the item is part of the merged-links
129 /// <param name="name">name of the topic</param>
130 /// <param name="local">local of the topic</param>
131 /// <param name="openFiles">An arraylist of CHMFile instances.</param>
132 /// <returns>Returns true if this item is part of the merged-links</returns>
133 private bool IsMergedItem(string name, string local, ArrayList openFiles)
138 foreach(CHMFile curFile in openFiles)
140 foreach(TOCItem curItem in curFile.MergLinks)
141 if( (curItem.Name == name) && (curItem.Local == local) )
148 /// Checks if a topicname exists in a SINGLE toc level
150 /// <param name="arrToC">toc list</param>
151 /// <param name="Topic">topic to search</param>
152 /// <returns>Returns the topic item if found, otherwise null</returns>
153 private TOCItem ContainsToC(ArrayList arrToC, string Topic)
155 foreach(TOCItem curItem in arrToC)
157 if(curItem.Name == Topic)
165 /// Searches the table of contents for a special topic
167 /// <param name="topic">topic to search</param>
168 /// <returns>Returns an instance of TOCItem if found, otherwise null</returns>
169 public TOCItem SearchTopic(string topic)
171 return SearchTopic(topic, _toc);
175 /// Internal recursive tree search
177 /// <param name="topic">topic to search</param>
178 /// <param name="searchIn">tree level list to look in</param>
179 /// <returns>Returns an instance of TOCItem if found, otherwise null</returns>
180 private TOCItem SearchTopic(string topic, ArrayList searchIn)
182 foreach(TOCItem curItem in searchIn)
184 if(curItem.Name.ToLower() == topic.ToLower() )
187 if(curItem.Children.Count>0)
189 TOCItem nf = SearchTopic(topic, curItem.Children);