1 # -*- coding: utf-8 -*- |
1 # -*- coding: utf-8 -*- |
2 |
2 |
3 # Copyright (c) 2002 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
3 # Copyright (c) 2002 - 2023 Detlev Offenbach <detlev@die-offenbachs.de> |
4 # |
4 # |
5 |
5 |
6 """ |
6 """ |
7 Module implementing the project browser part of the eric UI. |
7 Module implementing the project browser part of the eric UI. |
8 """ |
8 """ |
9 |
9 |
10 import contextlib |
10 import contextlib |
11 |
11 |
12 from PyQt6.QtCore import Qt, pyqtSignal |
12 from PyQt6.QtCore import Qt, pyqtSignal |
13 from PyQt6.QtGui import QColor, QIcon |
13 from PyQt6.QtGui import QColor, QIcon |
|
14 from PyQt6.QtWidgets import QToolButton |
14 |
15 |
15 from eric7 import Preferences |
16 from eric7 import Preferences |
16 from eric7.EricGui import EricPixmapCache |
17 from eric7.EricGui import EricPixmapCache |
17 from eric7.EricWidgets import EricMessageBox |
18 from eric7.EricWidgets import EricMessageBox |
18 from eric7.EricWidgets.EricLed import EricClickableLed |
19 from eric7.EricWidgets.EricLed import EricClickableLed |
19 from eric7.EricWidgets.EricTabWidget import EricTabWidget |
20 from eric7.EricWidgets.EricTabWidget import EricTabWidget |
20 |
21 |
21 from .ProjectBrowserRepositoryItem import ProjectBrowserRepositoryItem |
22 from .ProjectBrowserRepositoryItem import ProjectBrowserRepositoryItem |
22 from .ProjectFormsBrowser import ProjectFormsBrowser |
23 from .ProjectFormsBrowser import ProjectFormsBrowser |
23 from .ProjectInterfacesBrowser import ProjectInterfacesBrowser |
|
24 from .ProjectOthersBrowser import ProjectOthersBrowser |
24 from .ProjectOthersBrowser import ProjectOthersBrowser |
25 from .ProjectProtocolsBrowser import ProjectProtocolsBrowser |
|
26 from .ProjectResourcesBrowser import ProjectResourcesBrowser |
25 from .ProjectResourcesBrowser import ProjectResourcesBrowser |
27 from .ProjectSourcesBrowser import ProjectSourcesBrowser |
26 from .ProjectSourcesBrowser import ProjectSourcesBrowser |
28 from .ProjectTranslationsBrowser import ProjectTranslationsBrowser |
27 from .ProjectTranslationsBrowser import ProjectTranslationsBrowser |
29 |
28 |
30 |
29 |
104 |
103 |
105 self.setWindowIcon(EricPixmapCache.getIcon("eric")) |
104 self.setWindowIcon(EricPixmapCache.getIcon("eric")) |
106 |
105 |
107 self.setUsesScrollButtons(True) |
106 self.setUsesScrollButtons(True) |
108 |
107 |
109 self.vcsStatusIndicator = EricClickableLed(self) |
|
110 self.setCornerWidget(self.vcsStatusIndicator, Qt.Corner.TopLeftCorner) |
|
111 self.vcsStatusIndicator.clicked.connect(self.__vcsStatusIndicatorClicked) |
|
112 self.vcsStatusColorNames = { |
108 self.vcsStatusColorNames = { |
113 "A": "VcsAdded", |
109 "A": "VcsAdded", |
114 "M": "VcsModified", |
110 "M": "VcsModified", |
115 "O": "VcsRemoved", |
111 "O": "VcsRemoved", |
116 "R": "VcsReplaced", |
112 "R": "VcsReplaced", |
124 "O": self.tr("files removed"), |
120 "O": self.tr("files removed"), |
125 "R": self.tr("files replaced"), |
121 "R": self.tr("files replaced"), |
126 "U": self.tr("update required"), |
122 "U": self.tr("update required"), |
127 "Z": self.tr("conflict"), |
123 "Z": self.tr("conflict"), |
128 } |
124 } |
|
125 self.vcsStatusIndicator = EricClickableLed(self) |
|
126 self.vcsStatusIndicator.clicked.connect(self.__vcsStatusIndicatorClicked) |
|
127 self.setCornerWidget(self.vcsStatusIndicator, Qt.Corner.TopLeftCorner) |
|
128 self.vcsCheckStatusButton = QToolButton(self) |
|
129 self.vcsCheckStatusButton.setIcon(EricPixmapCache.getIcon("reload")) |
|
130 self.vcsCheckStatusButton.setToolTip( |
|
131 self.tr("Press to check the current VCS status.") |
|
132 ) |
|
133 self.vcsCheckStatusButton.clicked.connect(self.project.checkVCSStatus) |
|
134 self.setCornerWidget(self.vcsCheckStatusButton, Qt.Corner.TopRightCorner) |
129 self.__vcsStateChanged(" ") |
135 self.__vcsStateChanged(" ") |
130 |
136 |
131 self.__currentBrowsersList = [] |
137 self.__currentBrowsersList = [] |
132 self.__browserRepository = {} |
138 self.__browserRepository = {} |
133 self.__fileFilterMapping = {} # redundant data store for speed reasons |
139 self.__fileFilterMapping = {} # redundant data store for speed reasons |
139 ProjectSourcesBrowser, |
145 ProjectSourcesBrowser, |
140 ProjectFormsBrowser, |
146 ProjectFormsBrowser, |
141 ProjectResourcesBrowser, |
147 ProjectResourcesBrowser, |
142 ProjectTranslationsBrowser, |
148 ProjectTranslationsBrowser, |
143 ProjectOthersBrowser, |
149 ProjectOthersBrowser, |
144 # TODO: move the next two browsers to plugins |
|
145 ProjectInterfacesBrowser, |
|
146 ProjectProtocolsBrowser, |
|
147 ): |
150 ): |
148 browserClass(self.project, self) |
151 browserClass(self.project, self) |
149 |
152 |
150 # add signal connection to ourselves |
153 # add signal connection to ourselves |
151 self.project.projectOpened.connect(self.__projectOpened) |
154 self.project.projectOpened.connect(self.__projectOpened) |
311 while self.count() > 0: |
314 while self.count() > 0: |
312 self.removeTab(0) |
315 self.removeTab(0) |
313 |
316 |
314 # step 2: add browsers |
317 # step 2: add browsers |
315 for browser in sorted( |
318 for browser in sorted( |
316 browsersList, |
319 [b for b in browsersList if b in self.__browserRepository], |
317 key=lambda x: self.__browserRepository[x].priority, |
320 key=lambda x: self.__browserRepository[x].priority, |
318 reverse=True, |
321 reverse=True, |
319 ): |
322 ): |
320 index = self.addTab( |
323 index = self.addTab( |
321 self.__browserRepository[browser].projectBrowser, |
324 self.__browserRepository[browser].projectBrowser, |
343 Private slot to handle the projectOpened signal. |
346 Private slot to handle the projectOpened signal. |
344 """ |
347 """ |
345 self.__projectPropertiesChanged() |
348 self.__projectPropertiesChanged() |
346 self.setCurrentIndex(0) |
349 self.setCurrentIndex(0) |
347 self.__vcsStateChanged(" ") |
350 self.__vcsStateChanged(" ") |
|
351 self.vcsStatusIndicator.setVisible(self.project.isVcsControlled()) |
|
352 self.vcsCheckStatusButton.setVisible(self.project.isVcsControlled()) |
348 |
353 |
349 def __projectClosed(self): |
354 def __projectClosed(self): |
350 """ |
355 """ |
351 Private slot to handle the projectClosed signal. |
356 Private slot to handle the projectClosed signal. |
352 """ |
357 """ |
353 self.__projectPropertiesChanged() |
358 self.__projectPropertiesChanged() |
354 self.setCurrentIndex(0) |
359 self.setCurrentIndex(0) |
355 self.__setSourcesIcon() |
360 self.__setSourcesIcon() |
356 self.__vcsStateChanged(" ") |
361 self.__vcsStateChanged(" ") |
|
362 self.vcsStatusIndicator.setVisible(False) |
|
363 self.vcsCheckStatusButton.setVisible(False) |
357 |
364 |
358 def __newProject(self): |
365 def __newProject(self): |
359 """ |
366 """ |
360 Private slot to handle the newProject signal. |
367 Private slot to handle the newProject signal. |
361 """ |
368 """ |
434 |
441 |
435 def __vcsStateChanged(self, state): |
442 def __vcsStateChanged(self, state): |
436 """ |
443 """ |
437 Private slot to handle a change in the vcs state. |
444 Private slot to handle a change in the vcs state. |
438 |
445 |
439 @param state new vcs state (string) |
446 @param state new vcs state |
440 """ |
447 @type str |
|
448 """ |
|
449 self.vcsStatusIndicator.setVisible(self.project.isVcsControlled()) |
|
450 self.vcsCheckStatusButton.setVisible(self.project.isVcsControlled()) |
|
451 |
441 self.currentVcsStatus = state |
452 self.currentVcsStatus = state |
442 if state == " " or state not in self.vcsStatusColorNames: |
453 if state == " " or state not in self.vcsStatusColorNames: |
443 self.vcsStatusIndicator.setColor(QColor(Qt.GlobalColor.lightGray)) |
454 self.vcsStatusIndicator.setColor(QColor(Qt.GlobalColor.lightGray)) |
444 else: |
455 else: |
445 self.vcsStatusIndicator.setColor( |
456 self.vcsStatusIndicator.setColor( |