eric6/Project/ProjectBaseBrowser.py

changeset 7771
787a6b3f8c9f
parent 7759
51aa6c6b66f7
child 7780
41420f82c0ac
equal deleted inserted replaced
7770:49f3377aebf1 7771:787a6b3f8c9f
12 12
13 from PyQt5.QtCore import ( 13 from PyQt5.QtCore import (
14 QModelIndex, pyqtSignal, Qt, QCoreApplication, QItemSelectionModel, 14 QModelIndex, pyqtSignal, Qt, QCoreApplication, QItemSelectionModel,
15 QItemSelection, QElapsedTimer 15 QItemSelection, QElapsedTimer
16 ) 16 )
17 from PyQt5.QtGui import QCursor
18 from PyQt5.QtWidgets import ( 17 from PyQt5.QtWidgets import (
19 QTreeView, QApplication, QMenu, QDialog, QAbstractItemView 18 QTreeView, QApplication, QMenu, QDialog, QAbstractItemView
20 ) 19 )
21 20
22 from E5Gui.E5Application import e5App 21 from E5Gui.E5Application import e5App
23 from E5Gui import E5MessageBox 22 from E5Gui import E5MessageBox
23 from E5Gui.E5OverrideCursor import E5OverrideCursor
24 24
25 from UI.Browser import Browser 25 from UI.Browser import Browser
26 from UI.BrowserModel import BrowserDirectoryItem, BrowserFileItem 26 from UI.BrowserModel import BrowserDirectoryItem, BrowserFileItem
27 27
28 from .ProjectBrowserModel import ( 28 from .ProjectBrowserModel import (
364 def _expandAllDirs(self): 364 def _expandAllDirs(self):
365 """ 365 """
366 Protected slot to handle the 'Expand all directories' menu action. 366 Protected slot to handle the 'Expand all directories' menu action.
367 """ 367 """
368 self._disconnectExpandedCollapsed() 368 self._disconnectExpandedCollapsed()
369 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) 369 with E5OverrideCursor():
370 QApplication.processEvents() 370 index = self.model().index(0, 0)
371 index = self.model().index(0, 0) 371 while index.isValid():
372 while index.isValid(): 372 itm = self.model().item(index)
373 itm = self.model().item(index) 373 if (
374 if ( 374 isinstance(
375 isinstance( 375 itm,
376 itm, 376 (ProjectBrowserSimpleDirectoryItem,
377 (ProjectBrowserSimpleDirectoryItem, 377 ProjectBrowserDirectoryItem)) and
378 ProjectBrowserDirectoryItem)) and 378 not self.isExpanded(index)
379 not self.isExpanded(index) 379 ):
380 ): 380 self.expand(index)
381 self.expand(index) 381 index = self.indexBelow(index)
382 index = self.indexBelow(index) 382 self.layoutDisplay()
383 self.layoutDisplay()
384 self._connectExpandedCollapsed() 383 self._connectExpandedCollapsed()
385 QApplication.restoreOverrideCursor()
386 384
387 def _collapseAllDirs(self): 385 def _collapseAllDirs(self):
388 """ 386 """
389 Protected slot to handle the 'Collapse all directories' menu action. 387 Protected slot to handle the 'Collapse all directories' menu action.
390 """ 388 """
391 self._disconnectExpandedCollapsed() 389 self._disconnectExpandedCollapsed()
392 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) 390 with E5OverrideCursor():
393 QApplication.processEvents() 391 # step 1: find last valid index
394 # step 1: find last valid index 392 vindex = QModelIndex()
395 vindex = QModelIndex() 393 index = self.model().index(0, 0)
396 index = self.model().index(0, 0) 394 while index.isValid():
397 while index.isValid(): 395 vindex = index
398 vindex = index 396 index = self.indexBelow(index)
399 index = self.indexBelow(index) 397
400 398 # step 2: go up collapsing all directory items
401 # step 2: go up collapsing all directory items 399 index = vindex
402 index = vindex 400 while index.isValid():
403 while index.isValid(): 401 itm = self.model().item(index)
404 itm = self.model().item(index) 402 if (
405 if ( 403 isinstance(
406 isinstance( 404 itm,
407 itm, 405 (ProjectBrowserSimpleDirectoryItem,
408 (ProjectBrowserSimpleDirectoryItem, 406 ProjectBrowserDirectoryItem)) and
409 ProjectBrowserDirectoryItem)) and 407 self.isExpanded(index)
410 self.isExpanded(index) 408 ):
411 ): 409 self.collapse(index)
412 self.collapse(index) 410 index = self.indexAbove(index)
413 index = self.indexAbove(index) 411 self.layoutDisplay()
414 self.layoutDisplay()
415 self._connectExpandedCollapsed() 412 self._connectExpandedCollapsed()
416 QApplication.restoreOverrideCursor()
417 413
418 def _showContextMenu(self, menu): 414 def _showContextMenu(self, menu):
419 """ 415 """
420 Protected slot called before the context menu is shown. 416 Protected slot called before the context menu is shown.
421 417
504 compareString = self.project.vcs.vcsName() 500 compareString = self.project.vcs.vcsName()
505 501
506 # expand all directories in order to iterate over all entries 502 # expand all directories in order to iterate over all entries
507 self._expandAllDirs() 503 self._expandAllDirs()
508 504
509 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
510 QApplication.processEvents()
511 self.selectionModel().clear() 505 self.selectionModel().clear()
512 QApplication.processEvents() 506
513 507 with E5OverrideCursor():
514 # now iterate over all entries 508 # now iterate over all entries
515 startIndex = None 509 startIndex = None
516 endIndex = None 510 endIndex = None
517 selectedEntries = 0 511 selectedEntries = 0
518 index = self.model().index(0, 0) 512 index = self.model().index(0, 0)
519 while index.isValid(): 513 while index.isValid():
520 itm = self.model().item(index) 514 itm = self.model().item(index)
521 if (
522 self.wantedItem(itm, filterList) and
523 compareString == itm.data(1)
524 ):
525 if ( 515 if (
526 startIndex is not None and 516 self.wantedItem(itm, filterList) and
527 startIndex.parent() != index.parent() 517 compareString == itm.data(1)
528 ): 518 ):
529 self._setItemRangeSelected(startIndex, endIndex, True) 519 if (
530 startIndex = None 520 startIndex is not None and
531 selectedEntries += 1 521 startIndex.parent() != index.parent()
532 if startIndex is None: 522 ):
533 startIndex = index 523 self._setItemRangeSelected(startIndex, endIndex, True)
534 endIndex = index 524 startIndex = None
535 else: 525 selectedEntries += 1
536 if startIndex is not None: 526 if startIndex is None:
537 self._setItemRangeSelected(startIndex, endIndex, True) 527 startIndex = index
538 startIndex = None 528 endIndex = index
539 index = self.indexBelow(index) 529 else:
540 if startIndex is not None: 530 if startIndex is not None:
541 self._setItemRangeSelected(startIndex, endIndex, True) 531 self._setItemRangeSelected(startIndex, endIndex, True)
542 QApplication.restoreOverrideCursor() 532 startIndex = None
543 QApplication.processEvents() 533 index = self.indexBelow(index)
534 if startIndex is not None:
535 self._setItemRangeSelected(startIndex, endIndex, True)
544 536
545 if selectedEntries == 0: 537 if selectedEntries == 0:
546 E5MessageBox.information( 538 E5MessageBox.information(
547 self, 539 self,
548 QCoreApplication.translate( 540 QCoreApplication.translate(
626 """ 618 """
627 Protected slot to handle the prepareRepopulateItem signal. 619 Protected slot to handle the prepareRepopulateItem signal.
628 620
629 @param name relative name of file item to be repopulated (string) 621 @param name relative name of file item to be repopulated (string)
630 """ 622 """
631 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
632 QApplication.processEvents()
633 itm = self.currentItem() 623 itm = self.currentItem()
634 if itm is not None: 624 if itm is not None:
635 self.currentItemName = itm.data(0) 625 self.currentItemName = itm.data(0)
636 self.expandedNames = [] 626 self.expandedNames = []
637 sindex = self._model.itemIndexByName(name) 627 sindex = self._model.itemIndexByName(name)
682 childIndex = self.indexBelow(childIndex) 672 childIndex = self.indexBelow(childIndex)
683 else: 673 else:
684 self._selectSingleItem(index) 674 self._selectSingleItem(index)
685 self.expandedNames = [] 675 self.expandedNames = []
686 self.currentItemName = None 676 self.currentItemName = None
687 QApplication.restoreOverrideCursor()
688 QApplication.processEvents()
689 self._resort() 677 self._resort()
690 678
691 def currentItem(self): 679 def currentItem(self):
692 """ 680 """
693 Public method to get a reference to the current item. 681 Public method to get a reference to the current item.

eric ide

mercurial