Continued implementing functionality to save expanded file and directory entries of the project browsers to the session.

Thu, 22 May 2014 18:23:29 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 22 May 2014 18:23:29 +0200
changeset 3601
236578b22511
parent 3600
7d17c492ab95
child 3602
73cad09faca9

Continued implementing functionality to save expanded file and directory entries of the project browsers to the session.

E5XML/SessionReader.py file | annotate | diff | comparison | revisions
Project/ProjectBaseBrowser.py file | annotate | diff | comparison | revisions
UI/BrowserModel.py file | annotate | diff | comparison | revisions
--- a/E5XML/SessionReader.py	Wed May 21 19:45:39 2014 +0200
+++ b/E5XML/SessionReader.py	Thu May 22 18:23:29 2014 +0200
@@ -368,9 +368,10 @@
         while not self.atEnd():
             self.readNext()
             if self.isEndElement() and self.name() == "ProjectBrowserState":
-                # TODO: implement the expand logic
-                print(browserName)
-                print(expandedNames)
+                projectBrowser = \
+                    self.projectBrowser.getProjectBrowser(browserName)
+                if projectBrowser is not None:
+                    projectBrowser.expandItemsByName(expandedNames)
                 break
             
             if self.isStartElement():
--- a/Project/ProjectBaseBrowser.py	Wed May 21 19:45:39 2014 +0200
+++ b/Project/ProjectBaseBrowser.py	Thu May 22 18:23:29 2014 +0200
@@ -572,25 +572,36 @@
         
         @return list of expanded items names (list of string)
         """
-        # step 1: find the top most index
-        childIndex = self.currentIndex()
-        if not childIndex.isValid():
-            return []
+        expandedNames = []
         
-        while childIndex.isValid():
-            topIndex = childIndex
-            childIndex = self.indexAbove(childIndex)
-        
-        # step 2: get names of expanded items
-        expandedNames = []
-        childIndex = topIndex
+        childIndex = self.model().index(0, 0)
         while childIndex.isValid():
             if self.isExpanded(childIndex):
-                expandedNames.append(
-                    self.model().item(childIndex).name())
+                try:
+                    expandedNames.append(
+                        self.model().item(childIndex).name())
+                except AttributeError:
+                    # only items defining the name() method are returned
+                    pass
             childIndex = self.indexBelow(childIndex)
+        
         return expandedNames
         
+    def expandItemsByName(self, names):
+        """
+        Public method to expand items given their names.
+        
+        @param names list of item names to be expanded (list of string)
+        """
+        model = self.model()
+        for name in names:
+            childIndex = model.index(0, 0)
+            while childIndex.isValid():
+                if model.item(childIndex).name() == name:
+                    self.setExpanded(childIndex, True)
+                    break
+                childIndex = self.indexBelow(childIndex)
+        
     def _prepareRepopulateItem(self, name):
         """
         Protected slot to handle the prepareRepopulateItem signal.
--- a/UI/BrowserModel.py	Wed May 21 19:45:39 2014 +0200
+++ b/UI/BrowserModel.py	Thu May 22 18:23:29 2014 +0200
@@ -1318,7 +1318,7 @@
         BrowserItem.__init__(self, parent, name)
         
         self.type_ = BrowserItemClass
-        self.name = name
+        self._name = name
         self._classObject = cl
         self._filename = filename
         
@@ -1438,7 +1438,7 @@
         
         import Utilities.ClassBrowsers.ClbrBaseClasses
         self.type_ = BrowserItemMethod
-        self.name = name
+        self._name = name
         self._functionObject = fn
         self._filename = filename
         if self._functionObject.modifier == \
@@ -1506,9 +1506,9 @@
         @return true, if this item is less than other (boolean)
         """
         if issubclass(other.__class__, BrowserMethodItem):
-            if self.name.startswith('__init__'):
+            if self._name.startswith('__init__'):
                 return order == Qt.AscendingOrder
-            if other.name.startswith('__init__'):
+            if other._name.startswith('__init__'):
                 return order == Qt.DescendingOrder
         elif issubclass(other.__class__, BrowserClassAttributesItem):
             return order == Qt.DescendingOrder

eric ide

mercurial