55 self.__sysPathInterpreter = "" |
55 self.__sysPathInterpreter = "" |
56 self.__sysPathItem = None |
56 self.__sysPathItem = None |
57 |
57 |
58 if not nopopulate: |
58 if not nopopulate: |
59 self.watchedItems = {} |
59 self.watchedItems = {} |
|
60 self.watchedFileItems = {} |
60 self.watcher = QFileSystemWatcher(self) |
61 self.watcher = QFileSystemWatcher(self) |
61 self.watcher.directoryChanged.connect(self.directoryChanged) |
62 self.watcher.directoryChanged.connect(self.directoryChanged) |
|
63 self.watcher.fileChanged.connect(self.fileChanged) |
62 |
64 |
63 rootData = QCoreApplication.translate("BrowserModel", "Name") |
65 rootData = QCoreApplication.translate("BrowserModel", "Name") |
64 self.rootItem = BrowserItem(None, rootData) |
66 self.rootItem = BrowserItem(None, rootData) |
65 |
67 |
66 self.__populateModel() |
68 self.__populateModel() |
689 isModule=False) |
691 isModule=False) |
690 self._addItem(mn_node, m_node) |
692 self._addItem(mn_node, m_node) |
691 if repopulate: |
693 if repopulate: |
692 self.endInsertRows() |
694 self.endInsertRows() |
693 parentItem._populated = True |
695 parentItem._populated = True |
|
696 if fileName not in self.watchedFileItems: |
|
697 self.watcher.addPath(fileName) |
|
698 self.watchedFileItems[fileName] = parentItem |
|
699 |
|
700 def repopulateFileItem(self, itm): |
|
701 """ |
|
702 Public method to repopulate a file item. |
|
703 |
|
704 @param itm reference to the item to be repopulated |
|
705 @type BrowserFileItem |
|
706 """ |
|
707 if isinstance(itm, BrowserFileItem) and itm.isLazyPopulated(): |
|
708 if not itm.isPopulated(): |
|
709 # item is not populated yet, nothing to do |
|
710 return |
|
711 |
|
712 if itm.childCount(): |
|
713 index = self.createIndex(itm.row(), 0, itm) |
|
714 self.beginRemoveRows(index, 0, itm.childCount() - 1) |
|
715 itm.removeChildren() |
|
716 self.endRemoveRows() |
|
717 |
|
718 self.populateFileItem(itm, True) |
|
719 |
|
720 def fileChanged(self, fileName): |
|
721 """ |
|
722 Public method to react upon file changes. |
|
723 |
|
724 @param fileName path of the changed file |
|
725 @type str |
|
726 """ |
|
727 if fileName in self.watchedFileItems: |
|
728 if os.path.exists(fileName): |
|
729 # the file was changed |
|
730 self.repopulateFileItem(self.watchedFileItems[fileName]) |
|
731 else: |
|
732 # the file does not exist anymore |
|
733 del self.watchedFileItems[fileName] |
694 |
734 |
695 def populateClassItem(self, parentItem, repopulate=False): |
735 def populateClassItem(self, parentItem, repopulate=False): |
696 """ |
736 """ |
697 Public method to populate a class item's subtree. |
737 Public method to populate a class item's subtree. |
698 |
738 |