71 @type bool |
69 @type bool |
72 """ |
70 """ |
73 self.__filename = self.__editor.getFileName() |
71 self.__filename = self.__editor.getFileName() |
74 self.__module = os.path.basename(self.__filename) |
72 self.__module = os.path.basename(self.__filename) |
75 |
73 |
76 language = self.__editor.getLanguage() |
74 dictionary = ClassBrowsers.scan( |
77 if language in EditorOutlineModel.SupportedLanguages: |
75 self.__editor.text(), self.__filename, self.__module |
78 mod = ClassBrowsers.getClassBrowserModule( |
76 ) |
79 EditorOutlineModel.SupportedLanguages[language] |
77 if dictionary is not None: |
80 ) |
78 keys = list(dictionary.keys()) |
81 if mod: |
79 if len(keys) > 0: |
82 dictionary = mod.scan( |
80 parentItem = self.rootItem |
83 self.__editor.text(), self.__filename, self.__module |
81 |
84 ) |
82 if repopulate: |
85 mod.clearModulesCache() |
83 last = len(keys) - 1 |
86 |
84 if "@@Coding@@" in keys and not Preferences.getEditor( |
87 keys = list(dictionary.keys()) |
|
88 if len(keys) > 0: |
|
89 parentItem = self.rootItem |
|
90 |
|
91 if repopulate: |
|
92 last = len(keys) - 1 |
|
93 if "@@Coding@@" in keys and not Preferences.getEditor( |
|
94 "SourceOutlineShowCoding" |
|
95 ): |
|
96 last -= 1 |
|
97 self.beginInsertRows(QModelIndex(), 0, last) |
|
98 |
|
99 for key in keys: |
|
100 if key.startswith("@@"): |
|
101 # special treatment done later |
|
102 continue |
|
103 cl = dictionary[key] |
|
104 with contextlib.suppress(AttributeError): |
|
105 if cl.module == self.__module: |
|
106 node = BrowserClassItem(parentItem, cl, self.__filename) |
|
107 self._addItem(node, parentItem) |
|
108 if "@@Coding@@" in keys and Preferences.getEditor( |
|
109 "SourceOutlineShowCoding" |
85 "SourceOutlineShowCoding" |
110 ): |
86 ): |
111 node = BrowserCodingItem( |
87 last -= 1 |
112 parentItem, |
88 self.beginInsertRows(QModelIndex(), 0, last) |
113 QCoreApplication.translate( |
89 |
114 "EditorOutlineModel", "Coding: {0}" |
90 for key in keys: |
115 ).format(dictionary["@@Coding@@"].coding), |
91 if key.startswith("@@"): |
116 dictionary["@@Coding@@"].linenumber, |
92 # special treatment done later |
117 ) |
93 continue |
118 self._addItem(node, parentItem) |
94 cl = dictionary[key] |
119 if "@@Globals@@" in keys: |
95 with contextlib.suppress(AttributeError): |
120 node = BrowserGlobalsItem( |
96 if cl.module == self.__module: |
121 parentItem, |
97 node = BrowserClassItem(parentItem, cl, self.__filename) |
122 dictionary["@@Globals@@"].globals, |
98 self._addItem(node, parentItem) |
123 QCoreApplication.translate("EditorOutlineModel", "Globals"), |
99 if "@@Coding@@" in keys and Preferences.getEditor( |
124 ) |
100 "SourceOutlineShowCoding" |
125 self._addItem(node, parentItem) |
101 ): |
126 if "@@Import@@" in keys or "@@ImportFrom@@" in keys: |
102 node = BrowserCodingItem( |
127 node = BrowserImportsItem( |
103 parentItem, |
128 parentItem, |
104 QCoreApplication.translate( |
129 QCoreApplication.translate("EditorOutlineModel", "Imports"), |
105 "EditorOutlineModel", "Coding: {0}" |
130 ) |
106 ).format(dictionary["@@Coding@@"].coding), |
131 self._addItem(node, parentItem) |
107 dictionary["@@Coding@@"].linenumber, |
132 if "@@Import@@" in keys: |
108 ) |
133 for importedModule in ( |
109 self._addItem(node, parentItem) |
134 dictionary["@@Import@@"].getImports().values() |
110 if "@@Globals@@" in keys: |
135 ): |
111 node = BrowserGlobalsItem( |
136 m_node = BrowserImportItem( |
112 parentItem, |
137 node, |
113 dictionary["@@Globals@@"].globals, |
138 importedModule.importedModuleName, |
114 QCoreApplication.translate("EditorOutlineModel", "Globals"), |
|
115 ) |
|
116 self._addItem(node, parentItem) |
|
117 if "@@Import@@" in keys or "@@ImportFrom@@" in keys: |
|
118 node = BrowserImportsItem( |
|
119 parentItem, |
|
120 QCoreApplication.translate("EditorOutlineModel", "Imports"), |
|
121 ) |
|
122 self._addItem(node, parentItem) |
|
123 if "@@Import@@" in keys: |
|
124 for importedModule in ( |
|
125 dictionary["@@Import@@"].getImports().values() |
|
126 ): |
|
127 m_node = BrowserImportItem( |
|
128 node, |
|
129 importedModule.importedModuleName, |
|
130 importedModule.file, |
|
131 importedModule.linenos, |
|
132 ) |
|
133 self._addItem(m_node, node) |
|
134 for ( |
|
135 importedName, |
|
136 linenos, |
|
137 ) in importedModule.importedNames.items(): |
|
138 mn_node = BrowserImportItem( |
|
139 m_node, |
|
140 importedName, |
139 importedModule.file, |
141 importedModule.file, |
140 importedModule.linenos, |
142 linenos, |
|
143 isModule=False, |
141 ) |
144 ) |
142 self._addItem(m_node, node) |
145 self._addItem(mn_node, m_node) |
143 for ( |
146 if repopulate: |
144 importedName, |
147 self.endInsertRows() |
145 linenos, |
148 |
146 ) in importedModule.importedNames.items(): |
149 self.__populated = True |
147 mn_node = BrowserImportItem( |
150 return |
148 m_node, |
|
149 importedName, |
|
150 importedModule.file, |
|
151 linenos, |
|
152 isModule=False, |
|
153 ) |
|
154 self._addItem(mn_node, m_node) |
|
155 if repopulate: |
|
156 self.endInsertRows() |
|
157 |
|
158 self.__populated = True |
|
159 return |
|
160 |
151 |
161 self.clear() |
152 self.clear() |
162 self.__populated = False |
153 self.__populated = False |
163 |
154 |
164 def isPopulated(self): |
155 def isPopulated(self): |