17 from eric7.EricWidgets import EricMessageBox |
18 from eric7.EricWidgets import EricMessageBox |
18 from eric7.EricWidgets.EricApplication import ericApp |
19 from eric7.EricWidgets.EricApplication import ericApp |
19 from eric7.SystemUtilities import FileSystemUtilities |
20 from eric7.SystemUtilities import FileSystemUtilities |
20 |
21 |
21 |
22 |
|
23 # TODO: add info about connected eric-ide server |
22 class SessionFile(QObject): |
24 class SessionFile(QObject): |
23 """ |
25 """ |
24 Class representing the session JSON file. |
26 Class representing the session JSON file. |
25 """ |
27 """ |
26 |
28 |
45 @type str |
47 @type str |
46 @return flag indicating a successful write |
48 @return flag indicating a successful write |
47 @rtype bool |
49 @rtype bool |
48 """ |
50 """ |
49 # get references to objects we need |
51 # get references to objects we need |
50 fsInterface = ( |
52 serverInterface = ericApp().getObject("EricServer") |
51 ericApp().getObject("EricServer").getServiceInterface("FileSystem") |
53 fsInterface = serverInterface.getServiceInterface("FileSystem") |
52 ) |
|
53 |
54 |
54 project = ericApp().getObject("Project") |
55 project = ericApp().getObject("Project") |
55 projectBrowser = ericApp().getObject("ProjectBrowser") |
56 projectBrowser = ericApp().getObject("ProjectBrowser") |
56 multiProject = ericApp().getObject("MultiProject") |
57 multiProject = ericApp().getObject("MultiProject") |
57 vm = ericApp().getObject("ViewManager") |
58 vm = ericApp().getObject("ViewManager") |
70 ] = "This file was generated automatically, do not edit." |
71 ] = "This file was generated automatically, do not edit." |
71 |
72 |
72 if Preferences.getProject("TimestampFile") or self.__isGlobal: |
73 if Preferences.getProject("TimestampFile") or self.__isGlobal: |
73 sessionDict["header"]["saved"] = time.strftime("%Y-%m-%d, %H:%M:%S") |
74 sessionDict["header"]["saved"] = time.strftime("%Y-%m-%d, %H:%M:%S") |
74 |
75 |
75 # step 1: open multi project and project for global session |
76 # TODO: save currently connected server (host and port) |
|
77 # step 1: eric-ide Server Connection |
|
78 # ================================== |
|
79 sessionDict["RemoteServer"] = ( |
|
80 serverInterface.getHost() if serverInterface.isServerConnected() else "" |
|
81 ) |
|
82 |
|
83 # step 2: open multi project and project for global session |
|
84 # ========================================================= |
76 sessionDict["MultiProject"] = "" |
85 sessionDict["MultiProject"] = "" |
77 sessionDict["Project"] = "" |
86 sessionDict["Project"] = "" |
78 if self.__isGlobal: |
87 if self.__isGlobal: |
79 if multiProject.isOpen(): |
88 if multiProject.isOpen(): |
80 sessionDict["MultiProject"] = multiProject.getMultiProjectFile() |
89 sessionDict["MultiProject"] = multiProject.getMultiProjectFile() |
81 if project.isOpen(): |
90 if project.isOpen(): |
82 sessionDict["Project"] = project.getProjectFile() |
91 sessionDict["Project"] = project.getProjectFile() |
83 |
92 |
84 # step 2: all open (project) filenames and the active editor |
93 # step 3: all open (project) filenames and the active editor |
|
94 # ========================================================== |
85 if vm.canSplit(): |
95 if vm.canSplit(): |
86 sessionDict["ViewManagerSplits"] = { |
96 sessionDict["ViewManagerSplits"] = { |
87 "Count": vm.splitCount(), |
97 "Count": vm.splitCount(), |
88 "Orientation": vm.getSplitOrientation().value, |
98 "Orientation": vm.getSplitOrientation().value, |
89 } |
99 } |
123 sessionDict["ActiveWindow"] = { |
133 sessionDict["ActiveWindow"] = { |
124 "Filename": aw, |
134 "Filename": aw, |
125 "Cursor": ed.getCursorPosition(), |
135 "Cursor": ed.getCursorPosition(), |
126 } |
136 } |
127 |
137 |
128 # step 3: breakpoints |
138 # step 4: breakpoints |
|
139 # =================== |
129 allBreaks = Preferences.getProject("SessionAllBreakpoints") |
140 allBreaks = Preferences.getProject("SessionAllBreakpoints") |
130 projectFiles = project.getSources(True) |
141 projectFiles = project.getSources(True) |
131 bpModel = dbs.getBreakPointModel() |
142 bpModel = dbs.getBreakPointModel() |
132 if self.__isGlobal or allBreaks: |
143 if self.__isGlobal or allBreaks: |
133 sessionDict["Breakpoints"] = bpModel.getAllBreakpoints() |
144 sessionDict["Breakpoints"] = bpModel.getAllBreakpoints() |
134 else: |
145 else: |
135 sessionDict["Breakpoints"] = [ |
146 sessionDict["Breakpoints"] = [ |
136 bp for bp in bpModel.getAllBreakpoints() if bp[0] in projectFiles |
147 bp for bp in bpModel.getAllBreakpoints() if bp[0] in projectFiles |
137 ] |
148 ] |
138 |
149 |
139 # step 4: watch expressions |
150 # step 5: watch expressions |
|
151 # ========================= |
140 wpModel = dbs.getWatchPointModel() |
152 wpModel = dbs.getWatchPointModel() |
141 sessionDict["Watchpoints"] = wpModel.getAllWatchpoints() |
153 sessionDict["Watchpoints"] = wpModel.getAllWatchpoints() |
142 |
154 |
143 # step 5: debug info |
155 # step 6: debug info |
|
156 # ================== |
144 if self.__isGlobal: |
157 if self.__isGlobal: |
145 if len(dbg.scriptsHistory): |
158 if len(dbg.scriptsHistory): |
146 dbgScriptName = dbg.scriptsHistory[0] |
159 dbgScriptName = dbg.scriptsHistory[0] |
147 else: |
160 else: |
148 dbgScriptName = "" |
161 dbgScriptName = "" |
194 "EnableMultiprocess": project.dbgEnableMultiprocess, |
207 "EnableMultiprocess": project.dbgEnableMultiprocess, |
195 "MultiprocessNoDebug": project.dbgMultiprocessNoDebug, |
208 "MultiprocessNoDebug": project.dbgMultiprocessNoDebug, |
196 "GlobalConfigOverride": project.dbgGlobalConfigOverride, |
209 "GlobalConfigOverride": project.dbgGlobalConfigOverride, |
197 } |
210 } |
198 |
211 |
199 # step 6: bookmarks |
212 # step 7: bookmarks |
|
213 # ================= |
200 bookmarksList = [] |
214 bookmarksList = [] |
201 for fileName in editorsDict: |
215 for fileName in editorsDict: |
202 if self.__isGlobal or project.isProjectFile(fileName): |
216 if self.__isGlobal or project.isProjectFile(fileName): |
203 editor = editorsDict[fileName] |
217 editor = editorsDict[fileName] |
204 bookmarks = editor.getBookmarks() |
218 bookmarks = editor.getBookmarks() |
209 "Lines": bookmarks, |
223 "Lines": bookmarks, |
210 } |
224 } |
211 ) |
225 ) |
212 sessionDict["Bookmarks"] = bookmarksList |
226 sessionDict["Bookmarks"] = bookmarksList |
213 |
227 |
214 # step 7: state of the various project browsers |
228 # step 8: state of the various project browsers |
|
229 # ============================================= |
215 browsersList = [] |
230 browsersList = [] |
216 for browserName in projectBrowser.getProjectBrowserNames(): |
231 for browserName in projectBrowser.getProjectBrowserNames(): |
217 expandedItems = projectBrowser.getProjectBrowser( |
232 expandedItems = projectBrowser.getProjectBrowser( |
218 browserName |
233 browserName |
219 ).getExpandedItemNames() |
234 ).getExpandedItemNames() |
288 multiProject = ericApp().getObject("MultiProject") |
303 multiProject = ericApp().getObject("MultiProject") |
289 vm = ericApp().getObject("ViewManager") |
304 vm = ericApp().getObject("ViewManager") |
290 dbg = ericApp().getObject("DebugUI") |
305 dbg = ericApp().getObject("DebugUI") |
291 dbs = ericApp().getObject("DebugServer") |
306 dbs = ericApp().getObject("DebugServer") |
292 |
307 |
293 # step 1: multi project and project |
308 serverInterface = ericApp().getObject("EricServer") |
|
309 |
|
310 # step 1: eric-ide Server Connection |
|
311 # ================================== |
|
312 with contextlib.suppress(KeyError): |
|
313 if sessionDict["RemoteServer"]: |
|
314 hostname, port = serverInterface.parseHost(sessionDict["RemoteServer"]) |
|
315 serverInterface.connectToServer(hostname, port) |
|
316 |
|
317 # step 2: multi project and project |
294 # ================================= |
318 # ================================= |
295 if sessionDict["MultiProject"]: |
319 if sessionDict["MultiProject"]: |
296 multiProject.openMultiProject(sessionDict["MultiProject"], False) |
320 multiProject.openMultiProject(sessionDict["MultiProject"], False) |
297 if sessionDict["Project"]: |
321 if sessionDict["Project"]: |
298 project.openProject(sessionDict["Project"], False) |
322 project.openProject(sessionDict["Project"], False) |
299 |
323 |
300 # step 2: (project) filenames and the active editor |
324 # step 3: (project) filenames and the active editor |
301 # ================================================= |
325 # ================================================= |
302 vm.setSplitOrientation( |
326 vm.setSplitOrientation( |
303 Qt.Orientation(sessionDict["ViewManagerSplits"]["Orientation"]) |
327 Qt.Orientation(sessionDict["ViewManagerSplits"]["Orientation"]) |
304 ) |
328 ) |
305 vm.setSplitCount(sessionDict["ViewManagerSplits"]["Count"]) |
329 vm.setSplitCount(sessionDict["ViewManagerSplits"]["Count"]) |
325 if editorDict["Folds"]: |
349 if editorDict["Folds"]: |
326 ed.recolor() |
350 ed.recolor() |
327 ed.setContractedFolds(editorDict["Folds"]) |
351 ed.setContractedFolds(editorDict["Folds"]) |
328 ed.setCursorPosition(*editorDict["Cursor"]) |
352 ed.setCursorPosition(*editorDict["Cursor"]) |
329 |
353 |
330 # step 3: breakpoints |
354 # step 4: breakpoints |
331 # =================== |
355 # =================== |
332 bpModel = dbs.getBreakPointModel() |
356 bpModel = dbs.getBreakPointModel() |
333 bpModel.addBreakPoints(sessionDict["Breakpoints"]) |
357 bpModel.addBreakPoints(sessionDict["Breakpoints"]) |
334 |
358 |
335 # step 4: watch expressions |
359 # step 5: watch expressions |
336 # ========================= |
360 # ========================= |
337 wpModel = dbs.getWatchPointModel() |
361 wpModel = dbs.getWatchPointModel() |
338 wpModel.addWatchPoints(sessionDict["Watchpoints"]) |
362 wpModel.addWatchPoints(sessionDict["Watchpoints"]) |
339 |
363 |
340 # step 5: debug info |
364 # step 6: debug info |
341 # ================== |
365 # ================== |
342 debugInfoDict = sessionDict["DebugInfo"] |
366 debugInfoDict = sessionDict["DebugInfo"] |
343 |
367 |
344 # adjust for newer session types |
368 # adjust for newer session types |
345 if "GlobalConfigOverride" not in debugInfoDict: |
369 if "GlobalConfigOverride" not in debugInfoDict: |
377 debugInfoDict["EnableMultiprocess"], |
401 debugInfoDict["EnableMultiprocess"], |
378 debugInfoDict["MultiprocessNoDebug"], |
402 debugInfoDict["MultiprocessNoDebug"], |
379 debugInfoDict["GlobalConfigOverride"], |
403 debugInfoDict["GlobalConfigOverride"], |
380 ) |
404 ) |
381 |
405 |
382 # step 6: bookmarks |
406 # step 7: bookmarks |
383 # ================= |
407 # ================= |
384 for bookmark in sessionDict["Bookmarks"]: |
408 for bookmark in sessionDict["Bookmarks"]: |
385 editor = vm.getOpenEditor(bookmark["Filename"]) |
409 editor = vm.getOpenEditor(bookmark["Filename"]) |
386 if editor is not None: |
410 if editor is not None: |
387 for lineno in bookmark["Lines"]: |
411 for lineno in bookmark["Lines"]: |
388 editor.toggleBookmark(lineno) |
412 editor.toggleBookmark(lineno) |
389 |
413 |
390 # step 7: state of the various project browsers |
414 # step 8: state of the various project browsers |
391 # ============================================= |
415 # ============================================= |
392 for browserState in sessionDict["ProjectBrowserStates"]: |
416 for browserState in sessionDict["ProjectBrowserStates"]: |
393 browser = projectBrowser.getProjectBrowser(browserState["Name"]) |
417 browser = projectBrowser.getProjectBrowser(browserState["Name"]) |
394 if browser is not None: |
418 if browser is not None: |
395 browser.expandItemsByName(browserState["ExpandedItems"]) |
419 browser.expandItemsByName(browserState["ExpandedItems"]) |
396 |
420 |
397 # step 8: active window |
421 # step 9: active window |
398 # ===================== |
422 # ===================== |
399 if sessionDict["ActiveWindow"]: |
423 if sessionDict["ActiveWindow"]: |
400 vm.openFiles(sessionDict["ActiveWindow"]["Filename"]) |
424 vm.openFiles(sessionDict["ActiveWindow"]["Filename"]) |
401 ed = vm.getOpenEditor(sessionDict["ActiveWindow"]["Filename"]) |
425 ed = vm.getOpenEditor(sessionDict["ActiveWindow"]["Filename"]) |
402 if ed is not None: |
426 if ed is not None: |