--- a/src/eric7/UI/BrowserModel.py Sat Oct 05 10:28:34 2024 +0200 +++ b/src/eric7/UI/BrowserModel.py Sat Oct 05 11:35:07 2024 +0200 @@ -168,6 +168,12 @@ font = QFont(QApplication.font("QTreeView")) font.setItalic(True) return font + elif item.isRemote(): + font = QFont(QApplication.font("QTreeView")) + font.setUnderline(True) + return font + elif role == Qt.ItemDataRole.ToolTipRole: + return index.internalPointer().getRemoteInfo() return None @@ -440,6 +446,20 @@ return False + def refreshDirectory(self, index): + """ + Public method to refresh the directory with the given index. + + @param index index of the directory item + @type QModelIndex + """ + item = self.item(index) + self.beginRemoveRows(index, 0, item.childCount() - 1) + item.removeChildren() + item._populated = False + self.endRemoveRows() + self.populateItem(item, repopulate=True) + def __populateModel(self): """ Private method to populate the browser model. @@ -530,15 +550,22 @@ """ Public method to add a new toplevel directory. + If the directory does not contain a host connection info but is a remote + directory, this info is added. + @param dirname name of the new toplevel directory @type str """ + if FileSystemUtilities.isRemoteFileName(dirname) and "@@" not in dirname: + dirname = ( + f"{dirname}@@{self.__remotefsInterface.serverInterface().getHost()}" + ) if dirname not in self.toplevelDirs: itm = BrowserDirectoryItem( self.rootItem, dirname, fsInterface=self.__remotefsInterface ) self.addItem(itm) - self.toplevelDirs.append(itm.dirName()) + self.toplevelDirs.append(dirname) def removeToplevelDir(self, index): """ @@ -681,7 +708,7 @@ self.beginInsertRows( self.createIndex(parentItem.row(), 0, parentItem), 0, - len(entryInfoList) - 1, + len(entriesList) - 1, ) for entry in entriesList: if entry["is_dir"]: @@ -1066,6 +1093,8 @@ self._populated = True self._lazyPopulation = False self.symlink = False + self.remote = False + self.remoteInfo = "" def appendChild(self, child): """ @@ -1230,13 +1259,31 @@ def isSymlink(self): """ - Public method to check, if the items is a symbolic link. + Public method to check, if the item is a symbolic link. @return flag indicating a symbolic link @rtype bool """ return self.symlink + def isRemote(self): + """ + Public method to check, if the item is a remote path item. + + @return flag indicating a remote path item + @rtype bool + """ + return self.remote + + def getRemoteInfo(self): + """ + Public method to get data about the remote connection. + + @return string describing the remote connection + @rtype str + """ + return self.remoteInfo + def lineno(self): """ Public method to return the line number of the item. @@ -1365,7 +1412,7 @@ @param parent parent item @type BrowserItem - @param dinfo dinfo is the string for the directory + @param dinfo string containing the directory info @type str @param full flag indicating full pathname should be displayed (defaults to True) @type bool (optional) @@ -1375,12 +1422,7 @@ """ self.__fsInterface = fsInterface - if FileSystemUtilities.isRemoteFileName(dinfo): - self._dirName = dinfo - dn = self._dirName if full else self.__fsInterface.basename(self._dirName) - else: - self._dirName = os.path.abspath(dinfo) - dn = self._dirName if full else os.path.basename(self._dirName) + dn, isRemote, host = self.__prepareInfo(dinfo, full=full) super().__init__(parent, dn) self.type_ = BrowserItemType.Directory @@ -1396,6 +1438,8 @@ self.icon = EricPixmapCache.getIcon("open-remote") else: self.icon = EricPixmapCache.getIcon("dirClosed") + self.remote = isRemote + self.remoteInfo = host self._populated = False self._lazyPopulation = True @@ -1403,18 +1447,46 @@ """ Public method to set the directory name. - @param dinfo dinfo is the string for the directory + @param dinfo string containing the directory info @type str - @param full flag indicating full pathname should be displayed - @type bool + @param full flag indicating full pathname should be displayed (defaults to True) + @type bool (optional) + """ + dn, isRemote, host = self.__prepareInfo(dinfo, full=full) + self.itemData[0] = dn + self.remoteInfo = host + + def __prepareInfo(self, dinfo, full=True): + """ + Private method to prepare the information to be stored. + + @param dinfo string containing the directory info + @type str + @param full flag indicating full pathname should be displayed (defaults to True) + @type bool (optional) + @return tuple containing the path name to be shown, a flag indicating a + remote (eric-ide server) path and a string with the connection info + @rtype tuple of (str, bool) """ if FileSystemUtilities.isRemoteFileName(dinfo): + if "@@" in dinfo: + dinfo, host = dinfo.split("@@") + else: + host = "" + self._dirName = dinfo - dn = self._dirName if full else self.__fsInterface.basename(self._dirName) + return ( + self._dirName if full else self.__fsInterface.basename(self._dirName), + True, + host, + ) else: self._dirName = os.path.abspath(dinfo) - dn = self._dirName if full else os.path.basename(self._dirName) - self.itemData[0] = dn + return ( + self._dirName if full else os.path.basename(self._dirName), + False, + "", + ) def dirName(self): """