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 #include "eclipsehelp.h"
16 #include "util.h"
17 #include "config.h"
18 #include "message.h"
19 #include "doxygen.h"
20 #include <qfile.h>
21 
22 EclipseHelp::EclipseHelp() : m_depth(0), m_endtag(FALSE), m_openTags(0), m_tocfile(0)
23 {
24 }
25 
27 {
28 }
29 
31 {
32  int i;
33  for (i=0; i<m_depth; i++)
34  {
35  m_tocstream << " ";
36  }
37 }
38 
40 {
41  if (m_endtag)
42  {
43  m_tocstream << "/>" << endl;
44  m_endtag = FALSE;
45  }
46 }
47 
49 {
50  if (m_endtag)
51  {
52  m_tocstream << ">" << endl;
53  m_endtag = FALSE;
54  ++m_openTags;
55  }
56 }
57 
58 /*!
59  * \brief Initialize the Eclipse generator
60  *
61  * This method opens the XML TOC file and writes headers of the files.
62  * \sa finalize()
63  */
65 {
66  // -- read path prefix from the configuration
67  //m_pathprefix = Config_getString("ECLIPSE_PATHPREFIX");
68  //if (m_pathprefix.isEmpty()) m_pathprefix = "html/";
69 
70  // -- open the contents file
71  QCString name = Config_getString("HTML_OUTPUT") + "/toc.xml";
72  m_tocfile = new QFile(name);
73  if (!m_tocfile->open(IO_WriteOnly))
74  {
75  err("Could not open file %s for writing\n", name.data());
76  exit(1);
77  }
78 
79  // -- initialize its text stream
81  //m_tocstream.setEncoding(FTextStream::UnicodeUTF8);
82 
83  // -- write the opening tag
84  QCString title = Config_getString("PROJECT_NAME");
85  if (title.isEmpty())
86  {
87  title = "Doxygen generated documentation";
88  }
89  m_tocstream << "<toc label=\"" << convertToXML(title)
90  << "\" topic=\"" << convertToXML(m_pathprefix)
91  << "index" << Doxygen::htmlFileExtension << "\">" << endl;
92  ++ m_depth;
93 }
94 
95 /*!
96  * \brief Finish generation of the Eclipse specific help files
97  *
98  * This method writes footers of the files and closes them.
99  * \sa initialize()
100  */
102 {
103  closedTag(); // -- close previous tag
104 
105  // -- write ending tag
106  --m_depth;
107  m_tocstream << "</toc>" << endl;
108 
109  // -- close the content file
111  m_tocfile->close();
112  delete m_tocfile; m_tocfile = 0;
113 
114  QCString name = Config_getString("HTML_OUTPUT") + "/plugin.xml";
115  QFile pluginFile(name);
116  if (pluginFile.open(IO_WriteOnly))
117  {
118  QString docId = Config_getString("ECLIPSE_DOC_ID");
119  FTextStream t(&pluginFile);
120  t << "<plugin name=\"" << docId << "\" id=\"" << docId << "\"" << endl;
121  t << " version=\"1.0.0\" provider-name=\"Doxygen\">" << endl;
122  t << " <extension point=\"org.eclipse.help.toc\">" << endl;
123  t << " <toc file=\"toc.xml\" primary=\"true\" />" << endl;
124  t << " </extension>" << endl;
125  t << "</plugin>" << endl;
126  }
127 }
128 
129 /*!
130  * \brief Increase the level of content hierarchy
131  */
133 {
134  openedTag();
135  ++m_depth;
136 }
137 
138 /*!
139  * \brief Decrease the level of content hierarchy
140  *
141  * It closes currently opened topic tag.
142  */
144 {
145  // -- end of the opened topic
146  closedTag();
147  --m_depth;
148 
149  if (m_openTags==m_depth)
150  {
151  --m_openTags;
152  indent();
153  m_tocstream << "</topic>" << endl;
154  }
155 }
156 
157 /*!
158  * \brief Add an item to the content
159  *
160  * @param isDir Flag whether the argument \a file is a directory or a file entry
161  * @param name Name of the item
162  * @param ref URL of the item
163  * @param file Name of a file which the item is defined in (without extension)
164  * @param anchor Name of an anchor of the item.
165  * @param separateIndex not used.
166  * @param addToNavIndex not used.
167  * @param def not used.
168  */
170  bool /* isDir */,
171  const char *name,
172  const char * /* ref */,
173  const char *file,
174  const char *anchor,
175  bool /* separateIndex */,
176  bool /* addToNavIndex */,
177  Definition * /*def*/)
178 {
179  // -- write the topic tag
180  closedTag();
181  if (file)
182  {
183  switch (file[0]) // check for special markers (user defined URLs)
184  {
185  case '^':
186  // URL not supported by eclipse toc.xml
187  break;
188 
189  case '!':
190  indent();
191  m_tocstream << "<topic label=\"" << convertToXML(name) << "\"";
192  m_tocstream << " href=\"" << convertToXML(m_pathprefix) << &file[1] << "\"";
193  m_endtag = TRUE;
194  break;
195 
196  default:
197  indent();
198  m_tocstream << "<topic label=\"" << convertToXML(name) << "\"";
199  m_tocstream << " href=\"" << convertToXML(m_pathprefix)
200  << file << Doxygen::htmlFileExtension;
201  if (anchor)
202  {
203  m_tocstream << "#" << anchor;
204  }
205  m_tocstream << "\"";
206  m_endtag = TRUE;
207  break;
208  }
209  }
210  else
211  {
212  indent();
213  m_tocstream << "<topic label=\"" << convertToXML(name) << "\"";
214  m_endtag = TRUE;
215  }
216 }
217 
219  Definition * /* context */,
220  MemberDef * /* md */,
221  const char * /* sectionAnchor */,
222  const char * /* title */)
223 {
224 }
225 
226 void EclipseHelp::addIndexFile(const char * /* name */)
227 {
228 }
229 
230 void EclipseHelp::addImageFile(const char * /* name */)
231 {
232 }
233 
234 void EclipseHelp::addStyleSheetFile(const char * /* name */)
235 {
236 }
237 
static QCString name
Definition: declinfo.cpp:673
QCString convertToXML(const char *s)
Definition: util.cpp:5717
void openedTag()
Definition: eclipsehelp.cpp:48
virtual void addIndexFile(const char *name)
virtual void addImageFile(const char *name)
bool isEmpty() const
Definition: qcstring.h:189
#define IO_WriteOnly
Definition: qiodevice.h:62
static QCString htmlFileExtension
Definition: doxygen.h:130
void setDevice(QIODevice *)
const bool FALSE
Definition: qglobal.h:370
QCString m_pathprefix
Definition: eclipsehelp.h:67
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
Simplified and optimized version of QTextStream.
Definition: ftextstream.h:11
void unsetDevice()
virtual void finalize()
Finish generation of the Eclipse specific help files.
void indent()
Definition: eclipsehelp.cpp:30
FTextStream m_tocstream
Definition: eclipsehelp.h:66
virtual void addStyleSheetFile(const char *name)
bool open(int)
Definition: qfile_unix.cpp:134
virtual ~EclipseHelp()
Definition: eclipsehelp.cpp:26
QFile * m_tocfile
Definition: eclipsehelp.h:65
A bunch of utility functions.
int m_openTags
Definition: eclipsehelp.h:63
const char * data() const
Definition: qcstring.h:207
#define Config_getString(val)
Definition: config.cpp:660
bool m_endtag
Definition: eclipsehelp.h:62
void err(const char *fmt,...)
Definition: message.cpp:226
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
void closedTag()
Definition: eclipsehelp.cpp:39
virtual void initialize()
Initialize the Eclipse generator.
Definition: eclipsehelp.cpp:64
virtual void addContentsItem(bool isDir, const char *name, const char *ref, const char *file, const char *anchor, bool separateIndex, bool addToNavIndex, Definition *def)
Add an item to the content.
virtual void incContentsDepth()
Increase the level of content hierarchy.
virtual void addIndexItem(Definition *context, MemberDef *md, const char *sectionAnchor, const char *title)
void close()
Definition: qfile_unix.cpp:614
const bool TRUE
Definition: qglobal.h:371
virtual void decContentsDepth()
Decrease the level of content hierarchy.
QTextStream & endl(QTextStream &s)