src/eric7/Sessions/SessionFile.py

branch
server
changeset 10596
ea35c92a3c7c
parent 10459
5c5ed40d533d
child 10632
1109854f15f9
--- a/src/eric7/Sessions/SessionFile.py	Mon Feb 19 19:37:00 2024 +0100
+++ b/src/eric7/Sessions/SessionFile.py	Thu Feb 22 16:26:46 2024 +0100
@@ -16,6 +16,7 @@
 from eric7.EricGui.EricOverrideCursor import EricOverridenCursor
 from eric7.EricWidgets import EricMessageBox
 from eric7.EricWidgets.EricApplication import ericApp
+from eric7.SystemUtilities import FileSystemUtilities
 
 
 class SessionFile(QObject):
@@ -46,6 +47,10 @@
         @rtype bool
         """
         # get references to objects we need
+        fsInterface = (
+            ericApp().getObject("EricServer").getServiceInterface("FileSystem")
+        )
+
         project = ericApp().getObject("Project")
         projectBrowser = ericApp().getObject("ProjectBrowser")
         multiProject = ericApp().getObject("MultiProject")
@@ -223,13 +228,18 @@
 
         try:
             jsonString = json.dumps(sessionDict, indent=2) + "\n"
-            with open(filename, "w") as f:
-                f.write(jsonString)
+            if FileSystemUtilities.isRemoteFileName(filename):
+                title = self.tr("Save Remote Session")
+                fsInterface.writeFile(filename, jsonString.encode("utf-8"))
+            else:
+                title = self.tr("Save Session")
+                with open(filename, "w") as f:
+                    f.write(jsonString)
         except (OSError, TypeError) as err:
             with EricOverridenCursor():
                 EricMessageBox.critical(
                     None,
-                    self.tr("Save Session"),
+                    title,
                     self.tr(
                         "<p>The session file <b>{0}</b> could not be"
                         " written.</p><p>Reason: {1}</p>"
@@ -248,14 +258,23 @@
         @return flag indicating a successful read
         @rtype bool
         """
+        fsInterface = (
+            ericApp().getObject("EricServer").getServiceInterface("FileSystem")
+        )
+
         try:
-            with open(filename, "r") as f:
-                jsonString = f.read()
+            if FileSystemUtilities.isRemoteFileName(filename):
+                title = self.tr("Read Remote Session")
+                jsonString = fsInterface.readFile(filename).decode("utf-8")
+            else:
+                title = self.tr("Read Session")
+                with open(filename, "r") as f:
+                    jsonString = f.read()
             sessionDict = json.loads(jsonString)
         except (OSError, json.JSONDecodeError) as err:
             EricMessageBox.critical(
                 None,
-                self.tr("Read Session"),
+                title,
                 self.tr(
                     "<p>The session file <b>{0}</b> could not be read.</p>"
                     "<p>Reason: {1}</p>"

eric ide

mercurial