--- a/src/eric7/QScintilla/EditorOutlineModel.py Sun Dec 11 18:24:41 2022 +0100 +++ b/src/eric7/QScintilla/EditorOutlineModel.py Mon Dec 12 16:35:21 2022 +0100 @@ -33,9 +33,7 @@ """ SupportedLanguages = { - "IDL": "idl", "JavaScript": "javascript", - "Protocol": "protobuf", "Python3": "python", "MicroPython": "python", "Cython": "python", @@ -73,90 +71,83 @@ self.__filename = self.__editor.getFileName() self.__module = os.path.basename(self.__filename) - language = self.__editor.getLanguage() - if language in EditorOutlineModel.SupportedLanguages: - mod = ClassBrowsers.getClassBrowserModule( - EditorOutlineModel.SupportedLanguages[language] - ) - if mod: - dictionary = mod.scan( - self.__editor.text(), self.__filename, self.__module - ) - mod.clearModulesCache() - - keys = list(dictionary.keys()) - if len(keys) > 0: - parentItem = self.rootItem + dictionary = ClassBrowsers.scan( + self.__editor.text(), self.__filename, self.__module + ) + if dictionary is not None: + 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( - "SourceOutlineShowCoding" - ): - last -= 1 - self.beginInsertRows(QModelIndex(), 0, last) - - 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( + if repopulate: + last = len(keys) - 1 + if "@@Coding@@" in keys and not 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, + last -= 1 + self.beginInsertRows(QModelIndex(), 0, last) + + 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, - importedModule.linenos, + linenos, + isModule=False, ) - 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._addItem(mn_node, m_node) + if repopulate: + self.endInsertRows() - self.__populated = True - return + self.__populated = True + return self.clear() self.__populated = False @@ -269,3 +260,15 @@ return QModelIndex() return QModelIndex() + + @classmethod + def getSupportedLanguages(cls): + """ + Class method to get the list of supported programming languages. + + @return list of supported programming languages + @rtype str + """ + return list(ClassBrowsers.ClassBrowserRegistry.keys()) + list( + cls.SupportedLanguages.keys() + )