E5XML/SessionWriter.py

changeset 6052
8b49d3e0b4c8
parent 6048
82ad8ec9548c
child 6352
4bdc6503df81
diff -r 6e09a9a73cb7 -r 8b49d3e0b4c8 E5XML/SessionWriter.py
--- a/E5XML/SessionWriter.py	Sun Dec 31 18:54:06 2017 +0100
+++ b/E5XML/SessionWriter.py	Mon Jan 01 19:06:33 2018 +0100
@@ -27,9 +27,11 @@
         """
         Constructor
         
-        @param device reference to the I/O device to write to (QIODevice)
-        @param projectName name of the project (string) or None for the
+        @param device reference to the I/O device to write to
+        @type QIODevice
+        @param projectName name of the project or None for the
             global session
+        @type str or None
         """
         XMLStreamWriterBase.__init__(self, device)
         
@@ -75,36 +77,44 @@
                 self.writeTextElement("Project", self.project.getProjectFile())
         
         # step 1: save all open (project) filenames and the active window
-        allOpenFiles = self.vm.getOpenFilenames()
+        if self.vm.canSplit():
+            self.writeEmptyElement("ViewManagerSplits")
+            self.writeAttribute("count", str(self.vm.splitCount()))
+            self.writeAttribute("orientation",
+                                str(self.vm.getSplitOrientation()))
+        
+        allOpenEditorLists = self.vm.getOpenEditorsForSession()
+        editorDict = {}     # remember editors by file name to detect clones
         self.writeStartElement("Filenames")
-        for of in allOpenFiles:
-            if isGlobal or of.startswith(self.project.ppath):
-                ed = self.vm.getOpenEditor(of)
-                if ed is not None:
-                    line, index = ed.getCursorPosition()
+        for splitIndex, openEditorList in enumerate(allOpenEditorLists):
+            for editorIndex, editor in enumerate(openEditorList):
+                fileName = editor.getFileName()
+                if isGlobal or self.project.isProjectFile(fileName):
+                    line, index = editor.getCursorPosition()
                     folds = ','.join(
-                        [str(i + 1) for i in ed.contractedFolds()])
-                    zoom = ed.getZoom()
-                else:
-                    line, index = 0, 0
-                    folds = ''
-                    zoom = -9999
-                self.writeStartElement("Filename")
-                self.writeAttribute("cline", str(line))
-                self.writeAttribute("cindex", str(index))
-                self.writeAttribute("folds", folds)
-                self.writeAttribute("zoom", str(zoom))
-                self.writeCharacters(of)
-                self.writeEndElement()
+                        [str(i + 1) for i in editor.contractedFolds()])
+                    zoom = editor.getZoom()
+                    if fileName in editorDict:
+                        isClone = int(editorDict[fileName].isClone(editor))
+                    else:
+                        isClone = 0
+                        editorDict[fileName] = editor
+                    self.writeStartElement("Filename")
+                    self.writeAttribute("cline", str(line))
+                    self.writeAttribute("cindex", str(index))
+                    self.writeAttribute("folds", folds)
+                    self.writeAttribute("zoom", str(zoom))
+                    self.writeAttribute("cloned", str(isClone))
+                    self.writeAttribute("splitindex", str(splitIndex))
+                    self.writeAttribute("editorindex", str(editorIndex))
+                    self.writeCharacters(fileName)
+                    self.writeEndElement()
         self.writeEndElement()
         
         aw = self.vm.getActiveName()
-        if aw and aw.startswith(self.project.ppath):
+        if aw and self.project.isProjectFile(aw):
             ed = self.vm.getOpenEditor(aw)
-            if ed is not None:
-                line, index = ed.getCursorPosition()
-            else:
-                line, index = 0, 0
+            line, index = ed.getCursorPosition()
             self.writeStartElement("ActiveWindow")
             self.writeAttribute("cline", str(line))
             self.writeAttribute("cindex", str(index))
@@ -220,12 +230,12 @@
         
         # step 4: save bookmarks of all open (project) files
         self.writeStartElement("Bookmarks")
-        for of in allOpenFiles:
-            if isGlobal or of.startswith(self.project.ppath):
-                editor = self.vm.getOpenEditor(of)
+        for fileName in editorDict:
+            if isGlobal or self.project.isProjectFile(fileName):
+                editor = editorDict[fileName]
                 for bookmark in editor.getBookmarks():
                     self.writeStartElement("Bookmark")
-                    self.writeTextElement("BmFilename", of)
+                    self.writeTextElement("BmFilename", fileName)
                     self.writeEmptyElement("Linenumber")
                     self.writeAttribute("value", str(bookmark))
                     self.writeEndElement()

eric ide

mercurial