219 self.rootItem = BrowserItem(None, rootData) |
219 self.rootItem = BrowserItem(None, rootData) |
220 self.rootItem.itemData.append(self.trUtf8("VCS Status")) |
220 self.rootItem.itemData.append(self.trUtf8("VCS Status")) |
221 |
221 |
222 self.progDir = None |
222 self.progDir = None |
223 self.project = parent |
223 self.project = parent |
|
224 |
|
225 self.watchedItems = {} |
|
226 self.watcher = QFileSystemWatcher(self) |
|
227 self.watcher.directoryChanged.connect(self.directoryChanged) |
224 |
228 |
225 self.inRefresh = False |
229 self.inRefresh = False |
226 |
230 |
227 self.projectBrowserTypes = { |
231 self.projectBrowserTypes = { |
228 "SOURCES" : ProjectBrowserSourceType, |
232 "SOURCES" : ProjectBrowserSourceType, |
566 index = QModelIndex() |
575 index = QModelIndex() |
567 else: |
576 else: |
568 index = self.createIndex(itm.row(), 0, itm) |
577 index = self.createIndex(itm.row(), 0, itm) |
569 return index |
578 return index |
570 |
579 |
|
580 def directoryChanged(self, path): |
|
581 """ |
|
582 Public slot to handle the directoryChanged signal of the watcher. |
|
583 |
|
584 @param path path of the directory (string) |
|
585 """ |
|
586 if path not in self.watchedItems: |
|
587 # just ignore the situation we don't have a reference to the item |
|
588 return |
|
589 |
|
590 for itm in self.watchedItems[path]: |
|
591 oldCnt = itm.childCount() |
|
592 |
|
593 qdir = QDir(itm.dirName()) |
|
594 |
|
595 entryInfoList = qdir.entryInfoList( |
|
596 QDir.Filters(QDir.AllEntries | QDir.NoDotAndDotDot)) |
|
597 |
|
598 # step 1: check for new entries |
|
599 children = itm.children() |
|
600 for f in entryInfoList: |
|
601 fpath = f.absoluteFilePath() |
|
602 childFound = False |
|
603 for child in children: |
|
604 if child.name() == fpath: |
|
605 childFound = True |
|
606 children.remove(child) |
|
607 break |
|
608 if childFound: |
|
609 continue |
|
610 |
|
611 cnt = itm.childCount() |
|
612 self.beginInsertRows(self.createIndex(itm.row(), 0, itm), |
|
613 cnt, cnt) |
|
614 if f.isDir(): |
|
615 node = ProjectBrowserDirectoryItem(itm, |
|
616 Utilities.toNativeSeparators(f.absoluteFilePath()), |
|
617 itm.getProjectTypes()[0], |
|
618 False) |
|
619 else: |
|
620 node = ProjectBrowserFileItem(itm, |
|
621 Utilities.toNativeSeparators(f.absoluteFilePath()), |
|
622 itm.getProjectTypes()[0]) |
|
623 self._addItem(node, itm) |
|
624 if self.project.vcs is not None: |
|
625 self.project.vcs.clearStatusCache() |
|
626 state = self.project.vcs.vcsRegisteredState(node.name()) |
|
627 if state == self.project.vcs.canBeCommitted: |
|
628 node.addVcsStatus(self.project.vcs.vcsName()) |
|
629 else: |
|
630 node.addVcsStatus(self.trUtf8("local")) |
|
631 self.endInsertRows() |
|
632 |
|
633 # step 2: check for removed entries |
|
634 if len(entryInfoList) != itm.childCount(): |
|
635 for row in range(oldCnt - 1, -1, -1): |
|
636 child = itm.child(row) |
|
637 entryFound = False |
|
638 for f in entryInfoList: |
|
639 if f.absoluteFilePath() == child.name(): |
|
640 entryFound = True |
|
641 entryInfoList.remove(f) |
|
642 break |
|
643 if entryFound: |
|
644 continue |
|
645 |
|
646 self._removeWatchedItem(child) |
|
647 self.beginRemoveRows(self.createIndex(itm.row(), 0, itm), |
|
648 row, row) |
|
649 itm.removeChild(child) |
|
650 self.endRemoveRows() |
|
651 |
571 def __addVCSStatus(self, item, name): |
652 def __addVCSStatus(self, item, name): |
572 """ |
653 """ |
573 Private method used to set the vcs status of a node. |
654 Private method used to set the vcs status of a node. |
574 |
655 |
575 @param item item to work on |
656 @param item item to work on |
588 """ |
669 """ |
589 Private method used to update the vcs status of a node. |
670 Private method used to update the vcs status of a node. |
590 |
671 |
591 @param item item to work on |
672 @param item item to work on |
592 @param name filename belonging to this item (string) |
673 @param name filename belonging to this item (string) |
593 @param recursive flag indicating a recursive update (boolean) |
674 @keyparam recursive flag indicating a recursive update (boolean) |
594 """ |
675 """ |
595 if self.project.vcs is not None: |
676 if self.project.vcs is not None: |
596 self.project.vcs.clearStatusCache() |
677 self.project.vcs.clearStatusCache() |
597 state = self.project.vcs.vcsRegisteredState(name) |
678 state = self.project.vcs.vcsRegisteredState(name) |
598 if state == self.project.vcs.canBeCommitted: |
679 if state == self.project.vcs.canBeCommitted: |