E5XML/SessionWriter.py

changeset 6052
8b49d3e0b4c8
parent 6048
82ad8ec9548c
child 6352
4bdc6503df81
equal deleted inserted replaced
6051:6e09a9a73cb7 6052:8b49d3e0b4c8
25 """ 25 """
26 def __init__(self, device, projectName): 26 def __init__(self, device, projectName):
27 """ 27 """
28 Constructor 28 Constructor
29 29
30 @param device reference to the I/O device to write to (QIODevice) 30 @param device reference to the I/O device to write to
31 @param projectName name of the project (string) or None for the 31 @type QIODevice
32 @param projectName name of the project or None for the
32 global session 33 global session
34 @type str or None
33 """ 35 """
34 XMLStreamWriterBase.__init__(self, device) 36 XMLStreamWriterBase.__init__(self, device)
35 37
36 self.name = projectName 38 self.name = projectName
37 self.project = e5App().getObject("Project") 39 self.project = e5App().getObject("Project")
73 "MultiProject", self.multiProject.getMultiProjectFile()) 75 "MultiProject", self.multiProject.getMultiProjectFile())
74 if self.project.isOpen(): 76 if self.project.isOpen():
75 self.writeTextElement("Project", self.project.getProjectFile()) 77 self.writeTextElement("Project", self.project.getProjectFile())
76 78
77 # step 1: save all open (project) filenames and the active window 79 # step 1: save all open (project) filenames and the active window
78 allOpenFiles = self.vm.getOpenFilenames() 80 if self.vm.canSplit():
81 self.writeEmptyElement("ViewManagerSplits")
82 self.writeAttribute("count", str(self.vm.splitCount()))
83 self.writeAttribute("orientation",
84 str(self.vm.getSplitOrientation()))
85
86 allOpenEditorLists = self.vm.getOpenEditorsForSession()
87 editorDict = {} # remember editors by file name to detect clones
79 self.writeStartElement("Filenames") 88 self.writeStartElement("Filenames")
80 for of in allOpenFiles: 89 for splitIndex, openEditorList in enumerate(allOpenEditorLists):
81 if isGlobal or of.startswith(self.project.ppath): 90 for editorIndex, editor in enumerate(openEditorList):
82 ed = self.vm.getOpenEditor(of) 91 fileName = editor.getFileName()
83 if ed is not None: 92 if isGlobal or self.project.isProjectFile(fileName):
84 line, index = ed.getCursorPosition() 93 line, index = editor.getCursorPosition()
85 folds = ','.join( 94 folds = ','.join(
86 [str(i + 1) for i in ed.contractedFolds()]) 95 [str(i + 1) for i in editor.contractedFolds()])
87 zoom = ed.getZoom() 96 zoom = editor.getZoom()
88 else: 97 if fileName in editorDict:
89 line, index = 0, 0 98 isClone = int(editorDict[fileName].isClone(editor))
90 folds = '' 99 else:
91 zoom = -9999 100 isClone = 0
92 self.writeStartElement("Filename") 101 editorDict[fileName] = editor
93 self.writeAttribute("cline", str(line)) 102 self.writeStartElement("Filename")
94 self.writeAttribute("cindex", str(index)) 103 self.writeAttribute("cline", str(line))
95 self.writeAttribute("folds", folds) 104 self.writeAttribute("cindex", str(index))
96 self.writeAttribute("zoom", str(zoom)) 105 self.writeAttribute("folds", folds)
97 self.writeCharacters(of) 106 self.writeAttribute("zoom", str(zoom))
98 self.writeEndElement() 107 self.writeAttribute("cloned", str(isClone))
108 self.writeAttribute("splitindex", str(splitIndex))
109 self.writeAttribute("editorindex", str(editorIndex))
110 self.writeCharacters(fileName)
111 self.writeEndElement()
99 self.writeEndElement() 112 self.writeEndElement()
100 113
101 aw = self.vm.getActiveName() 114 aw = self.vm.getActiveName()
102 if aw and aw.startswith(self.project.ppath): 115 if aw and self.project.isProjectFile(aw):
103 ed = self.vm.getOpenEditor(aw) 116 ed = self.vm.getOpenEditor(aw)
104 if ed is not None: 117 line, index = ed.getCursorPosition()
105 line, index = ed.getCursorPosition()
106 else:
107 line, index = 0, 0
108 self.writeStartElement("ActiveWindow") 118 self.writeStartElement("ActiveWindow")
109 self.writeAttribute("cline", str(line)) 119 self.writeAttribute("cline", str(line))
110 self.writeAttribute("cindex", str(index)) 120 self.writeAttribute("cindex", str(index))
111 self.writeCharacters(aw) 121 self.writeCharacters(aw)
112 self.writeEndElement() 122 self.writeEndElement()
218 self.writeEmptyElement("CovexcPattern") # kept for compatibility 228 self.writeEmptyElement("CovexcPattern") # kept for compatibility
219 self.writeEndElement() 229 self.writeEndElement()
220 230
221 # step 4: save bookmarks of all open (project) files 231 # step 4: save bookmarks of all open (project) files
222 self.writeStartElement("Bookmarks") 232 self.writeStartElement("Bookmarks")
223 for of in allOpenFiles: 233 for fileName in editorDict:
224 if isGlobal or of.startswith(self.project.ppath): 234 if isGlobal or self.project.isProjectFile(fileName):
225 editor = self.vm.getOpenEditor(of) 235 editor = editorDict[fileName]
226 for bookmark in editor.getBookmarks(): 236 for bookmark in editor.getBookmarks():
227 self.writeStartElement("Bookmark") 237 self.writeStartElement("Bookmark")
228 self.writeTextElement("BmFilename", of) 238 self.writeTextElement("BmFilename", fileName)
229 self.writeEmptyElement("Linenumber") 239 self.writeEmptyElement("Linenumber")
230 self.writeAttribute("value", str(bookmark)) 240 self.writeAttribute("value", str(bookmark))
231 self.writeEndElement() 241 self.writeEndElement()
232 self.writeEndElement() 242 self.writeEndElement()
233 243

eric ide

mercurial