Permalink
Browse files

Added mainpage to context and improved page tree

  • Loading branch information...
Dimitri van Heesch
Dimitri van Heesch committed May 11, 2014
1 parent 963e0ad commit 2e837e0be05636923ef593c29299ff76c4590a09
Showing with 130 additions and 34 deletions.
  1. +117 −22 src/context.cpp
  2. +3 −2 src/context.h
  3. +0 −10 src/index.cpp
  4. +8 −0 src/util.cpp
  5. +2 −0 src/util.h
@@ -2590,32 +2590,48 @@ 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);
addProperty("subhighlight",this,&Private::subHighlight);
}
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);
@@ -309,15 +309,15 @@ 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;
virtual int addRef() { return RefCountedContext::addRef(); }
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);
@@ -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);
@@ -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;
}
@@ -456,5 +456,7 @@ void convertProtectionLevel(
int *outListType2
);
bool mainPageHasTitle();
#endif

0 comments on commit 2e837e0

Please sign in to comment.