diff --git a/addons/symbolviewer/plugin_katesymbolviewer.h b/addons/symbolviewer/plugin_katesymbolviewer.h --- a/addons/symbolviewer/plugin_katesymbolviewer.h +++ b/addons/symbolviewer/plugin_katesymbolviewer.h @@ -109,6 +109,10 @@ private: KTextEditor::MainWindow *m_mainWindow; KatePluginSymbolViewer *m_plugin; + // I chose a more generic name because the "highlightMode" we ask + // is only a randomly suitable emergency aid, + // "m_docType" would be my preffered name, shorter but still full understandable. + QString m_documentType; QMenu *m_popup; QWidget *m_toolview; QTreeWidget *m_symbols; diff --git a/addons/symbolviewer/plugin_katesymbolviewer.cpp b/addons/symbolviewer/plugin_katesymbolviewer.cpp --- a/addons/symbolviewer/plugin_katesymbolviewer.cpp +++ b/addons/symbolviewer/plugin_katesymbolviewer.cpp @@ -161,17 +161,25 @@ void KatePluginSymbolViewerView::slotDocChanged() { - parseSymbols(); + // This time I have this block indent to be consistent (in this file) and some line wrapped - KTextEditor::View *view = m_mainWindow->activeView(); - //qDebug()<<"Document changed !!!!" << view; - if (view) { - connect(view, &KTextEditor::View::cursorPositionChanged, this, &KatePluginSymbolViewerView::cursorPositionChanged, Qt::UniqueConnection); + KTextEditor::View *view = m_mainWindow->activeView(); + //qDebug()<<"Document changed !!!!" << view; + if (view) { + connect(view, &KTextEditor::View::cursorPositionChanged + , this, &KatePluginSymbolViewerView::cursorPositionChanged, Qt::UniqueConnection); - if (view->document()) { - connect(view->document(), &KTextEditor::Document::textChanged, this, &KatePluginSymbolViewerView::slotDocEdited, Qt::UniqueConnection); - } - } + if (view->document()) { + connect(view->document(), &KTextEditor::Document::textChanged + , this, &KatePluginSymbolViewerView::slotDocEdited, Qt::UniqueConnection); + + // So, once again: What's up with this mode() function? Is it deprecated or not? + // Get the current highlight mode as document type detector + m_documentType = view->document()->mode(); + } + } + + parseSymbols(); } void KatePluginSymbolViewerView::slotDocEdited() @@ -286,38 +294,29 @@ if (!m_mainWindow->activeView()) return; - KTextEditor::Document *doc = m_mainWindow->activeView()->document(); - - // be sure we have some document around ! - if (!doc) - return; - - /** Get the current highlighting mode */ - QString hlModeName = doc->mode(); - - if (hlModeName.contains(QLatin1String("C++")) || hlModeName == QLatin1String("C") || hlModeName == QLatin1String("ANSI C89")) + if (m_documentType.contains(QLatin1String("C++")) || m_documentType == QLatin1String("C") || m_documentType == QLatin1String("ANSI C89")) parseCppSymbols(); - else if (hlModeName == QLatin1String("PHP (HTML)")) + else if (m_documentType == QLatin1String("PHP (HTML)")) parsePhpSymbols(); - else if (hlModeName == QLatin1String("Tcl/Tk")) + else if (m_documentType == QLatin1String("Tcl/Tk")) parseTclSymbols(); - else if (hlModeName == QLatin1String("Fortran")) + else if (m_documentType == QLatin1String("Fortran")) parseFortranSymbols(); - else if (hlModeName == QLatin1String("Perl")) + else if (m_documentType == QLatin1String("Perl")) parsePerlSymbols(); - else if (hlModeName == QLatin1String("Python")) + else if (m_documentType == QLatin1String("Python")) parsePythonSymbols(); - else if (hlModeName == QLatin1String("Ruby")) + else if (m_documentType == QLatin1String("Ruby")) parseRubySymbols(); - else if (hlModeName == QLatin1String("Java")) + else if (m_documentType == QLatin1String("Java")) parseCppSymbols(); - else if (hlModeName == QLatin1String("xslt")) + else if (m_documentType == QLatin1String("xslt")) parseXsltSymbols(); - else if (hlModeName == QLatin1String("Bash")) + else if (m_documentType == QLatin1String("Bash")) parseBashSymbols(); - else if (hlModeName == QLatin1String("ActionScript 2.0") || - hlModeName == QLatin1String("JavaScript") || - hlModeName == QLatin1String("QML")) + else if (m_documentType == QLatin1String("ActionScript 2.0") || + m_documentType == QLatin1String("JavaScript") || + m_documentType == QLatin1String("QML")) parseEcmaSymbols(); else { QTreeWidgetItem *node = new QTreeWidgetItem(m_symbols); @@ -325,7 +324,7 @@ // Setting invalid line number avoid jump to top of document when clicked node->setText(1, QLatin1String("-1")); node = new QTreeWidgetItem(m_symbols); - node->setText(0, i18n("File type: %1", hlModeName)); + node->setText(0, i18n("File type: %1", m_documentType)); node->setText(1, QLatin1String("-1")); }