Project/ProjectBaseBrowser.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2791
a9577f248f04
parent 3010
befeff46ec0f
child 3058
0a02c433f52d
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
10 from __future__ import unicode_literals # __IGNORE_WARNING__ 10 from __future__ import unicode_literals # __IGNORE_WARNING__
11 11
12 import os 12 import os
13 13
14 from PyQt4.QtCore import QModelIndex, pyqtSignal, Qt 14 from PyQt4.QtCore import QModelIndex, pyqtSignal, Qt
15 from PyQt4.QtGui import QTreeView, QCursor, QItemSelection, QItemSelectionModel, \ 15 from PyQt4.QtGui import QTreeView, QCursor, QItemSelection, \
16 QApplication, QMenu, QAbstractItemView, QDialog 16 QItemSelectionModel, QApplication, QMenu, QAbstractItemView, QDialog
17 17
18 from E5Gui.E5Application import e5App 18 from E5Gui.E5Application import e5App
19 from E5Gui import E5MessageBox 19 from E5Gui import E5MessageBox
20 20
21 from UI.Browser import Browser 21 from UI.Browser import Browser
22 22
23 from .ProjectBrowserModel import ProjectBrowserSimpleDirectoryItem, \ 23 from .ProjectBrowserModel import ProjectBrowserSimpleDirectoryItem, \
24 ProjectBrowserDirectoryItem, ProjectBrowserFileItem 24 ProjectBrowserDirectoryItem, ProjectBrowserFileItem
25 from .ProjectBrowserSortFilterProxyModel import ProjectBrowserSortFilterProxyModel 25 from .ProjectBrowserSortFilterProxyModel import \
26 ProjectBrowserSortFilterProxyModel
26 27
27 28
28 class ProjectBaseBrowser(Browser): 29 class ProjectBaseBrowser(Browser):
29 """ 30 """
30 Baseclass implementing common functionality for the various project browsers. 31 Baseclass implementing common functionality for the various project
32 browsers.
31 33
32 @signal closeSourceWindow(str) emitted to close a source file 34 @signal closeSourceWindow(str) emitted to close a source file
33 """ 35 """
34 closeSourceWindow = pyqtSignal(str) 36 closeSourceWindow = pyqtSignal(str)
35 37
36 def __init__(self, project, type_, parent=None): 38 def __init__(self, project, type_, parent=None):
37 """ 39 """
38 Constructor 40 Constructor
39 41
40 @param project reference to the project object 42 @param project reference to the project object
41 @param type project browser type (string) 43 @param type_ project browser type (string)
42 @param parent parent widget of this browser 44 @param parent parent widget of this browser
43 """ 45 """
44 QTreeView.__init__(self, parent) 46 QTreeView.__init__(self, parent)
45 47
46 self.project = project 48 self.project = project
110 QApplication.translate('ProjectBaseBrowser', 'Open'), 112 QApplication.translate('ProjectBaseBrowser', 'Open'),
111 self._openItem) 113 self._openItem)
112 114
113 # create the menu for multiple selected files 115 # create the menu for multiple selected files
114 self.multiMenu = QMenu(self) 116 self.multiMenu = QMenu(self)
115 self.multiMenu.addAction(QApplication.translate('ProjectBaseBrowser', 'Open'), 117 self.multiMenu.addAction(
118 QApplication.translate('ProjectBaseBrowser', 'Open'),
116 self._openItem) 119 self._openItem)
117 120
118 # create the background menu 121 # create the background menu
119 self.backMenu = None 122 self.backMenu = None
120 123
270 dn = itm.dirName() 273 dn = itm.dirName()
271 self.project.removeDirectory(dn) 274 self.project.removeDirectory(dn)
272 275
273 def _deleteDirectory(self): 276 def _deleteDirectory(self):
274 """ 277 """
275 Protected method to delete the selected directory from the project data area. 278 Protected method to delete the selected directory from the project
279 data area.
276 """ 280 """
277 itmList = self.getSelectedItems() 281 itmList = self.getSelectedItems()
278 282
279 dirs = [] 283 dirs = []
280 fullNames = [] 284 fullNames = []
282 dn = itm.dirName() 286 dn = itm.dirName()
283 fullNames.append(dn) 287 fullNames.append(dn)
284 dn = self.project.getRelativePath(dn) 288 dn = self.project.getRelativePath(dn)
285 dirs.append(dn) 289 dirs.append(dn)
286 290
287 from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog 291 from UI.DeleteFilesConfirmationDialog import \
292 DeleteFilesConfirmationDialog
288 dlg = DeleteFilesConfirmationDialog(self.parent(), 293 dlg = DeleteFilesConfirmationDialog(self.parent(),
289 self.trUtf8("Delete directories"), 294 self.trUtf8("Delete directories"),
290 self.trUtf8("Do you really want to delete these directories from" 295 self.trUtf8("Do you really want to delete these directories from"
291 " the project?"), 296 " the project?"),
292 dirs) 297 dirs)
411 else: 416 else:
412 self.vcsHelper.showContextMenu(menu, self.menuActions) 417 self.vcsHelper.showContextMenu(menu, self.menuActions)
413 418
414 def _showContextMenuMulti(self, menu): 419 def _showContextMenuMulti(self, menu):
415 """ 420 """
416 Protected slot called before the context menu (multiple selections) is shown. 421 Protected slot called before the context menu (multiple selections) is
422 shown.
417 423
418 It enables/disables the VCS menu entries depending on the overall 424 It enables/disables the VCS menu entries depending on the overall
419 VCS status and the files status. 425 VCS status and the files status.
420 426
421 @param menu reference to the menu to be shown (QMenu) 427 @param menu reference to the menu to be shown (QMenu)
452 """ 458 """
453 if self.project.vcs is None: 459 if self.project.vcs is None:
454 for act in self.dirMultiMenuActions: 460 for act in self.dirMultiMenuActions:
455 act.setEnabled(True) 461 act.setEnabled(True)
456 else: 462 else:
457 self.vcsHelper.showContextMenuDirMulti(menu, self.dirMultiMenuActions) 463 self.vcsHelper.showContextMenuDirMulti(
464 menu, self.dirMultiMenuActions)
458 465
459 def _showContextMenuBack(self, menu): 466 def _showContextMenuBack(self, menu):
460 """ 467 """
461 Protected slot called before the context menu is shown. 468 Protected slot called before the context menu is shown.
462 469
467 474
468 def _selectEntries(self, local=True, filter=None): 475 def _selectEntries(self, local=True, filter=None):
469 """ 476 """
470 Protected method to select entries based on their VCS status. 477 Protected method to select entries based on their VCS status.
471 478
472 @param local flag indicating local (i.e. non VCS controlled) file/directory 479 @param local flag indicating local (i.e. non VCS controlled)
473 entries should be selected (boolean) 480 file/directory entries should be selected (boolean)
474 @param filter list of classes to check against 481 @param filter list of classes to check against
475 """ 482 """
476 if self.project.vcs is None: 483 if self.project.vcs is None:
477 return 484 return
478 485
479 if local: 486 if local:
480 compareString = QApplication.translate('ProjectBaseBrowser', "local") 487 compareString = \
488 QApplication.translate('ProjectBaseBrowser', "local")
481 else: 489 else:
482 compareString = self.project.vcs.vcsName() 490 compareString = self.project.vcs.vcsName()
483 491
484 # expand all directories in order to iterate over all entries 492 # expand all directories in order to iterate over all entries
485 self._expandAllDirs() 493 self._expandAllDirs()
522 QApplication.translate('ProjectBaseBrowser', 530 QApplication.translate('ProjectBaseBrowser',
523 """There were no matching entries found.""")) 531 """There were no matching entries found."""))
524 532
525 def selectLocalEntries(self): 533 def selectLocalEntries(self):
526 """ 534 """
527 Public slot to handle the select local files context menu entries 535 Public slot to handle the select local files context menu entries.
528 """ 536 """
529 self._selectEntries(local=True, filter=[ProjectBrowserFileItem]) 537 self._selectEntries(local=True, filter=[ProjectBrowserFileItem])
530 538
531 def selectVCSEntries(self): 539 def selectVCSEntries(self):
532 """ 540 """
533 Public slot to handle the select VCS files context menu entries 541 Public slot to handle the select VCS files context menu entries.
534 """ 542 """
535 self._selectEntries(local=False, filter=[ProjectBrowserFileItem]) 543 self._selectEntries(local=False, filter=[ProjectBrowserFileItem])
536 544
537 def selectLocalDirEntries(self): 545 def selectLocalDirEntries(self):
538 """ 546 """
539 Public slot to handle the select local directories context menu entries 547 Public slot to handle the select local directories context menu
548 entries.
540 """ 549 """
541 self._selectEntries(local=True, 550 self._selectEntries(local=True,
542 filter=[ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem]) 551 filter=[ProjectBrowserSimpleDirectoryItem,
552 ProjectBrowserDirectoryItem])
543 553
544 def selectVCSDirEntries(self): 554 def selectVCSDirEntries(self):
545 """ 555 """
546 Public slot to handle the select VCS directories context menu entries 556 Public slot to handle the select VCS directories context menu entries.
547 """ 557 """
548 self._selectEntries(local=False, 558 self._selectEntries(local=False,
549 filter=[ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem]) 559 filter=[ProjectBrowserSimpleDirectoryItem,
560 ProjectBrowserDirectoryItem])
550 561
551 def _prepareRepopulateItem(self, name): 562 def _prepareRepopulateItem(self, name):
552 """ 563 """
553 Protected slot to handle the prepareRepopulateItem signal. 564 Protected slot to handle the prepareRepopulateItem signal.
554 565
571 childIndex = self.indexBelow(index) 582 childIndex = self.indexBelow(index)
572 while childIndex.isValid(): 583 while childIndex.isValid():
573 if childIndex.parent() == index.parent(): 584 if childIndex.parent() == index.parent():
574 break 585 break
575 if self.isExpanded(childIndex): 586 if self.isExpanded(childIndex):
576 self.expandedNames.append(self.model().item(childIndex).data(0)) 587 self.expandedNames.append(
588 self.model().item(childIndex).data(0))
577 childIndex = self.indexBelow(childIndex) 589 childIndex = self.indexBelow(childIndex)
578 590
579 def _completeRepopulateItem(self, name): 591 def _completeRepopulateItem(self, name):
580 """ 592 """
581 Protected slot to handle the completeRepopulateItem signal. 593 Protected slot to handle the completeRepopulateItem signal.
587 index = self.model().mapFromSource(sindex) 599 index = self.model().mapFromSource(sindex)
588 if index.isValid(): 600 if index.isValid():
589 if self.isExpanded(index): 601 if self.isExpanded(index):
590 childIndex = self.indexBelow(index) 602 childIndex = self.indexBelow(index)
591 while childIndex.isValid(): 603 while childIndex.isValid():
592 if not childIndex.isValid() or childIndex.parent() == index.parent(): 604 if not childIndex.isValid() or \
605 childIndex.parent() == index.parent():
593 break 606 break
594 itm = self.model().item(childIndex) 607 itm = self.model().item(childIndex)
595 if itm is not None: 608 if itm is not None:
596 itemData = itm.data(0) 609 itemData = itm.data(0)
597 if self.currentItemName and self.currentItemName == itemData: 610 if self.currentItemName and \
611 self.currentItemName == itemData:
598 self._selectSingleItem(childIndex) 612 self._selectSingleItem(childIndex)
599 if itemData in self.expandedNames: 613 if itemData in self.expandedNames:
600 self.setExpanded(childIndex, True) 614 self.setExpanded(childIndex, True)
601 childIndex = self.indexBelow(childIndex) 615 childIndex = self.indexBelow(childIndex)
602 else: 616 else:
614 @return reference to the current item 628 @return reference to the current item
615 """ 629 """
616 itm = self.model().item(self.currentIndex()) 630 itm = self.model().item(self.currentIndex())
617 return itm 631 return itm
618 632
619 ############################################################################ 633 ###########################################################################
620 ## Support for hooks below 634 ## Support for hooks below
621 ############################################################################ 635 ###########################################################################
622 636
623 def _initHookMethods(self): 637 def _initHookMethods(self):
624 """ 638 """
625 Protected method to initialize the hooks dictionary. 639 Protected method to initialize the hooks dictionary.
626 640
630 """ 644 """
631 self.hooks = {} 645 self.hooks = {}
632 646
633 def __checkHookKey(self, key): 647 def __checkHookKey(self, key):
634 """ 648 """
635 Private method to check a hook key 649 Private method to check a hook key.
650
651 @param key key of the hook to check (string)
652 @exception KeyError raised to indicate an invalid hook
636 """ 653 """
637 if len(self.hooks) == 0: 654 if len(self.hooks) == 0:
638 raise KeyError("Hooks are not initialized.") 655 raise KeyError("Hooks are not initialized.")
639 656
640 if key not in self.hooks: 657 if key not in self.hooks:
678 695
679 def _configure(self): 696 def _configure(self):
680 """ 697 """
681 Protected method to open the configuration dialog. 698 Protected method to open the configuration dialog.
682 """ 699 """
683 e5App().getObject("UserInterface").showPreferences("projectBrowserPage") 700 e5App().getObject("UserInterface")\
701 .showPreferences("projectBrowserPage")

eric ide

mercurial