Peter Suter avatar Peter Suter committed d024c37

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

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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.