Doxygen
eclipsehelp.cpp
浏览该文件的文档.
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 #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_openTags(0)
22 {
23 }
24 
26 {
27 }
28 
30 {
31  int i;
32  for (i=0; i<m_depth; i++)
33  {
34  m_tocstream << " ";
35  }
36 }
37 
39 {
40  if (m_endtag)
41  {
42  m_tocstream << "/>\n";
43  m_endtag = FALSE;
44  }
45 }
46 
48 {
49  if (m_endtag)
50  {
51  m_tocstream << ">\n";
52  m_endtag = FALSE;
53  ++m_openTags;
54  }
55 }
56 
57 /*!
58  * \brief Initialize the Eclipse generator
59  *
60  * This method opens the XML TOC file and writes headers of the files.
61  * \sa finalize()
62  */
64 {
65  // -- read path prefix from the configuration
66  //m_pathprefix = Config_getString(ECLIPSE_PATHPREFIX);
67  //if (m_pathprefix.isEmpty()) m_pathprefix = "html/";
68 
69  // -- open the contents file
70  QCString name = Config_getString(HTML_OUTPUT) + "/toc.xml";
71  m_tocstream.open(name.str(), std::ofstream::out | std::ofstream::binary);
72  if (!m_tocstream.is_open())
73  {
74  term("Could not open file %s for writing\n", qPrint(name));
75  }
76 
77  // -- write the opening tag
78  QCString title = Config_getString(PROJECT_NAME);
79  if (title.isEmpty())
80  {
81  title = "Doxygen generated documentation";
82  }
83  m_tocstream << "<toc label=\"" << convertToXML(title)
84  << "\" topic=\"" << convertToXML(m_pathprefix)
85  << "index" << Doxygen::htmlFileExtension << "\">\n";
86  ++ m_depth;
87 }
88 
89 /*!
90  * \brief Finish generation of the Eclipse specific help files
91  *
92  * This method writes footers of the files and closes them.
93  * \sa initialize()
94  */
96 {
97  closedTag(); // -- close previous tag
98 
99  // -- write ending tag
100  --m_depth;
101  m_tocstream << "</toc>\n";
102 
103  // -- close the content file
104  m_tocstream.close();
105 
106  QCString name = Config_getString(HTML_OUTPUT) + "/plugin.xml";
107  std::ofstream t(name.str(),std::ofstream::out | std::ofstream::binary);
108  if (t.is_open())
109  {
110  QCString docId = Config_getString(ECLIPSE_DOC_ID);
111  t << "<plugin name=\"" << docId << "\" id=\"" << docId << "\"\n";
112  t << " version=\"1.0.0\" provider-name=\"Doxygen\">\n";
113  t << " <extension point=\"org.eclipse.help.toc\">\n";
114  t << " <toc file=\"toc.xml\" primary=\"true\" />\n";
115  t << " </extension>\n";
116  t << "</plugin>\n";
117  }
118 }
119 
120 /*!
121  * \brief Increase the level of content hierarchy
122  */
124 {
125  openedTag();
126  ++m_depth;
127 }
128 
129 /*!
130  * \brief Decrease the level of content hierarchy
131  *
132  * It closes currently opened topic tag.
133  */
135 {
136  // -- end of the opened topic
137  closedTag();
138  --m_depth;
139 
140  if (m_openTags==m_depth)
141  {
142  --m_openTags;
143  indent();
144  m_tocstream << "</topic>\n";
145  }
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  * @param separateIndex not used.
157  * @param addToNavIndex not used.
158  * @param def not used.
159  */
161  bool /* isDir */,
162  const QCString &name,
163  const QCString & /* ref */,
164  const QCString &file,
165  const QCString &anchor,
166  bool /* separateIndex */,
167  bool /* addToNavIndex */,
168  const Definition * /*def*/)
169 {
170  // -- write the topic tag
171  closedTag();
172  if (!file.isEmpty())
173  {
174  switch (file[0]) // check for special markers (user defined URLs)
175  {
176  case '^':
177  // URL not supported by eclipse toc.xml
178  break;
179 
180  case '!':
181  indent();
182  m_tocstream << "<topic label=\"" << convertToXML(name) << "\"";
183  m_tocstream << " href=\"" << convertToXML(m_pathprefix) << &file[1] << "\"";
184  m_endtag = TRUE;
185  break;
186 
187  default:
188  indent();
189  m_tocstream << "<topic label=\"" << convertToXML(name) << "\"";
190  m_tocstream << " href=\"" << convertToXML(m_pathprefix)
191  << addHtmlExtensionIfMissing(file);
192  if (!anchor.isEmpty())
193  {
194  m_tocstream << "#" << anchor;
195  }
196  m_tocstream << "\"";
197  m_endtag = TRUE;
198  break;
199  }
200  }
201  else
202  {
203  indent();
204  m_tocstream << "<topic label=\"" << convertToXML(name) << "\"";
205  m_endtag = TRUE;
206  }
207 }
208 
210  const Definition * /* context */,
211  const MemberDef * /* md */,
212  const QCString & /* sectionAnchor */,
213  const QCString & /* title */)
214 {
215 }
216 
217 void EclipseHelp::addIndexFile(const QCString & /* name */)
218 {
219 }
220 
221 void EclipseHelp::addImageFile(const QCString & /* name */)
222 {
223 }
224 
225 void EclipseHelp::addStyleSheetFile(const QCString & /* name */)
226 {
227 }
228 
EclipseHelp::m_pathprefix
QCString m_pathprefix
Definition: eclipsehelp.h:66
EclipseHelp::addStyleSheetFile
virtual void addStyleSheetFile(const QCString &name)
Definition: eclipsehelp.cpp:225
Definition
The common base class of all entity definitions found in the sources.
Definition: definition.h:76
EclipseHelp::indent
void indent()
Definition: eclipsehelp.cpp:29
QCString::isEmpty
bool isEmpty() const
Returns TRUE iff the string is empty
Definition: qcstring.h:144
EclipseHelp::finalize
virtual void finalize()
Finish generation of the Eclipse specific help files
Definition: eclipsehelp.cpp:95
QCString::str
std::string str() const
Definition: qcstring.h:442
EclipseHelp::addImageFile
virtual void addImageFile(const QCString &name)
Definition: eclipsehelp.cpp:221
EclipseHelp::incContentsDepth
virtual void incContentsDepth()
Increase the level of content hierarchy
Definition: eclipsehelp.cpp:123
addHtmlExtensionIfMissing
QCString addHtmlExtensionIfMissing(const QCString &fName)
Definition: util.cpp:5275
MemberDef
A model of a class/file/namespace member symbol.
Definition: memberdef.h:45
EclipseHelp::openedTag
void openedTag()
Definition: eclipsehelp.cpp:47
eclipsehelp.h
message.h
EclipseHelp::initialize
virtual void initialize()
Initialize the Eclipse generator
Definition: eclipsehelp.cpp:63
EclipseHelp::addContentsItem
virtual void addContentsItem(bool isDir, const QCString &name, const QCString &ref, const QCString &file, const QCString &anchor, bool separateIndex, bool addToNavIndex, const Definition *def)
Add an item to the content
Definition: eclipsehelp.cpp:160
doxygen.h
EclipseHelp::closedTag
void closedTag()
Definition: eclipsehelp.cpp:38
EclipseHelp::m_tocstream
std::ofstream m_tocstream
Definition: eclipsehelp.h:65
TRUE
#define TRUE
Definition: qcstring.h:36
EclipseHelp::m_endtag
bool m_endtag
Definition: eclipsehelp.h:62
EclipseHelp::addIndexItem
virtual void addIndexItem(const Definition *context, const MemberDef *md, const QCString &sectionAnchor, const QCString &title)
Definition: eclipsehelp.cpp:209
EclipseHelp::m_depth
int m_depth
Definition: eclipsehelp.h:61
EclipseHelp::~EclipseHelp
virtual ~EclipseHelp()
Definition: eclipsehelp.cpp:25
EclipseHelp::addIndexFile
virtual void addIndexFile(const QCString &name)
Definition: eclipsehelp.cpp:217
Doxygen::htmlFileExtension
static QCString htmlFileExtension
Definition: doxygen.h:103
EclipseHelp::m_openTags
int m_openTags
Definition: eclipsehelp.h:63
term
void term(const char *fmt,...)
Definition: message.cpp:220
qPrint
const char * qPrint(const char *s)
Definition: qcstring.h:589
Config_getString
#define Config_getString(name)
Definition: config.h:32
config.h
convertToXML
QCString convertToXML(const QCString &s, bool keepEntities)
Definition: util.cpp:3948
EclipseHelp::EclipseHelp
EclipseHelp()
Definition: eclipsehelp.cpp:21
EclipseHelp::decContentsDepth
virtual void decContentsDepth()
Decrease the level of content hierarchy
Definition: eclipsehelp.cpp:134
util.h
A bunch of utility functions.
FALSE
#define FALSE
Definition: qcstring.h:33
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108