106 self._projectTypes.append(type_) |
106 self._projectTypes.append(type_) |
107 |
107 |
108 |
108 |
109 class ProjectBrowserSimpleDirectoryItem(BrowserItem, ProjectBrowserItemMixin): |
109 class ProjectBrowserSimpleDirectoryItem(BrowserItem, ProjectBrowserItemMixin): |
110 """ |
110 """ |
111 Class implementing the data structure for project browser simple directory items. |
111 Class implementing the data structure for project browser simple directory |
|
112 items. |
112 """ |
113 """ |
113 def __init__(self, parent, projectType, text, path=""): |
114 def __init__(self, parent, projectType, text, path=""): |
114 """ |
115 """ |
115 Constructor |
116 Constructor |
116 |
117 |
165 return order == Qt.AscendingOrder |
166 return order == Qt.AscendingOrder |
166 |
167 |
167 return BrowserItem.lessThan(self, other, column, order) |
168 return BrowserItem.lessThan(self, other, column, order) |
168 |
169 |
169 |
170 |
170 class ProjectBrowserDirectoryItem(BrowserDirectoryItem, ProjectBrowserItemMixin): |
171 class ProjectBrowserDirectoryItem(BrowserDirectoryItem, |
|
172 ProjectBrowserItemMixin): |
171 """ |
173 """ |
172 Class implementing the data structure for project browser directory items. |
174 Class implementing the data structure for project browser directory items. |
173 """ |
175 """ |
174 def __init__(self, parent, dinfo, projectType, full=True, bold=False): |
176 def __init__(self, parent, dinfo, projectType, full=True, bold=False): |
175 """ |
177 """ |
263 "R": Preferences.getProjectBrowserColour(self.colorNames["R"]), |
265 "R": Preferences.getProjectBrowserColour(self.colorNames["R"]), |
264 "U": Preferences.getProjectBrowserColour(self.colorNames["U"]), |
266 "U": Preferences.getProjectBrowserColour(self.colorNames["U"]), |
265 "Z": Preferences.getProjectBrowserColour(self.colorNames["Z"]), |
267 "Z": Preferences.getProjectBrowserColour(self.colorNames["Z"]), |
266 } |
268 } |
267 |
269 |
268 self.highLightColor = Preferences.getProjectBrowserColour("Highlighted") |
270 self.highLightColor = \ |
|
271 Preferences.getProjectBrowserColour("Highlighted") |
269 # needed by preferencesChanged() |
272 # needed by preferencesChanged() |
270 |
273 |
271 self.vcsStatusReport = {} |
274 self.vcsStatusReport = {} |
272 |
275 |
273 def data(self, index, role): |
276 def data(self, index, role): |
287 return index.internalPointer().getTextColor() |
290 return index.internalPointer().getTextColor() |
288 except AttributeError: |
291 except AttributeError: |
289 return None |
292 return None |
290 elif role == Qt.BackgroundColorRole: |
293 elif role == Qt.BackgroundColorRole: |
291 try: |
294 try: |
292 col = self.itemBackgroundColors[index.internalPointer().vcsState] |
295 col = self.itemBackgroundColors[ |
|
296 index.internalPointer().vcsState] |
293 if col.isValid(): |
297 if col.isValid(): |
294 return col |
298 return col |
295 else: |
299 else: |
296 return None |
300 return None |
297 except AttributeError: |
301 except AttributeError: |
327 self._addWatchedItem(parentItem) |
331 self._addWatchedItem(parentItem) |
328 |
332 |
329 qdir = QDir(parentItem.dirName()) |
333 qdir = QDir(parentItem.dirName()) |
330 |
334 |
331 if Preferences.getUI("BrowsersListHiddenFiles"): |
335 if Preferences.getUI("BrowsersListHiddenFiles"): |
332 filter = QDir.Filters(QDir.AllEntries | QDir.Hidden | QDir.NoDotAndDotDot) |
336 filter = QDir.Filters(QDir.AllEntries | |
|
337 QDir.Hidden | |
|
338 QDir.NoDotAndDotDot) |
333 else: |
339 else: |
334 filter = QDir.Filters(QDir.AllEntries | QDir.NoDotAndDotDot) |
340 filter = QDir.Filters(QDir.AllEntries | QDir.NoDotAndDotDot) |
335 entryInfoList = qdir.entryInfoList(filter) |
341 entryInfoList = qdir.entryInfoList(filter) |
336 |
342 |
337 if len(entryInfoList) > 0: |
343 if len(entryInfoList) > 0: |
338 if repopulate: |
344 if repopulate: |
339 self.beginInsertRows(self.createIndex(parentItem.row(), 0, parentItem), |
345 self.beginInsertRows(self.createIndex( |
|
346 parentItem.row(), 0, parentItem), |
340 0, len(entryInfoList) - 1) |
347 0, len(entryInfoList) - 1) |
341 states = {} |
348 states = {} |
342 if self.project.vcs is not None: |
349 if self.project.vcs is not None: |
343 for f in entryInfoList: |
350 for f in entryInfoList: |
344 fname = f.absoluteFilePath() |
351 fname = f.absoluteFilePath() |
356 node = ProjectBrowserFileItem(parentItem, |
363 node = ProjectBrowserFileItem(parentItem, |
357 Utilities.toNativeSeparators(f.absoluteFilePath()), |
364 Utilities.toNativeSeparators(f.absoluteFilePath()), |
358 parentItem.getProjectTypes()[0]) |
365 parentItem.getProjectTypes()[0]) |
359 if self.project.vcs is not None: |
366 if self.project.vcs is not None: |
360 fname = f.absoluteFilePath() |
367 fname = f.absoluteFilePath() |
361 if states[os.path.normcase(fname)] == self.project.vcs.canBeCommitted: |
368 if states[os.path.normcase(fname)] == \ |
|
369 self.project.vcs.canBeCommitted: |
362 node.addVcsStatus(self.project.vcs.vcsName()) |
370 node.addVcsStatus(self.project.vcs.vcsName()) |
363 self.project.clearStatusMonitorCachedState(f.absoluteFilePath()) |
371 self.project.clearStatusMonitorCachedState( |
|
372 f.absoluteFilePath()) |
364 else: |
373 else: |
365 node.addVcsStatus(self.trUtf8("local")) |
374 node.addVcsStatus(self.trUtf8("local")) |
366 self._addItem(node, parentItem) |
375 self._addItem(node, parentItem) |
367 if repopulate: |
376 if repopulate: |
368 self.endInsertRows() |
377 self.endInsertRows() |
384 # reset the module parser cache |
393 # reset the module parser cache |
385 Utilities.ModuleParser.resetParsedModules() |
394 Utilities.ModuleParser.resetParsedModules() |
386 |
395 |
387 def projectOpened(self): |
396 def projectOpened(self): |
388 """ |
397 """ |
389 Public method used to populate the model after a project has been opened. |
398 Public method used to populate the model after a project has been |
|
399 opened. |
390 """ |
400 """ |
391 self.__vcsStatus = {} |
401 self.__vcsStatus = {} |
392 states = {} |
402 states = {} |
393 keys = list(self.projectBrowserTypes.keys())[:] |
403 keys = list(self.projectBrowserTypes.keys())[:] |
394 |
404 |
395 if self.project.vcs is not None: |
405 if self.project.vcs is not None: |
396 for key in keys: |
406 for key in keys: |
397 for fn in self.project.pdata[key]: |
407 for fn in self.project.pdata[key]: |
398 states[os.path.normcase(os.path.join(self.project.ppath, fn))] = 0 |
408 states[os.path.normcase( |
|
409 os.path.join(self.project.ppath, fn))] = 0 |
399 |
410 |
400 self.project.vcs.clearStatusCache() |
411 self.project.vcs.clearStatusCache() |
401 states = self.project.vcs.vcsAllRegisteredStates(states, self.project.ppath) |
412 states = self.project.vcs.vcsAllRegisteredStates( |
|
413 states, self.project.ppath) |
402 |
414 |
403 self.inRefresh = True |
415 self.inRefresh = True |
404 for key in keys: |
416 for key in keys: |
405 # Show the entry in bold in the others browser to make it more distinguishable |
417 # Show the entry in bold in the others browser to make it more |
|
418 # distinguishable |
406 if key == "OTHERS": |
419 if key == "OTHERS": |
407 bold = True |
420 bold = True |
408 else: |
421 else: |
409 bold = False |
422 bold = False |
410 |
423 |
413 else: |
426 else: |
414 sourceLanguage = "" |
427 sourceLanguage = "" |
415 |
428 |
416 for fn in self.project.pdata[key]: |
429 for fn in self.project.pdata[key]: |
417 fname = os.path.join(self.project.ppath, fn) |
430 fname = os.path.join(self.project.ppath, fn) |
418 parentItem, dt = \ |
431 parentItem, dt = self.findParentItemByName( |
419 self.findParentItemByName(self.projectBrowserTypes[key], fn) |
432 self.projectBrowserTypes[key], fn) |
420 if os.path.isdir(fname): |
433 if os.path.isdir(fname): |
421 itm = ProjectBrowserDirectoryItem(parentItem, fname, |
434 itm = ProjectBrowserDirectoryItem(parentItem, fname, |
422 self.projectBrowserTypes[key], False, bold) |
435 self.projectBrowserTypes[key], False, bold) |
423 else: |
436 else: |
424 itm = ProjectBrowserFileItem(parentItem, fname, |
437 itm = ProjectBrowserFileItem(parentItem, fname, |
425 self.projectBrowserTypes[key], False, bold, |
438 self.projectBrowserTypes[key], False, bold, |
426 sourceLanguage=sourceLanguage) |
439 sourceLanguage=sourceLanguage) |
427 self._addItem(itm, parentItem) |
440 self._addItem(itm, parentItem) |
428 if self.project.vcs is not None: |
441 if self.project.vcs is not None: |
429 if states[os.path.normcase(fname)] == self.project.vcs.canBeCommitted: |
442 if states[os.path.normcase(fname)] == \ |
|
443 self.project.vcs.canBeCommitted: |
430 itm.addVcsStatus(self.project.vcs.vcsName()) |
444 itm.addVcsStatus(self.project.vcs.vcsName()) |
431 else: |
445 else: |
432 itm.addVcsStatus(self.trUtf8("local")) |
446 itm.addVcsStatus(self.trUtf8("local")) |
433 else: |
447 else: |
434 itm.addVcsStatus("") |
448 itm.addVcsStatus("") |
459 path = self.project.ppath |
473 path = self.project.ppath |
460 for p in pathlist[:-1]: |
474 for p in pathlist[:-1]: |
461 itm = self.findChildItem(p, 0, olditem) |
475 itm = self.findChildItem(p, 0, olditem) |
462 path = os.path.join(path, p) |
476 path = os.path.join(path, p) |
463 if itm is None: |
477 if itm is None: |
464 itm = ProjectBrowserSimpleDirectoryItem(olditem, type_, p, path) |
478 itm = ProjectBrowserSimpleDirectoryItem( |
|
479 olditem, type_, p, path) |
465 self.__addVCSStatus(itm, path) |
480 self.__addVCSStatus(itm, path) |
466 if self.inRefresh: |
481 if self.inRefresh: |
467 self._addItem(itm, olditem) |
482 self._addItem(itm, olditem) |
468 else: |
483 else: |
469 if olditem == self.rootItem: |
484 if olditem == self.rootItem: |
470 oldindex = QModelIndex() |
485 oldindex = QModelIndex() |
471 else: |
486 else: |
472 oldindex = self.createIndex(olditem.row(), 0, olditem) |
487 oldindex = self.createIndex( |
|
488 olditem.row(), 0, olditem) |
473 self.addItem(itm, oldindex) |
489 self.addItem(itm, oldindex) |
474 else: |
490 else: |
475 if type_ and type_ not in itm.getProjectTypes(): |
491 if type_ and type_ not in itm.getProjectTypes(): |
476 itm.addProjectType(type_) |
492 itm.addProjectType(type_) |
477 index = self.createIndex(itm.row(), 0, itm) |
493 index = self.createIndex(itm.row(), 0, itm) |
505 |
521 |
506 @param typeString string denoting the type of the new item (string) |
522 @param typeString string denoting the type of the new item (string) |
507 @param name name of the new item (string) |
523 @param name name of the new item (string) |
508 @param additionalTypeStrings names of additional types (list of string) |
524 @param additionalTypeStrings names of additional types (list of string) |
509 """ |
525 """ |
510 # Show the entry in bold in the others browser to make it more distinguishable |
526 # Show the entry in bold in the others browser to make it more |
|
527 # distinguishable |
511 if typeString == "OTHERS": |
528 if typeString == "OTHERS": |
512 bold = True |
529 bold = True |
513 else: |
530 else: |
514 bold = False |
531 bold = False |
515 |
532 |
516 fname = os.path.join(self.project.ppath, name) |
533 fname = os.path.join(self.project.ppath, name) |
517 parentItem, dt = \ |
534 parentItem, dt = self.findParentItemByName( |
518 self.findParentItemByName(self.projectBrowserTypes[typeString], name) |
535 self.projectBrowserTypes[typeString], name) |
519 if parentItem == self.rootItem: |
536 if parentItem == self.rootItem: |
520 parentIndex = QModelIndex() |
537 parentIndex = QModelIndex() |
521 else: |
538 else: |
522 parentIndex = self.createIndex(parentItem.row(), 0, parentItem) |
539 parentIndex = self.createIndex(parentItem.row(), 0, parentItem) |
523 if os.path.isdir(fname): |
540 if os.path.isdir(fname): |
636 if path not in self.watchedItems: |
653 if path not in self.watchedItems: |
637 # just ignore the situation we don't have a reference to the item |
654 # just ignore the situation we don't have a reference to the item |
638 return |
655 return |
639 |
656 |
640 if Preferences.getUI("BrowsersListHiddenFiles"): |
657 if Preferences.getUI("BrowsersListHiddenFiles"): |
641 filter = QDir.Filters(QDir.AllEntries | QDir.Hidden | QDir.NoDotAndDotDot) |
658 filter = QDir.Filters(QDir.AllEntries | |
|
659 QDir.Hidden | |
|
660 QDir.NoDotAndDotDot) |
642 else: |
661 else: |
643 filter = QDir.Filters(QDir.AllEntries | QDir.NoDotAndDotDot) |
662 filter = QDir.Filters(QDir.AllEntries | QDir.NoDotAndDotDot) |
644 |
663 |
645 for itm in self.watchedItems[path]: |
664 for itm in self.watchedItems[path]: |
646 oldCnt = itm.childCount() |
665 oldCnt = itm.childCount() |
809 |
828 |
810 def changeVCSStates(self, statesList): |
829 def changeVCSStates(self, statesList): |
811 """ |
830 """ |
812 Public slot to record the (non normal) VCS states. |
831 Public slot to record the (non normal) VCS states. |
813 |
832 |
814 @param statesList list of VCS state entries (list of strings) giving the |
833 @param statesList list of VCS state entries (list of strings) giving |
815 states in the first column and the path relative to the project |
834 the states in the first column and the path relative to the project |
816 directory starting with the third column. The allowed status flags |
835 directory starting with the third column. The allowed status flags |
817 are: |
836 are: |
818 <ul> |
837 <ul> |
819 <li>"A" path was added but not yet comitted</li> |
838 <li>"A" path was added but not yet comitted</li> |
820 <li>"M" path has local changes</li> |
839 <li>"M" path has local changes</li> |