Changeset View
Changeset View
Standalone View
Standalone View
addons/symbolviewer/plugin_katesymbolviewer.cpp
Show First 20 Lines • Show All 170 Lines • ▼ Show 20 Line(s) | |||||
171 | 171 | | |||
172 | void KatePluginSymbolViewerView::toggleShowFunctions(void) | 172 | void KatePluginSymbolViewerView::toggleShowFunctions(void) | ||
173 | { | 173 | { | ||
174 | func_on = m_func->isChecked(); | 174 | func_on = m_func->isChecked(); | ||
175 | slotRefreshSymbol(); | 175 | slotRefreshSymbol(); | ||
176 | } | 176 | } | ||
177 | 177 | | |||
178 | void KatePluginSymbolViewerView::slotRefreshSymbol() | 178 | void KatePluginSymbolViewerView::slotRefreshSymbol() | ||
179 | { | 179 | { | ||
sars: I like this change! :)
Checking pointers should be done close to where you use them.
I think… | |||||
Is that a request to do it in this patch? Then I will. loh.tar: > I think we even could merge slotRefreshSymbols() with parseSymbols() as the first now just… | |||||
180 | if (!m_symbols) | | |||
181 | return; | | |||
182 | | ||||
183 | parseSymbols(); | 180 | parseSymbols(); | ||
184 | } | 181 | } | ||
185 | 182 | | |||
186 | void KatePluginSymbolViewerView::slotChangeMode() | 183 | void KatePluginSymbolViewerView::slotChangeMode() | ||
187 | { | 184 | { | ||
188 | m_plugin->treeOn = m_treeOn->isChecked(); | 185 | m_plugin->treeOn = m_treeOn->isChecked(); | ||
189 | parseSymbols(); | 186 | parseSymbols(); | ||
190 | } | 187 | } | ||
191 | 188 | | |||
192 | void KatePluginSymbolViewerView::slotEnableSorting() | 189 | void KatePluginSymbolViewerView::slotEnableSorting() | ||
193 | { | 190 | { | ||
194 | m_plugin->sortOn = m_sort->isChecked(); | 191 | m_plugin->sortOn = m_sort->isChecked(); | ||
195 | m_symbols->setSortingEnabled(m_sort->isChecked()); | 192 | m_symbols->setSortingEnabled(m_sort->isChecked()); | ||
196 | 193 | | |||
197 | parseSymbols(); | 194 | parseSymbols(); | ||
198 | } | 195 | } | ||
199 | 196 | | |||
200 | void KatePluginSymbolViewerView::slotDocChanged() | 197 | void KatePluginSymbolViewerView::slotDocChanged() | ||
201 | { | 198 | { | ||
202 | slotRefreshSymbol(); | 199 | slotRefreshSymbol(); | ||
As you noticed this change is not good. It does not decrease the number of calls to parseSymbols() it just adds a delay of 500ms. Notice that cursorPositionChanged and slotDocEdited are connected later in this slot and therefore not trigger any calls to them. sars: As you noticed this change is not good. It does not decrease the number of calls to… | |||||
loh.tar: Yes, will revert this | |||||
203 | 200 | | |||
204 | KTextEditor::View *view = m_mainWindow->activeView(); | 201 | KTextEditor::View *view = m_mainWindow->activeView(); | ||
205 | //qDebug()<<"Document changed !!!!" << view; | 202 | //qDebug()<<"Document changed !!!!" << view; | ||
206 | if (view) { | 203 | if (view) { | ||
207 | connect(view, &KTextEditor::View::cursorPositionChanged, this, &KatePluginSymbolViewerView::cursorPositionChanged, Qt::UniqueConnection); | 204 | connect(view, &KTextEditor::View::cursorPositionChanged, this, &KatePluginSymbolViewerView::cursorPositionChanged, Qt::UniqueConnection); | ||
208 | 205 | | |||
209 | if (view->document()) { | 206 | if (view->document()) { | ||
210 | connect(view->document(), &KTextEditor::Document::textChanged, this, &KatePluginSymbolViewerView::slotDocEdited, Qt::UniqueConnection); | 207 | connect(view->document(), &KTextEditor::Document::textChanged, this, &KatePluginSymbolViewerView::slotDocEdited, Qt::UniqueConnection); | ||
211 | } | 208 | } | ||
212 | } | 209 | } | ||
213 | } | 210 | } | ||
214 | 211 | | |||
215 | void KatePluginSymbolViewerView::slotDocEdited() | 212 | void KatePluginSymbolViewerView::slotDocEdited() | ||
216 | { | 213 | { | ||
214 | m_currItemTimer.stop(); // Avoid unneeded update | ||||
217 | m_updateTimer.start(500); | 215 | m_updateTimer.start(500); | ||
218 | } | 216 | } | ||
219 | 217 | | |||
220 | void KatePluginSymbolViewerView::cursorPositionChanged() | 218 | void KatePluginSymbolViewerView::cursorPositionChanged() | ||
221 | { | 219 | { | ||
220 | if (m_updateTimer.isActive()) { | ||||
221 | // No need for update, will come anyway | ||||
222 | return; | ||||
223 | } | ||||
222 | m_currItemTimer.start(100); | 224 | m_currItemTimer.start(100); | ||
223 | } | 225 | } | ||
224 | 226 | | |||
225 | void KatePluginSymbolViewerView::updateCurrTreeItem() | 227 | void KatePluginSymbolViewerView::updateCurrTreeItem() | ||
226 | { | 228 | { | ||
227 | if (!m_mainWindow) { | 229 | if (!m_mainWindow) { | ||
228 | return; | 230 | return; | ||
229 | } | 231 | } | ||
230 | KTextEditor::View* editView = m_mainWindow->activeView(); | 232 | KTextEditor::View* editView = m_mainWindow->activeView(); | ||
231 | if (!editView) { | 233 | if (!editView) { | ||
232 | return; | 234 | return; | ||
233 | } | 235 | } | ||
234 | KTextEditor::Document* doc = editView->document(); | 236 | KTextEditor::Document* doc = editView->document(); | ||
235 | if (!doc) { | 237 | if (!doc) { | ||
236 | return; | 238 | return; | ||
237 | } | 239 | } | ||
240 | | ||||
238 | int currLine = editView->cursorPositionVirtual().line(); | 241 | int currLine = editView->cursorPositionVirtual().line(); | ||
242 | if (currLine == m_oldCursorLine) { | ||||
243 | // Nothing to do | ||||
244 | return; | ||||
245 | } | ||||
246 | m_oldCursorLine = currLine; | ||||
239 | 247 | | |||
240 | int newItemLine = 0; | 248 | int newItemLine = 0; | ||
241 | QTreeWidgetItem *newItem = nullptr; | 249 | QTreeWidgetItem *newItem = nullptr; | ||
242 | QTreeWidgetItem *tmp = nullptr; | 250 | QTreeWidgetItem *tmp = nullptr; | ||
243 | for (int i=0; i<m_symbols->topLevelItemCount(); i++) { | 251 | for (int i=0; i<m_symbols->topLevelItemCount(); i++) { | ||
244 | tmp = newActveItem(newItemLine, currLine, m_symbols->topLevelItem(i)); | 252 | tmp = newActveItem(newItemLine, currLine, m_symbols->topLevelItem(i)); | ||
245 | if (tmp) newItem = tmp; | 253 | if (tmp) newItem = tmp; | ||
246 | } | 254 | } | ||
Show All 39 Lines | |||||
286 | 294 | | |||
287 | void KatePluginSymbolViewerView::slotShowContextMenu(const QPoint&) | 295 | void KatePluginSymbolViewerView::slotShowContextMenu(const QPoint&) | ||
288 | { | 296 | { | ||
289 | m_popup->popup(QCursor::pos(), m_treeOn); | 297 | m_popup->popup(QCursor::pos(), m_treeOn); | ||
290 | } | 298 | } | ||
291 | 299 | | |||
292 | void KatePluginSymbolViewerView::parseSymbols(void) | 300 | void KatePluginSymbolViewerView::parseSymbols(void) | ||
293 | { | 301 | { | ||
302 | if (!m_symbols) | ||||
303 | return; | ||||
304 | | ||||
294 | m_symbols->clear(); | 305 | m_symbols->clear(); | ||
295 | // Qt docu recommends to populate view with disabled sorting | 306 | // Qt docu recommends to populate view with disabled sorting | ||
296 | // https://doc.qt.io/qt-5/qtreeview.html#sortingEnabled-prop | 307 | // https://doc.qt.io/qt-5/qtreeview.html#sortingEnabled-prop | ||
297 | m_symbols->setSortingEnabled(false); | 308 | m_symbols->setSortingEnabled(false); | ||
298 | 309 | | |||
299 | if (!m_mainWindow->activeView()) | 310 | if (!m_mainWindow->activeView()) | ||
300 | return; | 311 | return; | ||
301 | 312 | | |||
Show All 28 Lines | 340 | else if (hlModeName == QLatin1String("Bash")) | |||
330 | parseBashSymbols(); | 341 | parseBashSymbols(); | ||
331 | else if (hlModeName == QLatin1String("ActionScript 2.0") || | 342 | else if (hlModeName == QLatin1String("ActionScript 2.0") || | ||
332 | hlModeName == QLatin1String("JavaScript") || | 343 | hlModeName == QLatin1String("JavaScript") || | ||
333 | hlModeName == QLatin1String("QML")) | 344 | hlModeName == QLatin1String("QML")) | ||
334 | parseEcmaSymbols(); | 345 | parseEcmaSymbols(); | ||
335 | else | 346 | else | ||
336 | new QTreeWidgetItem(m_symbols, QStringList(i18n("Sorry. Language not supported yet") ) ); | 347 | new QTreeWidgetItem(m_symbols, QStringList(i18n("Sorry. Language not supported yet") ) ); | ||
337 | 348 | | |||
349 | m_oldCursorLine = -1; | ||||
338 | updateCurrTreeItem(); | 350 | updateCurrTreeItem(); | ||
339 | if (m_sort->isChecked()) | 351 | if (m_sort->isChecked()) | ||
340 | m_symbols->sortItems(0, Qt::AscendingOrder); | 352 | m_symbols->sortItems(0, Qt::AscendingOrder); | ||
341 | } | 353 | } | ||
342 | 354 | | |||
343 | void KatePluginSymbolViewerView::goToSymbol(QTreeWidgetItem *it) | 355 | void KatePluginSymbolViewerView::goToSymbol(QTreeWidgetItem *it) | ||
344 | { | 356 | { | ||
345 | KTextEditor::View *kv = m_mainWindow->activeView(); | 357 | KTextEditor::View *kv = m_mainWindow->activeView(); | ||
▲ Show 20 Lines • Show All 113 Lines • Show Last 20 Lines |
I like this change! :)
Checking pointers should be done close to where you use them.
I think we even could merge slotRefreshSymbols() with parseSymbols() as the first now just calls the later.