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