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