summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitri van Heesch <dimitri@stack.nl>2014-05-11 14:53:47 (GMT)
committerDimitri van Heesch <dimitri@stack.nl>2014-08-02 12:36:44 (GMT)
commit2e837e0be05636923ef593c29299ff76c4590a09 (patch)
treea766d6d1abd6e6005a4d63a1e10fcceb2d407e45
parent963e0adfd76e6a59ace5e7318f948632322b1e51 (diff)
downloadDoxygen-2e837e0be05636923ef593c29299ff76c4590a09.zip
Doxygen-2e837e0be05636923ef593c29299ff76c4590a09.tar.gz
Doxygen-2e837e0be05636923ef593c29299ff76c4590a09.tar.bz2
Added mainpage to context and improved page tree
-rw-r--r--src/context.cpp139
-rw-r--r--src/context.h5
-rw-r--r--src/index.cpp10
-rw-r--r--src/util.cpp8
-rw-r--r--src/util.h2
5 files changed, 130 insertions, 34 deletions
diff --git a/src/context.cpp b/src/context.cpp
index 9bbed6a..6f91d32 100644
--- a/src/context.cpp
+++ b/src/context.cpp
@@ -2590,7 +2590,8 @@ TemplateVariant DirContext::get(const char *n) const
class PageContext::Private : public DefinitionContext<PageContext::Private>
{
public:
- Private(PageDef *pd) : DefinitionContext<PageContext::Private>(pd) , m_pageDef(pd)
+ Private(PageDef *pd,bool isMainPage)
+ : DefinitionContext<PageContext::Private>(pd) , m_pageDef(pd), m_isMainPage(isMainPage)
{
addProperty("title",this,&Private::title);
addProperty("highlight",this,&Private::highlight);
@@ -2598,24 +2599,39 @@ class PageContext::Private : public DefinitionContext<PageContext::Private>
}
TemplateVariant title() const
{
- return TemplateVariant(m_pageDef->title());
+ if (m_isMainPage)
+ {
+ if (mainPageHasTitle())
+ {
+ return m_pageDef->title();
+ }
+ else
+ {
+ return theTranslator->trMainPage();
+ }
+ }
+ else
+ {
+ return m_pageDef->title();
+ }
}
TemplateVariant highlight() const
{
- return TemplateVariant("pages");
+ return "pages";
}
TemplateVariant subHighlight() const
{
- return TemplateVariant("");
+ return "";
}
private:
PageDef *m_pageDef;
+ bool m_isMainPage;
};
//%% }
-PageContext::PageContext(PageDef *pd) : RefCountedContext("PageContext")
+PageContext::PageContext(PageDef *pd,bool isMainPage) : RefCountedContext("PageContext")
{
- p = new Private(pd);
+ p = new Private(pd,isMainPage);
}
PageContext::~PageContext()
@@ -4240,6 +4256,8 @@ class NestingNodeContext::Private : public PropertyMapper
addProperty("file",this,&Private::getFile);
//%% [optional] Dir dir: directory info (if this node represents a directory)
addProperty("dir",this,&Private::getDir);
+ //%% [optional] Page page: page info (if this node represents a page)
+ addProperty("page",this,&Private::getPage);
//%% int id
addProperty("id",this,&Private::id);
//%% string level
@@ -4256,6 +4274,7 @@ class NestingNodeContext::Private : public PropertyMapper
addNamespaces(addCls);
addClasses();
addDirFiles();
+ addPages();
}
TemplateVariant isLeafNode() const
{
@@ -4325,6 +4344,21 @@ class NestingNodeContext::Private : public PropertyMapper
return TemplateVariant(FALSE);
}
}
+ TemplateVariant getPage() const
+ {
+ if (!m_cache.pageContext && m_def->definitionType()==Definition::TypePage)
+ {
+ m_cache.pageContext.reset(PageContext::alloc((PageDef*)m_def));
+ }
+ if (m_cache.pageContext)
+ {
+ return m_cache.pageContext.get();
+ }
+ else
+ {
+ return TemplateVariant(FALSE);
+ }
+ }
TemplateVariant level() const
{
return m_level;
@@ -4406,6 +4440,14 @@ class NestingNodeContext::Private : public PropertyMapper
}
}
}
+ void addPages()
+ {
+ PageDef *pd = m_def->definitionType()==Definition::TypePage ? (PageDef*)m_def : 0;
+ if (pd && pd->getSubPages())
+ {
+ m_children->addPages(*pd->getSubPages(),FALSE);
+ }
+ }
private:
const NestingNodeContext *m_parent;
Definition *m_def;
@@ -4418,6 +4460,7 @@ class NestingNodeContext::Private : public PropertyMapper
SharedPtr<NamespaceContext> namespaceContext;
SharedPtr<DirContext> dirContext;
SharedPtr<FileContext> fileContext;
+ SharedPtr<PageContext> pageContext;
ScopedPtr<TemplateVariant> brief;
};
mutable Cachable m_cache;
@@ -4554,6 +4597,21 @@ class NestingContext::Private : public GenericNodeListContext
m_index++;
}
}
+ void addPages(const PageSDict &pages,bool rootOnly)
+ {
+ SDict<PageDef>::Iterator pli(pages);
+ PageDef *pd;
+ for (pli.toFirst();(pd=pli.current());++pli)
+ {
+ if (!rootOnly ||
+ pd->getOuterScope()==0 ||
+ pd->getOuterScope()->definitionType()!=Definition::TypePage)
+ {
+ append(NestingNodeContext::alloc(m_parent,pd,m_index,m_level,FALSE));
+ m_index++;
+ }
+ }
+ }
private:
const NestingNodeContext *m_parent;
int m_level;
@@ -4616,6 +4674,10 @@ void NestingContext::addFiles(const FileList &files)
p->addFiles(files);
}
+void NestingContext::addPages(const PageSDict &pages,bool rootOnly)
+{
+ p->addPages(pages,rootOnly);
+}
//------------------------------------------------------------------------
@@ -5247,6 +5309,7 @@ class PageNodeListContext::Private : public GenericNodeListContext
public:
void addPages(const PageSDict &pages,bool rootOnly)
{
+ //printf("** PageNodeListContext::Private(%d)\n",rootOnly);
SDict<PageDef>::Iterator pli(pages);
PageDef *pd;
for (pli.toFirst();(pd=pli.current());++pli)
@@ -5299,9 +5362,28 @@ void PageNodeListContext::addPages(const PageSDict &pages,bool rootOnly)
class PageTreeContext::Private : public PropertyMapper
{
public:
+ Private()
+ {
+ m_pageTree.reset(NestingContext::alloc(0,0));
+ // Add pages
+ if (Doxygen::pageSDict)
+ {
+ m_pageTree->addPages(*Doxygen::pageSDict,TRUE);
+ }
+
+ //%% PageNodeList tree:
+ addProperty("tree",this,&Private::tree);
+ addProperty("fileName",this,&Private::fileName);
+ addProperty("relPath",this,&Private::relPath);
+ addProperty("highlight",this,&Private::highlight);
+ addProperty("subhighlight",this,&Private::subhighlight);
+ addProperty("title",this,&Private::title);
+ addProperty("preferredDepth",this,&Private::preferredDepth);
+ addProperty("maxDepth",this,&Private::maxDepth);
+ }
TemplateVariant tree() const
{
- return m_pageList.get();
+ return m_pageTree.get();
}
TemplateVariant fileName() const
{
@@ -5323,25 +5405,35 @@ class PageTreeContext::Private : public PropertyMapper
{
return theTranslator->trRelatedPages();
}
- Private()
+ TemplateVariant maxDepth() const
{
- m_pageList.reset(PageNodeListContext::alloc());
- // Add pages
- if (Doxygen::pageSDict)
+ if (!m_cache.maxDepthComputed)
{
- m_pageList->addPages(*Doxygen::pageSDict,TRUE);
+ m_cache.maxDepth = computeMaxDepth(m_pageTree.get());
+ m_cache.maxDepthComputed=TRUE;
}
-
- //%% PageNodeList tree:
- addProperty("tree",this,&Private::tree);
- addProperty("fileName",this,&Private::fileName);
- addProperty("relPath",this,&Private::relPath);
- addProperty("highlight",this,&Private::highlight);
- addProperty("subhighlight",this,&Private::subhighlight);
- addProperty("title",this,&Private::title);
+ return m_cache.maxDepth;
+ }
+ TemplateVariant preferredDepth() const
+ {
+ if (!m_cache.preferredDepthComputed)
+ {
+ m_cache.preferredDepth = computePreferredDepth(m_pageTree.get(),maxDepth().toInt());
+ m_cache.preferredDepthComputed=TRUE;
+ }
+ return m_cache.preferredDepth;
}
private:
- SharedPtr<PageNodeListContext> m_pageList;
+ SharedPtr<NestingContext> m_pageTree;
+ struct Cachable
+ {
+ Cachable() : maxDepthComputed(FALSE), preferredDepthComputed(FALSE) {}
+ int maxDepth;
+ bool maxDepthComputed;
+ int preferredDepth;
+ bool preferredDepthComputed;
+ };
+ mutable Cachable m_cache;
};
//%% }
@@ -5663,7 +5755,7 @@ class NavPathElemContext::Private : public PropertyMapper
{
text = ((const GroupDef*)m_def)->groupTitle();
}
- else if (type==Definition::TypePage && !(((const PageDef*)this)->title().isEmpty()))
+ else if (type==Definition::TypePage && !(((const PageDef*)m_def)->title().isEmpty()))
{
text = ((const PageDef*)m_def)->title();
}
@@ -6859,6 +6951,7 @@ void generateOutputViaTemplate()
SharedPtr<PageListContext> pageList (PageListContext::alloc());
SharedPtr<ModuleTreeContext> moduleTree (ModuleTreeContext::alloc());
SharedPtr<ExampleListContext> exampleList (ExampleListContext::alloc());
+ SharedPtr<PageContext> mainPage (PageContext::alloc(Doxygen::mainPage,TRUE));
//%% Doxygen doxygen:
ctx->set("doxygen",doxygen.get());
@@ -6891,6 +6984,8 @@ void generateOutputViaTemplate()
ctx->set("exampleList",exampleList.get());
//%% DirList dirList
ctx->set("dirList",dirList.get());
+ //%% Page mainPage
+ ctx->set("mainPage",mainPage.get());
// render HTML output
Template *tpl = e.loadByName("htmllayout.tpl",1);
diff --git a/src/context.h b/src/context.h
index 18fa519..cc42527 100644
--- a/src/context.h
+++ b/src/context.h
@@ -309,7 +309,7 @@ class DirContext : public RefCountedContext, public TemplateStructIntf
class PageContext : public RefCountedContext, public TemplateStructIntf
{
public:
- static PageContext *alloc(PageDef *pd) { return new PageContext(pd); }
+ static PageContext *alloc(PageDef *pd,bool isMainPage=FALSE) { return new PageContext(pd,isMainPage); }
// TemplateStructIntf methods
virtual TemplateVariant get(const char *name) const;
@@ -317,7 +317,7 @@ class PageContext : public RefCountedContext, public TemplateStructIntf
virtual int release() { return RefCountedContext::release(); }
private:
- PageContext(PageDef *);
+ PageContext(PageDef *,bool isMainPage);
~PageContext();
class Private;
Private *p;
@@ -536,6 +536,7 @@ class NestingContext : public RefCountedContext, public TemplateListIntf
void addDirs(const DirList &);
void addFiles(const FileNameList &);
void addFiles(const FileList &);
+ void addPages(const PageSDict &pages,bool rootOnly);
private:
NestingContext(const NestingNodeContext *parent,int level);
diff --git a/src/index.cpp b/src/index.cpp
index 4f83c6a..e6ec8be 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -3071,16 +3071,6 @@ static void countRelatedPages(int &docPages,int &indexPages)
//----------------------------------------------------------------------------
-static bool mainPageHasTitle()
-{
- if (Doxygen::mainPage==0) return FALSE;
- if (Doxygen::mainPage->title().isEmpty()) return FALSE;
- if (Doxygen::mainPage->title().lower()=="notitle") return FALSE;
- return TRUE;
-}
-
-//----------------------------------------------------------------------------
-
static void writePages(PageDef *pd,FTVHelp *ftv)
{
//printf("writePages()=%s pd=%p mainpage=%p\n",pd->name().data(),pd,Doxygen::mainPage);
diff --git a/src/util.cpp b/src/util.cpp
index 0113e62..7fff1b9 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -8222,3 +8222,11 @@ void convertProtectionLevel(
// inListType,inProt,*outListType1,*outListType2);
}
+bool mainPageHasTitle()
+{
+ if (Doxygen::mainPage==0) return FALSE;
+ if (Doxygen::mainPage->title().isEmpty()) return FALSE;
+ if (Doxygen::mainPage->title().lower()=="notitle") return FALSE;
+ return TRUE;
+}
+
diff --git a/src/util.h b/src/util.h
index c131dd0..f74fad0 100644
--- a/src/util.h
+++ b/src/util.h
@@ -456,5 +456,7 @@ void convertProtectionLevel(
int *outListType2
);
+bool mainPageHasTitle();
+
#endif