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

Wed, 21 May 2014 19:45:39 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 21 May 2014 19:45:39 +0200
changeset 3600
7d17c492ab95
parent 3598
37fdb72a2388
child 3601
236578b22511

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

DTDs/Session-5.0.dtd file | annotate | diff | comparison | revisions
E5XML/Config.py file | annotate | diff | comparison | revisions
E5XML/SessionReader.py file | annotate | diff | comparison | revisions
E5XML/SessionWriter.py file | annotate | diff | comparison | revisions
Project/Project.py file | annotate | diff | comparison | revisions
Project/ProjectBaseBrowser.py file | annotate | diff | comparison | revisions
Project/ProjectBrowser.py file | annotate | diff | comparison | revisions
Project/ProjectBrowserModel.py file | annotate | diff | comparison | revisions
UI/UserInterface.py file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DTDs/Session-5.0.dtd	Wed May 21 19:45:39 2014 +0200
@@ -0,0 +1,114 @@
+<!-- This is the DTD for eric's (project) session file version 4.4 -->
+
+<!ELEMENT   MultiProject    (#PCDATA)>
+
+<!ELEMENT   Project         (#PCDATA)>
+
+<!ELEMENT   Filename        (#PCDATA)>
+<!ATTLIST   Filename
+    cline       CDATA   #REQUIRED
+    cindex      CDATA   #REQUIRED
+    folds       CDATA   #REQUIRED
+    zoom        CDATA   #REQUIRED>
+
+<!ELEMENT   Filenames       (Filename*)>
+
+<!ELEMENT   ActiveWindow    (#PCDATA)>
+<!ATTLIST   ActiveWindow
+    cline       CDATA   #REQUIRED
+    cindex      CDATA   #REQUIRED>
+
+<!ELEMENT   BpFilename      (#PCDATA)>
+<!ELEMENT   Linenumber      EMPTY>
+<!ATTLIST   Linenumber
+    value       CDATA   #REQUIRED>
+<!ELEMENT   Condition       (#PCDATA)>
+<!ELEMENT   Temporary       EMPTY>
+<!ATTLIST   Temporary
+    value       CDATA   #REQUIRED>
+<!ELEMENT   Enabled         EMPTY>
+<!ATTLIST   Enabled
+    value       CDATA   #REQUIRED>
+<!ELEMENT   Count           EMPTY>
+<!ATTLIST   Count
+    value       CDATA   #REQUIRED>
+
+<!ELEMENT   Breakpoint      (BpFilename,
+                             Linenumber,
+                             Condition,
+                             Temporary,
+                             Enabled,
+                             Count)>
+
+<!ELEMENT   Breakpoints     (Breakpoint*)>
+
+<!ELEMENT   Special         (#PCDATA)>
+
+<!ELEMENT   Watchexpression (Condition,
+                             Temporary,
+                             Enabled,
+                             Count,
+                             Special)>
+
+<!ELEMENT   Watchexpressions (Watchexpression*)>
+
+<!ELEMENT   Exception       (#PCDATA)>
+
+<!ELEMENT   IgnoredException (#PCDATA)>
+
+<!ELEMENT   CommandLine      (#PCDATA)>
+<!ELEMENT   WorkingDirectory (#PCDATA)>
+<!ELEMENT   Environment      (#PCDATA)>
+<!ELEMENT   ReportExceptions EMPTY>
+<!ATTLIST   ReportExceptions
+    value       CDATA   #REQUIRED>
+<!ELEMENT   Exceptions       (Exception*)>
+<!ELEMENT   IgnoredExceptions (IgnoredException*)>
+<!ELEMENT   AutoClearShell   EMPTY>
+<!ATTLIST   AutoClearShell
+    value       CDATA   #REQUIRED>
+<!ELEMENT   TracePython      EMPTY>
+<!ATTLIST   TracePython
+    value       CDATA   #REQUIRED>
+<!ELEMENT   AutoContinue     EMPTY>
+<!ATTLIST   AutoContinue
+    value       CDATA   #REQUIRED>
+<!ELEMENT   CovexcPattern    (#PCDATA)>
+
+<!ELEMENT   DebugInfo       (CommandLine,
+                             WorkingDirectory,
+                             Environment,
+                             ReportExceptions,
+                             Exceptions,
+                             IgnoredExceptions,
+                             AutoClearShell,
+                             TracePython,
+                             AutoContinue,
+                             CovexcPattern)>
+
+<!ELEMENT   BmFilename      (#PCDATA)>
+
+<!ELEMENT   Bookmark        (BmFilename,
+                             Linenumber)>
+
+<!ELEMENT   Bookmarks       (Bookmark*)>
+
+<!ELEMENT   ExpandedItemName     (#PCDATA)>
+
+<!ELEMENT   ProjectBrowserState  (ExpandedItemName*)>
+<!ATTLIST   ProjectBrowserState
+    name        CDATA   #REQUIRED>
+
+<!ELEMENT   ProjectBrowserStates (ProjectBrowserState*)>
+
+<!ELEMENT   Session         (MultiProject?,
+                             Project?,
+                             Filenames,
+                             ActiveWindow?,
+                             Breakpoints,
+                             Watchexpressions,
+                             DebugInfo,
+                             Bookmarks,
+                             ProjectBrowserStates?)>
+<!ATTLIST   Session
+    version     CDATA   #REQUIRED>
--- a/E5XML/Config.py	Wed May 21 18:47:56 2014 +0200
+++ b/E5XML/Config.py	Wed May 21 19:45:39 2014 +0200
@@ -17,7 +17,7 @@
 userProjectFileFormatVersion = "4.0"
 
 # version number of the project session file
-sessionFileFormatVersion = "4.4"
+sessionFileFormatVersion = "5.0"
 
 # version number of the shortcuts file
 shortcutsFileFormatVersion = "3.6"
--- a/E5XML/SessionReader.py	Wed May 21 18:47:56 2014 +0200
+++ b/E5XML/SessionReader.py	Wed May 21 19:45:39 2014 +0200
@@ -19,7 +19,7 @@
     """
     Class for reading an XML session file.
     """
-    supportedVersions = ["4.3", "4.4"]
+    supportedVersions = ["4.3", "4.4", "5.0"]
     
     def __init__(self, device, isGlobal):
         """
@@ -34,6 +34,7 @@
         self.isGlobal = isGlobal
         
         self.project = e5App().getObject("Project")
+        self.projectBrowser = e5App().getObject("ProjectBrowser")
         self.multiProject = e5App().getObject("MultiProject")
         self.vm = e5App().getObject("ViewManager")
         self.dbg = e5App().getObject("DebugUI")
@@ -89,6 +90,8 @@
                     self.__readDebugInfo()
                 elif self.name() == "Bookmarks":
                     self.__readBookmarks()
+                elif self.name() == "ProjectBrowserStates":
+                    self.__readProjectBrowserStates()
                 else:
                     self.raiseUnexpectedStartTag(self.name())
         
@@ -335,3 +338,45 @@
                     lineno = int(self.attribute("value", "0"))
                 else:
                     self.raiseUnexpectedStartTag(self.name())
+    
+    def __readProjectBrowserStates(self):
+        """
+        Private method to read the project browser state infos.
+        """
+        while not self.atEnd():
+            self.readNext()
+            if self.isEndElement() and self.name() == "ProjectBrowserStates":
+                break
+            
+            if self.isStartElement():
+                if self.name() == "ProjectBrowserState":
+                    browserName = self.attribute("name", "")
+                    if not browserName:
+                        self.raiseBadValue("ProjectBrowserState.name")
+                    self.__readProjectBrowserState(browserName)
+                else:
+                    self.raiseUnexpectedStartTag(self.name())
+        
+    def __readProjectBrowserState(self, browserName):
+        """
+        Private method to read the project browser state info.
+        
+        @param browserName name of the project browser (string)
+        """
+        expandedNames = []
+        
+        while not self.atEnd():
+            self.readNext()
+            if self.isEndElement() and self.name() == "ProjectBrowserState":
+                # TODO: implement the expand logic
+                print(browserName)
+                print(expandedNames)
+                break
+            
+            if self.isStartElement():
+                if self.name() == "ExpandedItemName":
+                    itemName = self.readElementText()
+                    if itemName:
+                        expandedNames.append(itemName)
+                else:
+                    self.raiseUnexpectedStartTag(self.name())
--- a/E5XML/SessionWriter.py	Wed May 21 18:47:56 2014 +0200
+++ b/E5XML/SessionWriter.py	Wed May 21 19:45:39 2014 +0200
@@ -35,6 +35,7 @@
         
         self.name = projectName
         self.project = e5App().getObject("Project")
+        self.projectBrowser = e5App().getObject("ProjectBrowser")
         self.multiProject = e5App().getObject("MultiProject")
         self.vm = e5App().getObject("ViewManager")
         self.dbg = e5App().getObject("DebugUI")
@@ -224,6 +225,20 @@
                     self.writeEndElement()
         self.writeEndElement()
         
+        # step 5: save state of the various project browsers
+        if not isGlobal:
+            self.writeStartElement("ProjectBrowserStates")
+            for browserName in self.projectBrowser.getProjectBrowserNames():
+                self.writeStartElement("ProjectBrowserState")
+                self.writeAttribute("name", browserName)
+                # get the names of expanded files and directories
+                names = self.projectBrowser\
+                    .getProjectBrowser(browserName).getExpandedItemNames()
+                for name in names:
+                    self.writeTextElement("ExpandedItemName", name)
+                self.writeEndElement()
+            self.writeEndElement()
+        
         # add the main end tag
         self.writeEndElement()
         self.writeEndDocument()
--- a/Project/Project.py	Wed May 21 18:47:56 2014 +0200
+++ b/Project/Project.py	Wed May 21 19:45:39 2014 +0200
@@ -852,9 +852,11 @@
             enable = False
         else:
             fn, ext = os.path.splitext(os.path.basename(self.pfile))
-            fn = os.path.join(self.getProjectManagementDir(),
-                              '{0}.e4s'.format(fn))
-            enable = os.path.exists(fn)
+            fn_new = os.path.join(self.getProjectManagementDir(),
+                                  '{0}.e5s'.format(fn))
+            fn_old = os.path.join(self.getProjectManagementDir(),
+                                  '{0}.e4s'.format(fn))
+            enable = os.path.exists(fn_new) or os.path.exists(fn_old)
         self.sessActGrp.findChild(
             QAction, "project_load_session").setEnabled(enable)
         self.sessActGrp.findChild(
@@ -863,7 +865,7 @@
     @pyqtSlot()
     def __readSession(self, quiet=False, indicator=""):
         """
-        Private method to read in the project session file (.e4s).
+        Private method to read in the project session file (.e5s or .e4s).
         
         @param quiet flag indicating quiet operations.
                 If this flag is true, no errors are reported.
@@ -877,9 +879,12 @@
                     self.tr("Please save the project first."))
             return
             
-        fn, ext = os.path.splitext(os.path.basename(self.pfile))
+        fn1, ext = os.path.splitext(os.path.basename(self.pfile))
         fn = os.path.join(self.getProjectManagementDir(),
-                          '{0}{1}.e4s'.format(fn, indicator))
+                          '{0}{1}.e5s'.format(fn1, indicator))
+        if not os.path.exists(fn):
+            fn = os.path.join(self.getProjectManagementDir(),
+                              '{0}{1}.e4s'.format(fn1, indicator))
         
         f = QFile(fn)
         if f.open(QIODevice.ReadOnly):
@@ -899,7 +904,7 @@
     @pyqtSlot()
     def __writeSession(self, quiet=False, indicator=""):
         """
-        Private method to write the session data to an XML file (.e4s).
+        Private method to write the session data to an XML file (.e5s).
         
         @param quiet flag indicating quiet operations.
                 If this flag is true, no errors are reported.
@@ -915,7 +920,7 @@
         
         fn, ext = os.path.splitext(os.path.basename(self.pfile))
         fn = os.path.join(self.getProjectManagementDir(),
-                          '{0}{1}.e4s'.format(fn, indicator))
+                          '{0}{1}.e5s'.format(fn, indicator))
         
         f = QFile(fn)
         if f.open(QIODevice.WriteOnly):
@@ -945,7 +950,10 @@
             
         fname, ext = os.path.splitext(os.path.basename(self.pfile))
         
-        for fn in [os.path.join(
+        for fn in [
+            os.path.join(
+                self.getProjectManagementDir(), "{0}.e5s".format(fname)),
+            os.path.join(
                 self.getProjectManagementDir(), "{0}.e4s".format(fname))]:
             if os.path.exists(fn):
                 try:
--- a/Project/ProjectBaseBrowser.py	Wed May 21 18:47:56 2014 +0200
+++ b/Project/ProjectBaseBrowser.py	Wed May 21 19:45:39 2014 +0200
@@ -566,6 +566,31 @@
             filter=[ProjectBrowserSimpleDirectoryItem,
                     ProjectBrowserDirectoryItem])
         
+    def getExpandedItemNames(self):
+        """
+        Public method to get the file/directory names of all expanded items.
+        
+        @return list of expanded items names (list of string)
+        """
+        # step 1: find the top most index
+        childIndex = self.currentIndex()
+        if not childIndex.isValid():
+            return []
+        
+        while childIndex.isValid():
+            topIndex = childIndex
+            childIndex = self.indexAbove(childIndex)
+        
+        # step 2: get names of expanded items
+        expandedNames = []
+        childIndex = topIndex
+        while childIndex.isValid():
+            if self.isExpanded(childIndex):
+                expandedNames.append(
+                    self.model().item(childIndex).name())
+            childIndex = self.indexBelow(childIndex)
+        return expandedNames
+        
     def _prepareRepopulateItem(self, name):
         """
         Protected slot to handle the prepareRepopulateItem signal.
--- a/Project/ProjectBrowser.py	Wed May 21 18:47:56 2014 +0200
+++ b/Project/ProjectBrowser.py	Wed May 21 19:45:39 2014 +0200
@@ -376,6 +376,15 @@
         else:
             return None
     
+    def getProjectBrowserNames(self):
+        """
+        Public method to get the names of the various project browsers.
+        
+        @return list of project browser names (list of string)
+        """
+        return ["sources", "forms", "resources",
+                "translations", "interfaces", "others"]
+    
     def handlePreferencesChanged(self):
         """
         Public slot used to handle the preferencesChanged signal.
--- a/Project/ProjectBrowserModel.py	Wed May 21 18:47:56 2014 +0200
+++ b/Project/ProjectBrowserModel.py	Wed May 21 19:45:39 2014 +0200
@@ -152,6 +152,14 @@
         """
         return self._dirName
     
+    def name(self):
+        """
+        Public method to return the name of the item.
+        
+        @return name of the item (string)
+        """
+        return self._dirName
+    
     def lessThan(self, other, column, order):
         """
         Public method to check, if the item is less than the other one.
--- a/UI/UserInterface.py	Wed May 21 18:47:56 2014 +0200
+++ b/UI/UserInterface.py	Wed May 21 19:45:39 2014 +0200
@@ -5478,9 +5478,9 @@
         
     def __writeSession(self):
         """
-        Private slot to write the session data to an XML file (.e4s).
-        """
-        fn = os.path.join(Utilities.getConfigDir(), "eric5session.e4s")
+        Private slot to write the session data to an XML file (.e5s).
+        """
+        fn = os.path.join(Utilities.getConfigDir(), "eric5session.e5s")
         f = QFile(fn)
         if f.open(QIODevice.WriteOnly):
             from E5XML.SessionWriter import SessionWriter
@@ -5496,17 +5496,20 @@
         
     def __readSession(self):
         """
-        Private slot to read in the session file (.e4s).
-        """
-        fn = os.path.join(Utilities.getConfigDir(), "eric5session.e4s")
+        Private slot to read in the session file (.e5s or .e4s).
+        """
+        fn = os.path.join(Utilities.getConfigDir(), "eric5session.e5s")
         if not os.path.exists(fn):
-            E5MessageBox.critical(
-                self,
-                self.tr("Read session"),
-                self.tr(
-                    "<p>The session file <b>{0}</b> could not be read.</p>")
-                .format(fn))
-            return
+            fn = os.path.join(Utilities.getConfigDir(), "eric5session.e4s")
+            if not os.path.exists(fn):
+                E5MessageBox.critical(
+                    self,
+                    self.tr("Read session"),
+                    self.tr(
+                        "<p>The session file <b>{0}</b> could not"
+                        " be read.</p>")
+                    .format(fn))
+                return
         
         f = QFile(fn)
         if f.open(QIODevice.ReadOnly):

eric ide

mercurial