src/eric7/Project/AddFileDialog.py

branch
server
changeset 10605
b6f5e27daeb5
parent 10439
21c28b0f9e41
child 10610
bb0149571d94
--- a/src/eric7/Project/AddFileDialog.py	Fri Feb 23 16:50:50 2024 +0100
+++ b/src/eric7/Project/AddFileDialog.py	Fri Feb 23 16:52:01 2024 +0100
@@ -10,9 +10,11 @@
 import os
 
 from PyQt6.QtCore import pyqtSlot
-from PyQt6.QtWidgets import QDialog
+from PyQt6.QtWidgets import QDialog, QDialogButtonBox
 
+from eric7.EricWidgets.EricApplication import ericApp
 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes
+from eric7.SystemUtilities import FileSystemUtilities
 
 from .Ui_AddFileDialog import Ui_AddFileDialog
 
@@ -42,9 +44,16 @@
             self.setObjectName(name)
         self.setupUi(self)
 
+        self.__remoteMode = (
+            bool(startdir) and FileSystemUtilities.isRemoteFileName(startdir)
+        ) or FileSystemUtilities.isRemoteFileName(pro.getProjectPath())
+
         self.sourceFilesPicker.setMode(EricPathPickerModes.OPEN_FILES_MODE)
+        self.sourceFilesPicker.setRemote(self.__remoteMode)
+
         self.targetDirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE)
         self.targetDirPicker.setDefaultDirectory(startdir)
+        self.targetDirPicker.setRemote(self.__remoteMode)
 
         if startdir:
             self.targetDirPicker.setText(startdir)
@@ -57,6 +66,8 @@
         if self.fileTypeFilter is not None:
             self.sourcecodeCheckBox.hide()
 
+        self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)
+
         msh = self.minimumSizeHint()
         self.resize(max(self.width(), msh.width()), msh.height())
 
@@ -66,12 +77,16 @@
         Private slot to perform actions before the source files selection
         dialog is shown.
         """
-        path = self.targetDirPicker.text()
-        if not path:
-            path = self.startdir
-        self.sourceFilesPicker.setDefaultDirectory(path)
+        targetPath = self.targetDirPicker.text()
+        if not targetPath:
+            targetPath = self.startdir
+        self.sourceFilesPicker.setDefaultDirectory(targetPath)
 
-        caption = self.tr("Select Files")
+        caption = (
+            self.tr("Select Files")
+            if self.__remoteMode
+            else self.tr("Select Remote Files")
+        )
         if self.fileTypeFilter is None:
             dfilter = self.__project.getFileCategoryFilterString(withAll=True)
         elif (
@@ -103,14 +118,23 @@
         @param sfile the text of the source file picker
         @type str
         """
-        sfile = str(self.sourceFilesPicker.firstPath())
+        sfile = self.sourceFilesPicker.firstStrPath()
         if sfile.startswith(self.__project.getProjectPath()):
-            if os.path.isdir(sfile):
-                directory = sfile
+            if self.__remoteMode:
+                fsInterface = (
+                    ericApp().getObject("EricServer").getServiceInterface("FileSystem")
+                )
+                directory = (
+                    sfile if fsInterface.isdir(sfile) else fsInterface.dirname(sfile)
+                )
             else:
-                directory = os.path.dirname(sfile)
+                directory = (
+                    sfile if os.path.isdir(sfile) else os.path.dirname(sfile)
+                )
             self.targetDirPicker.setText(directory)
 
+        self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(bool(sfile))
+
     def getData(self):
         """
         Public slot to retrieve the dialogs data.
@@ -120,7 +144,7 @@
         @rtype tuple of (list of string, string, boolean)
         """
         return (
-            [str(p) for p in self.sourceFilesPicker.paths()],
+            self.sourceFilesPicker.strPaths(),
             self.targetDirPicker.text(),
             self.sourcecodeCheckBox.isChecked(),
         )

eric ide

mercurial