src/eric7/Project/ProjectBaseBrowser.py

branch
eric7
changeset 10430
e440aaf179ce
parent 10398
ef1ea18994d5
child 10439
21c28b0f9e41
equal deleted inserted replaced
10429:643989a1e2bd 10430:e440aaf179ce
164 164
165 def _contextMenuRequested(self, coord): 165 def _contextMenuRequested(self, coord):
166 """ 166 """
167 Protected slot to show the context menu. 167 Protected slot to show the context menu.
168 168
169 @param coord the position of the mouse pointer (QPoint) 169 @param coord the position of the mouse pointer
170 @type QPoint
170 """ 171 """
171 if not self.project.isOpen(): 172 if not self.project.isOpen():
172 return 173 return
173 174
174 cnt = self.getSelectedItemsCount() 175 cnt = self.getSelectedItemsCount()
184 185
185 def _selectSingleItem(self, index): 186 def _selectSingleItem(self, index):
186 """ 187 """
187 Protected method to select a single item. 188 Protected method to select a single item.
188 189
189 @param index index of item to be selected (QModelIndex) 190 @param index index of item to be selected
191 @type QModelIndex
190 """ 192 """
191 if index.isValid(): 193 if index.isValid():
192 self.setCurrentIndex(index) 194 self.setCurrentIndex(index)
193 self.selectionModel().select( 195 self.selectionModel().select(
194 index, 196 index,
198 200
199 def _setItemSelected(self, index, selected): 201 def _setItemSelected(self, index, selected):
200 """ 202 """
201 Protected method to set the selection status of an item. 203 Protected method to set the selection status of an item.
202 204
203 @param index index of item to set (QModelIndex) 205 @param index index of item to set
204 @param selected flag giving the new selection status (boolean) 206 @type QModelIndex
207 @param selected flag giving the new selection status
208 @type bool
205 """ 209 """
206 if index.isValid(): 210 if index.isValid():
207 self.selectionModel().select( 211 self.selectionModel().select(
208 index, selected and self.SelectFlags or self.DeselectFlags 212 index, selected and self.SelectFlags or self.DeselectFlags
209 ) 213 )
210 214
211 def _setItemRangeSelected(self, startIndex, endIndex, selected): 215 def _setItemRangeSelected(self, startIndex, endIndex, selected):
212 """ 216 """
213 Protected method to set the selection status of a range of items. 217 Protected method to set the selection status of a range of items.
214 218
215 @param startIndex start index of range of items to set (QModelIndex) 219 @param startIndex start index of range of items to set
216 @param endIndex end index of range of items to set (QModelIndex) 220 @type QModelIndex
217 @param selected flag giving the new selection status (boolean) 221 @param endIndex end index of range of items to set
222 @type QModelIndex
223 @param selected flag giving the new selection status
224 @type bool
218 """ 225 """
219 selection = QItemSelection(startIndex, endIndex) 226 selection = QItemSelection(startIndex, endIndex)
220 self.selectionModel().select( 227 self.selectionModel().select(
221 selection, selected and self.SelectFlags or self.DeselectFlags 228 selection, selected and self.SelectFlags or self.DeselectFlags
222 ) 229 )
223 230
224 def __modelRowsInserted(self, parent, start, end): # noqa: U100 231 def __modelRowsInserted(self, parent, start, end): # noqa: U100
225 """ 232 """
226 Private slot called after rows have been inserted into the model. 233 Private slot called after rows have been inserted into the model.
227 234
228 @param parent parent index of inserted rows (QModelIndex) 235 @param parent parent index of inserted rows
229 @param start start row number (integer) 236 @type QModelIndex
230 @param end end row number (integer) 237 @param start start row number
238 @type int
239 @param end end row number
240 @type int
231 """ 241 """
232 self._resizeColumns() 242 self._resizeColumns()
233 243
234 def _projectClosed(self): 244 def _projectClosed(self):
235 """ 245 """
355 365
356 def selectFile(self, fn): 366 def selectFile(self, fn):
357 """ 367 """
358 Public method to highlight a node given its filename. 368 Public method to highlight a node given its filename.
359 369
360 @param fn filename of file to be highlighted (string) 370 @param fn filename of file to be highlighted
371 @type str
361 """ 372 """
362 newfn = os.path.abspath(fn) 373 newfn = os.path.abspath(fn)
363 newfn = self.project.getRelativePath(newfn) 374 newfn = self.project.getRelativePath(newfn)
364 sindex = self._model.itemIndexByName(newfn) 375 sindex = self._model.itemIndexByName(newfn)
365 if sindex.isValid(): 376 if sindex.isValid():
370 381
371 def selectFileLine(self, fn, lineno): 382 def selectFileLine(self, fn, lineno):
372 """ 383 """
373 Public method to highlight a node given its filename. 384 Public method to highlight a node given its filename.
374 385
375 @param fn filename of file to be highlighted (string) 386 @param fn filename of file to be highlighted
376 @param lineno one based line number of the item (integer) 387 @type str
388 @param lineno one based line number of the item
389 @type int
377 """ 390 """
378 newfn = os.path.abspath(fn) 391 newfn = os.path.abspath(fn)
379 newfn = self.project.getRelativePath(newfn) 392 newfn = self.project.getRelativePath(newfn)
380 sindex = self._model.itemIndexByNameAndLine(newfn, lineno) 393 sindex = self._model.itemIndexByNameAndLine(newfn, lineno)
381 if sindex.isValid(): 394 if sindex.isValid():
481 Protected slot called before the context menu is shown. 494 Protected slot called before the context menu is shown.
482 495
483 It enables/disables the VCS menu entries depending on the overall 496 It enables/disables the VCS menu entries depending on the overall
484 VCS status and the file status. 497 VCS status and the file status.
485 498
486 @param menu reference to the menu to be shown (QMenu) 499 @param menu reference to the menu to be shown
500 @type QMenu
487 """ 501 """
488 if self.project.vcs is None: 502 if self.project.vcs is None:
489 for act in self.menuActions: 503 for act in self.menuActions:
490 act.setEnabled(True) 504 act.setEnabled(True)
491 else: 505 else:
497 shown. 511 shown.
498 512
499 It enables/disables the VCS menu entries depending on the overall 513 It enables/disables the VCS menu entries depending on the overall
500 VCS status and the files status. 514 VCS status and the files status.
501 515
502 @param menu reference to the menu to be shown (QMenu) 516 @param menu reference to the menu to be shown
517 @type QMenu
503 """ 518 """
504 if self.project.vcs is None: 519 if self.project.vcs is None:
505 for act in self.multiMenuActions: 520 for act in self.multiMenuActions:
506 act.setEnabled(True) 521 act.setEnabled(True)
507 else: 522 else:
512 Protected slot called before the context menu is shown. 527 Protected slot called before the context menu is shown.
513 528
514 It enables/disables the VCS menu entries depending on the overall 529 It enables/disables the VCS menu entries depending on the overall
515 VCS status and the directory status. 530 VCS status and the directory status.
516 531
517 @param menu reference to the menu to be shown (QMenu) 532 @param menu reference to the menu to be shown
533 @type QMenu
518 """ 534 """
519 if self.project.vcs is None: 535 if self.project.vcs is None:
520 for act in self.dirMenuActions: 536 for act in self.dirMenuActions:
521 act.setEnabled(True) 537 act.setEnabled(True)
522 else: 538 else:
527 Protected slot called before the context menu is shown. 543 Protected slot called before the context menu is shown.
528 544
529 It enables/disables the VCS menu entries depending on the overall 545 It enables/disables the VCS menu entries depending on the overall
530 VCS status and the directory status. 546 VCS status and the directory status.
531 547
532 @param menu reference to the menu to be shown (QMenu) 548 @param menu reference to the menu to be shown
549 @type QMenu
533 """ 550 """
534 if self.project.vcs is None: 551 if self.project.vcs is None:
535 for act in self.dirMultiMenuActions: 552 for act in self.dirMultiMenuActions:
536 act.setEnabled(True) 553 act.setEnabled(True)
537 else: 554 else:
539 556
540 def _showContextMenuBack(self, menu): # noqa: U100 557 def _showContextMenuBack(self, menu): # noqa: U100
541 """ 558 """
542 Protected slot called before the context menu is shown. 559 Protected slot called before the context menu is shown.
543 560
544 @param menu reference to the menu to be shown (QMenu) 561 @param menu reference to the menu to be shown
562 @type QMenu
545 """ 563 """
546 # nothing to do for now 564 # nothing to do for now
547 return 565 return
548 566
549 def _selectEntries(self, local=True, filterList=None): 567 def _selectEntries(self, local=True, filterList=None):
550 """ 568 """
551 Protected method to select entries based on their VCS status. 569 Protected method to select entries based on their VCS status.
552 570
553 @param local flag indicating local (i.e. non VCS controlled) 571 @param local flag indicating local (i.e. non VCS controlled)
554 file/directory entries should be selected (boolean) 572 file/directory entries should be selected
573 @type boolean)
555 @param filterList list of classes to check against 574 @param filterList list of classes to check against
575 @type Class
556 """ 576 """
557 if self.project.vcs is None: 577 if self.project.vcs is None:
558 return 578 return
559 579
560 compareString = ( 580 compareString = (
634 654
635 def getExpandedItemNames(self): 655 def getExpandedItemNames(self):
636 """ 656 """
637 Public method to get the file/directory names of all expanded items. 657 Public method to get the file/directory names of all expanded items.
638 658
639 @return list of expanded items names (list of string) 659 @return list of expanded items names
660 @rtype list of str
640 """ 661 """
641 expandedNames = [] 662 expandedNames = []
642 663
643 childIndex = self.model().index(0, 0) 664 childIndex = self.model().index(0, 0)
644 while childIndex.isValid(): 665 while childIndex.isValid():
652 673
653 def expandItemsByName(self, names): 674 def expandItemsByName(self, names):
654 """ 675 """
655 Public method to expand items given their names. 676 Public method to expand items given their names.
656 677
657 @param names list of item names to be expanded (list of string) 678 @param names list of item names to be expanded
679 @type list of str
658 """ 680 """
659 model = self.model() 681 model = self.model()
660 for name in names: 682 for name in names:
661 childIndex = model.index(0, 0) 683 childIndex = model.index(0, 0)
662 while childIndex.isValid(): 684 while childIndex.isValid():
669 691
670 def _prepareRepopulateItem(self, name): 692 def _prepareRepopulateItem(self, name):
671 """ 693 """
672 Protected slot to handle the prepareRepopulateItem signal. 694 Protected slot to handle the prepareRepopulateItem signal.
673 695
674 @param name relative name of file item to be repopulated (string) 696 @param name relative name of file item to be repopulated
697 @type str
675 """ 698 """
676 itm = self.currentItem() 699 itm = self.currentItem()
677 if itm is not None: 700 if itm is not None:
678 self.currentItemName = itm.data(0) 701 self.currentItemName = itm.data(0)
679 self.expandedNames = [] 702 self.expandedNames = []
695 718
696 def _completeRepopulateItem(self, name): 719 def _completeRepopulateItem(self, name):
697 """ 720 """
698 Protected slot to handle the completeRepopulateItem signal. 721 Protected slot to handle the completeRepopulateItem signal.
699 722
700 @param name relative name of file item to be repopulated (string) 723 @param name relative name of file item to be repopulated
724 @type str
701 """ 725 """
702 sindex = self._model.itemIndexByName(name) 726 sindex = self._model.itemIndexByName(name)
703 if sindex.isValid(): 727 if sindex.isValid():
704 index = self.model().mapFromSource(sindex) 728 index = self.model().mapFromSource(sindex)
705 if index.isValid(): 729 if index.isValid():
731 def currentItem(self): 755 def currentItem(self):
732 """ 756 """
733 Public method to get a reference to the current item. 757 Public method to get a reference to the current item.
734 758
735 @return reference to the current item 759 @return reference to the current item
760 @rtype BrowserItem
736 """ 761 """
737 itm = self.model().item(self.currentIndex()) 762 itm = self.model().item(self.currentIndex())
738 return itm 763 return itm
739 764
740 def currentDirectory(self, relative=False): 765 def currentDirectory(self, relative=False):
799 824
800 def __checkHookKey(self, key): 825 def __checkHookKey(self, key):
801 """ 826 """
802 Private method to check a hook key. 827 Private method to check a hook key.
803 828
804 @param key key of the hook to check (string) 829 @param key key of the hook to check
830 @type str
805 @exception KeyError raised to indicate an invalid hook 831 @exception KeyError raised to indicate an invalid hook
806 """ 832 """
807 if len(self.hooks) == 0: 833 if len(self.hooks) == 0:
808 raise KeyError("Hooks are not initialized.") 834 raise KeyError("Hooks are not initialized.")
809 835
812 838
813 def addHookMethod(self, key, method): 839 def addHookMethod(self, key, method):
814 """ 840 """
815 Public method to add a hook method to the dictionary. 841 Public method to add a hook method to the dictionary.
816 842
817 @param key for the hook method (string) 843 @param key for the hook method
818 @param method reference to the hook method (method object) 844 @type str
845 @param method reference to the hook method
846 @type function
819 """ 847 """
820 self.__checkHookKey(key) 848 self.__checkHookKey(key)
821 self.hooks[key] = method 849 self.hooks[key] = method
822 850
823 def addHookMethodAndMenuEntry(self, key, method, menuEntry): 851 def addHookMethodAndMenuEntry(self, key, method, menuEntry):
824 """ 852 """
825 Public method to add a hook method to the dictionary. 853 Public method to add a hook method to the dictionary.
826 854
827 @param key for the hook method (string) 855 @param key for the hook method
828 @param method reference to the hook method (method object) 856 @type str
829 @param menuEntry entry to be shown in the context menu (string) 857 @param method reference to the hook method
858 @type function
859 @param menuEntry entry to be shown in the context menu
860 @type str
830 """ 861 """
831 self.addHookMethod(key, method) 862 self.addHookMethod(key, method)
832 self.hooksMenuEntries[key] = menuEntry 863 self.hooksMenuEntries[key] = menuEntry
833 864
834 def removeHookMethod(self, key): 865 def removeHookMethod(self, key):
835 """ 866 """
836 Public method to remove a hook method from the dictionary. 867 Public method to remove a hook method from the dictionary.
837 868
838 @param key for the hook method (string) 869 @param key for the hook method
870 @type str
839 """ 871 """
840 self.__checkHookKey(key) 872 self.__checkHookKey(key)
841 self.hooks[key] = None 873 self.hooks[key] = None
842 if key in self.hooksMenuEntries: 874 if key in self.hooksMenuEntries:
843 del self.hooksMenuEntries[key] 875 del self.hooksMenuEntries[key]

eric ide

mercurial