Doxygen
Loading...
Searching...
No Matches
ftvhelp.cpp
Go to the documentation of this file.
1/******************************************************************************
2 * ftvhelp.cpp,v 1.0 2000/09/06 16:09:00
3 *
4 * Copyright (C) 1997-2015 by Dimitri van Heesch.
5 *
6 * Permission to use, copy, modify, and distribute this software and its
7 * documentation under the terms of the GNU General Public License is hereby
8 * granted. No representations are made about the suitability of this software
9 * for any purpose. It is provided "as is" without express or implied warranty.
10 * See the GNU General Public License for more details.
11 *
12 * Documents produced by Doxygen are derivative works derived from the
13 * input used in their production; they are not affected by this license.
14 *
15 * Original version contributed by Kenney Wong <kwong@ea.com>
16 * Modified by Dimitri van Heesch
17 *
18 * Folder Tree View for offline help on browsers that do not support HTML Help.
19 */
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <algorithm>
24
25#include "ftvhelp.h"
26#include "config.h"
27#include "message.h"
28#include "doxygen.h"
29#include "language.h"
30#include "htmlgen.h"
31#include "layout.h"
32#include "pagedef.h"
33#include "docparser.h"
34#include "htmldocvisitor.h"
35#include "filedef.h"
36#include "classdef.h"
37#include "util.h"
38#include "resourcemgr.h"
39#include "portable.h"
40#include "outputlist.h"
41#include "threadpool.h"
42
43static int folderId=1;
44
45
46struct FTVNode;
47using FTVNodePtr = std::shared_ptr<FTVNode>;
48using FTVNodeWeakPtr = std::weak_ptr<FTVNode>;
49using FTVNodes = std::vector<FTVNodePtr>;
50
51struct FTVNode
52{
53 FTVNode(bool dir,const QCString &r,const QCString &f,const QCString &a,
54 const QCString &n,bool sepIndex,bool navIndex,const Definition *df,
55 const QCString &nameAsHtml_)
56 : isLast(TRUE), isDir(dir), ref(r), file(f), anchor(a), name(n), nameAsHtml(nameAsHtml_),
57 separateIndex(sepIndex), addToNavIndex(navIndex), def(df) {}
58 int computeTreeDepth(int level) const;
59 int numNodesAtLevel(int level,int maxLevel) const;
60 bool isLast;
61 bool isDir;
67 int index = 0;
73};
74
75int FTVNode::computeTreeDepth(int level) const
76{
77 int maxDepth=level;
78 for (const auto &n : children)
79 {
80 if (!n->children.empty())
81 {
82 int d = n->computeTreeDepth(level+1);
83 if (d>maxDepth) maxDepth=d;
84 }
85 }
86 return maxDepth;
87}
88
89int FTVNode::numNodesAtLevel(int level,int maxLevel) const
90{
91 int num=0;
92 if (level<maxLevel)
93 {
94 num++; // this node
95 for (const auto &n : children)
96 {
97 num+=n->numNodesAtLevel(level+1,maxLevel);
98 }
99 }
100 return num;
101}
102
103//----------------------------------------------------------------------------
104
106{
107 Private(bool TLI) : topLevelIndex(TLI) { indentNodes.resize(1); }
108 std::vector<FTVNodes> indentNodes;
109 int indent = 0;
111
112 void generateTree(TextStream &t,const FTVNodes &nl,int level,int maxLevel,int &index);
113 void generateLink(TextStream &t,const FTVNodePtr &n);
114};
115
116/*! Constructs an ftv help object.
117 * The object has to be \link initialize() initialized\endlink before it can
118 * be used.
119 */
120FTVHelp::FTVHelp(bool TLI) : p(std::make_unique<Private>(TLI)) {}
121FTVHelp::~FTVHelp() = default;
122
123/*! This will create a folder tree view table of contents file (tree.js).
124 * \sa finalize()
125 */
127{
128}
129
130/*! Finalizes the FTV help. This will finish and close the
131 * contents file (index.js).
132 * \sa initialize()
133 */
135{
137}
138
139/*! Increase the level of the contents hierarchy.
140 * This will start a new sublist in contents file.
141 * \sa decContentsDepth()
142 */
144{
145 //printf("%p: incContentsDepth() indent=%d\n",this,p->indent);
146 p->indent++;
147 p->indentNodes.resize(p->indent+1);
148}
149
150/*! Decrease the level of the contents hierarchy.
151 * This will end the current sublist.
152 * \sa incContentsDepth()
153 */
155{
156 //printf("%p: decContentsDepth() indent=%d\n",this,p->indent);
157 ASSERT(p->indent>0);
158 if (p->indent>0)
159 {
160 p->indent--;
161 auto &nl = p->indentNodes[p->indent];
162 if (!nl.empty())
163 {
164 auto &parent = nl.back();
165 auto &children = p->indentNodes[p->indent+1];
166 for (const auto &child : children)
167 {
168 parent->children.push_back(child);
169 }
170 children.clear();
171 }
172 }
173}
174
175/*! Add a list item to the contents file.
176 * \param isDir TRUE if the item is a directory, FALSE if it is a text
177 * \param name the name of the item.
178 * \param nameAsHtml the name of the item in HTML format.
179 * \param ref the URL of to the item.
180 * \param file the file containing the definition of the item
181 * \param anchor the anchor within the file.
182 * \param separateIndex put the entries in a separate index file
183 * \param addToNavIndex add this entry to the quick navigation index
184 * \param def Definition corresponding to this entry
185 */
187 const QCString &name,
188 const QCString &ref,
189 const QCString &file,
190 const QCString &anchor,
191 bool separateIndex,
192 bool addToNavIndex,
193 const Definition *def,
194 const QCString &nameAsHtml
195 )
196{
197 //printf("%p: p->indent=%d addContentsItem(isDir=%d,name=%s,ref=%s,file=%s,anchor=%s,nameAsHtml=%s)\n",(void*)this,p->indent,isDir,qPrint(name),qPrint(ref),qPrint(file),qPrint(anchor),qPrint(nameAsHtml));
198 auto &nl = p->indentNodes[p->indent];
199 if (!nl.empty())
200 {
201 nl.back()->isLast=FALSE;
202 }
203 auto newNode = std::make_shared<FTVNode>(isDir,ref,file,anchor,name,separateIndex,addToNavIndex,def,nameAsHtml);
204 nl.push_back(newNode);
205 newNode->index = static_cast<int>(nl.size()-1);
206 if (p->indent>0)
207 {
208 auto &pnl = p->indentNodes[p->indent-1];
209 if (!pnl.empty())
210 {
211 newNode->parent = pnl.back();
212 }
213 }
214}
215
216static QCString node2URL(const FTVNodePtr &n,bool overruleFile=FALSE,bool srcLink=FALSE)
217{
218 QCString url = n->file;
219 if (!url.isEmpty() && url.at(0)=='!') // relative URL
220 {
221 // remove leading !
222 url = url.mid(1);
223 }
224 else if (!url.isEmpty() && url.at(0)=='^') // absolute URL
225 {
226 // skip, keep ^ in the output
227 }
228 else // local file (with optional anchor)
229 {
230 if (overruleFile && n->def && n->def->definitionType()==Definition::TypeFile)
231 {
232 const FileDef *fd = toFileDef(n->def);
233 if (srcLink)
234 {
235 url = fd->getSourceFileBase();
236 }
237 else
238 {
239 url = fd->getOutputFileBase();
240 }
241 }
243 if (!n->anchor.isEmpty()) url+="#"+n->anchor;
244 }
245 return url;
246}
247
248static QCString generateIndentLabel(const FTVNodePtr &n,int level)
249{
250 QCString result;
251 auto parent = n->parent.lock();
252 if (parent)
253 {
254 result=generateIndentLabel(parent,level+1);
255 }
256 result+=QCString().setNum(n->index)+"_";
257 return result;
258}
259
260static void generateIndent(TextStream &t, const FTVNodePtr &n,bool opened)
261{
262 bool dynamicSections = Config_getBool(HTML_DYNAMIC_SECTIONS);
263 int indent=0;
264 auto parent = n->parent.lock();
265 while (parent) { indent++; parent=parent->parent.lock(); }
266 if (n->isDir && dynamicSections)
267 {
268 const char *ARROW_DOWN = "<span class=\"arrowhead opened\"></span>";
269 const char *ARROW_RIGHT = "<span class=\"arrowhead closed\"></span>";
270 QCString dir = opened ? ARROW_DOWN : ARROW_RIGHT;
271 t << "<span style=\"width:" << (indent*16) << "px;display:inline-block;\">&#160;</span>"
272 << "<span id=\"arr_" << generateIndentLabel(n,0) << "\" class=\"arrow\" ";
273 t << "onclick=\"dynsection.toggleFolder('" << generateIndentLabel(n,0) << "')\"";
274 t << ">" << dir
275 << "</span>";
276 }
277 else
278 {
279 t << "<span style=\"width:" << ((indent+1)*16) << "px;display:inline-block;\">&#160;</span>";
280 }
281}
282
284{
285 //printf("FTVHelp::generateLink(ref=%s,file=%s,anchor=%s\n",
286 // qPrint(n->ref),qPrint(n->file),qPrint(n->anchor));
287 bool setTarget = FALSE;
288 bool nameAsHtml = !n->nameAsHtml.isEmpty();
289 QCString text = nameAsHtml ? n->nameAsHtml : convertToHtml(n->name);
290 if (n->file.isEmpty()) // no link
291 {
292 t << "<b>" << text << "</b>";
293 }
294 else // link into other frame
295 {
296 if (!n->ref.isEmpty()) // link to entity imported via tag file
297 {
298 t << "<a class=\"elRef\" ";
299 QCString result = externalLinkTarget();
300 if (result != "") setTarget = TRUE;
301 t << result;
302 }
303 else // local link
304 {
305 t << "<a class=\"el\" ";
306 }
307 t << "href=\"";
308 t << externalRef("",n->ref,TRUE);
309 t << node2URL(n);
310 if (!setTarget)
311 {
312 if (topLevelIndex)
313 t << "\" target=\"basefrm\">";
314 else
315 t << "\" target=\"_self\">";
316 }
317 else
318 {
319 t << "\">";
320 }
321 t << text;
322 t << "</a>";
323 if (!n->ref.isEmpty())
324 {
325 t << "&#160;[external]";
326 }
327 }
328}
329
330static void generateBriefDoc(TextStream &t,const Definition *def)
331{
332 QCString brief = def->briefDescription(TRUE);
333 //printf("*** %p: generateBriefDoc(%s)='%s'\n",def,qPrint(def->name()),qPrint(brief));
334 if (!brief.isEmpty())
335 {
336 auto parser { createDocParser() };
337 auto ast { validatingParseDoc(*parser.get(),
338 def->briefFile(),
339 def->briefLine(),
340 def,
341 nullptr,
342 brief,
343 DocOptions()
344 .setSingleLine(true)
345 .setLinkFromIndex(true))
346 };
347 const DocNodeAST *astImpl = dynamic_cast<const DocNodeAST*>(ast.get());
348 if (astImpl)
349 {
351 OutputCodeList htmlList;
352 htmlList.add<HtmlCodeGenerator>(&t,relPath);
353 HtmlDocVisitor visitor(t,htmlList,def);
354 std::visit(visitor,astImpl->root);
355 }
356 }
357}
358
359static char compoundIcon(const ClassDef *cd)
360{
361 char icon='C';
362 if (cd->getLanguage() == SrcLangExt::Slice)
363 {
365 {
366 icon='I';
367 }
368 else if (cd->compoundType()==ClassDef::Struct)
369 {
370 icon='S';
371 }
372 else if (cd->compoundType()==ClassDef::Exception)
373 {
374 icon='E';
375 }
376 }
377 return icon;
378}
379
380void FTVHelp::Private::generateTree(TextStream &t, const FTVNodes &nl,int level,int maxLevel,int &index)
381{
382 bool dynamicSections = Config_getBool(HTML_DYNAMIC_SECTIONS);
383 for (const auto &n : nl)
384 {
385 t << "<tr id=\"row_" << generateIndentLabel(n,0) << "\"";
386 if ((index&1)==0) // even row
387 t << " class=\"even\"";
388 else
389 t << " class=\"odd\"";
390 if (level>=maxLevel && dynamicSections) // item invisible by default
391 t << " style=\"display:none;\"";
392 else // item visible by default
393 index++;
394 t << "><td class=\"entry\">";
395 bool nodeOpened = level+1<maxLevel;
396 generateIndent(t,n,nodeOpened);
397 if (n->isDir)
398 {
399 if (n->def && n->def->definitionType()==Definition::TypeGroup)
400 {
401 // no icon
402 }
403 else if (n->def && n->def->definitionType()==Definition::TypePage)
404 {
405 // no icon
406 }
407 else if (n->def && n->def->definitionType()==Definition::TypeNamespace)
408 {
409 if ((n->def->getLanguage() == SrcLangExt::Slice) || (n->def->getLanguage() == SrcLangExt::Fortran))
410 {
411 t << "<span class=\"icona\"><span class=\"icon\">M</span></span>";
412 }
413 else if ((n->def->getLanguage() == SrcLangExt::Java) || (n->def->getLanguage() == SrcLangExt::VHDL))
414 {
415 t << "<span class=\"icona\"><span class=\"icon\">P</span></span>";
416 }
417 else
418 {
419 t << "<span class=\"icona\"><span class=\"icon\">N</span></span>";
420 }
421 }
422 else if (n->def && n->def->definitionType()==Definition::TypeModule)
423 {
424 t << "<span class=\"icona\"><span class=\"icon\">M</span></span>";
425 }
426 else if (n->def && n->def->definitionType()==Definition::TypeClass)
427 {
428 char icon=compoundIcon(toClassDef(n->def));
429 t << "<span class=\"icona\"><span class=\"icon\">" << icon << "</span></span>";
430 }
431 else if (dynamicSections)
432 {
433 t << "<span id=\"img_" << generateIndentLabel(n,0) << "\" class=\"iconfolder"
434 << "\" onclick=\"dynsection.toggleFolder('" << generateIndentLabel(n,0)
435 << "')\"><div class=\"folder-icon"
436 << (nodeOpened ? " open" : "")
437 << "\"></div></span>";
438 }
439 generateLink(t,n);
440 t << "</td><td class=\"desc\">";
441 if (n->def)
442 {
443 generateBriefDoc(t,n->def);
444 }
445 t << "</td></tr>\n";
446 folderId++;
447 generateTree(t,n->children,level+1,maxLevel,index);
448 }
449 else // leaf node
450 {
451 const FileDef *srcRef=nullptr;
452 if (n->def && n->def->definitionType()==Definition::TypeFile &&
453 (toFileDef(n->def))->generateSourceFile())
454 {
455 srcRef = toFileDef(n->def);
456 }
457 if (srcRef)
458 {
459 QCString fn=srcRef->getSourceFileBase();
461 t << "<a href=\"" << fn << "\">";
462 }
463 if (n->def && n->def->definitionType()==Definition::TypeGroup)
464 {
465 // no icon
466 }
467 else if (n->def && n->def->definitionType()==Definition::TypePage)
468 {
469 // no icon
470 }
471 else if (n->def && n->def->definitionType()==Definition::TypeNamespace)
472 {
473 if ((n->def->getLanguage() == SrcLangExt::Slice) || (n->def->getLanguage() == SrcLangExt::Fortran))
474 {
475 t << "<span class=\"icona\"><span class=\"icon\">M</span></span>";
476 }
477 else if ((n->def->getLanguage() == SrcLangExt::Java) || (n->def->getLanguage() == SrcLangExt::VHDL))
478 {
479 t << "<span class=\"icona\"><span class=\"icon\">P</span></span>";
480 }
481 else
482 {
483 t << "<span class=\"icona\"><span class=\"icon\">N</span></span>";
484 }
485 }
486 else if (n->def && n->def->definitionType()==Definition::TypeModule)
487 {
488 t << "<span class=\"icona\"><span class=\"icon\">M</span></span>";
489 }
490 else if (n->def && n->def->definitionType()==Definition::TypeClass)
491 {
492 char icon=compoundIcon(toClassDef(n->def));
493 t << "<span class=\"icona\"><span class=\"icon\">" << icon << "</span></span>";
494 }
495 else if (n->def && n->def->definitionType()==Definition::TypeConcept)
496 {
497 t << "<span class=\"icona\"><span class=\"icon\">R</span></span>";
498 }
499 else if (n->def && n->def->definitionType()==Definition::TypeDir)
500 {
501 t << "<span class=\"iconfolder\"><div class=\"folder-icon\"></div></span>";
502 }
503 else
504 {
505 t << "<span class=\"icondoc\"><div class=\"doc-icon\"></div></span>";
506 }
507 if (srcRef)
508 {
509 t << "</a>";
510 }
511 generateLink(t,n);
512 t << "</td><td class=\"desc\">";
513 if (n->def)
514 {
515 generateBriefDoc(t,n->def);
516 }
517 t << "</td></tr>\n";
518 }
519 }
520}
521
522//-----------------------------------------------------------
523
525{
526 NavIndexEntry(const QCString &u,const QCString &p) : url(u), path(p) {}
529};
530
531class NavIndexEntryList : public std::vector<NavIndexEntry>
532{
533};
534
535static QCString pathToNode(const FTVNodePtr &leaf,const FTVNodePtr &n)
536{
537 QCString result;
538 auto parent = n->parent.lock();
539 if (parent)
540 {
541 result+=pathToNode(leaf,parent);
542 }
543 result+=QCString().setNum(n->index);
544 if (leaf!=n) result+=",";
545 return result;
546}
547
548static bool dupOfParent(const FTVNodePtr &n)
549{
550 auto parent = n->parent.lock();
551 if (!parent) return FALSE;
552 if (n->file==parent->file) return TRUE;
553 return FALSE;
554}
555
556static void generateJSLink(TextStream &t,const FTVNodePtr &n)
557{
558 bool nameAsHtml = !n->nameAsHtml.isEmpty();
559 QCString result = nameAsHtml ? n->nameAsHtml : n->name;
560 QCString link = convertToJSString(result,nameAsHtml);
561 if (n->file.isEmpty()) // no link
562 {
563 t << "\"" << link << "\", null, ";
564 }
565 else // link into other page
566 {
567 if (Config_getBool(HIDE_SCOPE_NAMES)) result=stripScope(result);
568 t << "\"" << link << "\", \"";
569 t << externalRef("",n->ref,TRUE);
570 t << node2URL(n);
571 t << "\", ";
572 }
573}
574
576{
577 QCString varId = fileId;
578 int i=varId.findRev('/');
579 if (i>=0) varId = varId.mid(i+1);
580 return substitute(varId,"-","_");
581}
582
583
585{
586 JSTreeFile(const QCString &fi,const FTVNodePtr &n) : fileId(fi), node(n) {}
589};
590
591using JSTreeFiles = std::vector<JSTreeFile>;
592
593static void collectJSTreeFiles(const FTVNodes &nl,JSTreeFiles &files)
594{
595 QCString htmlOutput = Config_getString(HTML_OUTPUT);
596 for (const auto &n : nl)
597 {
598 if (n->separateIndex) // add new file if there are children
599 {
600 if (!n->children.empty())
601 {
602 QCString fileId = n->file;
603 files.emplace_back(fileId,n);
604 collectJSTreeFiles(n->children,files);
605 }
606 }
607 else // traverse without adding a new file
608 {
609 collectJSTreeFiles(n->children,files);
610 }
611 }
612}
613
614static std::mutex g_navIndexMutex;
615
617 const FTVNodes &nl,int level,bool &first)
618{
619 QCString htmlOutput = Config_getString(HTML_OUTPUT);
620 QCString indentStr;
621 indentStr.fill(' ',level*2);
622
623 bool found=FALSE;
624 for (const auto &n : nl)
625 {
626 // terminate previous entry
627 if (!first) t << ",\n";
628 first=FALSE;
629
630 // start entry
631 if (!found)
632 {
633 t << "[\n";
634 }
635 found=TRUE;
636
637 if (n->addToNavIndex) // add entry to the navigation index
638 {
639 std::lock_guard lock(g_navIndexMutex);
640 if (n->def && n->def->definitionType()==Definition::TypeFile)
641 {
642 const FileDef *fd = toFileDef(n->def);
643 bool src = false;
644 bool doc = fileVisibleInIndex(fd,src);
645 if (doc)
646 {
647 navIndex.emplace_back(node2URL(n,TRUE,FALSE),pathToNode(n,n));
648 }
649 if (src)
650 {
651 navIndex.emplace_back(node2URL(n,TRUE,TRUE),pathToNode(n,n));
652 }
653 }
654 else
655 {
656 navIndex.emplace_back(node2URL(n),pathToNode(n,n));
657 }
658 }
659
660 if (n->separateIndex) // store items in a separate file for dynamic loading
661 {
662 t << indentStr << " [ ";
663 generateJSLink(t,n);
664 if (!n->children.empty()) // write children to separate file for dynamic loading
665 {
666 QCString fileId = n->file;
667 if (!n->anchor.isEmpty())
668 {
669 fileId+="_"+n->anchor;
670 }
671 if (dupOfParent(n))
672 {
673 fileId+="_dup";
674 }
675 t << "\"" << fileId << "\" ]";
676 }
677 else // no children
678 {
679 t << "null ]";
680 }
681 }
682 else // show items in this file
683 {
684 bool firstChild=TRUE;
685 t << indentStr << " [ ";
686 generateJSLink(t,n);
687 bool emptySection = !generateJSTree(navIndex,t,n->children,level+1,firstChild);
688 if (emptySection)
689 t << "null ]";
690 else
691 t << "\n" << indentStr << " ] ]";
692 }
693 }
694 return found;
695}
696
697static void generateJSTreeFiles(NavIndexEntryList &navIndex,TextStream &t,const FTVNodes &nodeList)
698{
699 QCString htmlOutput = Config_getString(HTML_OUTPUT);
700
701 auto getVarName = [](const FTVNodePtr n)
702 {
703 QCString fileId = n->file;
704 if (!n->anchor.isEmpty()) fileId+="_"+n->anchor;
705 if (dupOfParent(n)) fileId+="_dup";
706 return fileId;
707 };
708
709 auto generateJSFile = [&](const JSTreeFile &tf)
710 {
711 QCString fileId = getVarName(tf.node);
712 QCString fileName = htmlOutput+"/"+fileId+".js";
713 std::ofstream ff = Portable::openOutputStream(fileName);
714 if (ff.is_open())
715 {
716 bool firstChild = true;
717 TextStream tt(&ff);
718 tt << "var " << convertFileId2Var(fileId) << " =\n";
719 generateJSTree(navIndex,tt,tf.node->children,1,firstChild);
720 tt << "\n];";
721 }
722 };
723
724 JSTreeFiles jsTreeFiles;
725 collectJSTreeFiles(nodeList,jsTreeFiles);
726
727 std::size_t numThreads = static_cast<std::size_t>(Config_getInt(NUM_PROC_THREADS));
728 if (numThreads>1) // multi threaded version
729 {
730 ThreadPool threadPool(numThreads);
731 std::vector< std::future<void> > results;
732 for (const auto &tf : jsTreeFiles)
733 {
734 results.emplace_back(threadPool.queue([&](){ generateJSFile(tf); }));
735 }
736 // wait for the results
737 for (auto &f : results) f.get();
738 }
739 else // single threaded version
740 {
741 for (const auto &tf : jsTreeFiles)
742 {
743 generateJSFile(tf);
744 }
745 }
746}
747
748static void generateJSNavTree(const FTVNodes &nodeList)
749{
750 QCString htmlOutput = Config_getString(HTML_OUTPUT);
751 std::ofstream f = Portable::openOutputStream(htmlOutput+"/navtreedata.js");
752 NavIndexEntryList navIndex;
753 if (f.is_open())
754 {
755 TextStream t(&f);
756 //TextStream tidx(&fidx);
757 //tidx << "var NAVTREEINDEX =\n";
758 //tidx << "{\n";
760 t << "var NAVTREE =\n";
761 t << "[\n";
762 t << " [ ";
763 QCString projName = Config_getString(PROJECT_NAME);
764 if (projName.isEmpty())
765 {
766 if (mainPageHasTitle()) // Use title of main page as root
767 {
768 t << "\"" << convertToJSString(Doxygen::mainPage->title()) << "\", ";
769 }
770 else // Use default section title as root
771 {
772 LayoutNavEntry *lne = LayoutDocManager::instance().rootNavEntry()->find(LayoutNavEntry::MainPage);
773 t << "\"" << convertToJSString(lne->title()) << "\", ";
774 }
775 }
776 else // use PROJECT_NAME as root tree element
777 {
778 t << "\"" << convertToJSString(projName) << "\", ";
779 }
780 t << "\"index" << Doxygen::htmlFileExtension << "\", ";
781
782 // add special entry for index page
783 navIndex.emplace_back("index"+Doxygen::htmlFileExtension,"");
784 // related page index is written as a child of index.html, so add this as well
785 navIndex.emplace_back("pages"+Doxygen::htmlFileExtension,"");
786
787 bool first=TRUE;
788 generateJSTree(navIndex,t,nodeList,1,first);
789 generateJSTreeFiles(navIndex,t,nodeList);
790
791 if (first)
792 t << "]\n";
793 else
794 t << "\n ] ]\n";
795 t << "];\n\n";
796
797 // write the navigation index (and sub-indices)
798 std::stable_sort(navIndex.begin(),navIndex.end(),[](const auto &n1,const auto &n2)
799 { return !n1.url.isEmpty() && (n2.url.isEmpty() || (n1.url<n2.url)); });
800
801 int subIndex=0;
802 int elemCount=0;
803 const int maxElemCount=250;
804 std::ofstream tsidx = Portable::openOutputStream(htmlOutput+"/navtreeindex0.js");
805 if (tsidx.is_open())
806 {
807 t << "var NAVTREEINDEX =\n";
808 t << "[\n";
809 tsidx << "var NAVTREEINDEX" << subIndex << " =\n";
810 tsidx << "{\n";
811 first=TRUE;
812 auto it = navIndex.begin();
813 while (it!=navIndex.end())
814 {
815 const NavIndexEntry &e = *it;
816 if (elemCount==0)
817 {
818 if (!first)
819 {
820 t << ",\n";
821 }
822 else
823 {
824 first=FALSE;
825 }
826 t << "\"" << e.url << "\"";
827 }
828 tsidx << "\"" << e.url << "\":[" << e.path << "]";
829 ++it;
830 if (it!=navIndex.end() && elemCount<maxElemCount-1) tsidx << ","; // not last entry
831 tsidx << "\n";
832
833 elemCount++;
834 if (it!=navIndex.end() && elemCount>=maxElemCount) // switch to new sub-index
835 {
836 tsidx << "};\n";
837 elemCount=0;
838 tsidx.close();
839 subIndex++;
840 QCString fileName = htmlOutput+"/navtreeindex"+QCString().setNum(subIndex)+".js";
841 tsidx = Portable::openOutputStream(fileName);
842 if (!tsidx.is_open()) break;
843 tsidx << "var NAVTREEINDEX" << subIndex << " =\n";
844 tsidx << "{\n";
845 }
846 }
847 tsidx << "};\n";
848 t << "\n];\n";
849 }
850 t << "\nconst SYNCONMSG = '" << theTranslator->trPanelSynchronisationTooltip(FALSE) << "';";
851 t << "\nconst SYNCOFFMSG = '" << theTranslator->trPanelSynchronisationTooltip(TRUE) << "';";
852 t << "\nconst LISTOFALLMEMBERS = '" << theTranslator->trListOfAllMembers() << "';";
853 }
854
855 auto &mgr = ResourceMgr::instance();
856 {
857 std::ofstream fn = Portable::openOutputStream(htmlOutput+"/navtree.js");
858 if (fn.is_open())
859 {
860 TextStream t(&fn);
861 t << substitute(
862 substitute(mgr.getAsString("navtree.js"),
863 "$TREEVIEW_WIDTH", QCString().setNum(Config_getInt(TREEVIEW_WIDTH))),
864 "$PROJECTID",getProjectId());
865 }
866 }
867}
868
869//-----------------------------------------------------------
870
871// new style scripts
873{
874 QCString htmlOutput = Config_getString(HTML_OUTPUT);
875
876 // generate navtree.js & navtreeindex.js
877 generateJSNavTree(p->indentNodes[0]);
878}
879
880// write tree inside page
882{
883 bool dynamicSections = Config_getBool(HTML_DYNAMIC_SECTIONS);
884 int preferredNumEntries = Config_getInt(HTML_INDEX_NUM_ENTRIES);
885 t << "<div class=\"directory\">\n";
886 int d=1, depth=1;
887 for (const auto &n : p->indentNodes[0])
888 {
889 if (!n->children.empty())
890 {
891 d = n->computeTreeDepth(2);
892 if (d>depth) depth=d;
893 }
894 }
895 int preferredDepth = depth;
896 // write level selector
897 if (depth>1)
898 {
899 if (dynamicSections)
900 {
901 t << "<div class=\"levels\">[";
902 t << theTranslator->trDetailLevel();
903 t << " ";
904 for (int i=1;i<=depth;i++)
905 {
906 t << "<span onclick=\"javascript:dynsection.toggleLevel(" << i << ");\">" << i << "</span>";
907 }
908 t << "]</div>";
909 }
910
911 if (preferredNumEntries>0)
912 {
913 preferredDepth=1;
914 for (int i=1;i<=depth;i++)
915 {
916 int num=0;
917 for (const auto &n : p->indentNodes[0])
918 {
919 num+=n->numNodesAtLevel(0,i);
920 }
921 if (num<=preferredNumEntries)
922 {
923 preferredDepth=i;
924 }
925 else
926 {
927 break;
928 }
929 }
930 }
931 }
932 //printf("preferred depth=%d\n",preferredDepth);
933
934 if (!p->indentNodes[0].empty())
935 {
936 t << "<table class=\"directory\">\n";
937 int index=0;
938 p->generateTree(t,p->indentNodes[0],0,preferredDepth,index);
939 t << "</table>\n";
940 }
941
942 t << "</div><!-- directory -->\n";
943}
944
945// write old style index.html and tree.html
A abstract class representing of a compound symbol.
Definition classdef.h:104
@ Interface
Definition classdef.h:112
@ Exception
Definition classdef.h:115
virtual CompoundType compoundType() const =0
Returns the type of compound this is, i.e.
The common base class of all entity definitions found in the sources.
Definition definition.h:77
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
virtual int briefLine() const =0
virtual QCString briefDescription(bool abbreviate=FALSE) const =0
virtual QCString getSourceFileBase() const =0
virtual QCString briefFile() const =0
virtual QCString getOutputFileBase() const =0
Class representing the abstract syntax tree of a documentation block.
Definition docnode.h:1463
DocNodeVariant root
Definition docnode.h:1488
static std::unique_ptr< PageDef > mainPage
Definition doxygen.h:100
static QCString htmlFileExtension
Definition doxygen.h:121
std::unique_ptr< Private > p
Definition ftvhelp.h:69
void generateTreeView()
Definition ftvhelp.cpp:946
void decContentsDepth()
Definition ftvhelp.cpp:154
void finalize()
Definition ftvhelp.cpp:134
void initialize()
Definition ftvhelp.cpp:126
FTVHelp(bool LTI)
Definition ftvhelp.cpp:120
void incContentsDepth()
Definition ftvhelp.cpp:143
void addContentsItem(bool isDir, const QCString &name, const QCString &ref, const QCString &file, const QCString &anchor, bool separateIndex, bool addToNavIndex, const Definition *def, const QCString &nameAsHtml=QCString())
Definition ftvhelp.cpp:186
void generateTreeViewScripts()
Definition ftvhelp.cpp:872
void generateTreeViewInline(TextStream &t)
Definition ftvhelp.cpp:881
A model of a file symbol.
Definition filedef.h:99
Generator for HTML code fragments.
Definition htmlgen.h:26
Concrete visitor implementation for HTML output.
static LayoutDocManager & instance()
Returns a reference to this singleton.
Definition layout.cpp:1437
LayoutNavEntry * rootNavEntry() const
returns the (invisible) root of the navigation tree.
Definition layout.cpp:1448
Definition ftvhelp.cpp:532
Class representing a list of different code generators.
Definition outputlist.h:165
void add(OutputCodeIntfPtr &&p)
Definition outputlist.h:195
This is an alternative implementation of QCString.
Definition qcstring.h:101
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:241
char & at(size_t i)
Returns a reference to the character at index i.
Definition qcstring.h:593
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
QCString fill(char c, int len=-1)
Fills a string with a predefined character.
Definition qcstring.h:193
QCString & setNum(short n)
Definition qcstring.h:459
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition qcstring.cpp:96
static ResourceMgr & instance()
Returns the one and only instance of this class.
Text streaming class that buffers data.
Definition textstream.h:36
Class managing a pool of worker threads.
Definition threadpool.h:48
auto queue(F &&f, Args &&... args) -> std::future< decltype(f(args...))>
Queue the callable function f for the threads to execute.
Definition threadpool.h:77
ClassDef * toClassDef(Definition *d)
#define Config_getInt(name)
Definition config.h:34
#define Config_getBool(name)
Definition config.h:33
#define Config_getString(name)
Definition config.h:32
constexpr DocNodeVariant * parent(DocNodeVariant *n)
returns the parent node of a given node n or nullptr if the node has no parent.
Definition docnode.h:1327
IDocNodeASTPtr validatingParseDoc(IDocParser &parserIntf, const QCString &fileName, int startLine, const Definition *ctx, const MemberDef *md, const QCString &input, const DocOptions &options)
IDocParserPtr createDocParser()
factory function to create a parser
Definition docparser.cpp:55
FileDef * toFileDef(Definition *d)
Definition filedef.cpp:1966
static void generateLink(yyscan_t yyscanner, OutputCodeList &ol, const QCString &lname)
static bool dupOfParent(const FTVNodePtr &n)
Definition ftvhelp.cpp:548
static bool generateJSTree(NavIndexEntryList &navIndex, TextStream &t, const FTVNodes &nl, int level, bool &first)
Definition ftvhelp.cpp:616
static int folderId
Definition ftvhelp.cpp:43
static void generateJSLink(TextStream &t, const FTVNodePtr &n)
Definition ftvhelp.cpp:556
static QCString node2URL(const FTVNodePtr &n, bool overruleFile=FALSE, bool srcLink=FALSE)
Definition ftvhelp.cpp:216
static void generateBriefDoc(TextStream &t, const Definition *def)
Definition ftvhelp.cpp:330
static void collectJSTreeFiles(const FTVNodes &nl, JSTreeFiles &files)
Definition ftvhelp.cpp:593
static char compoundIcon(const ClassDef *cd)
Definition ftvhelp.cpp:359
static std::mutex g_navIndexMutex
Definition ftvhelp.cpp:614
static QCString pathToNode(const FTVNodePtr &leaf, const FTVNodePtr &n)
Definition ftvhelp.cpp:535
std::vector< FTVNodePtr > FTVNodes
Definition ftvhelp.cpp:49
std::weak_ptr< FTVNode > FTVNodeWeakPtr
Definition ftvhelp.cpp:48
static void generateIndent(TextStream &t, const FTVNodePtr &n, bool opened)
Definition ftvhelp.cpp:260
std::shared_ptr< FTVNode > FTVNodePtr
Definition ftvhelp.cpp:47
static void generateJSTreeFiles(NavIndexEntryList &navIndex, TextStream &t, const FTVNodes &nodeList)
Definition ftvhelp.cpp:697
std::vector< JSTreeFile > JSTreeFiles
Definition ftvhelp.cpp:591
static void generateJSNavTree(const FTVNodes &nodeList)
Definition ftvhelp.cpp:748
static QCString convertFileId2Var(const QCString &fileId)
Definition ftvhelp.cpp:575
static QCString generateIndentLabel(const FTVNodePtr &n, int level)
Definition ftvhelp.cpp:248
constexpr auto JAVASCRIPT_LICENSE_TEXT
Definition ftvhelp.h:72
Translator * theTranslator
Definition language.cpp:71
std::ofstream openOutputStream(const QCString &name, bool append=false)
Definition portable.cpp:648
Portable versions of functions that are platform dependent.
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:571
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34
#define ASSERT(x)
Definition qcstring.h:39
void generateTree(TextStream &t, const FTVNodes &nl, int level, int maxLevel, int &index)
Definition ftvhelp.cpp:380
void generateLink(TextStream &t, const FTVNodePtr &n)
Definition ftvhelp.cpp:283
std::vector< FTVNodes > indentNodes
Definition ftvhelp.cpp:108
Private(bool TLI)
Definition ftvhelp.cpp:107
FTVNode(bool dir, const QCString &r, const QCString &f, const QCString &a, const QCString &n, bool sepIndex, bool navIndex, const Definition *df, const QCString &nameAsHtml_)
Definition ftvhelp.cpp:53
bool separateIndex
Definition ftvhelp.cpp:70
bool isLast
Definition ftvhelp.cpp:60
const Definition * def
Definition ftvhelp.cpp:72
bool addToNavIndex
Definition ftvhelp.cpp:71
FTVNodeWeakPtr parent
Definition ftvhelp.cpp:69
FTVNodes children
Definition ftvhelp.cpp:68
QCString ref
Definition ftvhelp.cpp:62
int numNodesAtLevel(int level, int maxLevel) const
Definition ftvhelp.cpp:89
QCString anchor
Definition ftvhelp.cpp:64
QCString file
Definition ftvhelp.cpp:63
int computeTreeDepth(int level) const
Definition ftvhelp.cpp:75
QCString name
Definition ftvhelp.cpp:65
bool isDir
Definition ftvhelp.cpp:61
int index
Definition ftvhelp.cpp:67
QCString nameAsHtml
Definition ftvhelp.cpp:66
JSTreeFile(const QCString &fi, const FTVNodePtr &n)
Definition ftvhelp.cpp:586
FTVNodePtr node
Definition ftvhelp.cpp:588
QCString fileId
Definition ftvhelp.cpp:587
Base class for the layout of a navigation item at the top of the HTML pages.
Definition layout.h:156
QCString title() const
Definition layout.h:216
LayoutNavEntry * find(LayoutNavEntry::Kind k, const QCString &file=QCString()) const
Definition layout.cpp:133
Definition ftvhelp.cpp:525
QCString url
Definition ftvhelp.cpp:527
QCString path
Definition ftvhelp.cpp:528
NavIndexEntry(const QCString &u, const QCString &p)
Definition ftvhelp.cpp:526
QCString externalRef(const QCString &relPath, const QCString &ref, bool href)
Definition util.cpp:5755
QCString convertToJSString(const QCString &s, bool keepEntities, bool singleQuotes)
Definition util.cpp:4006
bool mainPageHasTitle()
Definition util.cpp:6286
QCString convertToHtml(const QCString &s, bool keepEntities)
Definition util.cpp:3946
QCString relativePathToRoot(const QCString &name)
Definition util.cpp:3562
bool fileVisibleInIndex(const FileDef *fd, bool &genSourceFile)
Definition util.cpp:6091
QCString stripScope(const QCString &name)
Definition util.cpp:3762
QCString getProjectId()
Definition util.cpp:6813
QCString externalLinkTarget(const bool parent)
Definition util.cpp:5707
void addHtmlExtensionIfMissing(QCString &fName)
Definition util.cpp:4904
A bunch of utility functions.