diff --git a/addons/symbolviewer/CMakeLists.txt b/addons/symbolviewer/CMakeLists.txt --- a/addons/symbolviewer/CMakeLists.txt +++ b/addons/symbolviewer/CMakeLists.txt @@ -1,7 +1,7 @@ add_definitions(-DTRANSLATION_DOMAIN=\"katesymbolviewer\") ########### next target ############### set(katesymbolviewerplugin_PART_SRCS cpp_parser.cpp tcl_parser.cpp fortran_parser.cpp perl_parser.cpp -php_parser.cpp xslt_parser.cpp ruby_parser.cpp python_parser.cpp bash_parser.cpp ecma_parser.cpp plugin_katesymbolviewer.cpp ) +php_parser.cpp xslt_parser.cpp xml_parser.cpp ruby_parser.cpp python_parser.cpp bash_parser.cpp ecma_parser.cpp plugin_katesymbolviewer.cpp ) # resource for ui file and stuff qt5_add_resources(katesymbolviewerplugin_PART_SRCS plugin.qrc) 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 @@ -133,6 +133,7 @@ void parsePythonSymbols(void); void parseRubySymbols(void); void parseXsltSymbols(void); + void parseXMLSymbols(void); void parsePhpSymbols(void); void parseBashSymbols(void); void parseEcmaSymbols(void); 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 @@ -332,6 +332,8 @@ parseCppSymbols(); else if (hlModeName == QLatin1String("xslt")) parseXsltSymbols(); + else if (hlModeName == QLatin1String("XML") || hlModeName == QLatin1String("HTML")) + parseXMLSymbols(); else if (hlModeName == QLatin1String("Bash")) parseBashSymbols(); else if (hlModeName == QLatin1String("ActionScript 2.0") || diff --git a/addons/symbolviewer/xml_parser.cpp b/addons/symbolviewer/xml_parser.cpp new file mode 100644 --- /dev/null +++ b/addons/symbolviewer/xml_parser.cpp @@ -0,0 +1,97 @@ +/*************************************************************************** + xml_parser.cpp - Produce a rudimentary list of tags/elements + present in XML or HTML files. In the tree view of the + symbolviewer plugin the list is grouped by the element type. + ------------------- + begin : May 3 2019 + author : 20019 Andreas Hohenegger based on + xslt_parser.cpp by jiri Tyr + email : hohenegger@gmail.com +***************************************************************************/ +/*************************************************************************** +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +***************************************************************************/ + +#include "plugin_katesymbolviewer.h" + +void KatePluginSymbolViewerView::parseXMLSymbols(void) +{ + if (!m_mainWindow->activeView()) + return; + + m_struct->setText(i18n("Show Tags")); + + QString cl; + QString stripped; + + char comment = 0; + int i; + + QPixmap cls( ( const char** ) class_xpm ); + QPixmap sct( ( const char** ) struct_xpm ); + + QTreeWidgetItem *node = nullptr; + QTreeWidgetItem *topNode = nullptr; + + KTextEditor::Document *kv = m_mainWindow->activeView()->document(); + + m_symbols->setRootIsDecorated(0); + + for (i=0; ilines(); i++) { + cl = kv->line(i); + cl = cl.trimmed(); + + if(cl.indexOf(QRegularExpression(QLatin1String(""))) >= 0) { + comment = 0; + continue; + } + + if (comment==1) { + continue; + } + + if(cl.indexOf(QRegularExpression(QLatin1String("^<[a-zA-Z_]+[a-zA-Z0-9_\\.\\-]*"))) == 0 && m_struct->isChecked()){ + + /* Get the tag type */ + QString type; + QRegularExpressionMatch match; + QRegularExpression re(QLatin1String("^<([a-zA-Z_]+[a-zA-Z0-9_\\.\\-]*)")); + if (cl.contains(re, &match)) + type = match.captured(1); + else + continue; + + QString stripped = cl.remove(QRegularExpression(QLatin1String("^<[a-zA-Z_]+[a-zA-Z0-9_\\.\\-]* *"))); + stripped = stripped.remove(QRegularExpression(QLatin1String(" */*>.*"))); + + if (m_treeOn->isChecked()) { + /* See if group already exists */ + QList reslist = m_symbols->findItems(type, Qt::MatchExactly); + if(reslist.isEmpty()) { + topNode = new QTreeWidgetItem(m_symbols, QStringList(type)); + topNode->setIcon(0, QIcon(cls)); + if (m_expandOn->isChecked()) { + m_symbols->expandItem(topNode); + } + } else { + topNode = reslist[0]; + } + node = new QTreeWidgetItem(topNode); + topNode->addChild(node); + } else { + node = new QTreeWidgetItem(m_symbols); + } + node->setIcon(0, QIcon(sct)); + node->setText(0, stripped); + node->setText(1, QString::number( i, 10)); + } + } +}