|
1 /****************************************************************************** |
|
2 * |
|
3 * Copyright (C) 1997-2009 by Dimitri van Heesch. |
|
4 * |
|
5 * Permission to use, copy, modify, and distribute this software and its |
|
6 * documentation under the terms of the GNU General Public License is hereby |
|
7 * granted. No representations are made about the suitability of this software |
|
8 * for any purpose. It is provided "as is" without express or implied warranty. |
|
9 * See the GNU General Public License for more details. |
|
10 * |
|
11 * Documents produced by Doxygen are derivative works derived from the |
|
12 * input used in their production; they are not affected by this license. |
|
13 * |
|
14 */ |
|
15 #include "eclipsehelp.h" |
|
16 #include "util.h" |
|
17 #include "config.h" |
|
18 #include "message.h" |
|
19 #include "doxygen.h" |
|
20 |
|
21 EclipseHelp::EclipseHelp() : m_depth(0), m_endtag(FALSE), m_tocfile(0) |
|
22 { |
|
23 } |
|
24 |
|
25 EclipseHelp::~EclipseHelp() |
|
26 { |
|
27 } |
|
28 |
|
29 void EclipseHelp::indent() |
|
30 { |
|
31 int i; |
|
32 for (i=0; i<m_depth; i++) |
|
33 { |
|
34 m_tocstream << " "; |
|
35 } |
|
36 } |
|
37 |
|
38 void EclipseHelp::closedTag() |
|
39 { |
|
40 if (m_endtag) |
|
41 { |
|
42 m_tocstream << "/>" << endl; |
|
43 m_endtag = FALSE; |
|
44 } |
|
45 } |
|
46 |
|
47 void EclipseHelp::openedTag() |
|
48 { |
|
49 if (m_endtag) |
|
50 { |
|
51 m_tocstream << ">" << endl; |
|
52 m_endtag = FALSE; |
|
53 } |
|
54 } |
|
55 |
|
56 /*! |
|
57 * \brief Initialize the Eclipse generator |
|
58 * |
|
59 * This method opens the XML TOC file and writes headers of the files. |
|
60 * \sa finalize() |
|
61 */ |
|
62 void EclipseHelp::initialize() |
|
63 { |
|
64 // -- read path prefix from the configuration |
|
65 //m_pathprefix = Config_getString("ECLIPSE_PATHPREFIX"); |
|
66 //if (m_pathprefix.isEmpty()) m_pathprefix = "html/"; |
|
67 |
|
68 // -- open the contents file |
|
69 QCString name = Config_getString("HTML_OUTPUT") + "/toc.xml"; |
|
70 m_tocfile = new QFile(name); |
|
71 if (!m_tocfile->open(IO_WriteOnly)) |
|
72 { |
|
73 err("Could not open file %s for writing\n", name.data()); |
|
74 exit(1); |
|
75 } |
|
76 |
|
77 // -- initialize its text stream |
|
78 m_tocstream.setDevice(m_tocfile); |
|
79 m_tocstream.setEncoding(QTextStream::UnicodeUTF8); |
|
80 |
|
81 // -- write the opening tag |
|
82 QCString title = Config_getString("PROJECT_NAME"); |
|
83 if (title.isEmpty()) |
|
84 { |
|
85 title = "Doxygen generated documentation"; |
|
86 } |
|
87 m_tocstream << "<toc label=\"" << convertToXML(title) << "\">" << endl; |
|
88 ++ m_depth; |
|
89 } |
|
90 |
|
91 /*! |
|
92 * \brief Finish generation of the Eclipse specific help files |
|
93 * |
|
94 * This method writes footers of the files and closes them. |
|
95 * \sa initialize() |
|
96 */ |
|
97 void EclipseHelp::finalize() |
|
98 { |
|
99 closedTag(); // -- close previous tag |
|
100 |
|
101 // -- write ending tag |
|
102 --m_depth; |
|
103 m_tocstream << "</toc>" << endl; |
|
104 |
|
105 // -- close the content file |
|
106 m_tocstream.unsetDevice(); |
|
107 m_tocfile->close(); |
|
108 delete m_tocfile; m_tocfile = 0; |
|
109 |
|
110 QCString name = Config_getString("HTML_OUTPUT") + "/plugin.xml"; |
|
111 QFile pluginFile(name); |
|
112 if (pluginFile.open(IO_WriteOnly)) |
|
113 { |
|
114 QString docId = Config_getString("ECLIPSE_DOC_ID"); |
|
115 QTextStream t(&pluginFile); |
|
116 t << "<plugin name=\"" << docId << "\" id=\"" << docId << "\"" << endl; |
|
117 t << " version=\"1.0.0\" provider-name=\"Doxygen\">" << endl; |
|
118 t << " <extension point=\"org.eclipse.help.toc\">" << endl; |
|
119 t << " <toc file=\"toc.xml\" primary=\"true\" />" << endl; |
|
120 t << " </extension>" << endl; |
|
121 t << "</plugin>" << endl; |
|
122 } |
|
123 } |
|
124 |
|
125 /*! |
|
126 * \brief Increase the level of content hierarchy |
|
127 */ |
|
128 void EclipseHelp::incContentsDepth() |
|
129 { |
|
130 openedTag(); |
|
131 ++m_depth; |
|
132 } |
|
133 |
|
134 /*! |
|
135 * \brief Decrease the level of content hierarchy |
|
136 * |
|
137 * It closes currently opened topic tag. |
|
138 */ |
|
139 void EclipseHelp::decContentsDepth() |
|
140 { |
|
141 // -- end of the opened topic |
|
142 closedTag(); |
|
143 --m_depth; |
|
144 indent(); |
|
145 m_tocstream << "</topic>" << endl; |
|
146 } |
|
147 |
|
148 /*! |
|
149 * \brief Add an item to the content |
|
150 * |
|
151 * @param isDir Flag whether the argument \a file is a directory or a file entry |
|
152 * @param name Name of the item |
|
153 * @param ref URL of the item |
|
154 * @param file Name of a file which the item is defined in (without extension) |
|
155 * @param anchor Name of an anchor of the item. |
|
156 */ |
|
157 void EclipseHelp::addContentsItem( |
|
158 bool isDir, |
|
159 const char *name, |
|
160 const char * /* ref */, |
|
161 const char *file, |
|
162 const char *anchor) |
|
163 { |
|
164 // -- write the topic tag |
|
165 closedTag(); |
|
166 indent(); |
|
167 m_tocstream << "<topic label=\"" << convertToXML(name) << "\""; |
|
168 if (!isDir && file) |
|
169 { // -- Eclipse help cannot handle directories |
|
170 m_tocstream << " href=\"" << convertToXML(m_pathprefix) |
|
171 << file << Doxygen::htmlFileExtension; |
|
172 if (anchor) |
|
173 { |
|
174 m_tocstream << "#" << anchor; |
|
175 } |
|
176 m_tocstream << "\""; |
|
177 } |
|
178 m_endtag = TRUE; |
|
179 } |
|
180 |
|
181 void EclipseHelp::addIndexItem( |
|
182 Definition * /* context */, |
|
183 MemberDef * /* md */, |
|
184 const char * /* anchor */, |
|
185 const char * /* word */) |
|
186 { |
|
187 } |
|
188 |
|
189 void EclipseHelp::addIndexFile(const char * /* name */) |
|
190 { |
|
191 } |
|
192 |
|
193 void EclipseHelp::addImageFile(const char * /* name */) |
|
194 { |
|
195 } |
|
196 |
|
197 void EclipseHelp::addStyleSheetFile(const char * /* name */) |
|
198 { |
|
199 } |
|
200 |