--- a/src/eric7/UI/BrowserModel.py Sat Jul 06 19:48:50 2024 +0200 +++ b/src/eric7/UI/BrowserModel.py Sun Jul 07 12:57:21 2024 +0200 @@ -57,12 +57,28 @@ PbFile = 102 +class BrowserModelType(enum.Enum): + """ + Class defining the various browser model types. + """ + + Generic = 0 + Project = 1 + EditorOutline = 2 + + class BrowserModel(QAbstractItemModel): """ Class implementing the browser model. """ - def __init__(self, parent=None, nopopulate=False, fsInterface=None): + def __init__( + self, + parent=None, + nopopulate=False, + fsInterface=None, + modelType=BrowserModelType.Generic, + ): """ Constructor @@ -73,6 +89,9 @@ @param fsInterface reference to the 'eric-ide' server interface object (defaults to None) @type EricServerFileSystemInterface (optional) + @param modelType type of the browser model (defaults to + BrowserModelType.Generic) + @type BrowserModelType (optional) """ super().__init__(parent) @@ -82,6 +101,7 @@ self.__sysPathItem = None self.__remotefsInterface = fsInterface + self._modelType = modelType if not nopopulate: self.watchedDirItems = {} @@ -769,9 +789,13 @@ if isinstance( cl, (ClbrBaseClasses.Class, ClbrBaseClasses.Module) ): - node = BrowserClassItem(parentItem, cl, fileName) + node = BrowserClassItem( + parentItem, cl, fileName, modelType=self._modelType + ) elif isinstance(cl, ClbrBaseClasses.Function): - node = BrowserMethodItem(parentItem, cl, fileName) + node = BrowserMethodItem( + parentItem, cl, fileName, modelType=self._modelType + ) else: node = None if node: @@ -806,6 +830,7 @@ importedModule.importedModuleName, importedModule.file, importedModule.linenos, + modelType=self._modelType, ) self._addItem(m_node, node) for ( @@ -818,6 +843,7 @@ importedModule.file, linenos, isModule=False, + modelType=self._modelType, ) self._addItem(mn_node, m_node) @@ -923,9 +949,13 @@ ) for key, kind in keys: if kind == "c": - node = BrowserClassItem(parentItem, cl.classes[key], file_) + node = BrowserClassItem( + parentItem, cl.classes[key], file_, modelType=self._modelType + ) elif kind == "m": - node = BrowserMethodItem(parentItem, cl.methods[key], file_) + node = BrowserMethodItem( + parentItem, cl.methods[key], file_, modelType=self._modelType + ) self._addItem(node, parentItem) if repopulate: self.endInsertRows() @@ -961,11 +991,17 @@ ) for key, kind in keys: if kind == "c": - node = BrowserClassItem(parentItem, fn.classes[key], file_) + node = BrowserClassItem( + parentItem, fn.classes[key], file_, modelType=self._modelType + ) elif kind == "m": - node = BrowserMethodItem(parentItem, fn.methods[key], file_) + node = BrowserMethodItem( + parentItem, fn.methods[key], file_, modelType=self._modelType + ) elif kind == "a": - node = BrowserClassAttributeItem(parentItem, fn.attributes[key]) + node = BrowserClassAttributeItem( + parentItem, fn.attributes[key], modelType=self._modelType + ) self._addItem(node, parentItem) if repopulate: self.endInsertRows() @@ -993,7 +1029,10 @@ ) for key in keys: node = BrowserClassAttributeItem( - parentItem, attributes[key], classAttributes + parentItem, + attributes[key], + classAttributes, + modelType=self._modelType, ) self._addItem(node, parentItem) if repopulate: @@ -1807,7 +1846,7 @@ Class implementing the data structure for browser class items. """ - def __init__(self, parent, cl, filename): + def __init__(self, parent, cl, filename, modelType=BrowserModelType.Generic): """ Constructor @@ -1817,6 +1856,9 @@ @type Class @param filename file name of the file defining this class @type str + @param modelType type of the browser model (defaults to + BrowserModelType.Generic) + @type BrowserModelType (optional) """ name = cl.name if hasattr(cl, "super") and cl.super: @@ -1833,6 +1875,7 @@ super().__init__(parent, name) + self._modelType = modelType self.type_ = BrowserItemType.Class self._name = name self._classObject = cl @@ -1949,7 +1992,16 @@ if issubclass(other.__class__, (BrowserCodingItem, BrowserClassAttributesItem)): return order == Qt.SortOrder.DescendingOrder - if Preferences.getUI("BrowsersListContentsByOccurrence") and column == 0: + if column == 0 and ( + ( + self._modelType == BrowserModelType.EditorOutline + and Preferences.getEditor("SourceOutlineListContentsByOccurrence") + ) + or ( + self._modelType != BrowserModelType.EditorOutline + and Preferences.getUI("BrowsersListContentsByOccurrence") + ) + ): if order == Qt.SortOrder.AscendingOrder: return self.lineno() < other.lineno() else: @@ -1972,7 +2024,7 @@ Class implementing the data structure for browser method items. """ - def __init__(self, parent, fn, filename): + def __init__(self, parent, fn, filename, modelType=BrowserModelType.Generic): """ Constructor @@ -1982,10 +2034,14 @@ @type Function @param filename filename of the file defining this class @type str + @param modelType type of the browser model (defaults to + BrowserModelType.Generic) + @type BrowserModelType (optional) """ name = fn.name super().__init__(parent, name) + self._modelType = modelType self.type_ = BrowserItemType.Method self._name = name self._functionObject = fn @@ -2094,7 +2150,16 @@ elif issubclass(other.__class__, BrowserClassAttributesItem): return order == Qt.SortOrder.DescendingOrder - if Preferences.getUI("BrowsersListContentsByOccurrence") and column == 0: + if column == 0 and ( + ( + self._modelType == BrowserModelType.EditorOutline + and Preferences.getEditor("SourceOutlineListContentsByOccurrence") + ) + or ( + self._modelType != BrowserModelType.EditorOutline + and Preferences.getUI("BrowsersListContentsByOccurrence") + ) + ): if order == Qt.SortOrder.AscendingOrder: return self.lineno() < other.lineno() else: @@ -2195,7 +2260,9 @@ Class implementing the data structure for browser class attribute items. """ - def __init__(self, parent, attribute, isClass=False): + def __init__( + self, parent, attribute, isClass=False, modelType=BrowserModelType.Generic + ): """ Constructor @@ -2203,11 +2270,15 @@ @type BrowserItem @param attribute reference to the attribute object @type Attribute - @param isClass flag indicating a class attribute - @type bool + @param isClass flag indicating a class attribute (defaults to False) + @type bool (optional) + @param modelType type of the browser model (defaults to + BrowserModelType.Generic) + @type BrowserModelType (optional) """ super().__init__(parent, attribute.name) + self._modelType = modelType self.type_ = BrowserItemType.Attribute self._attributeObject = attribute self.__public = attribute.isPublic() @@ -2287,7 +2358,16 @@ @return true, if this item is less than other @rtype bool """ - if Preferences.getUI("BrowsersListContentsByOccurrence") and column == 0: + if column == 0 and ( + ( + self._modelType == BrowserModelType.EditorOutline + and Preferences.getEditor("SourceOutlineListContentsByOccurrence") + ) + or ( + self._modelType != BrowserModelType.EditorOutline + and Preferences.getUI("BrowsersListContentsByOccurrence") + ) + ): if order == Qt.SortOrder.AscendingOrder: return self.lineno() < other.lineno() else: @@ -2413,7 +2493,15 @@ imported names items. """ - def __init__(self, parent, text, filename, lineNumbers, isModule=True): + def __init__( + self, + parent, + text, + filename, + lineNumbers, + isModule=True, + modelType=BrowserModelType.Generic, + ): """ Constructor @@ -2425,14 +2513,18 @@ @type str @param lineNumbers list of line numbers of the import statement @type list of int - @param isModule flag indicating a module item entry - @type bool + @param isModule flag indicating a module item entry (defaults to True) + @type bool (optional) + @param modelType type of the browser model (defaults to + BrowserModelType.Generic) + @type BrowserModelType (optional) """ super().__init__(parent, text) self.__filename = filename self.__linenos = lineNumbers[:] + self._modelType = modelType self.type_ = BrowserItemType.Import if isModule: self.icon = EricPixmapCache.getIcon("importedModule") @@ -2479,7 +2571,16 @@ @return true, if this item is less than other @rtype bool """ - if Preferences.getUI("BrowsersListContentsByOccurrence") and column == 0: + if column == 0 and ( + ( + self._modelType == BrowserModelType.EditorOutline + and Preferences.getEditor("SourceOutlineListContentsByOccurrence") + ) + or ( + self._modelType != BrowserModelType.EditorOutline + and Preferences.getUI("BrowsersListContentsByOccurrence") + ) + ): if order == Qt.SortOrder.AscendingOrder: return self.lineno() < other.lineno() else: