Index: /trac-plugins/navaddplugin/setup.py =================================================================== --- /trac-plugins/navaddplugin/setup.py (revision 172) +++ /trac-plugins/navaddplugin/setup.py (revision 172) @@ -0,0 +1,13 @@ +from setuptools import setup + +setup(name='NavAdd', + version='0.1', + packages=['navadd'], + entry_points = {'trac.plugins': ['navadd = navadd']}, + package_data={'navadd' : ['templates/*.cs', 'htdocs/js/*.js', 'htdocs/css/*.css']}, + author = 'Michael Renzmann', + author_email = 'mrenzmann@otaku42.de', + description = 'A plugin for adding navigation items into one of the navigation bars.', + license = 'BSD', + keywords = 'trac navigation main meta', + url = 'http://trac-hacks.org/wiki/NavAddPlugin') Index: /trac-plugins/navaddplugin/navadd/navadd.py =================================================================== --- /trac-plugins/navaddplugin/navadd/navadd.py (revision 172) +++ /trac-plugins/navaddplugin/navadd/navadd.py (revision 172) @@ -0,0 +1,51 @@ +from trac.core import * +from trac.web.chrome import INavigationContributor, ITemplateProvider +from trac.util import Markup +from trac.web.href import Href +from trac.ticket.report import ReportModule + +class NavAdd(Component): + """ Allows to add items to main and meta navigation bar""" + implements(INavigationContributor) + + nav_contributors = ExtensionPoint(INavigationContributor) + + # INavigationContributor methods + def get_active_navigation_item(self, req): + return '' + + def get_navigation_items(self, req): + add = self.env.config.get('navadd', 'add_items', ''). \ + replace(',', ' ').split() + + items = [] + for a in add: + title = self.env.config.get('navadd', '%s.title' % a) + url = self.env.config.get('navadd', '%s.url' % a) + perm = self.env.config.get('navadd', '%s.perm' % a) + target = self.env.config.get('navadd', '%s.target' % a) + + if url == '/report': + url = self.get_first_report_url() + + if perm and not req.perm.has_permission(perm): + continue + + if target not in ('mainnav', 'metanav'): + target = 'mainnav' + + # the conditional below was added to make sure that we got the correct links in our multi-trac setup + if url.startswith('/'): + url = req.href.wiki().replace('/wiki', '') + url + + items.append((target, a, Markup('%s' % (url, title)))) + + return items + + # The following method makes sure that we always get the first report for a given trac instance + def get_first_report_url(self): + db = self.env.get_db_cnx() + cursor = db.cursor() + cursor.execute('SELECT id AS report FROM report ORDER BY report LIMIT 1') + row = cursor.fetchone() + return '/report/' + str(row[0]); Index: /trac-plugins/navaddplugin/navadd/__init__.py =================================================================== --- /trac-plugins/navaddplugin/navadd/__init__.py (revision 172) +++ /trac-plugins/navaddplugin/navadd/__init__.py (revision 172) @@ -0,0 +1,1 @@ +from navadd import *