Doxygen
Loading...
Searching...
No Matches
eclipsehelp.cpp
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2015 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
16// own header
17#include "eclipsehelp.h"
18
19// standard includes
20#include "config.h"
21#include "doxygen.h"
22#include "message.h"
23#include "portable.h"
24#include "util.h"
25
27{
28 int depth = 0;
29 bool endtag = false;
30 int openTags = 0;
31
32 std::ofstream tocstream;
34
35 /* -- formatting helpers */
36 void indent()
37 {
38 for (int i=0; i<depth; i++)
39 {
40 tocstream << " ";
41 }
42 }
43 void closedTag()
44 {
45 if (endtag)
46 {
47 tocstream << "/>\n";
48 endtag = false;
49 }
50 }
51 void openedTag()
52 {
53 if (endtag)
54 {
55 tocstream << ">\n";
56 endtag = false;
57 ++openTags;
58 }
59 }
60};
61
62EclipseHelp::EclipseHelp() : p(std::make_unique<Private>()) {}
64
65/*!
66 * \brief Initialize the Eclipse generator
67 *
68 * This method opens the XML TOC file and writes headers of the files.
69 * \sa finalize()
70 */
72{
73 // -- open the contents file
74 DString name = Config_getString(HTML_OUTPUT) + "/toc.xml";
75 p->tocstream = Portable::openOutputStream(name);
76 if (!p->tocstream.is_open())
77 {
78 term("Could not open file {} for writing\n", name);
79 }
80
81 // -- write the opening tag
82 DString title = Config_getString(PROJECT_NAME);
83 if (title.empty())
84 {
85 title = "Doxygen generated documentation";
86 }
87 p->tocstream << "<toc label=\"" << convertToXML(title)
88 << "\" topic=\"" << convertToXML(p->pathprefix)
89 << "index" << Doxygen::htmlFileExtension << "\">\n";
90 ++ p->depth;
91}
92
93/*!
94 * \brief Finish generation of the Eclipse specific help files
95 *
96 * This method writes footers of the files and closes them.
97 * \sa initialize()
98 */
100{
101 p->closedTag(); // -- close previous tag
102
103 // -- write ending tag
104 --p->depth;
105 p->tocstream << "</toc>\n";
106
107 // -- close the content file
108 p->tocstream.close();
109
110 DString name = Config_getString(HTML_OUTPUT) + "/plugin.xml";
111 std::ofstream t = Portable::openOutputStream(name);
112 if (t.is_open())
113 {
114 DString docId = Config_getString(ECLIPSE_DOC_ID);
115 t << "<plugin name=\"" << docId << "\" id=\"" << docId << "\"\n";
116 t << " version=\"1.0.0\" provider-name=\"Doxygen\">\n";
117 t << " <extension point=\"org.eclipse.help.toc\">\n";
118 t << " <toc file=\"toc.xml\" primary=\"true\" />\n";
119 t << " </extension>\n";
120 t << "</plugin>\n";
121 }
122}
123
124/*!
125 * \brief Increase the level of content hierarchy
126 */
128{
129 p->openedTag();
130 ++p->depth;
131}
132
133/*!
134 * \brief Decrease the level of content hierarchy
135 *
136 * It closes currently opened topic tag.
137 */
139{
140 // -- end of the opened topic
141 p->closedTag();
142 --p->depth;
143
144 if (p->openTags==p->depth)
145 {
146 --p->openTags;
147 p->indent();
148 p->tocstream << "</topic>\n";
149 }
150}
151
152/*!
153 * \brief Add an item to the content
154 *
155 * @param isDir Flag whether the argument \a file is a directory or a file entry
156 * @param name Name of the item
157 * @param ref URL of the item
158 * @param file Name of a file which the item is defined in (without extension)
159 * @param anchor Name of an anchor of the item.
160 * @param separateIndex not used.
161 * @param addToNavIndex not used.
162 * @param def not used.
163 * @param nameAsHtml name parameter in HTML format
164 */
166 bool /* isDir */,
167 const DString &name,
168 const DString & /* ref */,
169 const DString &file,
170 const DString &anchor,
171 bool /* separateIndex */,
172 bool /* addToNavIndex */,
173 const Definition * /*def*/,
174 const DString & /* nameAsHtml */)
175{
176 // -- write the topic tag
177 p->closedTag();
178 if (!file.empty())
179 {
180 DString fn = file;
182 switch (file[0]) // check for special markers (user defined URLs)
183 {
184 case '^':
185 // URL not supported by eclipse toc.xml
186 break;
187
188 case '!':
189 p->indent();
190 p->tocstream << "<topic label=\"" << convertToXML(name) << "\"";
191 p->tocstream << " href=\"" << convertToXML(p->pathprefix) << &file[1] << "\"";
192 p->endtag = true;
193 break;
194
195 default:
196 p->indent();
197 p->tocstream << "<topic label=\"" << convertToXML(name) << "\"";
198 p->tocstream << " href=\"" << convertToXML(p->pathprefix) << fn;
199 if (!anchor.empty())
200 {
201 p->tocstream << "#" << anchor;
202 }
203 p->tocstream << "\"";
204 p->endtag = true;
205 break;
206 }
207 }
208 else
209 {
210 p->indent();
211 p->tocstream << "<topic label=\"" << convertToXML(name) << "\"";
212 p->endtag = true;
213 }
214}
215
217 const Definition * /* context */,
218 const MemberDef * /* md */,
219 const DString & /* sectionAnchor */,
220 const DString & /* title */)
221{
222}
223
224void EclipseHelp::addIndexFile(const DString & /* name */)
225{
226}
227
228void EclipseHelp::addImageFile(const DString & /* name */)
229{
230}
231
233{
234}
235
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
The common base class of all entity definitions found in the sources.
Definition definition.h:77
static DString htmlFileExtension
Definition doxygen.h:115
virtual ~EclipseHelp()
virtual void decContentsDepth()
Decrease the level of content hierarchy.
virtual void addContentsItem(bool isDir, const DString &name, const DString &ref, const DString &file, const DString &anchor, bool separateIndex, bool addToNavIndex, const Definition *def, const DString &nameAsHtml)
Add an item to the content.
virtual void addStyleSheetFile(const DString &name)
std::unique_ptr< Private > p
Definition eclipsehelp.h:64
virtual void finalize()
Finish generation of the Eclipse specific help files.
virtual void incContentsDepth()
Increase the level of content hierarchy.
virtual void addIndexItem(const Definition *context, const MemberDef *md, const DString &sectionAnchor, const DString &title)
virtual void addImageFile(const DString &name)
virtual void addIndexFile(const DString &name)
virtual void initialize()
Initialize the Eclipse generator.
A model of a class/file/namespace member symbol.
Definition memberdef.h:45
#define Config_getString(name)
Definition config.h:32
#define term(fmt,...)
Definition message.h:137
std::ofstream openOutputStream(const DString &name, bool append=false)
Definition portable.cpp:681
Definition dstring.h:913
Portable versions of functions that are platform dependent.
std::ofstream tocstream
void addHtmlExtensionIfMissing(DString &fName)
Definition util.cpp:3931
DString convertToXML(const DString &s, bool keepEntities, const bool citeEntry)
Definition util.cpp:3232
A bunch of utility functions.