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 |
|
11 |
10 from PyQt6.QtCore import Qt, pyqtSignal |
12 from PyQt6.QtCore import Qt, pyqtSignal |
11 from PyQt6.QtGui import QColor |
13 from PyQt6.QtGui import QColor |
12 from PyQt6.QtWidgets import QApplication |
14 from PyQt6.QtWidgets import QApplication |
13 |
15 |
14 from eric7 import Preferences |
16 from eric7 import Preferences |
15 from eric7.EricGui import EricPixmapCache |
17 from eric7.EricGui import EricPixmapCache |
|
18 from eric7.EricWidgets import EricMessageBox |
16 from eric7.EricWidgets.EricLed import EricClickableLed |
19 from eric7.EricWidgets.EricLed import EricClickableLed |
17 from eric7.EricWidgets.EricTabWidget import EricTabWidget |
20 from eric7.EricWidgets.EricTabWidget import EricTabWidget |
18 |
21 |
19 from .ProjectBrowserFlags import ( |
22 from .ProjectBrowserFlags import ( |
20 AllBrowsersFlag, |
23 AllBrowsersFlag, |
133 "U": self.tr("update required"), |
137 "U": self.tr("update required"), |
134 "Z": self.tr("conflict"), |
138 "Z": self.tr("conflict"), |
135 } |
139 } |
136 self.__vcsStateChanged(" ") |
140 self.__vcsStateChanged(" ") |
137 |
141 |
|
142 self.__browserRepository = {} |
|
143 |
138 # create all the individual browsers |
144 # create all the individual browsers |
139 self.__browsers = { |
145 for browserClass in ( |
140 # sources browser |
146 ProjectSourcesBrowser, |
141 "sources": ProjectSourcesBrowser(self.project, self), |
147 ProjectFormsBrowser, |
142 # forms browser |
148 ProjectResourcesBrowser, |
143 "forms": ProjectFormsBrowser(self.project, self), |
149 ProjectTranslationsBrowser, |
144 # resources browser |
150 ProjectOthersBrowser, |
145 "resources": ProjectResourcesBrowser(self.project, self), |
151 # TODO: move the next two browsers to plugins |
146 # translations browser |
152 ProjectInterfacesBrowser, |
147 "translations": ProjectTranslationsBrowser(self.project, self), |
153 ProjectProtocolsBrowser, |
148 # others browser |
154 ): |
149 "others": ProjectOthersBrowser(self.project, self), |
155 browserClass(self.project, self) |
150 # interfaces (IDL) browser |
|
151 "interfaces": ProjectInterfacesBrowser(self.project, self), |
|
152 # protocols (protobuf) browser |
|
153 "protocols": ProjectProtocolsBrowser(self.project, self), |
|
154 } |
|
155 |
156 |
156 # add signal connection to ourselves |
157 # add signal connection to ourselves |
157 self.project.projectOpened.connect(self.__projectOpened) |
158 self.project.projectOpened.connect(self.__projectOpened) |
158 self.project.projectClosed.connect(self.__projectClosed) |
159 self.project.projectClosed.connect(self.__projectClosed) |
159 self.project.newProject.connect(self.__newProject) |
160 self.project.newProject.connect(self.__newProject) |
163 |
164 |
164 self.__currentBrowsersFlags = 0 |
165 self.__currentBrowsersFlags = 0 |
165 self.__projectPropertiesChanged() |
166 self.__projectPropertiesChanged() |
166 self.setCurrentIndex(0) |
167 self.setCurrentIndex(0) |
167 |
168 |
|
169 def addTypedProjectBrowser(self, browserType, projectBrowserItem): |
|
170 """ |
|
171 Public method to add a project browser type to the browser repository. |
|
172 |
|
173 @param browserType type of the project browser |
|
174 @type str |
|
175 @param projectBrowserItem data structure containing the type specific data |
|
176 @type ProjectBrowserRepositoryItem |
|
177 @exception TypeError raised to signal a wrong type for the project browser item |
|
178 """ |
|
179 if not isinstance(projectBrowserItem, ProjectBrowserRepositoryItem): |
|
180 raise TypeError( |
|
181 "'projectBrowserItem' must be an instance of" |
|
182 " 'ProjectBrowserRepositoryItem'." |
|
183 ) |
|
184 |
|
185 if browserType in self.__browserRepository: |
|
186 EricMessageBox.critical( |
|
187 self.ui, |
|
188 self.tr("Add Project Browser Type"), |
|
189 self.tr( |
|
190 "<p>The project browser type <b>{0}</b> has already been added." |
|
191 " This attempt will be ignored.</p>" |
|
192 ), |
|
193 ) |
|
194 else: |
|
195 self.__browserRepository[browserType] = projectBrowserItem |
|
196 |
|
197 def removeTypedProjectBrowser(self, browserType): |
|
198 """ |
|
199 Public method to remove a browser type from the browsers repository. |
|
200 |
|
201 Note: If the browser type is not contained in the repository, the request to |
|
202 remove it will be ignored silently. |
|
203 |
|
204 @param browserType project browser type |
|
205 @type str |
|
206 """ |
|
207 with contextlib.suppress(KeyError): |
|
208 browserIndex = self.indexOf(self.getProjectBrowser(browserType)) |
|
209 if browserIndex >= 0: |
|
210 self.removeTab(browserIndex) |
|
211 del self.__browserRepository[browserType] |
|
212 |
|
213 def getProjectBrowsers(self): |
|
214 """ |
|
215 Public method to get references to the individual project browsers. |
|
216 |
|
217 @return list of references to project browsers |
|
218 @rtype list of ProjectBaseBrowser |
|
219 """ |
|
220 return [itm.projectBrowser for itm in self.__browserRepository.items()] |
|
221 |
|
222 def getProjectBrowser(self, browserType): |
|
223 """ |
|
224 Public method to get a reference to the project browser of given type. |
|
225 |
|
226 @param browserType type of the requested project browser |
|
227 @type str |
|
228 @return reference to the requested browser or None |
|
229 @rtype ProjectBaseBrowser or None |
|
230 """ |
|
231 try: |
|
232 return self.__browserRepository[browserType].projectBrowser |
|
233 except KeyError: |
|
234 return None |
|
235 |
|
236 def getProjectBrowserNames(self): |
|
237 """ |
|
238 Public method to get the types of the various project browsers. |
|
239 |
|
240 @return list of project browser types |
|
241 @rtype list of str |
|
242 """ |
|
243 return list(self.__browserRepository.keys()) |
|
244 |
168 def __setBrowsersAvailable(self, browserFlags): |
245 def __setBrowsersAvailable(self, browserFlags): |
169 """ |
246 """ |
170 Private method to add selected browsers to the project browser. |
247 Private method to add selected browsers to the project browser. |
171 |
248 |
172 @param browserFlags flags indicating the browsers to add (integer) |
249 @param browserFlags flags indicating the browsers to add (integer) |
174 # step 1: remove all tabs |
251 # step 1: remove all tabs |
175 while self.count() > 0: |
252 while self.count() > 0: |
176 self.removeTab(0) |
253 self.removeTab(0) |
177 |
254 |
178 # step 2: add browsers |
255 # step 2: add browsers |
|
256 # TODO: change the logic after browser flags have been eliminated |
179 if browserFlags & SourcesBrowserFlag: |
257 if browserFlags & SourcesBrowserFlag: |
180 index = self.addTab( |
258 index = self.addTab( |
181 self.__browsers["sources"], |
259 self.__browserRepository["sources"].projectBrowser, |
182 EricPixmapCache.getIcon("projectSources"), |
260 self.__browserRepository["sources"].getIcon(), |
183 "", |
261 "", |
184 ) |
262 ) |
185 self.setTabToolTip(index, self.__browsers["sources"].windowTitle()) |
263 self.setTabToolTip( |
|
264 index, |
|
265 self.__browserRepository["sources"].projectBrowser.windowTitle(), |
|
266 ) |
186 |
267 |
187 if browserFlags & FormsBrowserFlag: |
268 if browserFlags & FormsBrowserFlag: |
188 index = self.addTab( |
269 index = self.addTab( |
189 self.__browsers["forms"], EricPixmapCache.getIcon("projectForms"), "" |
270 self.__browserRepository["forms"].projectBrowser, |
190 ) |
271 self.__browserRepository["forms"].getIcon(), |
191 self.setTabToolTip(index, self.__browsers["forms"].windowTitle()) |
272 "", |
|
273 ) |
|
274 self.setTabToolTip( |
|
275 index, |
|
276 self.__browserRepository["forms"].projectBrowser.windowTitle(), |
|
277 ) |
192 |
278 |
193 if browserFlags & ResourcesBrowserFlag: |
279 if browserFlags & ResourcesBrowserFlag: |
194 index = self.addTab( |
280 index = self.addTab( |
195 self.__browsers["resources"], |
281 self.__browserRepository["resources"].projectBrowser, |
196 EricPixmapCache.getIcon("projectResources"), |
282 self.__browserRepository["resources"].getIcon(), |
197 "", |
283 "", |
198 ) |
284 ) |
199 self.setTabToolTip(index, self.__browsers["resources"].windowTitle()) |
285 self.setTabToolTip( |
|
286 index, |
|
287 self.__browserRepository["resources"].projectBrowser.windowTitle(), |
|
288 ) |
200 |
289 |
201 if browserFlags & TranslationsBrowserFlag: |
290 if browserFlags & TranslationsBrowserFlag: |
202 index = self.addTab( |
291 index = self.addTab( |
203 self.__browsers["translations"], |
292 self.__browserRepository["translations"].projectBrowser, |
204 EricPixmapCache.getIcon("projectTranslations"), |
293 self.__browserRepository["translations"].getIcon(), |
205 "", |
294 "", |
206 ) |
295 ) |
207 self.setTabToolTip(index, self.__browsers["translations"].windowTitle()) |
296 self.setTabToolTip( |
|
297 index, |
|
298 self.__browserRepository["translations"].projectBrowser.windowTitle(), |
|
299 ) |
208 |
300 |
209 if browserFlags & InterfacesBrowserFlag: |
301 if browserFlags & InterfacesBrowserFlag: |
210 index = self.addTab( |
302 index = self.addTab( |
211 self.__browsers["interfaces"], |
303 self.__browserRepository["interfaces"].projectBrowser, |
212 EricPixmapCache.getIcon("projectInterfaces"), |
304 self.__browserRepository["interfaces"].getIcon(), |
213 "", |
305 "", |
214 ) |
306 ) |
215 self.setTabToolTip(index, self.__browsers["interfaces"].windowTitle()) |
307 self.setTabToolTip( |
|
308 index, |
|
309 self.__browserRepository["interfaces"].projectBrowser.windowTitle(), |
|
310 ) |
216 |
311 |
217 if browserFlags & ProtocolsBrowserFlag: |
312 if browserFlags & ProtocolsBrowserFlag: |
218 index = self.addTab( |
313 index = self.addTab( |
219 self.__browsers["protocols"], EricPixmapCache.getIcon("protobuf"), "" |
314 self.__browserRepository["protocols"].projectBrowser, |
220 ) |
315 self.__browserRepository["protocols"].getIcon(), |
221 self.setTabToolTip(index, self.__browsers["protocols"].windowTitle()) |
316 "", |
|
317 ) |
|
318 self.setTabToolTip( |
|
319 index, |
|
320 self.__browserRepository["protocols"].projectBrowser.windowTitle(), |
|
321 ) |
222 |
322 |
223 if browserFlags & OthersBrowserFlag: |
323 if browserFlags & OthersBrowserFlag: |
224 index = self.addTab( |
324 index = self.addTab( |
225 self.__browsers["others"], EricPixmapCache.getIcon("projectOthers"), "" |
325 self.__browserRepository["others"].projectBrowser, |
226 ) |
326 self.__browserRepository["others"].getIcon(), |
227 self.setTabToolTip(index, self.__browsers["others"].windowTitle()) |
327 "", |
|
328 ) |
|
329 self.setTabToolTip( |
|
330 index, |
|
331 self.__browserRepository["others"].projectBrowser.windowTitle(), |
|
332 ) |
228 |
333 |
229 QApplication.processEvents() |
334 QApplication.processEvents() |
230 |
335 |
231 def __currentChanged(self, index): |
336 def __currentChanged(self, index): |
232 """ |
337 """ |
335 if ( |
441 if ( |
336 Preferences.getProject("FollowEditor") |
442 Preferences.getProject("FollowEditor") |
337 and Preferences.getProject("FollowCursorLine") |
443 and Preferences.getProject("FollowCursorLine") |
338 and self.project.isProjectCategory(fn, "SOURCES") |
444 and self.project.isProjectCategory(fn, "SOURCES") |
339 ): |
445 ): |
340 self.__browsers["sources"].selectFileLine(fn, lineno) |
446 self.getProjectBrowser("sources").selectFileLine(fn, lineno) |
341 |
|
342 def getProjectBrowsers(self): |
|
343 """ |
|
344 Public method to get references to the individual project browsers. |
|
345 |
|
346 @return list of references to project browsers |
|
347 @rtype list of ProjectBaseBrowser |
|
348 """ |
|
349 return list(self.__browsers.items()) |
|
350 |
|
351 def getProjectBrowser(self, name): |
|
352 """ |
|
353 Public method to get a reference to the named project browser. |
|
354 |
|
355 @param name name of the requested project browser. |
|
356 @type str |
|
357 @return reference to the requested browser or None |
|
358 @rtype ProjectBaseBrowser or None |
|
359 """ |
|
360 return self.__browsers.get(name, None) |
|
361 |
|
362 def getProjectBrowserNames(self): |
|
363 """ |
|
364 Public method to get the names of the various project browsers. |
|
365 |
|
366 @return list of project browser names |
|
367 @rtype list of str |
|
368 """ |
|
369 return list(self.__browsers.keys()) |
|
370 |
447 |
371 def handlePreferencesChanged(self): |
448 def handlePreferencesChanged(self): |
372 """ |
449 """ |
373 Public slot used to handle the preferencesChanged signal. |
450 Public slot used to handle the preferencesChanged signal. |
374 """ |
451 """ |