17 |
17 |
18 from UI.Browser import * |
18 from UI.Browser import * |
19 |
19 |
20 from .ProjectBrowserModel import * |
20 from .ProjectBrowserModel import * |
21 from .ProjectBrowserSortFilterProxyModel import ProjectBrowserSortFilterProxyModel |
21 from .ProjectBrowserSortFilterProxyModel import ProjectBrowserSortFilterProxyModel |
|
22 |
22 |
23 |
23 class ProjectBaseBrowser(Browser): |
24 class ProjectBaseBrowser(Browser): |
24 """ |
25 """ |
25 Baseclass implementing common functionality for the various project browsers. |
26 Baseclass implementing common functionality for the various project browsers. |
26 |
27 |
27 @signal closeSourceWindow(str) emitted to close a source file |
28 @signal closeSourceWindow(str) emitted to close a source file |
28 """ |
29 """ |
29 closeSourceWindow = pyqtSignal(str) |
30 closeSourceWindow = pyqtSignal(str) |
30 |
31 |
31 def __init__(self, project, type_, parent = None): |
32 def __init__(self, project, type_, parent=None): |
32 """ |
33 """ |
33 Constructor |
34 Constructor |
34 |
35 |
35 @param project reference to the project object |
36 @param project reference to the project object |
36 @param type project browser type (string) |
37 @param type project browser type (string) |
92 Protected overloaded method to generate the popup menus. |
93 Protected overloaded method to generate the popup menus. |
93 """ |
94 """ |
94 # create the popup menu for source files |
95 # create the popup menu for source files |
95 self.sourceMenu = QMenu(self) |
96 self.sourceMenu = QMenu(self) |
96 self.sourceMenu.addAction( |
97 self.sourceMenu.addAction( |
97 QApplication.translate('ProjectBaseBrowser', 'Open'), |
98 QApplication.translate('ProjectBaseBrowser', 'Open'), |
98 self._openItem) |
99 self._openItem) |
99 |
100 |
100 # create the popup menu for general use |
101 # create the popup menu for general use |
101 self.menu = QMenu(self) |
102 self.menu = QMenu(self) |
102 self.menu.addAction( |
103 self.menu.addAction( |
103 QApplication.translate('ProjectBaseBrowser', 'Open'), |
104 QApplication.translate('ProjectBaseBrowser', 'Open'), |
104 self._openItem) |
105 self._openItem) |
105 |
106 |
106 # create the menu for multiple selected files |
107 # create the menu for multiple selected files |
107 self.multiMenu = QMenu(self) |
108 self.multiMenu = QMenu(self) |
108 self.multiMenu.addAction(QApplication.translate('ProjectBaseBrowser', 'Open'), |
109 self.multiMenu.addAction(QApplication.translate('ProjectBaseBrowser', 'Open'), |
109 self._openItem) |
110 self._openItem) |
110 |
111 |
111 # create the background menu |
112 # create the background menu |
112 self.backMenu = None |
113 self.backMenu = None |
113 |
114 |
162 |
163 |
163 @param index index of item to set (QModelIndex) |
164 @param index index of item to set (QModelIndex) |
164 @param selected flag giving the new selection status (boolean) |
165 @param selected flag giving the new selection status (boolean) |
165 """ |
166 """ |
166 if index.isValid(): |
167 if index.isValid(): |
167 self.selectionModel().select(index, |
168 self.selectionModel().select(index, |
168 selected and self.SelectFlags or self.DeselectFlags) |
169 selected and self.SelectFlags or self.DeselectFlags) |
169 |
170 |
170 def _setItemRangeSelected(self, startIndex, endIndex, selected): |
171 def _setItemRangeSelected(self, startIndex, endIndex, selected): |
171 """ |
172 """ |
172 Protected method to set the selection status of a range of items. |
173 Protected method to set the selection status of a range of items. |
174 @param startIndex start index of range of items to set (QModelIndex) |
175 @param startIndex start index of range of items to set (QModelIndex) |
175 @param endIndex end index of range of items to set (QModelIndex) |
176 @param endIndex end index of range of items to set (QModelIndex) |
176 @param selected flag giving the new selection status (boolean) |
177 @param selected flag giving the new selection status (boolean) |
177 """ |
178 """ |
178 selection = QItemSelection(startIndex, endIndex) |
179 selection = QItemSelection(startIndex, endIndex) |
179 self.selectionModel().select(selection, |
180 self.selectionModel().select(selection, |
180 selected and self.SelectFlags or self.DeselectFlags) |
181 selected and self.SelectFlags or self.DeselectFlags) |
181 |
182 |
182 def __modelRowsInserted(self, parent, start, end): |
183 def __modelRowsInserted(self, parent, start, end): |
183 """ |
184 """ |
184 Private slot called after rows have been inserted into the model. |
185 Private slot called after rows have been inserted into the model. |
225 |
226 |
226 if self.backMenu is not None: |
227 if self.backMenu is not None: |
227 self.backMenu.setEnabled(True) |
228 self.backMenu.setEnabled(True) |
228 |
229 |
229 if self.project.vcs is not None: |
230 if self.project.vcs is not None: |
230 self.vcsHelper = self.project.vcs.vcsGetProjectBrowserHelper(self, |
231 self.vcsHelper = self.project.vcs.vcsGetProjectBrowserHelper(self, |
231 self.project, self.isTranslationsBrowser) |
232 self.project, self.isTranslationsBrowser) |
232 self.vcsHelper.addVCSMenus(self.mainMenu, self.multiMenu, |
233 self.vcsHelper.addVCSMenus(self.mainMenu, self.multiMenu, |
233 self.backMenu, self.dirMenu, self.dirMultiMenu) |
234 self.backMenu, self.dirMenu, self.dirMultiMenu) |
234 |
235 |
235 def _newProject(self): |
236 def _newProject(self): |
244 |
245 |
245 if self.backMenu is not None: |
246 if self.backMenu is not None: |
246 self.backMenu.setEnabled(True) |
247 self.backMenu.setEnabled(True) |
247 |
248 |
248 if self.project.vcs is not None: |
249 if self.project.vcs is not None: |
249 self.vcsHelper = self.project.vcs.vcsGetProjectBrowserHelper(self, |
250 self.vcsHelper = self.project.vcs.vcsGetProjectBrowserHelper(self, |
250 self.project, self.isTranslationsBrowser) |
251 self.project, self.isTranslationsBrowser) |
251 self.vcsHelper.addVCSMenus(self.mainMenu, self.multiMenu, |
252 self.vcsHelper.addVCSMenus(self.mainMenu, self.multiMenu, |
252 self.backMenu, self.dirMenu, self.dirMultiMenu) |
253 self.backMenu, self.dirMenu, self.dirMultiMenu) |
253 |
254 |
254 def _removeFile(self): |
255 def _removeFile(self): |
357 self._connectExpandedCollapsed() |
358 self._connectExpandedCollapsed() |
358 QApplication.restoreOverrideCursor() |
359 QApplication.restoreOverrideCursor() |
359 |
360 |
360 def _showContextMenu(self, menu): |
361 def _showContextMenu(self, menu): |
361 """ |
362 """ |
362 Protected slot called before the context menu is shown. |
363 Protected slot called before the context menu is shown. |
363 |
364 |
364 It enables/disables the VCS menu entries depending on the overall |
365 It enables/disables the VCS menu entries depending on the overall |
365 VCS status and the file status. |
366 VCS status and the file status. |
366 |
367 |
367 @param menu reference to the menu to be shown (QMenu) |
368 @param menu reference to the menu to be shown (QMenu) |
368 """ |
369 """ |
369 if self.project.vcs is None: |
370 if self.project.vcs is None: |
372 else: |
373 else: |
373 self.vcsHelper.showContextMenu(menu, self.menuActions) |
374 self.vcsHelper.showContextMenu(menu, self.menuActions) |
374 |
375 |
375 def _showContextMenuMulti(self, menu): |
376 def _showContextMenuMulti(self, menu): |
376 """ |
377 """ |
377 Protected slot called before the context menu (multiple selections) is shown. |
378 Protected slot called before the context menu (multiple selections) is shown. |
378 |
379 |
379 It enables/disables the VCS menu entries depending on the overall |
380 It enables/disables the VCS menu entries depending on the overall |
380 VCS status and the files status. |
381 VCS status and the files status. |
381 |
382 |
382 @param menu reference to the menu to be shown (QMenu) |
383 @param menu reference to the menu to be shown (QMenu) |
383 """ |
384 """ |
384 if self.project.vcs is None: |
385 if self.project.vcs is None: |
387 else: |
388 else: |
388 self.vcsHelper.showContextMenuMulti(menu, self.multiMenuActions) |
389 self.vcsHelper.showContextMenuMulti(menu, self.multiMenuActions) |
389 |
390 |
390 def _showContextMenuDir(self, menu): |
391 def _showContextMenuDir(self, menu): |
391 """ |
392 """ |
392 Protected slot called before the context menu is shown. |
393 Protected slot called before the context menu is shown. |
393 |
394 |
394 It enables/disables the VCS menu entries depending on the overall |
395 It enables/disables the VCS menu entries depending on the overall |
395 VCS status and the directory status. |
396 VCS status and the directory status. |
396 |
397 |
397 @param menu reference to the menu to be shown (QMenu) |
398 @param menu reference to the menu to be shown (QMenu) |
398 """ |
399 """ |
399 if self.project.vcs is None: |
400 if self.project.vcs is None: |
402 else: |
403 else: |
403 self.vcsHelper.showContextMenuDir(menu, self.dirMenuActions) |
404 self.vcsHelper.showContextMenuDir(menu, self.dirMenuActions) |
404 |
405 |
405 def _showContextMenuDirMulti(self, menu): |
406 def _showContextMenuDirMulti(self, menu): |
406 """ |
407 """ |
407 Protected slot called before the context menu is shown. |
408 Protected slot called before the context menu is shown. |
408 |
409 |
409 It enables/disables the VCS menu entries depending on the overall |
410 It enables/disables the VCS menu entries depending on the overall |
410 VCS status and the directory status. |
411 VCS status and the directory status. |
411 |
412 |
412 @param menu reference to the menu to be shown (QMenu) |
413 @param menu reference to the menu to be shown (QMenu) |
413 """ |
414 """ |
414 if self.project.vcs is None: |
415 if self.project.vcs is None: |
417 else: |
418 else: |
418 self.vcsHelper.showContextMenuDirMulti(menu, self.dirMultiMenuActions) |
419 self.vcsHelper.showContextMenuDirMulti(menu, self.dirMultiMenuActions) |
419 |
420 |
420 def _showContextMenuBack(self, menu): |
421 def _showContextMenuBack(self, menu): |
421 """ |
422 """ |
422 Protected slot called before the context menu is shown. |
423 Protected slot called before the context menu is shown. |
423 |
424 |
424 @param menu reference to the menu to be shown (QMenu) |
425 @param menu reference to the menu to be shown (QMenu) |
425 """ |
426 """ |
426 # nothing to do for now |
427 # nothing to do for now |
427 return |
428 return |
428 |
429 |
429 def _selectEntries(self, local = True, filter = None): |
430 def _selectEntries(self, local=True, filter=None): |
430 """ |
431 """ |
431 Protected method to select entries based on their VCS status. |
432 Protected method to select entries based on their VCS status. |
432 |
433 |
433 @param local flag indicating local (i.e. non VCS controlled) file/directory |
434 @param local flag indicating local (i.e. non VCS controlled) file/directory |
434 entries should be selected (boolean) |
435 entries should be selected (boolean) |
478 QApplication.processEvents() |
479 QApplication.processEvents() |
479 |
480 |
480 if selectedEntries == 0: |
481 if selectedEntries == 0: |
481 E5MessageBox.information(self, |
482 E5MessageBox.information(self, |
482 QApplication.translate('ProjectBaseBrowser', "Select entries"), |
483 QApplication.translate('ProjectBaseBrowser', "Select entries"), |
483 QApplication.translate('ProjectBaseBrowser', |
484 QApplication.translate('ProjectBaseBrowser', |
484 """There were no matching entries found.""")) |
485 """There were no matching entries found.""")) |
485 |
486 |
486 def selectLocalEntries(self): |
487 def selectLocalEntries(self): |
487 """ |
488 """ |
488 Public slot to handle the select local files context menu entries |
489 Public slot to handle the select local files context menu entries |
489 """ |
490 """ |
490 self._selectEntries(local = True, filter = [ProjectBrowserFileItem]) |
491 self._selectEntries(local=True, filter=[ProjectBrowserFileItem]) |
491 |
492 |
492 def selectVCSEntries(self): |
493 def selectVCSEntries(self): |
493 """ |
494 """ |
494 Public slot to handle the select VCS files context menu entries |
495 Public slot to handle the select VCS files context menu entries |
495 """ |
496 """ |
496 self._selectEntries(local = False, filter = [ProjectBrowserFileItem]) |
497 self._selectEntries(local=False, filter=[ProjectBrowserFileItem]) |
497 |
498 |
498 def selectLocalDirEntries(self): |
499 def selectLocalDirEntries(self): |
499 """ |
500 """ |
500 Public slot to handle the select local directories context menu entries |
501 Public slot to handle the select local directories context menu entries |
501 """ |
502 """ |
502 self._selectEntries(local = True, |
503 self._selectEntries(local=True, |
503 filter=[ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem]) |
504 filter=[ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem]) |
504 |
505 |
505 def selectVCSDirEntries(self): |
506 def selectVCSDirEntries(self): |
506 """ |
507 """ |
507 Public slot to handle the select VCS directories context menu entries |
508 Public slot to handle the select VCS directories context menu entries |
508 """ |
509 """ |
509 self._selectEntries(local = False, |
510 self._selectEntries(local=False, |
510 filter=[ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem]) |
511 filter=[ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem]) |
511 |
512 |
512 def _prepareRepopulateItem(self, name): |
513 def _prepareRepopulateItem(self, name): |
513 """ |
514 """ |
514 Protected slot to handle the prepareRepopulateItem signal. |
515 Protected slot to handle the prepareRepopulateItem signal. |