[Zope3-checkins] CVS: Zope3/src/zope/app/publisher/browser - globalbrowsermenuservice.py:1.27

Jim Fulton cvs-admin at zope.org
Wed Dec 3 00:42:04 EST 2003


Update of /cvs-repository/Zope3/src/zope/app/publisher/browser
In directory cvs.zope.org:/tmp/cvs-serv19258/src/zope/app/publisher/browser

Modified Files:
	globalbrowsermenuservice.py 
Log Message:
Added extra data to browser menu items to accomidate the needs of
add menus.

Changed menu item data to use objects rather than tuples to store the 
data,


=== Zope3/src/zope/app/publisher/browser/globalbrowsermenuservice.py 1.26 => 1.27 ===
--- Zope3/src/zope/app/publisher/browser/globalbrowsermenuservice.py:1.26	Tue Sep 23 21:52:33 2003
+++ Zope3/src/zope/app/publisher/browser/globalbrowsermenuservice.py	Wed Dec  3 00:41:34 2003
@@ -26,8 +26,9 @@
 from zope.security.management import getSecurityManager
 from zope.app.security.permission import checkPermission
 from zope.app.component.metaconfigure import handler
-from zope.app.interfaces.publisher.browser import \
-     IBrowserMenuService, IGlobalBrowserMenuService, IBrowserMenu
+from zope.app.interfaces.publisher.browser import IBrowserMenuService
+from zope.app.interfaces.publisher.browser import IGlobalBrowserMenuService
+from zope.app.interfaces.publisher.browser import IBrowserMenu
 from zope.app.pagetemplate.engine import Engine
 from zope.app.publication.browser import PublicationTraverser
 from zope.security.proxy import ProxyFactory
@@ -55,6 +56,26 @@
         return results
 
 
+class MenuItem:
+    """Browser menu item"""
+
+    def __init__(self, action, title, description, filter, permission,
+                 extra = None):
+        self.action = action
+        self.title = title
+        self.description = description
+        self.filter = filter
+        self.permission = permission
+        self.extra = extra
+
+    def __iter__(self):
+        # for backward compatability with code that thinks items are tuples
+        yield self.action
+        yield self.title
+        yield self.description
+        yield self.filter
+        yield self.permission
+
 class BaseBrowserMenuService:
     """Global Browser Menu Service"""
 
@@ -76,18 +97,18 @@
         # stuff for figuring out the selected view
         request_url = request.getURL()
 
-        for items in self.getAllMenuItems(menu_id, object):
-            action, title, description, filter, permission = items
+        for item in self.getAllMenuItems(menu_id, object):
 
             # Make sure we don't repeat a specification for a given title
+            title = item.title
             if title in seen:
                 continue
             seen[title] = 1
 
-            if filter is not None:
+            if item.filter is not None:
 
                 try:
-                    include = filter(Engine.getContext(
+                    include = item.filter(Engine.getContext(
                         context = object,
                         nothing = None,
                         request = request,
@@ -99,6 +120,9 @@
                 if not include:
                     continue
 
+            permission = item.permission
+            action = item.action
+            
             if permission:
                 # If we have an explicit permission, check that we
                 # can access it.
@@ -138,9 +162,10 @@
 
             result.append({
                 'title': title,
-                'description': description,
+                'description': item.description,
                 'action': "%s" % action,
-                'selected': selected
+                'selected': selected,
+                'extra': item.extra,
                 })
 
             if len(result) >= max:
@@ -180,6 +205,7 @@
 
     def menuItem(self, menu_id, interface, action, title,
                  description='', filter_string=None, permission=None,
+                 extra=None,
                  ):
 
         registry = self._registry[menu_id].registry
@@ -196,7 +222,9 @@
                 checkPermission(None, permission)
 
         data = registry.get(interface) or []
-        data.append((action, title, description, filter, permission))
+        data.append(
+            MenuItem(action, title, description, filter, permission, extra)
+            )
         registry.register(interface, data)
 
 
@@ -209,9 +237,9 @@
 
 def menuItemDirective(_context, menu, for_,
                       action, title, description='', filter=None,
-                      permission=None):
+                      permission=None, extra=None):
     return menuItemsDirective(_context, menu, for_).menuItem(
-        _context, action, title, description, filter, permission)
+        _context, action, title, description, filter, permission, extra)
 
 
 class menuItemsDirective:
@@ -221,13 +249,13 @@
         self.menu = menu
 
     def menuItem(self, _context, action, title, description='',
-                 filter=None, permission=None):
+                 filter=None, permission=None, extra=None):
         _context.action(
             discriminator = ('browser:menuItem',
                              self.menu, self.interface, title),
             callable = globalBrowserMenuService.menuItem,
             args = (self.menu, self.interface,
-                    action, title, description, filter, permission),
+                    action, title, description, filter, permission, extra),
             ),
 
     def __call__(self, _context):




More information about the Zope3-Checkins mailing list