eclipsehelp.cpp 5.59 KB
Newer Older
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1 2
/******************************************************************************
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
3
 * Copyright (C) 1997-2014 by Dimitri van Heesch.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby 
 * granted. No representations are made about the suitability of this software 
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 * Documents produced by Doxygen are derivative works derived from the
 * input used in their production; they are not affected by this license.
 *
 */
#include "eclipsehelp.h"
#include "util.h"
#include "config.h"
#include "message.h"
#include "doxygen.h"
20
#include <qfile.h>
Dimitri van Heesch's avatar
Dimitri van Heesch committed
21

Dimitri van Heesch's avatar
Dimitri van Heesch committed
22
EclipseHelp::EclipseHelp() : m_depth(0), m_endtag(FALSE), m_openTags(0), m_tocfile(0) 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
{
}

EclipseHelp::~EclipseHelp() 
{
}

void EclipseHelp::indent()
{
  int i;
  for (i=0; i<m_depth; i++)
  {
    m_tocstream << "  ";
  }
}

void EclipseHelp::closedTag()
{
  if (m_endtag) 
  {
    m_tocstream << "/>" << endl;
    m_endtag = FALSE;
  }
}

void EclipseHelp::openedTag()
{
  if (m_endtag) 
  {
    m_tocstream << ">" << endl;
    m_endtag = FALSE;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
54
    ++m_openTags;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  }
}

/*!
 * \brief Initialize the Eclipse generator
 *
 * This method opens the XML TOC file and writes headers of the files.
 * \sa finalize()
 */
void EclipseHelp::initialize() 
{
  // -- read path prefix from the configuration
  //m_pathprefix = Config_getString("ECLIPSE_PATHPREFIX");
  //if (m_pathprefix.isEmpty()) m_pathprefix = "html/";

  // -- open the contents file 
  QCString name = Config_getString("HTML_OUTPUT") + "/toc.xml";
  m_tocfile = new QFile(name);
  if (!m_tocfile->open(IO_WriteOnly)) 
  {
    err("Could not open file %s for writing\n", name.data());
    exit(1);
  }

  // -- initialize its text stream
  m_tocstream.setDevice(m_tocfile);
81
  //m_tocstream.setEncoding(FTextStream::UnicodeUTF8);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
82 83 84 85 86 87 88

  // -- write the opening tag
  QCString title = Config_getString("PROJECT_NAME");
  if (title.isEmpty())
  {
    title = "Doxygen generated documentation";
  }
89 90 91
  m_tocstream << "<toc label=\"" << convertToXML(title) 
              << "\" topic=\"" << convertToXML(m_pathprefix) 
              << "index" << Doxygen::htmlFileExtension << "\">" << endl;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
  ++ m_depth;
}

/*!
 * \brief Finish generation of the Eclipse specific help files
 *
 * This method writes footers of the files and closes them.
 * \sa initialize()
 */
void EclipseHelp::finalize() 
{
  closedTag(); // -- close previous tag

  // -- write ending tag 
  --m_depth;
  m_tocstream << "</toc>" << endl;

  // -- close the content file
  m_tocstream.unsetDevice();
  m_tocfile->close();
  delete m_tocfile; m_tocfile = 0;

  QCString name = Config_getString("HTML_OUTPUT") + "/plugin.xml";
  QFile pluginFile(name);
  if (pluginFile.open(IO_WriteOnly))
  {
    QString docId = Config_getString("ECLIPSE_DOC_ID");
119
    FTextStream t(&pluginFile);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
    t << "<plugin name=\""  << docId << "\" id=\"" << docId << "\"" << endl;
    t << "        version=\"1.0.0\" provider-name=\"Doxygen\">" << endl;
    t << "  <extension point=\"org.eclipse.help.toc\">" << endl;
    t << "    <toc file=\"toc.xml\" primary=\"true\" />" << endl;
    t << "  </extension>" << endl;
    t << "</plugin>" << endl;
  }
}

/*!
 * \brief Increase the level of content hierarchy
 */
void EclipseHelp::incContentsDepth() 
{
  openedTag();
  ++m_depth;
}

/*!
 * \brief Decrease the level of content hierarchy
 *
 * It closes currently opened topic tag.
 */
void EclipseHelp::decContentsDepth() 
{
  // -- end of the opened topic
  closedTag();
  --m_depth;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
148 149 150 151 152 153 154

  if (m_openTags==m_depth)
  {
    --m_openTags;
    indent();
    m_tocstream << "</topic>" << endl;
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
155 156 157 158 159 160 161 162 163 164
}

/*!
 * \brief Add an item to the content
 *
 * @param isDir Flag whether the argument \a file is a directory or a file entry
 * @param name Name of the item
 * @param ref URL of the item
 * @param file Name of a file which the item is defined in (without extension)
 * @param anchor Name of an anchor of the item.
165 166
 * @param separateIndex not used.
 * @param addToNavIndex not used.
167
 * @param def not used.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
168 169
 */
void EclipseHelp::addContentsItem(
170
    bool /* isDir */,
Dimitri van Heesch's avatar
Dimitri van Heesch committed
171 172 173
    const char *name,
    const char * /* ref */,
    const char *file,
174 175
    const char *anchor,
    bool /* separateIndex */,
176 177
    bool /* addToNavIndex */,
    Definition * /*def*/) 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
178 179 180
{
  // -- write the topic tag 
  closedTag();
181 182
  if (file) 
  { 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
183
    switch (file[0]) // check for special markers (user defined URLs)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
184
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
      case '^':
        // URL not supported by eclipse toc.xml
	break;

      case '!':
        indent();
        m_tocstream << "<topic label=\"" << convertToXML(name) << "\"";
        m_tocstream << " href=\"" << convertToXML(m_pathprefix) << &file[1] << "\"";
        m_endtag = TRUE;
	break;

      default:
        indent();
        m_tocstream << "<topic label=\"" << convertToXML(name) << "\"";
        m_tocstream << " href=\"" << convertToXML(m_pathprefix) 
                    << file << Doxygen::htmlFileExtension;
        if (anchor)
        {
          m_tocstream << "#" << anchor;
        }
        m_tocstream << "\"";
        m_endtag = TRUE;
	break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
208 209
    }
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
210 211 212 213 214 215
  else
  {
    indent();
    m_tocstream << "<topic label=\"" << convertToXML(name) << "\"";
    m_endtag = TRUE;
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
216 217 218 219 220
}

void EclipseHelp::addIndexItem(
    Definition * /* context */,
    MemberDef * /* md */,
221
    const char * /* sectionAnchor */,
222
    const char * /* title */)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
{
}

void EclipseHelp::addIndexFile(const char * /* name */) 
{
}

void EclipseHelp::addImageFile(const char * /* name */) 
{
}

void EclipseHelp::addStyleSheetFile(const char * /* name */) 
{
}