Project/ProjectBrowserModel.py

changeset 234
caed45a134f8
parent 216
6f9713e8d570
child 237
607a05c6989b
equal deleted inserted replaced
233:9d2677615a3d 234:caed45a134f8
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,
308 Public method to populate a directory item's subtree. 312 Public method to populate a directory item's subtree.
309 313
310 @param parentItem reference to the directory item to be populated 314 @param parentItem reference to the directory item to be populated
311 @param repopulate flag indicating a repopulation (boolean) 315 @param repopulate flag indicating a repopulation (boolean)
312 """ 316 """
317 self._addWatchedItem(parentItem)
318
313 qdir = QDir(parentItem.dirName()) 319 qdir = QDir(parentItem.dirName())
314 320
315 entryInfoList = \ 321 entryInfoList = \
316 qdir.entryInfoList(QDir.Filters(QDir.AllEntries | QDir.NoDotAndDotDot)) 322 qdir.entryInfoList(QDir.Filters(QDir.AllEntries | QDir.NoDotAndDotDot))
317 323
351 def projectClosed(self): 357 def projectClosed(self):
352 """ 358 """
353 Public method called after a project has been closed. 359 Public method called after a project has been closed.
354 """ 360 """
355 self.__vcsStatus = {} 361 self.__vcsStatus = {}
362
363 self.watchedItems = {}
364 self.watcher.removePaths(self.watcher.directories())
356 365
357 self.rootItem.removeChildren() 366 self.rootItem.removeChildren()
358 self.reset() 367 self.reset()
359 368
360 # reset the module parser cache 369 # reset the module parser cache
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:

eric ide

mercurial