--- a/src/eric7/UI/Browser.py Mon Feb 19 15:34:54 2024 +0100 +++ b/src/eric7/UI/Browser.py Mon Feb 19 15:56:51 2024 +0100 @@ -35,6 +35,7 @@ from eric7.EricWidgets import EricFileDialog, EricMessageBox from eric7.EricWidgets.EricApplication import ericApp from eric7.Project.ProjectBrowserModel import ProjectBrowserSimpleDirectoryItem +from eric7.RemoteServerInterface import EricServerFileDialog from eric7.SystemUtilities import FileSystemUtilities from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog from eric7.Utilities import MimeTypes @@ -106,10 +107,12 @@ pdfFile = pyqtSignal(str) testFile = pyqtSignal(str) - def __init__(self, parent=None): + def __init__(self, serverInterface, parent=None): """ Constructor + @param serverInterface reference to the 'eric-ide' server interface object + @type EricServerInterface @param parent parent widget @type QWidget """ @@ -118,7 +121,10 @@ self.setWindowTitle(QCoreApplication.translate("Browser", "File-Browser")) self.setWindowIcon(EricPixmapCache.getIcon("eric")) - self.__model = BrowserModel() + self.__ericServerInterface = serverInterface + self.__remotefsInterface = serverInterface.getServiceInterface("FileSystem") + + self.__model = BrowserModel(fsInterface=self.__remotefsInterface) self.__sortModel = BrowserSortFilterProxyModel() self.__sortModel.setSourceModel(self.__model) self.setModel(self.__sortModel) @@ -338,15 +344,19 @@ # create the directory menu self.dirMenu = QMenu(self) self.dirMenu.addAction( - QCoreApplication.translate("Browser", "New toplevel directory..."), - self.__newToplevelDir, + QCoreApplication.translate("Browser", "New Top Level Directory..."), + self.__newTopLevelDir, + ) + self.__dmRemoteTopLevelAct = self.dirMenu.addAction( + QCoreApplication.translate("Browser", "New Remote Top Level Directory..."), + self.__newRemoteTopLevelDir, ) self.addAsTopLevelAct = self.dirMenu.addAction( - QCoreApplication.translate("Browser", "Add as toplevel directory"), + QCoreApplication.translate("Browser", "Add as top level directory"), self.__addAsToplevelDir, ) self.removeFromToplevelAct = self.dirMenu.addAction( - QCoreApplication.translate("Browser", "Remove from toplevel"), + QCoreApplication.translate("Browser", "Remove from top level"), self.__removeToplevel, ) self.dirMenu.addSeparator() @@ -387,8 +397,12 @@ self.attributeMenu = QMenu(self) self.attributeMenu.addAction( - QCoreApplication.translate("Browser", "New toplevel directory..."), - self.__newToplevelDir, + QCoreApplication.translate("Browser", "New Top Level Directory..."), + self.__newTopLevelDir, + ) + self.__amRemoteTopLevelAct = self.attributeMenu.addAction( + QCoreApplication.translate("Browser", "New Remote Top Level Directory..."), + self.__newRemoteTopLevelDir, ) self.attributeMenu.addSeparator() self.attributeMenu.addMenu(self.gotoMenu) @@ -396,8 +410,12 @@ # create the background menu self.backMenu = QMenu(self) self.backMenu.addAction( - QCoreApplication.translate("Browser", "New toplevel directory..."), - self.__newToplevelDir, + QCoreApplication.translate("Browser", "New Top Level Directory..."), + self.__newTopLevelDir, + ) + self.__bmRemoteTopLevelAct = self.backMenu.addAction( + QCoreApplication.translate("Browser", "New Remote Top Level Directory..."), + self.__newRemoteTopLevelDir, ) self.backMenu.addSeparator() self.backMenu.addAction(self.showHiddenFilesAct) @@ -431,7 +449,7 @@ def _contextMenuRequested(self, coord): """ - Protected slot to show the context menu of the listview. + Protected slot to show the context menu of the list view. @param coord the position of the mouse pointer @type QPoint @@ -475,6 +493,9 @@ self.openInPdfViewerAct.setVisible(False) self.menu.popup(coord) elif isinstance(itm, BrowserClassAttributeItem): + self.__amRemoteTopLevelAct.setEnabled( + self.__ericServerInterface.isServerConnected() + ) self.attributeMenu.popup(coord) elif isinstance(itm, BrowserDirectoryItem): if not index.parent().isValid(): @@ -483,10 +504,19 @@ else: self.removeFromToplevelAct.setEnabled(False) self.addAsTopLevelAct.setEnabled(True) + self.__dmRemoteTopLevelAct.setEnabled( + self.__ericServerInterface.isServerConnected() + ) self.dirMenu.popup(coord) else: + self.__bmRemoteTopLevelAct.setEnabled( + self.__ericServerInterface.isServerConnected() + ) self.backMenu.popup(coord) else: + self.__bmRemoteTopLevelAct.setEnabled( + self.__ericServerInterface.isServerConnected() + ) self.backMenu.popup(self.mapToGlobal(coord)) def _showGotoMenu(self): @@ -755,6 +785,7 @@ # remember the current state Preferences.setUI("BrowsersListHiddenFiles", checked) + @pyqtSlot() def handleTesting(self): """ Public slot to handle the testing popup menu entry. @@ -769,13 +800,14 @@ if pyfn is not None: self.testFile.emit(pyfn) - def __newToplevelDir(self): + @pyqtSlot() + def __newTopLevelDir(self): """ - Private slot to handle the New toplevel directory popup menu entry. + Private slot to handle the New Top Level Directory popup menu entry. """ dname = EricFileDialog.getExistingDirectory( None, - QCoreApplication.translate("Browser", "New toplevel directory"), + QCoreApplication.translate("Browser", "New Top Level Directory"), "", EricFileDialog.ShowDirsOnly, ) @@ -783,22 +815,39 @@ dname = os.path.abspath(FileSystemUtilities.toNativeSeparators(dname)) self.__model.addTopLevelDir(dname) + @pyqtSlot() + def __newRemoteTopLevelDir(self): + """ + Private slot to handle the New Remote Top Level Directory popup menu entry. + """ + dname = EricServerFileDialog.getExistingDirectory( + None, + QCoreApplication.translate("Browser", "New Remote Top Level Directory"), + "", + dirsOnly=True, + ) + if dname: + self.__model.addTopLevelDir(dname) + + @pyqtSlot() def __removeToplevel(self): """ - Private slot to handle the Remove from toplevel popup menu entry. + Private slot to handle the Remove from top level popup menu entry. """ index = self.currentIndex() sindex = self.model().mapToSource(index) self.__model.removeToplevelDir(sindex) + @pyqtSlot() def __addAsToplevelDir(self): """ - Private slot to handle the Add as toplevel directory popup menu entry. + Private slot to handle the Add as top level directory popup menu entry. """ index = self.currentIndex() dname = self.model().item(index).dirName() self.__model.addTopLevelDir(dname) + @pyqtSlot() def __refreshDirectory(self): """ Private slot to refresh a directory entry. @@ -807,6 +856,7 @@ refreshDir = self.model().item(index).dirName() self.__model.directoryChanged(refreshDir) + @pyqtSlot() def __findInDirectory(self): """ Private slot to handle the Find in directory popup menu entry. @@ -816,6 +866,7 @@ ericApp().getObject("UserInterface").showFindFilesWidget(searchDir=searchDir) + @pyqtSlot() def __replaceInDirectory(self): """ Private slot to handle the Find&Replace in directory popup menu entry. @@ -825,6 +876,7 @@ ericApp().getObject("UserInterface").showReplaceFilesWidget(searchDir=searchDir) + @pyqtSlot(str) def handleProgramChange(self, fn): """ Public slot to handle the programChange signal. @@ -834,6 +886,7 @@ """ self.__model.programChange(os.path.dirname(fn)) + @pyqtSlot(str) def handleInterpreterChanged(self, interpreter): """ Public slot to handle a change of the debug client's interpreter.