Index: quintagroup.dropdownmenu/trunk/quintagroup/dropdownmenu/browser/viewlets.py
===================================================================
--- quintagroup.dropdownmenu/trunk/quintagroup/dropdownmenu/browser/viewlets.py	(revision 2712)
+++ quintagroup.dropdownmenu/trunk/quintagroup/dropdownmenu/browser/viewlets.py	(revision 2768)
@@ -25,4 +25,5 @@
     recurse = ViewPageTemplateFile('templates/sections_recurse.pt')
 
+
     def update(self):
         # we may need some previously defined variables
@@ -37,4 +38,7 @@
         self.context_state = getMultiAdapter((self.context, self.request), 
                                               name="plone_context_state")
+        self.context_url =  self.context_state.is_default_page() and \
+            '/'.join(self.context.absolute_url().split('/')[:-1]) or \
+            self.context.absolute_url()
 
         # fetch actions-based tabs?
@@ -63,17 +67,28 @@
             return []
 
-        #category_ids = category.objectIds()
-        #selectedTabs = self.context.restrictedTraverse('selectedTabs')
-        ## try to find out selected subtab
-        #if tab['id'] == self.selected_portal_tab:
-            #selection = selectedTabs(None, None, tab['subtabs'])
-            #self.selected_sub_tab = selection['portal']
-        return self._subactions(tool._getOb(conf.actions_category), context)
-
-    def _subactions(self, category, object, level=0):
+        self.chain = []  #save not traversable chain here
+        self.tchain = []  #save the best traversable chain here
+        self.res, c = self._subactions(tool._getOb(conf.actions_category), context, 0, self.chain)
+        self.tchain.reverse()
+        self.chain.reverse()
+        self.chain = self.chain and self.chain or self.tchain
+        self._activate(self.res)
+        return self.res
+    
+    def _activate(self, res, level=0):
+        """Mark selected chain in the tabs dictionary"""
+        if self.chain and len(self.chain) > level:
+            res[self.chain[level]]['currentItem'] = True
+            res[self.chain[level]]['currentParent'] = True
+            if level + 1 < len(self.chain):
+                self._activate(res[self.chain[level]]['children'], level+1)
+
+
+    def _subactions(self, category, object, level=0, lchain=[]):
+        """Build tabs dictionary out of portal actions"""
         tabs = []
         currentParentId = -1
         index = -1
-        currentParent = False
+        local = False      
         for info in self._actionInfos(category, object):
             # prepare data for action
@@ -81,9 +96,18 @@
             #       done on a template level because of separate content and
             #       actions tabs are rendered separately
-            currentItem = False
 
             index += 1
             icon = info['icon'] and '<img src="%s" />' % info['icon'] or ''
-
+    
+            if  self.context_url.startswith(info['url']) and info['url'] != self.site_url:
+                if currentParentId > -1:
+                    if len(tabs[currentParentId]['getURL']) < len(info['url']): 
+                        currentParentId = index
+                else:
+                    currentParentId = index
+            if  self.context_url == info['url']:
+                lchain.append(index)
+                local = True
+                
             # look up children for a given action
             children = []
@@ -100,17 +124,8 @@
                     subcat = category._getOb(subcat_id)
                     if IActionCategory.providedBy(subcat):
-                        children = self._subactions(subcat, object, level+1)
-
-            url = self.context_state.is_default_page() and \
-                  '/'.join(self.context.absolute_url().split('/')[:-1]) or \
-                  self.context.absolute_url()
-            if url.startswith(info['url']) and info['url'] != self.site_url:
-                if currentParentId > -1:
-                    if len(tabs[currentParentId]['getURL']) < len(info['url']): 
-                        currentParentId = index
-                else:
-                    currentParentId = index
-            if url == info['url']:
-                currentItem = True
+                        children, local = self._subactions(subcat, object, level+1, lchain)
+                        if local:
+                            lchain.append(index)
+            
             # make up final tab dictionary
             tab = {'Title': info['title'],
@@ -119,12 +134,13 @@
                    'show_children': len(children) > 0,
                    'children': children,
-                   'currentItem': currentItem,
-                   'currentParent': currentParent,
+                   'currentItem': False, 
+                   'currentParent': False,
                    'item_icon': {'html_tag': icon},
                    'normalized_review_state': 'visible'}
             tabs.append(tab)
+
         if currentParentId > -1:
-            tabs[currentParentId]['currentParent'] = True
-        return tabs
+            self.tchain.append(currentParentId)
+        return tabs, local
 
     def _actionInfos(self, category, object, check_visibility=1,
