src/eric7/ViewManager/ViewManager.py

branch
server
changeset 10539
4274f189ff78
parent 10523
e4069ddd7dc7
child 10546
300487f5f517
--- a/src/eric7/ViewManager/ViewManager.py	Mon Jan 29 19:50:44 2024 +0100
+++ b/src/eric7/ViewManager/ViewManager.py	Fri Feb 02 11:29:08 2024 +0100
@@ -39,6 +39,7 @@
 from eric7.QScintilla.SpellChecker import SpellChecker
 from eric7.QScintilla.SpellingDictionaryEditDialog import SpellingDictionaryEditDialog
 from eric7.QScintilla.ZoomDialog import ZoomDialog
+from eric7.RemoteServerInterface import EricServerFileDialog
 from eric7.SystemUtilities import FileSystemUtilities, OSUtilities
 
 
@@ -650,6 +651,30 @@
         self.openAct.triggered.connect(self.__openFiles)
         self.fileActions.append(self.openAct)
 
+        self.openRemoteAct = EricAction(
+            QCoreApplication.translate("ViewManager", "Open Remote"),
+            EricPixmapCache.getIcon("open-remote"),
+            QCoreApplication.translate("ViewManager", "Open Remote..."),
+            0,
+            0,
+            self,
+            "vm_file_open_remote",
+        )
+        self.openRemoteAct.setStatusTip(
+            QCoreApplication.translate("ViewManager", "Open a remote file")
+        )
+        self.openRemoteAct.setWhatsThis(
+            QCoreApplication.translate(
+                "ViewManager",
+                """<b>Open a remote file</b>"""
+                """<p>You will be asked for the name of a remote file to be opened"""
+                """ in an editor window.</p>""",
+            )
+        )
+        self.openRemoteAct.triggered.connect(self.__openRemoteFiles)
+        self.openRemoteAct.setEnabled(False)
+        self.fileActions.append(self.openRemoteAct)
+
         self.closeActGrp = createActionGroup(self)
 
         self.closeAct = EricAction(
@@ -896,6 +921,7 @@
 
         menu.addAction(self.newAct)
         menu.addAction(self.openAct)
+        menu.addAction(self.openRemoteAct)
         self.menuRecentAct = menu.addMenu(self.recentMenu)
         menu.addMenu(self.bookmarkedMenu)
         menu.addSeparator()
@@ -938,6 +964,7 @@
 
         tb.addAction(self.newAct)
         tb.addAction(self.openAct)
+        tb.addAction(self.openRemoteAct)
         tb.addAction(self.closeAct)
         tb.addSeparator()
         tb.addAction(self.saveAct)
@@ -5389,20 +5416,17 @@
     ## Methods and slots that deal with file and window handling
     ##################################################################
 
+    @pyqtSlot()
     def __openFiles(self):
         """
         Private slot to open some files.
         """
-        # set the cwd of the dialog based on the following search criteria:
-        #     1: Directory of currently active editor
-        #     2: Directory of currently active project
-        #     3: CWD
         from eric7.QScintilla import Lexers
 
         fileFilter = self._getOpenFileFilter()
         progs = EricFileDialog.getOpenFileNamesAndFilter(
             self.ui,
-            QCoreApplication.translate("ViewManager", "Open files"),
+            QCoreApplication.translate("ViewManager", "Open Files"),
             self._getOpenStartDir(),
             Lexers.getOpenFileFiltersList(True, True),
             fileFilter,
@@ -5410,6 +5434,34 @@
         for prog in progs:
             self.openFiles(prog)
 
+    @pyqtSlot()
+    def __openRemoteFiles(self):
+        """
+        Private slot to open some files.
+        """
+        from eric7.QScintilla import Lexers
+
+        if ericApp().getObject("EricServer").isServerConnected():
+            fileFilter = self._getOpenFileFilter()
+            progs = EricServerFileDialog.getOpenFileNames(
+                self.ui,
+                QCoreApplication.translate("ViewManager", "Open Remote Files"),
+                self._getOpenStartDir(forRemote=True),
+                Lexers.getOpenFileFiltersList(True, True),
+                fileFilter,
+            )
+            for prog in progs:
+                self.openFiles(prog)
+        else:
+            EricMessageBox.critical(
+                self.ui,
+                self.tr("Open Remote Files"),
+                self.tr(
+                    "You must be connected to a remote eric-ide server. Aborting..."
+                ),
+            )
+            
+
     def openFiles(self, prog):
         """
         Public slot to open some files.
@@ -5417,7 +5469,8 @@
         @param prog name of file to be opened
         @type str
         """
-        prog = os.path.abspath(prog)
+        if FileSystemUtilities.isPlainFileName(prog):
+            prog = os.path.abspath(prog)
         # Open up the new files.
         self.openSourceFile(prog)
 
@@ -5618,6 +5671,25 @@
             if FileSystemUtilities.isDeviceFileName(editor.getFileName()):
                 self.closeEditor(editor, ignoreDirty=True)
 
+    @pyqtSlot()
+    def closeRemoteEditors(self):
+        """
+        Public slot to close all editors related to a connected eric-ide server.
+        """
+        for editor in self.editors[:]:
+            if FileSystemUtilities.isRemoteFileName(editor.getFileName()):
+                self.closeEditor(editor, ignoreDirty=True)
+
+    @pyqtSlot(bool)
+    def remoteConnectionChanged(self, connected):
+        """
+        Public slot handling a change of the connection state to an eric-ide server.
+
+        @param connected flag indicating the connection state
+        @type bool
+        """
+        self.openRemoteAct.setEnabled(connected)
+
     def exit(self):
         """
         Public method to handle the debugged program terminating.
@@ -8034,7 +8106,7 @@
     ## Below are protected utility methods
     ##################################################################
 
-    def _getOpenStartDir(self):
+    def _getOpenStartDir(self, forRemote=False):
         """
         Protected method to return the starting directory for a file open
         dialog.
@@ -8043,22 +8115,39 @@
         using the following search order, until a match is found:<br />
             1: Directory of currently active editor<br />
             2: Directory of currently active Project<br />
-            3: CWD
-
+            3: Directory defined as the workspace (only for local access)<br />
+            4: CWD
+
+        @param forRemote flag indicating to get the start directory for a remote
+            operation (defaults to False)
+        @type bool (optional)
         @return name of directory to start
         @rtype str
         """
         # if we have an active source, return its path
-        if self.activeWindow() is not None and self.activeWindow().getFileName():
-            return os.path.dirname(self.activeWindow().getFileName())
+        if self.activeWindow() is not None:
+            fn = self.activeWindow().getFileName()
+            if (
+                (forRemote and FileSystemUtilities.isRemoteFileName(fn))
+                or (not forRemote and FileSystemUtilities.isPlainFileName(fn))
+            ):
+                return os.path.dirname(self.activeWindow().getFileName())
 
         # check, if there is an active project and return its path
-        elif ericApp().getObject("Project").isOpen():
-            return ericApp().getObject("Project").ppath
-
-        else:
+        if ericApp().getObject("Project").isOpen():
+            ppath = ericApp().getObject("Project").ppath
+            if (
+                (forRemote and FileSystemUtilities.isRemoteFileName(ppath))
+                or (not forRemote and FileSystemUtilities.isPlainFileName(ppath))
+            ):
+                return ppath
+
+        if not forRemote:
             return Preferences.getMultiProject("Workspace") or OSUtilities.getHomeDir()
 
+        # return empty string
+        return ""
+
     def _getOpenFileFilter(self):
         """
         Protected method to return the active filename filter for a file open

eric ide

mercurial