src/eric7/UI/BrowserModel.py

branch
eric7
changeset 10949
2057b1b198a5
parent 10848
328c9a177c64
child 11090
f5f5f5803935
equal deleted inserted replaced
10948:89b36a39fe69 10949:2057b1b198a5
166 item = index.internalPointer() 166 item = index.internalPointer()
167 if item.isSymlink(): 167 if item.isSymlink():
168 font = QFont(QApplication.font("QTreeView")) 168 font = QFont(QApplication.font("QTreeView"))
169 font.setItalic(True) 169 font.setItalic(True)
170 return font 170 return font
171 elif item.isRemote():
172 font = QFont(QApplication.font("QTreeView"))
173 font.setUnderline(True)
174 return font
175 elif role == Qt.ItemDataRole.ToolTipRole:
176 return index.internalPointer().getRemoteInfo()
171 177
172 return None 178 return None
173 179
174 def flags(self, index): 180 def flags(self, index):
175 """ 181 """
438 self.endRemoveRows() 444 self.endRemoveRows()
439 return True 445 return True
440 446
441 return False 447 return False
442 448
449 def refreshDirectory(self, index):
450 """
451 Public method to refresh the directory with the given index.
452
453 @param index index of the directory item
454 @type QModelIndex
455 """
456 item = self.item(index)
457 self.beginRemoveRows(index, 0, item.childCount() - 1)
458 item.removeChildren()
459 item._populated = False
460 self.endRemoveRows()
461 self.populateItem(item, repopulate=True)
462
443 def __populateModel(self): 463 def __populateModel(self):
444 """ 464 """
445 Private method to populate the browser model. 465 Private method to populate the browser model.
446 """ 466 """
447 self.toplevelDirs = [] 467 self.toplevelDirs = []
528 548
529 def addTopLevelDir(self, dirname): 549 def addTopLevelDir(self, dirname):
530 """ 550 """
531 Public method to add a new toplevel directory. 551 Public method to add a new toplevel directory.
532 552
553 If the directory does not contain a host connection info but is a remote
554 directory, this info is added.
555
533 @param dirname name of the new toplevel directory 556 @param dirname name of the new toplevel directory
534 @type str 557 @type str
535 """ 558 """
559 if FileSystemUtilities.isRemoteFileName(dirname) and "@@" not in dirname:
560 dirname = (
561 f"{dirname}@@{self.__remotefsInterface.serverInterface().getHost()}"
562 )
536 if dirname not in self.toplevelDirs: 563 if dirname not in self.toplevelDirs:
537 itm = BrowserDirectoryItem( 564 itm = BrowserDirectoryItem(
538 self.rootItem, dirname, fsInterface=self.__remotefsInterface 565 self.rootItem, dirname, fsInterface=self.__remotefsInterface
539 ) 566 )
540 self.addItem(itm) 567 self.addItem(itm)
541 self.toplevelDirs.append(itm.dirName()) 568 self.toplevelDirs.append(dirname)
542 569
543 def removeToplevelDir(self, index): 570 def removeToplevelDir(self, index):
544 """ 571 """
545 Public method to remove a toplevel directory. 572 Public method to remove a toplevel directory.
546 573
679 if len(entriesList) > 0: 706 if len(entriesList) > 0:
680 if repopulate: 707 if repopulate:
681 self.beginInsertRows( 708 self.beginInsertRows(
682 self.createIndex(parentItem.row(), 0, parentItem), 709 self.createIndex(parentItem.row(), 0, parentItem),
683 0, 710 0,
684 len(entryInfoList) - 1, 711 len(entriesList) - 1,
685 ) 712 )
686 for entry in entriesList: 713 for entry in entriesList:
687 if entry["is_dir"]: 714 if entry["is_dir"]:
688 node = BrowserDirectoryItem( 715 node = BrowserDirectoryItem(
689 parentItem, 716 parentItem,
1064 self.type_ = BrowserItemType.Root 1091 self.type_ = BrowserItemType.Root
1065 self.icon = EricPixmapCache.getIcon("empty") 1092 self.icon = EricPixmapCache.getIcon("empty")
1066 self._populated = True 1093 self._populated = True
1067 self._lazyPopulation = False 1094 self._lazyPopulation = False
1068 self.symlink = False 1095 self.symlink = False
1096 self.remote = False
1097 self.remoteInfo = ""
1069 1098
1070 def appendChild(self, child): 1099 def appendChild(self, child):
1071 """ 1100 """
1072 Public method to add a child to this item. 1101 Public method to add a child to this item.
1073 1102
1228 except IndexError: 1257 except IndexError:
1229 return False 1258 return False
1230 1259
1231 def isSymlink(self): 1260 def isSymlink(self):
1232 """ 1261 """
1233 Public method to check, if the items is a symbolic link. 1262 Public method to check, if the item is a symbolic link.
1234 1263
1235 @return flag indicating a symbolic link 1264 @return flag indicating a symbolic link
1236 @rtype bool 1265 @rtype bool
1237 """ 1266 """
1238 return self.symlink 1267 return self.symlink
1268
1269 def isRemote(self):
1270 """
1271 Public method to check, if the item is a remote path item.
1272
1273 @return flag indicating a remote path item
1274 @rtype bool
1275 """
1276 return self.remote
1277
1278 def getRemoteInfo(self):
1279 """
1280 Public method to get data about the remote connection.
1281
1282 @return string describing the remote connection
1283 @rtype str
1284 """
1285 return self.remoteInfo
1239 1286
1240 def lineno(self): 1287 def lineno(self):
1241 """ 1288 """
1242 Public method to return the line number of the item. 1289 Public method to return the line number of the item.
1243 1290
1363 """ 1410 """
1364 Constructor 1411 Constructor
1365 1412
1366 @param parent parent item 1413 @param parent parent item
1367 @type BrowserItem 1414 @type BrowserItem
1368 @param dinfo dinfo is the string for the directory 1415 @param dinfo string containing the directory info
1369 @type str 1416 @type str
1370 @param full flag indicating full pathname should be displayed (defaults to True) 1417 @param full flag indicating full pathname should be displayed (defaults to True)
1371 @type bool (optional) 1418 @type bool (optional)
1372 @param fsInterface reference to the 'eric-ide' server file system interface 1419 @param fsInterface reference to the 'eric-ide' server file system interface
1373 (defaults to None) 1420 (defaults to None)
1374 @type EricServerFileSystemInterface (optional) 1421 @type EricServerFileSystemInterface (optional)
1375 """ 1422 """
1376 self.__fsInterface = fsInterface 1423 self.__fsInterface = fsInterface
1377 1424
1378 if FileSystemUtilities.isRemoteFileName(dinfo): 1425 dn, isRemote, host = self.__prepareInfo(dinfo, full=full)
1379 self._dirName = dinfo
1380 dn = self._dirName if full else self.__fsInterface.basename(self._dirName)
1381 else:
1382 self._dirName = os.path.abspath(dinfo)
1383 dn = self._dirName if full else os.path.basename(self._dirName)
1384 super().__init__(parent, dn) 1426 super().__init__(parent, dn)
1385 1427
1386 self.type_ = BrowserItemType.Directory 1428 self.type_ = BrowserItemType.Directory
1387 if ( 1429 if (
1388 FileSystemUtilities.isPlainFileName(self._dirName) 1430 FileSystemUtilities.isPlainFileName(self._dirName)
1394 self.icon = EricPixmapCache.getSymlinkIcon("dirClosed") 1436 self.icon = EricPixmapCache.getSymlinkIcon("dirClosed")
1395 elif FileSystemUtilities.isRemoteFileName(self._dirName): 1437 elif FileSystemUtilities.isRemoteFileName(self._dirName):
1396 self.icon = EricPixmapCache.getIcon("open-remote") 1438 self.icon = EricPixmapCache.getIcon("open-remote")
1397 else: 1439 else:
1398 self.icon = EricPixmapCache.getIcon("dirClosed") 1440 self.icon = EricPixmapCache.getIcon("dirClosed")
1441 self.remote = isRemote
1442 self.remoteInfo = host
1399 self._populated = False 1443 self._populated = False
1400 self._lazyPopulation = True 1444 self._lazyPopulation = True
1401 1445
1402 def setName(self, dinfo, full=True): 1446 def setName(self, dinfo, full=True):
1403 """ 1447 """
1404 Public method to set the directory name. 1448 Public method to set the directory name.
1405 1449
1406 @param dinfo dinfo is the string for the directory 1450 @param dinfo string containing the directory info
1407 @type str 1451 @type str
1408 @param full flag indicating full pathname should be displayed 1452 @param full flag indicating full pathname should be displayed (defaults to True)
1409 @type bool 1453 @type bool (optional)
1454 """
1455 dn, isRemote, host = self.__prepareInfo(dinfo, full=full)
1456 self.itemData[0] = dn
1457 self.remoteInfo = host
1458
1459 def __prepareInfo(self, dinfo, full=True):
1460 """
1461 Private method to prepare the information to be stored.
1462
1463 @param dinfo string containing the directory info
1464 @type str
1465 @param full flag indicating full pathname should be displayed (defaults to True)
1466 @type bool (optional)
1467 @return tuple containing the path name to be shown, a flag indicating a
1468 remote (eric-ide server) path and a string with the connection info
1469 @rtype tuple of (str, bool)
1410 """ 1470 """
1411 if FileSystemUtilities.isRemoteFileName(dinfo): 1471 if FileSystemUtilities.isRemoteFileName(dinfo):
1472 if "@@" in dinfo:
1473 dinfo, host = dinfo.split("@@")
1474 else:
1475 host = ""
1476
1412 self._dirName = dinfo 1477 self._dirName = dinfo
1413 dn = self._dirName if full else self.__fsInterface.basename(self._dirName) 1478 return (
1479 self._dirName if full else self.__fsInterface.basename(self._dirName),
1480 True,
1481 host,
1482 )
1414 else: 1483 else:
1415 self._dirName = os.path.abspath(dinfo) 1484 self._dirName = os.path.abspath(dinfo)
1416 dn = self._dirName if full else os.path.basename(self._dirName) 1485 return (
1417 self.itemData[0] = dn 1486 self._dirName if full else os.path.basename(self._dirName),
1487 False,
1488 "",
1489 )
1418 1490
1419 def dirName(self): 1491 def dirName(self):
1420 """ 1492 """
1421 Public method returning the directory name. 1493 Public method returning the directory name.
1422 1494

eric ide

mercurial