Commits

Peter Suter committed d024c37

Add "context navigation" link from /browser to /newhgrepo.

  • Participants
  • Parent commits a9fa26c

Comments (0)

Files changed (1)

hgdirmanager/hgdirmanager.py

+from genshi.builder import tag
+
 from trac.core import *
 from trac.perm import IPermissionRequestor
 from trac.util.html import html
 from trac.util.translation import _
-from trac.web import IRequestHandler, HTTPNotFound
-from trac.web.chrome import ITemplateProvider, add_warning, add_notice
+from trac.web import IRequestHandler, IRequestFilter, HTTPNotFound
+from trac.web.chrome import ITemplateProvider, add_warning, add_notice, add_ctxtnav
 from trac.versioncontrol.api import IRepositoryProvider, RepositoryManager
 
 import os, os.path
 
 class HgDirManager(Component):
     """Provides the ability to create and delete Mercurial repositories."""
-    implements(IRequestHandler, ITemplateProvider, IPermissionRequestor)
+    implements(IRequestHandler, IRequestFilter, ITemplateProvider, IPermissionRequestor)
 
     # IPermissionRequestor
     def get_permission_actions(self):
         elif req.path_info.startswith('/deletehgrepo/'):
             return self._delete_repo(req, req.path_info.split('/', 2)[2])
 
+    # IRequestFilter
+    def pre_process_request(self, req, handler):
+        if req.path_info == '/browser':
+            add_ctxtnav(req, tag.a(_('New HG Repository'), 
+                                   href=req.href.newhgrepo()))
+        return handler
+
+    def post_process_request(self, req, template, content_type):
+        return template, content_type
+
     # ITemplateProvider
     def get_templates_dirs(self):
         from pkg_resources import resource_filename