Commit 2e837e0b authored by Dimitri van Heesch's avatar Dimitri van Heesch

Added mainpage to context and improved page tree

parent 963e0adf
...@@ -2590,7 +2590,8 @@ TemplateVariant DirContext::get(const char *n) const ...@@ -2590,7 +2590,8 @@ TemplateVariant DirContext::get(const char *n) const
class PageContext::Private : public DefinitionContext<PageContext::Private> class PageContext::Private : public DefinitionContext<PageContext::Private>
{ {
public: 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("title",this,&Private::title);
addProperty("highlight",this,&Private::highlight); addProperty("highlight",this,&Private::highlight);
...@@ -2598,24 +2599,39 @@ class PageContext::Private : public DefinitionContext<PageContext::Private> ...@@ -2598,24 +2599,39 @@ class PageContext::Private : public DefinitionContext<PageContext::Private>
} }
TemplateVariant title() const 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 TemplateVariant highlight() const
{ {
return TemplateVariant("pages"); return "pages";
} }
TemplateVariant subHighlight() const TemplateVariant subHighlight() const
{ {
return TemplateVariant(""); return "";
} }
private: private:
PageDef *m_pageDef; 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() PageContext::~PageContext()
...@@ -4240,6 +4256,8 @@ class NestingNodeContext::Private : public PropertyMapper ...@@ -4240,6 +4256,8 @@ class NestingNodeContext::Private : public PropertyMapper
addProperty("file",this,&Private::getFile); addProperty("file",this,&Private::getFile);
//%% [optional] Dir dir: directory info (if this node represents a directory) //%% [optional] Dir dir: directory info (if this node represents a directory)
addProperty("dir",this,&Private::getDir); addProperty("dir",this,&Private::getDir);
//%% [optional] Page page: page info (if this node represents a page)
addProperty("page",this,&Private::getPage);
//%% int id //%% int id
addProperty("id",this,&Private::id); addProperty("id",this,&Private::id);
//%% string level //%% string level
...@@ -4256,6 +4274,7 @@ class NestingNodeContext::Private : public PropertyMapper ...@@ -4256,6 +4274,7 @@ class NestingNodeContext::Private : public PropertyMapper
addNamespaces(addCls); addNamespaces(addCls);
addClasses(); addClasses();
addDirFiles(); addDirFiles();
addPages();
} }
TemplateVariant isLeafNode() const TemplateVariant isLeafNode() const
{ {
...@@ -4325,6 +4344,21 @@ class NestingNodeContext::Private : public PropertyMapper ...@@ -4325,6 +4344,21 @@ class NestingNodeContext::Private : public PropertyMapper
return TemplateVariant(FALSE); 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 TemplateVariant level() const
{ {
return m_level; return m_level;
...@@ -4406,6 +4440,14 @@ class NestingNodeContext::Private : public PropertyMapper ...@@ -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: private:
const NestingNodeContext *m_parent; const NestingNodeContext *m_parent;
Definition *m_def; Definition *m_def;
...@@ -4418,6 +4460,7 @@ class NestingNodeContext::Private : public PropertyMapper ...@@ -4418,6 +4460,7 @@ class NestingNodeContext::Private : public PropertyMapper
SharedPtr<NamespaceContext> namespaceContext; SharedPtr<NamespaceContext> namespaceContext;
SharedPtr<DirContext> dirContext; SharedPtr<DirContext> dirContext;
SharedPtr<FileContext> fileContext; SharedPtr<FileContext> fileContext;
SharedPtr<PageContext> pageContext;
ScopedPtr<TemplateVariant> brief; ScopedPtr<TemplateVariant> brief;
}; };
mutable Cachable m_cache; mutable Cachable m_cache;
...@@ -4554,6 +4597,21 @@ class NestingContext::Private : public GenericNodeListContext ...@@ -4554,6 +4597,21 @@ class NestingContext::Private : public GenericNodeListContext
m_index++; 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: private:
const NestingNodeContext *m_parent; const NestingNodeContext *m_parent;
int m_level; int m_level;
...@@ -4616,6 +4674,10 @@ void NestingContext::addFiles(const FileList &files) ...@@ -4616,6 +4674,10 @@ void NestingContext::addFiles(const FileList &files)
p->addFiles(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 ...@@ -5247,6 +5309,7 @@ class PageNodeListContext::Private : public GenericNodeListContext
public: public:
void addPages(const PageSDict &pages,bool rootOnly) void addPages(const PageSDict &pages,bool rootOnly)
{ {
//printf("** PageNodeListContext::Private(%d)\n",rootOnly);
SDict<PageDef>::Iterator pli(pages); SDict<PageDef>::Iterator pli(pages);
PageDef *pd; PageDef *pd;
for (pli.toFirst();(pd=pli.current());++pli) for (pli.toFirst();(pd=pli.current());++pli)
...@@ -5299,9 +5362,28 @@ void PageNodeListContext::addPages(const PageSDict &pages,bool rootOnly) ...@@ -5299,9 +5362,28 @@ void PageNodeListContext::addPages(const PageSDict &pages,bool rootOnly)
class PageTreeContext::Private : public PropertyMapper class PageTreeContext::Private : public PropertyMapper
{ {
public: 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 TemplateVariant tree() const
{ {
return m_pageList.get(); return m_pageTree.get();
} }
TemplateVariant fileName() const TemplateVariant fileName() const
{ {
...@@ -5323,25 +5405,35 @@ class PageTreeContext::Private : public PropertyMapper ...@@ -5323,25 +5405,35 @@ class PageTreeContext::Private : public PropertyMapper
{ {
return theTranslator->trRelatedPages(); return theTranslator->trRelatedPages();
} }
Private() TemplateVariant maxDepth() const
{ {
m_pageList.reset(PageNodeListContext::alloc()); if (!m_cache.maxDepthComputed)
// Add pages
if (Doxygen::pageSDict)
{ {
m_pageList->addPages(*Doxygen::pageSDict,TRUE); m_cache.maxDepth = computeMaxDepth(m_pageTree.get());
m_cache.maxDepthComputed=TRUE;
} }
return m_cache.maxDepth;
//%% PageNodeList tree: }
addProperty("tree",this,&Private::tree); TemplateVariant preferredDepth() const
addProperty("fileName",this,&Private::fileName); {
addProperty("relPath",this,&Private::relPath); if (!m_cache.preferredDepthComputed)
addProperty("highlight",this,&Private::highlight); {
addProperty("subhighlight",this,&Private::subhighlight); m_cache.preferredDepth = computePreferredDepth(m_pageTree.get(),maxDepth().toInt());
addProperty("title",this,&Private::title); m_cache.preferredDepthComputed=TRUE;
}
return m_cache.preferredDepth;
} }
private: 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 ...@@ -5663,7 +5755,7 @@ class NavPathElemContext::Private : public PropertyMapper
{ {
text = ((const GroupDef*)m_def)->groupTitle(); 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(); text = ((const PageDef*)m_def)->title();
} }
...@@ -6859,6 +6951,7 @@ void generateOutputViaTemplate() ...@@ -6859,6 +6951,7 @@ void generateOutputViaTemplate()
SharedPtr<PageListContext> pageList (PageListContext::alloc()); SharedPtr<PageListContext> pageList (PageListContext::alloc());
SharedPtr<ModuleTreeContext> moduleTree (ModuleTreeContext::alloc()); SharedPtr<ModuleTreeContext> moduleTree (ModuleTreeContext::alloc());
SharedPtr<ExampleListContext> exampleList (ExampleListContext::alloc()); SharedPtr<ExampleListContext> exampleList (ExampleListContext::alloc());
SharedPtr<PageContext> mainPage (PageContext::alloc(Doxygen::mainPage,TRUE));
//%% Doxygen doxygen: //%% Doxygen doxygen:
ctx->set("doxygen",doxygen.get()); ctx->set("doxygen",doxygen.get());
...@@ -6891,6 +6984,8 @@ void generateOutputViaTemplate() ...@@ -6891,6 +6984,8 @@ void generateOutputViaTemplate()
ctx->set("exampleList",exampleList.get()); ctx->set("exampleList",exampleList.get());
//%% DirList dirList //%% DirList dirList
ctx->set("dirList",dirList.get()); ctx->set("dirList",dirList.get());
//%% Page mainPage
ctx->set("mainPage",mainPage.get());
// render HTML output // render HTML output
Template *tpl = e.loadByName("htmllayout.tpl",1); Template *tpl = e.loadByName("htmllayout.tpl",1);
......
...@@ -309,7 +309,7 @@ class DirContext : public RefCountedContext, public TemplateStructIntf ...@@ -309,7 +309,7 @@ class DirContext : public RefCountedContext, public TemplateStructIntf
class PageContext : public RefCountedContext, public TemplateStructIntf class PageContext : public RefCountedContext, public TemplateStructIntf
{ {
public: 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 // TemplateStructIntf methods
virtual TemplateVariant get(const char *name) const; virtual TemplateVariant get(const char *name) const;
...@@ -317,7 +317,7 @@ class PageContext : public RefCountedContext, public TemplateStructIntf ...@@ -317,7 +317,7 @@ class PageContext : public RefCountedContext, public TemplateStructIntf
virtual int release() { return RefCountedContext::release(); } virtual int release() { return RefCountedContext::release(); }
private: private:
PageContext(PageDef *); PageContext(PageDef *,bool isMainPage);
~PageContext(); ~PageContext();
class Private; class Private;
Private *p; Private *p;
...@@ -536,6 +536,7 @@ class NestingContext : public RefCountedContext, public TemplateListIntf ...@@ -536,6 +536,7 @@ class NestingContext : public RefCountedContext, public TemplateListIntf
void addDirs(const DirList &); void addDirs(const DirList &);
void addFiles(const FileNameList &); void addFiles(const FileNameList &);
void addFiles(const FileList &); void addFiles(const FileList &);
void addPages(const PageSDict &pages,bool rootOnly);
private: private:
NestingContext(const NestingNodeContext *parent,int level); NestingContext(const NestingNodeContext *parent,int level);
......
...@@ -3071,16 +3071,6 @@ static void countRelatedPages(int &docPages,int &indexPages) ...@@ -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) static void writePages(PageDef *pd,FTVHelp *ftv)
{ {
//printf("writePages()=%s pd=%p mainpage=%p\n",pd->name().data(),pd,Doxygen::mainPage); //printf("writePages()=%s pd=%p mainpage=%p\n",pd->name().data(),pd,Doxygen::mainPage);
......
...@@ -8222,3 +8222,11 @@ void convertProtectionLevel( ...@@ -8222,3 +8222,11 @@ void convertProtectionLevel(
// inListType,inProt,*outListType1,*outListType2); // 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( ...@@ -456,5 +456,7 @@ void convertProtectionLevel(
int *outListType2 int *outListType2
); );
bool mainPageHasTitle();
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment