22 Qt, |
22 Qt, |
23 ) |
23 ) |
24 from PyQt6.QtGui import QFont, QImageReader |
24 from PyQt6.QtGui import QFont, QImageReader |
25 from PyQt6.QtWidgets import QApplication |
25 from PyQt6.QtWidgets import QApplication |
26 |
26 |
27 from eric7 import Preferences, Utilities |
27 from eric7 import Preferences |
28 from eric7.EricGui import EricPixmapCache |
28 from eric7.EricGui import EricPixmapCache |
|
29 from eric7.SystemUtilities import FileSystemUtilities |
29 from eric7.Utilities import ClassBrowsers |
30 from eric7.Utilities import ClassBrowsers |
30 from eric7.Utilities.ClassBrowsers import ClbrBaseClasses |
31 from eric7.Utilities.ClassBrowsers import ClbrBaseClasses |
31 |
32 |
32 BrowserItemRoot = 0 |
33 BrowserItemRoot = 0 |
33 BrowserItemDirectory = 1 |
34 BrowserItemDirectory = 1 |
334 entryInfoList = qdir.entryInfoList(dirFilter) |
335 entryInfoList = qdir.entryInfoList(dirFilter) |
335 |
336 |
336 # step 1: check for new entries |
337 # step 1: check for new entries |
337 children = itm.children() |
338 children = itm.children() |
338 for f in entryInfoList: |
339 for f in entryInfoList: |
339 fpath = Utilities.toNativeSeparators(f.absoluteFilePath()) |
340 fpath = FileSystemUtilities.toNativeSeparators(f.absoluteFilePath()) |
340 childFound = False |
341 childFound = False |
341 for child in children: |
342 for child in children: |
342 if child.name() == fpath: |
343 if child.name() == fpath: |
343 childFound = True |
344 childFound = True |
344 children.remove(child) |
345 children.remove(child) |
348 |
349 |
349 cnt = itm.childCount() |
350 cnt = itm.childCount() |
350 self.beginInsertRows(self.createIndex(itm.row(), 0, itm), cnt, cnt) |
351 self.beginInsertRows(self.createIndex(itm.row(), 0, itm), cnt, cnt) |
351 node = ( |
352 node = ( |
352 BrowserDirectoryItem( |
353 BrowserDirectoryItem( |
353 itm, Utilities.toNativeSeparators(f.absoluteFilePath()), False |
354 itm, |
|
355 FileSystemUtilities.toNativeSeparators(f.absoluteFilePath()), |
|
356 False, |
354 ) |
357 ) |
355 if f.isDir() |
358 if f.isDir() |
356 else BrowserFileItem( |
359 else BrowserFileItem( |
357 itm, Utilities.toNativeSeparators(f.absoluteFilePath()) |
360 itm, |
|
361 FileSystemUtilities.toNativeSeparators(f.absoluteFilePath()), |
358 ) |
362 ) |
359 ) |
363 ) |
360 self._addItem(node, itm) |
364 self._addItem(node, itm) |
361 self.endInsertRows() |
365 self.endInsertRows() |
362 |
366 |
363 # step 2: check for removed entries |
367 # step 2: check for removed entries |
364 if len(entryInfoList) != itm.childCount(): |
368 if len(entryInfoList) != itm.childCount(): |
365 for row in range(oldCnt - 1, -1, -1): |
369 for row in range(oldCnt - 1, -1, -1): |
366 child = itm.child(row) |
370 child = itm.child(row) |
367 childname = Utilities.fromNativeSeparators(child.name()) |
371 childname = FileSystemUtilities.fromNativeSeparators(child.name()) |
368 entryFound = False |
372 entryFound = False |
369 for f in entryInfoList: |
373 for f in entryInfoList: |
370 if f.absoluteFilePath() == childname: |
374 if f.absoluteFilePath() == childname: |
371 entryFound = True |
375 entryFound = True |
372 entryInfoList.remove(f) |
376 entryInfoList.remove(f) |
386 self.toplevelDirs = [] |
390 self.toplevelDirs = [] |
387 tdp = Preferences.getSettings().value("BrowserModel/ToplevelDirs") |
391 tdp = Preferences.getSettings().value("BrowserModel/ToplevelDirs") |
388 if tdp: |
392 if tdp: |
389 self.toplevelDirs = tdp |
393 self.toplevelDirs = tdp |
390 else: |
394 else: |
391 self.toplevelDirs.append(Utilities.toNativeSeparators(QDir.homePath())) |
395 self.toplevelDirs.append( |
|
396 FileSystemUtilities.toNativeSeparators(QDir.homePath()) |
|
397 ) |
392 for d in QDir.drives(): |
398 for d in QDir.drives(): |
393 self.toplevelDirs.append( |
399 self.toplevelDirs.append( |
394 Utilities.toNativeSeparators(d.absoluteFilePath()) |
400 FileSystemUtilities.toNativeSeparators(d.absoluteFilePath()) |
395 ) |
401 ) |
396 |
402 |
397 for d in self.toplevelDirs: |
403 for d in self.toplevelDirs: |
398 itm = BrowserDirectoryItem(self.rootItem, d) |
404 itm = BrowserDirectoryItem(self.rootItem, d) |
399 self._addItem(itm, self.rootItem) |
405 self._addItem(itm, self.rootItem) |
564 ) |
570 ) |
565 for f in entryInfoList: |
571 for f in entryInfoList: |
566 if f.isDir(): |
572 if f.isDir(): |
567 node = BrowserDirectoryItem( |
573 node = BrowserDirectoryItem( |
568 parentItem, |
574 parentItem, |
569 Utilities.toNativeSeparators(f.absoluteFilePath()), |
575 FileSystemUtilities.toNativeSeparators(f.absoluteFilePath()), |
570 False, |
576 False, |
571 ) |
577 ) |
572 else: |
578 else: |
573 fileFilters = Preferences.getUI("BrowsersFileFilters").split(";") |
579 fileFilters = Preferences.getUI("BrowsersFileFilters").split(";") |
574 if fileFilters: |
580 if fileFilters: |
575 fn = f.fileName() |
581 fn = f.fileName() |
576 if any(fnmatch.fnmatch(fn, ff.strip()) for ff in fileFilters): |
582 if any(fnmatch.fnmatch(fn, ff.strip()) for ff in fileFilters): |
577 continue |
583 continue |
578 node = BrowserFileItem( |
584 node = BrowserFileItem( |
579 parentItem, Utilities.toNativeSeparators(f.absoluteFilePath()) |
585 parentItem, |
|
586 FileSystemUtilities.toNativeSeparators(f.absoluteFilePath()), |
580 ) |
587 ) |
581 self._addItem(node, parentItem) |
588 self._addItem(node, parentItem) |
582 if repopulate: |
589 if repopulate: |
583 self.endInsertRows() |
590 self.endInsertRows() |
584 |
591 |
1059 dn = self._dirName if full else os.path.basename(self._dirName) |
1066 dn = self._dirName if full else os.path.basename(self._dirName) |
1060 BrowserItem.__init__(self, parent, dn) |
1067 BrowserItem.__init__(self, parent, dn) |
1061 |
1068 |
1062 self.type_ = BrowserItemDirectory |
1069 self.type_ = BrowserItemDirectory |
1063 if ( |
1070 if ( |
1064 not Utilities.isDrive(self._dirName) |
1071 not FileSystemUtilities.isDrive(self._dirName) |
1065 and os.path.lexists(self._dirName) |
1072 and os.path.lexists(self._dirName) |
1066 and os.path.islink(self._dirName) |
1073 and os.path.islink(self._dirName) |
1067 ): |
1074 ): |
1068 self.symlink = True |
1075 self.symlink = True |
1069 self.icon = EricPixmapCache.getSymlinkIcon("dirClosed") |
1076 self.icon = EricPixmapCache.getSymlinkIcon("dirClosed") |