--- a/src/eric7/QScintilla/EditorOutlineModel.py Tue Nov 08 18:03:11 2022 +0100 +++ b/src/eric7/QScintilla/EditorOutlineModel.py Tue Nov 08 18:18:01 2022 +0100 @@ -24,6 +24,7 @@ BrowserMethodItem, BrowserModel, ) +from eric7.Utilities import ClassBrowsers class EditorOutlineModel(BrowserModel): @@ -31,15 +32,15 @@ Class implementing the editor outline model. """ - SupportedLanguages = ( - "IDL", - "JavaScript", - "Protocol", - "Python3", - "MicroPython", - "Cython", - "Ruby", - ) + SupportedLanguages = { + "IDL": "idl", + "JavaScript": "javascript", + "Protocol": "protobuf", + "Python3": "python", + "MicroPython": "python", + "Cython": "python", + "Ruby": "ruby", + } def __init__(self, editor, populate=True): """ @@ -74,119 +75,91 @@ language = self.__editor.getLanguage() if language in EditorOutlineModel.SupportedLanguages: - if language == "IDL": - from eric7.Utilities.ClassBrowsers import idlclbr # __IGNORE_WARNING__ - - dictionary = idlclbr.scan( - self.__editor.text(), self.__filename, self.__module - ) - idlclbr._modules.clear() - elif language == "Protocol": - from eric7.Utilities.ClassBrowsers import ( # __IGNORE_WARNING_I101__ - protoclbr, - ) - - dictionary = protoclbr.scan( - self.__editor.text(), self.__filename, self.__module - ) - protoclbr._modules.clear() - elif language == "Ruby": - from eric7.Utilities.ClassBrowsers import rbclbr # __IGNORE_WARNING__ - - dictionary = rbclbr.scan( + mod = ClassBrowsers.getClassBrowserModule( + EditorOutlineModel.SupportedLanguages[language] + ) + if mod: + dictionary = mod.scan( self.__editor.text(), self.__filename, self.__module ) - rbclbr._modules.clear() - elif language == "JavaScript": - from eric7.Utilities.ClassBrowsers import jsclbr # __IGNORE_WARNING__ + mod.clearModulesCache() - dictionary = jsclbr.scan( - self.__editor.text(), self.__filename, self.__module - ) - jsclbr._modules.clear() - elif language in ("Python3", "MicroPython", "Cython"): - from eric7.Utilities.ClassBrowsers import pyclbr # __IGNORE_WARNING__ + keys = list(dictionary.keys()) + if len(keys) > 0: + parentItem = self.rootItem - dictionary = pyclbr.scan( - self.__editor.text(), self.__filename, self.__module - ) - pyclbr._modules.clear() + if repopulate: + last = len(keys) - 1 + if "@@Coding@@" in keys and not Preferences.getEditor( + "SourceOutlineShowCoding" + ): + last -= 1 + self.beginInsertRows(QModelIndex(), 0, last) - keys = list(dictionary.keys()) - if len(keys) > 0: - parentItem = self.rootItem - - if repopulate: - last = len(keys) - 1 - if "@@Coding@@" in keys and not Preferences.getEditor( + for key in keys: + if key.startswith("@@"): + # special treatment done later + continue + cl = dictionary[key] + with contextlib.suppress(AttributeError): + if cl.module == self.__module: + node = BrowserClassItem(parentItem, cl, self.__filename) + self._addItem(node, parentItem) + if "@@Coding@@" in keys and Preferences.getEditor( "SourceOutlineShowCoding" ): - last -= 1 - self.beginInsertRows(QModelIndex(), 0, last) + node = BrowserCodingItem( + parentItem, + QCoreApplication.translate( + "EditorOutlineModel", "Coding: {0}" + ).format(dictionary["@@Coding@@"].coding), + dictionary["@@Coding@@"].linenumber, + ) + self._addItem(node, parentItem) + if "@@Globals@@" in keys: + node = BrowserGlobalsItem( + parentItem, + dictionary["@@Globals@@"].globals, + QCoreApplication.translate("EditorOutlineModel", "Globals"), + ) + self._addItem(node, parentItem) + if "@@Import@@" in keys or "@@ImportFrom@@" in keys: + node = BrowserImportsItem( + parentItem, + QCoreApplication.translate("EditorOutlineModel", "Imports"), + ) + self._addItem(node, parentItem) + if "@@Import@@" in keys: + for importedModule in ( + dictionary["@@Import@@"].getImports().values() + ): + m_node = BrowserImportItem( + node, + importedModule.importedModuleName, + importedModule.file, + importedModule.linenos, + ) + self._addItem(m_node, node) + for ( + importedName, + linenos, + ) in importedModule.importedNames.items(): + mn_node = BrowserImportItem( + m_node, + importedName, + importedModule.file, + linenos, + isModule=False, + ) + self._addItem(mn_node, m_node) + if repopulate: + self.endInsertRows() - for key in keys: - if key.startswith("@@"): - # special treatment done later - continue - cl = dictionary[key] - with contextlib.suppress(AttributeError): - if cl.module == self.__module: - node = BrowserClassItem(parentItem, cl, self.__filename) - self._addItem(node, parentItem) - if "@@Coding@@" in keys and Preferences.getEditor( - "SourceOutlineShowCoding" - ): - node = BrowserCodingItem( - parentItem, - QCoreApplication.translate( - "EditorOutlineModel", "Coding: {0}" - ).format(dictionary["@@Coding@@"].coding), - dictionary["@@Coding@@"].linenumber, - ) - self._addItem(node, parentItem) - if "@@Globals@@" in keys: - node = BrowserGlobalsItem( - parentItem, - dictionary["@@Globals@@"].globals, - QCoreApplication.translate("EditorOutlineModel", "Globals"), - ) - self._addItem(node, parentItem) - if "@@Import@@" in keys or "@@ImportFrom@@" in keys: - node = BrowserImportsItem( - parentItem, - QCoreApplication.translate("EditorOutlineModel", "Imports"), - ) - self._addItem(node, parentItem) - if "@@Import@@" in keys: - for importedModule in ( - dictionary["@@Import@@"].getImports().values() - ): - m_node = BrowserImportItem( - node, - importedModule.importedModuleName, - importedModule.file, - importedModule.linenos, - ) - self._addItem(m_node, node) - for ( - importedName, - linenos, - ) in importedModule.importedNames.items(): - mn_node = BrowserImportItem( - m_node, - importedName, - importedModule.file, - linenos, - isModule=False, - ) - self._addItem(mn_node, m_node) - if repopulate: - self.endInsertRows() + self.__populated = True + return - self.__populated = True - else: - self.clear() - self.__populated = False + self.clear() + self.__populated = False def isPopulated(self): """