Project/ProjectBaseBrowser.py

changeset 2995
63d874899b8b
parent 2965
d133c7edd88a
child 3010
befeff46ec0f
equal deleted inserted replaced
2994:5ae1349b8fb4 2995:63d874899b8b
8 """ 8 """
9 9
10 import os 10 import os
11 11
12 from PyQt4.QtCore import QModelIndex, pyqtSignal, Qt 12 from PyQt4.QtCore import QModelIndex, pyqtSignal, Qt
13 from PyQt4.QtGui import QTreeView, QCursor, QItemSelection, QItemSelectionModel, \ 13 from PyQt4.QtGui import QTreeView, QCursor, QItemSelection, \
14 QApplication, QMenu, QAbstractItemView, QDialog 14 QItemSelectionModel, QApplication, QMenu, QAbstractItemView, QDialog
15 15
16 from E5Gui.E5Application import e5App 16 from E5Gui.E5Application import e5App
17 from E5Gui import E5MessageBox 17 from E5Gui import E5MessageBox
18 18
19 from UI.Browser import Browser 19 from UI.Browser import Browser
20 20
21 from .ProjectBrowserModel import ProjectBrowserSimpleDirectoryItem, \ 21 from .ProjectBrowserModel import ProjectBrowserSimpleDirectoryItem, \
22 ProjectBrowserDirectoryItem, ProjectBrowserFileItem 22 ProjectBrowserDirectoryItem, ProjectBrowserFileItem
23 from .ProjectBrowserSortFilterProxyModel import ProjectBrowserSortFilterProxyModel 23 from .ProjectBrowserSortFilterProxyModel import \
24 ProjectBrowserSortFilterProxyModel
24 25
25 26
26 class ProjectBaseBrowser(Browser): 27 class ProjectBaseBrowser(Browser):
27 """ 28 """
28 Baseclass implementing common functionality for the various project 29 Baseclass implementing common functionality for the various project
109 QApplication.translate('ProjectBaseBrowser', 'Open'), 110 QApplication.translate('ProjectBaseBrowser', 'Open'),
110 self._openItem) 111 self._openItem)
111 112
112 # create the menu for multiple selected files 113 # create the menu for multiple selected files
113 self.multiMenu = QMenu(self) 114 self.multiMenu = QMenu(self)
114 self.multiMenu.addAction(QApplication.translate('ProjectBaseBrowser', 'Open'), 115 self.multiMenu.addAction(
116 QApplication.translate('ProjectBaseBrowser', 'Open'),
115 self._openItem) 117 self._openItem)
116 118
117 # create the background menu 119 # create the background menu
118 self.backMenu = None 120 self.backMenu = None
119 121
269 dn = itm.dirName() 271 dn = itm.dirName()
270 self.project.removeDirectory(dn) 272 self.project.removeDirectory(dn)
271 273
272 def _deleteDirectory(self): 274 def _deleteDirectory(self):
273 """ 275 """
274 Protected method to delete the selected directory from the project data area. 276 Protected method to delete the selected directory from the project
277 data area.
275 """ 278 """
276 itmList = self.getSelectedItems() 279 itmList = self.getSelectedItems()
277 280
278 dirs = [] 281 dirs = []
279 fullNames = [] 282 fullNames = []
281 dn = itm.dirName() 284 dn = itm.dirName()
282 fullNames.append(dn) 285 fullNames.append(dn)
283 dn = self.project.getRelativePath(dn) 286 dn = self.project.getRelativePath(dn)
284 dirs.append(dn) 287 dirs.append(dn)
285 288
286 from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog 289 from UI.DeleteFilesConfirmationDialog import \
290 DeleteFilesConfirmationDialog
287 dlg = DeleteFilesConfirmationDialog(self.parent(), 291 dlg = DeleteFilesConfirmationDialog(self.parent(),
288 self.trUtf8("Delete directories"), 292 self.trUtf8("Delete directories"),
289 self.trUtf8("Do you really want to delete these directories from" 293 self.trUtf8("Do you really want to delete these directories from"
290 " the project?"), 294 " the project?"),
291 dirs) 295 dirs)
410 else: 414 else:
411 self.vcsHelper.showContextMenu(menu, self.menuActions) 415 self.vcsHelper.showContextMenu(menu, self.menuActions)
412 416
413 def _showContextMenuMulti(self, menu): 417 def _showContextMenuMulti(self, menu):
414 """ 418 """
415 Protected slot called before the context menu (multiple selections) is shown. 419 Protected slot called before the context menu (multiple selections) is
420 shown.
416 421
417 It enables/disables the VCS menu entries depending on the overall 422 It enables/disables the VCS menu entries depending on the overall
418 VCS status and the files status. 423 VCS status and the files status.
419 424
420 @param menu reference to the menu to be shown (QMenu) 425 @param menu reference to the menu to be shown (QMenu)
451 """ 456 """
452 if self.project.vcs is None: 457 if self.project.vcs is None:
453 for act in self.dirMultiMenuActions: 458 for act in self.dirMultiMenuActions:
454 act.setEnabled(True) 459 act.setEnabled(True)
455 else: 460 else:
456 self.vcsHelper.showContextMenuDirMulti(menu, self.dirMultiMenuActions) 461 self.vcsHelper.showContextMenuDirMulti(
462 menu, self.dirMultiMenuActions)
457 463
458 def _showContextMenuBack(self, menu): 464 def _showContextMenuBack(self, menu):
459 """ 465 """
460 Protected slot called before the context menu is shown. 466 Protected slot called before the context menu is shown.
461 467
466 472
467 def _selectEntries(self, local=True, filter=None): 473 def _selectEntries(self, local=True, filter=None):
468 """ 474 """
469 Protected method to select entries based on their VCS status. 475 Protected method to select entries based on their VCS status.
470 476
471 @param local flag indicating local (i.e. non VCS controlled) file/directory 477 @param local flag indicating local (i.e. non VCS controlled)
472 entries should be selected (boolean) 478 file/directory entries should be selected (boolean)
473 @param filter list of classes to check against 479 @param filter list of classes to check against
474 """ 480 """
475 if self.project.vcs is None: 481 if self.project.vcs is None:
476 return 482 return
477 483
478 if local: 484 if local:
479 compareString = QApplication.translate('ProjectBaseBrowser', "local") 485 compareString = \
486 QApplication.translate('ProjectBaseBrowser', "local")
480 else: 487 else:
481 compareString = self.project.vcs.vcsName() 488 compareString = self.project.vcs.vcsName()
482 489
483 # expand all directories in order to iterate over all entries 490 # expand all directories in order to iterate over all entries
484 self._expandAllDirs() 491 self._expandAllDirs()
536 def selectLocalDirEntries(self): 543 def selectLocalDirEntries(self):
537 """ 544 """
538 Public slot to handle the select local directories context menu entries. 545 Public slot to handle the select local directories context menu entries.
539 """ 546 """
540 self._selectEntries(local=True, 547 self._selectEntries(local=True,
541 filter=[ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem]) 548 filter=[ProjectBrowserSimpleDirectoryItem,
549 ProjectBrowserDirectoryItem])
542 550
543 def selectVCSDirEntries(self): 551 def selectVCSDirEntries(self):
544 """ 552 """
545 Public slot to handle the select VCS directories context menu entries. 553 Public slot to handle the select VCS directories context menu entries.
546 """ 554 """
547 self._selectEntries(local=False, 555 self._selectEntries(local=False,
548 filter=[ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem]) 556 filter=[ProjectBrowserSimpleDirectoryItem,
557 ProjectBrowserDirectoryItem])
549 558
550 def _prepareRepopulateItem(self, name): 559 def _prepareRepopulateItem(self, name):
551 """ 560 """
552 Protected slot to handle the prepareRepopulateItem signal. 561 Protected slot to handle the prepareRepopulateItem signal.
553 562
570 childIndex = self.indexBelow(index) 579 childIndex = self.indexBelow(index)
571 while childIndex.isValid(): 580 while childIndex.isValid():
572 if childIndex.parent() == index.parent(): 581 if childIndex.parent() == index.parent():
573 break 582 break
574 if self.isExpanded(childIndex): 583 if self.isExpanded(childIndex):
575 self.expandedNames.append(self.model().item(childIndex).data(0)) 584 self.expandedNames.append(
585 self.model().item(childIndex).data(0))
576 childIndex = self.indexBelow(childIndex) 586 childIndex = self.indexBelow(childIndex)
577 587
578 def _completeRepopulateItem(self, name): 588 def _completeRepopulateItem(self, name):
579 """ 589 """
580 Protected slot to handle the completeRepopulateItem signal. 590 Protected slot to handle the completeRepopulateItem signal.
586 index = self.model().mapFromSource(sindex) 596 index = self.model().mapFromSource(sindex)
587 if index.isValid(): 597 if index.isValid():
588 if self.isExpanded(index): 598 if self.isExpanded(index):
589 childIndex = self.indexBelow(index) 599 childIndex = self.indexBelow(index)
590 while childIndex.isValid(): 600 while childIndex.isValid():
591 if not childIndex.isValid() or childIndex.parent() == index.parent(): 601 if not childIndex.isValid() or \
602 childIndex.parent() == index.parent():
592 break 603 break
593 itm = self.model().item(childIndex) 604 itm = self.model().item(childIndex)
594 if itm is not None: 605 if itm is not None:
595 itemData = itm.data(0) 606 itemData = itm.data(0)
596 if self.currentItemName and self.currentItemName == itemData: 607 if self.currentItemName and \
608 self.currentItemName == itemData:
597 self._selectSingleItem(childIndex) 609 self._selectSingleItem(childIndex)
598 if itemData in self.expandedNames: 610 if itemData in self.expandedNames:
599 self.setExpanded(childIndex, True) 611 self.setExpanded(childIndex, True)
600 childIndex = self.indexBelow(childIndex) 612 childIndex = self.indexBelow(childIndex)
601 else: 613 else:
613 @return reference to the current item 625 @return reference to the current item
614 """ 626 """
615 itm = self.model().item(self.currentIndex()) 627 itm = self.model().item(self.currentIndex())
616 return itm 628 return itm
617 629
618 ############################################################################ 630 ###########################################################################
619 ## Support for hooks below 631 ## Support for hooks below
620 ############################################################################ 632 ###########################################################################
621 633
622 def _initHookMethods(self): 634 def _initHookMethods(self):
623 """ 635 """
624 Protected method to initialize the hooks dictionary. 636 Protected method to initialize the hooks dictionary.
625 637
680 692
681 def _configure(self): 693 def _configure(self):
682 """ 694 """
683 Protected method to open the configuration dialog. 695 Protected method to open the configuration dialog.
684 """ 696 """
685 e5App().getObject("UserInterface").showPreferences("projectBrowserPage") 697 e5App().getObject("UserInterface")\
698 .showPreferences("projectBrowserPage")

eric ide

mercurial