Commits

Gary Kramlich  committed 497cdab

hide the "API Reference" link if no books have been added
only show the context link (for other books) if theres more than 1 book added

  • Participants
  • Parent commits 88fab6d

Comments (0)

Files changed (1)

File trac/gtkdoc/tracgtkdoc/core.py

 from trac.core import *
 from trac.util.html import html
 from trac.web import IRequestHandler
-from trac.web.chrome import INavigationContributor, ITemplateProvider, add_stylesheet, add_script
+from trac.web.chrome import INavigationContributor, ITemplateProvider, add_stylesheet, \
+                            add_script, add_ctxtnav
 from trac.perm import IPermissionRequestor
 
 import os
 import re
+import urllib
 
 class GtkDocPlugin(Component):
     implements(INavigationContributor, IRequestHandler, ITemplateProvider, IPermissionRequestor)
 
+    def _books(self):
+        books = {}
+
+        if 'gtkdoc' in self.config:
+            for book, path in self.config['gtkdoc'].options():
+                if 'default' in book:
+                    continue
+
+                books[book] = path
+
+        return books
+
     # INavigationContributor methods
     def get_active_navigation_item(self, req):
         return 'gtkdoc'
 
     def get_navigation_items(self, req):
-        yield('mainnav', 'gtkdoc', html.a('API Reference', href=req.href.gtkdoc()))
+        if len(self._books()) > 0:
+            yield('mainnav', 'gtkdoc', html.a('API Reference', href=req.href.gtkdoc()))
 
     # IRequestHandler
     def match_request(self, req):
         path = self.config.get('gtkdoc', book)
         real_path = page and os.path.join(path, page) or path
 
-        add_script(req, 'tracgtkdoc/js/gtkdoc.js')
-
         req.send_file(real_path)
 
     def _process_wrapper(self, req):
         add_stylesheet(req, 'tracgtkdoc/css/gtkdoc.css')
         add_script(req, 'tracgtkdoc/js/autoHeight.js')
 
+        books = self._books()
+        if len(books) > 1:
+            for book in books.keys():
+                url = '%s/%s' % (req.href.gtkdoc(), book)
+                add_ctxtnav(req, book, urllib.quote(url))
+
         return 'gtkdoc-wrapper.html', data, None
 
     def process_request(self, req):