src/eric7/Sessions/SessionFile.py

branch
eric7
changeset 10958
79842be466d3
parent 10632
1109854f15f9
child 10967
454391fb0bdf
diff -r fbd61fd3fdc1 -r 79842be466d3 src/eric7/Sessions/SessionFile.py
--- a/src/eric7/Sessions/SessionFile.py	Tue Oct 08 11:44:28 2024 +0200
+++ b/src/eric7/Sessions/SessionFile.py	Tue Oct 08 19:27:23 2024 +0200
@@ -7,6 +7,7 @@
 Module implementing a class representing the session JSON file.
 """
 
+import contextlib
 import json
 import time
 
@@ -19,6 +20,7 @@
 from eric7.SystemUtilities import FileSystemUtilities
 
 
+# TODO: add info about connected eric-ide server
 class SessionFile(QObject):
     """
     Class representing the session JSON file.
@@ -47,9 +49,8 @@
         @rtype bool
         """
         # get references to objects we need
-        fsInterface = (
-            ericApp().getObject("EricServer").getServiceInterface("FileSystem")
-        )
+        serverInterface = ericApp().getObject("EricServer")
+        fsInterface = serverInterface.getServiceInterface("FileSystem")
 
         project = ericApp().getObject("Project")
         projectBrowser = ericApp().getObject("ProjectBrowser")
@@ -72,7 +73,15 @@
         if Preferences.getProject("TimestampFile") or self.__isGlobal:
             sessionDict["header"]["saved"] = time.strftime("%Y-%m-%d, %H:%M:%S")
 
-        # step 1: open multi project and project for global session
+        # TODO: save currently connected server (host and port)
+        # step 1: eric-ide Server Connection
+        # ==================================
+        sessionDict["RemoteServer"] = (
+            serverInterface.getHost() if serverInterface.isServerConnected() else ""
+        )
+
+        # step 2: open multi project and project for global session
+        # =========================================================
         sessionDict["MultiProject"] = ""
         sessionDict["Project"] = ""
         if self.__isGlobal:
@@ -81,7 +90,8 @@
             if project.isOpen():
                 sessionDict["Project"] = project.getProjectFile()
 
-        # step 2: all open (project) filenames and the active editor
+        # step 3: all open (project) filenames and the active editor
+        # ==========================================================
         if vm.canSplit():
             sessionDict["ViewManagerSplits"] = {
                 "Count": vm.splitCount(),
@@ -125,7 +135,8 @@
                 "Cursor": ed.getCursorPosition(),
             }
 
-        # step 3: breakpoints
+        # step 4: breakpoints
+        # ===================
         allBreaks = Preferences.getProject("SessionAllBreakpoints")
         projectFiles = project.getSources(True)
         bpModel = dbs.getBreakPointModel()
@@ -136,11 +147,13 @@
                 bp for bp in bpModel.getAllBreakpoints() if bp[0] in projectFiles
             ]
 
-        # step 4: watch expressions
+        # step 5: watch expressions
+        # =========================
         wpModel = dbs.getWatchPointModel()
         sessionDict["Watchpoints"] = wpModel.getAllWatchpoints()
 
-        # step 5: debug info
+        # step 6: debug info
+        # ==================
         if self.__isGlobal:
             if len(dbg.scriptsHistory):
                 dbgScriptName = dbg.scriptsHistory[0]
@@ -196,7 +209,8 @@
                 "GlobalConfigOverride": project.dbgGlobalConfigOverride,
             }
 
-        # step 6: bookmarks
+        # step 7: bookmarks
+        # =================
         bookmarksList = []
         for fileName in editorsDict:
             if self.__isGlobal or project.isProjectFile(fileName):
@@ -211,7 +225,8 @@
                     )
         sessionDict["Bookmarks"] = bookmarksList
 
-        # step 7: state of the various project browsers
+        # step 8: state of the various project browsers
+        # =============================================
         browsersList = []
         for browserName in projectBrowser.getProjectBrowserNames():
             expandedItems = projectBrowser.getProjectBrowser(
@@ -290,14 +305,23 @@
         dbg = ericApp().getObject("DebugUI")
         dbs = ericApp().getObject("DebugServer")
 
-        # step 1: multi project and project
+        serverInterface = ericApp().getObject("EricServer")
+
+        # step 1: eric-ide Server Connection
+        # ==================================
+        with contextlib.suppress(KeyError):
+            if sessionDict["RemoteServer"]:
+                hostname, port = serverInterface.parseHost(sessionDict["RemoteServer"])
+                serverInterface.connectToServer(hostname, port)
+
+        # step 2: multi project and project
         # =================================
         if sessionDict["MultiProject"]:
             multiProject.openMultiProject(sessionDict["MultiProject"], False)
         if sessionDict["Project"]:
             project.openProject(sessionDict["Project"], False)
 
-        # step 2: (project) filenames and the active editor
+        # step 3: (project) filenames and the active editor
         # =================================================
         vm.setSplitOrientation(
             Qt.Orientation(sessionDict["ViewManagerSplits"]["Orientation"])
@@ -327,17 +351,17 @@
                     ed.setContractedFolds(editorDict["Folds"])
                 ed.setCursorPosition(*editorDict["Cursor"])
 
-        # step 3: breakpoints
+        # step 4: breakpoints
         # ===================
         bpModel = dbs.getBreakPointModel()
         bpModel.addBreakPoints(sessionDict["Breakpoints"])
 
-        # step 4: watch expressions
+        # step 5: watch expressions
         # =========================
         wpModel = dbs.getWatchPointModel()
         wpModel.addWatchPoints(sessionDict["Watchpoints"])
 
-        # step 5: debug info
+        # step 6: debug info
         # ==================
         debugInfoDict = sessionDict["DebugInfo"]
 
@@ -379,7 +403,7 @@
                 debugInfoDict["GlobalConfigOverride"],
             )
 
-        # step 6: bookmarks
+        # step 7: bookmarks
         # =================
         for bookmark in sessionDict["Bookmarks"]:
             editor = vm.getOpenEditor(bookmark["Filename"])
@@ -387,14 +411,14 @@
                 for lineno in bookmark["Lines"]:
                     editor.toggleBookmark(lineno)
 
-        # step 7: state of the various project browsers
+        # step 8: state of the various project browsers
         # =============================================
         for browserState in sessionDict["ProjectBrowserStates"]:
             browser = projectBrowser.getProjectBrowser(browserState["Name"])
             if browser is not None:
                 browser.expandItemsByName(browserState["ExpandedItems"])
 
-        # step 8: active window
+        # step 9: active window
         # =====================
         if sessionDict["ActiveWindow"]:
             vm.openFiles(sessionDict["ActiveWindow"]["Filename"])

eric ide

mercurial