diff --git a/addons/symbolviewer/bash_parser.cpp b/addons/symbolviewer/bash_parser.cpp
index 6058c3aa3..5b56fc9cd 100644
--- a/addons/symbolviewer/bash_parser.cpp
+++ b/addons/symbolviewer/bash_parser.cpp
@@ -1,106 +1,106 @@
/***************************************************************************
bash_parser.cpp - description
-------------------
begin : dec 12 2008
author : Daniel Dumitrache
email : daniel.dumitrache@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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
***************************************************************************/
#include "plugin_katesymbolviewer.h"
void KatePluginSymbolViewerView::parseBashSymbols(void)
{
if (!m_mainWindow->activeView())
return;
QString currline;
QString funcStr(QLatin1String("function "));
int i;
//bool mainprog;
QTreeWidgetItem *node = nullptr;
QTreeWidgetItem *funcNode = nullptr;
QTreeWidgetItem *lastFuncNode = nullptr;
QPixmap func( ( const char** ) class_xpm );
//It is necessary to change names
m_func->setText(i18n("Show Functions"));
- if(m_plugin->treeOn)
+ if(m_treeOn->isChecked())
{
funcNode = new QTreeWidgetItem(m_symbols, QStringList(i18n("Functions") ) );
funcNode->setIcon(0, QIcon(func));
if (m_plugin->expandedOn)
{
m_symbols->expandItem(funcNode);
}
lastFuncNode = funcNode;
m_symbols->setRootIsDecorated(1);
}
else
m_symbols->setRootIsDecorated(0);
KTextEditor::Document *kDoc = m_mainWindow->activeView()->document();
for (i = 0; i < kDoc->lines(); i++)
{
currline = kDoc->line(i);
currline = currline.trimmed();
currline = currline.simplified();
bool comment = false;
//qDebug(13000)<isChecked())
{
QString funcName;
// skip line if no function defined
// note: function name must match regex: [a-zA-Z0-9-_]+
if(!currline.contains(QRegExp(QLatin1String("^(function )*[a-zA-Z0-9-_]+ *\\( *\\)")))
&& !currline.contains(QRegExp(QLatin1String("^function [a-zA-Z0-9-_]+"))))
continue;
// strip everything unneeded and get the function's name
currline.remove(QRegExp(QLatin1String("^(function )*")));
funcName = currline.split(QRegExp(QLatin1String("((\\( *\\))|[^a-zA-Z0-9-_])")))[0].simplified();
if(!funcName.size())
continue;
funcName.append(QLatin1String("()"));
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(funcNode, lastFuncNode);
lastFuncNode = node;
}
else
node = new QTreeWidgetItem(m_symbols);
node->setText(0, funcName);
node->setIcon(0, QIcon(func));
node->setText(1, QString::number( i, 10));
}
} //for i loop
}
diff --git a/addons/symbolviewer/cpp_parser.cpp b/addons/symbolviewer/cpp_parser.cpp
index 89dd0a5e7..509e545c4 100644
--- a/addons/symbolviewer/cpp_parser.cpp
+++ b/addons/symbolviewer/cpp_parser.cpp
@@ -1,365 +1,365 @@
/***************************************************************************
cpp_parser.cpp - description
-------------------
begin : Apr 2 2003
author : 2003 Massimo Callegari
email : massimocallegari@yahoo.it
***************************************************************************/
/***************************************************************************
* *
* 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::parseCppSymbols(void)
{
if (!m_mainWindow->activeView())
return;
QString cl; // Current Line
QString stripped;
int i, j, tmpPos = 0;
int par = 0, graph = 0/*, retry = 0*/;
char mclass = 0, block = 0, comment = 0; // comment: 0-no comment 1-inline comment 2-multiline comment 3-string
char macro = 0/*, macro_pos = 0*/, func_close = 0;
bool structure = false;
QPixmap cls( ( const char** ) class_xpm );
QPixmap sct( ( const char** ) struct_xpm );
QPixmap mcr( ( const char** ) macro_xpm );
QPixmap mtd( ( const char** ) method_xpm );
//It is necessary to change names to defaults
m_macro->setText(i18n("Show Macros"));
m_struct->setText(i18n("Show Structures"));
m_func->setText(i18n("Show Functions"));
QTreeWidgetItem *node = nullptr;
QTreeWidgetItem *mcrNode = nullptr, *sctNode = nullptr, *clsNode = nullptr, *mtdNode = nullptr;
QTreeWidgetItem *lastMcrNode = nullptr, *lastSctNode = nullptr, *lastClsNode = nullptr, *lastMtdNode = nullptr;
KTextEditor::Document *kv = m_mainWindow->activeView()->document();
//qDebug(13000)<<"Lines counted :"<lines();
- if(m_plugin->treeOn)
+ if(m_treeOn->isChecked())
{
mcrNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Macros") ) );
sctNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Structures") ) );
clsNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Functions") ) );
mcrNode->setIcon(0, QIcon(mcr));
sctNode->setIcon(0, QIcon(sct));
clsNode->setIcon(0, QIcon(cls));
if (m_plugin->expandedOn)
{
m_symbols->expandItem(mcrNode);
m_symbols->expandItem(sctNode);
m_symbols->expandItem(clsNode);
}
lastMcrNode = mcrNode;
lastSctNode = sctNode;
lastClsNode = clsNode;
mtdNode = clsNode;
lastMtdNode = clsNode;
m_symbols->setRootIsDecorated(1);
}
else m_symbols->setRootIsDecorated(0);
for (i=0; ilines(); i++)
{
//qDebug(13000)<<"Current line :"<line(i);
cl = cl.trimmed();
func_close = 0;
if ( (cl.length()>=2) && (cl.at(0) == QLatin1Char('/') && cl.at(1) == QLatin1Char('/'))) continue;
if(cl.indexOf(QLatin1String("/*")) == 0 && (cl.indexOf(QLatin1String("*/")) == ((signed)cl.length() - 2)) && graph == 0) continue; // workaround :(
if(cl.indexOf(QLatin1String("/*")) >= 0 && graph == 0) comment = 1;
if(cl.indexOf(QLatin1String("*/")) >= 0 && graph == 0) comment = 0;
if(cl.indexOf(QLatin1Char('#')) >= 0 && graph == 0 ) macro = 1;
if (comment != 1)
{
/* *********************** MACRO PARSING *****************************/
if(macro == 1)
{
//macro_pos = cl.indexOf(QLatin1Char('#'));
for (j = 0; j < cl.length(); j++)
{
if ( ((j+1) = 0x20) stripped += cl.at(j);
if (cl.at(j) == QLatin1Char(' ') || cl.at(j) == QLatin1Char('\t') || j == cl.length() - 1)
macro = 4;
}
//qDebug(13000)<<"Macro -- Stripped : "<isChecked())
{
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(mcrNode, lastMcrNode);
lastMcrNode = node;
}
else node = new QTreeWidgetItem(m_symbols);
node->setText(0, stripped);
node->setIcon(0, QIcon(mcr));
node->setText(1, QString::number( i, 10));
}
macro = 0;
//macro_pos = 0;
stripped.clear();
//qDebug(13000)<<"Macro -- Inserted : "<= 0 && graph == 0 && block == 0))
{
mclass = 1;
for (j = 0; j < cl.length(); j++)
{
if(((j+1) < cl.length()) && (cl.at(j)==QLatin1Char('/') && cl.at(j+1)==QLatin1Char('/'))) { mclass = 2; break; }
if(cl.at(j)==QLatin1Char('{')) { mclass = 4; break;}
stripped += cl.at(j);
}
if(m_func->isChecked())
{
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(clsNode, lastClsNode);
if (m_plugin->expandedOn) m_symbols->expandItem(node);
lastClsNode = node;
mtdNode = lastClsNode;
lastMtdNode = lastClsNode;
}
else node = new QTreeWidgetItem(m_symbols);
node->setText(0, stripped);
node->setIcon(0, QIcon(cls));
node->setText(1, QString::number( i, 10));
stripped.clear();
if (mclass == 1) mclass = 3;
}
continue;
}
if (mclass == 3)
{
if (cl.indexOf(QLatin1Char('{')) >= 0)
{
cl = cl.mid(cl.indexOf(QLatin1Char('{')));
mclass = 4;
}
}
if(cl.indexOf(QLatin1Char('(')) >= 0 && cl.at(0) != QLatin1Char('#') && block == 0 && comment != 2)
{ structure = false; block = 1; }
if((cl.indexOf(QLatin1String("typedef")) >= 0 || cl.indexOf(QLatin1String("struct")) >= 0) &&
graph == 0 && block == 0)
{ structure = true; block = 2; stripped.clear(); }
//if(cl.indexOf(QLatin1Char(';')) >= 0 && graph == 0)
// block = 0;
if(block > 0 && mclass != 1 )
{
for (j = 0; j < cl.length(); j++)
{
if ( ((j+1) < cl.length()) && (cl.at(j) == QLatin1Char('/') && (cl.at(j + 1) == QLatin1Char('*')) && comment != 3)) comment = 2;
if ( ((j+1) < cl.length()) && (cl.at(j) == QLatin1Char('*') && (cl.at(j + 1) == QLatin1Char('/')) && comment != 3) )
{ comment = 0; j+=2; if (j>=cl.length()) break;}
// Skip escaped double quotes
if ( ((j+1) < cl.length()) && (cl.at(j) == QLatin1Char('\\') && (cl.at(j + 1) == QLatin1Char('"')) && comment == 3) )
{ j+=2; if (j>=cl.length()) break;}
// Skip char declarations that could be interpreted as range start/end
if ( ((cl.indexOf(QStringLiteral("'\"'"), j) == j) ||
(cl.indexOf(QStringLiteral("'{'"), j) == j) ||
(cl.indexOf(QStringLiteral("'}'"), j) == j)) && comment != 3 )
{ j+=3; if (j>=cl.length()) break;}
// Handles a string. Those are freaking evilish !
if (cl.at(j) == QLatin1Char('"') && comment == 3) { comment = 0; j++; if (j>=cl.length()) break;}
else if (cl.at(j) == QLatin1Char('"') && comment == 0) comment = 3;
if ( ((j+1) = 0x20) stripped += cl.at(j);
if(cl.at(j) == QLatin1Char('(')) par++;
if(cl.at(j) == QLatin1Char(')'))
{
par--;
if(par == 0)
{
stripped = stripped.trimmed();
stripped.remove(QLatin1String("static "));
//qDebug(13000)<<"Function -- Inserted : "< (int)j))
{
stripped.replace(0x9, QLatin1String(" "));
if(m_func->isChecked())
{
QString strippedWithTypes = stripped;
if (m_plugin->typesOn == false)
{
while (stripped.indexOf(QLatin1Char('(')) >= 0)
stripped = stripped.left(stripped.indexOf(QLatin1Char('(')));
while (stripped.indexOf(QLatin1String("::")) >= 0)
stripped = stripped.mid(stripped.indexOf(QLatin1String("::")) + 2);
stripped = stripped.trimmed();
while (stripped.indexOf(0x20) >= 0)
stripped = stripped.mid(stripped.indexOf(0x20, 0) + 1);
while (
(stripped.length()>0) &&
(
(stripped.at(0)==QLatin1Char('*')) ||
(stripped.at(0)==QLatin1Char('&'))
)
) stripped=stripped.right(stripped.length()-1);
}
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
if (mclass == 4)
{
node = new QTreeWidgetItem(mtdNode, lastMtdNode);
lastMtdNode = node;
}
else
{
node = new QTreeWidgetItem(clsNode, lastClsNode);
lastClsNode = node;
}
}
else
node = new QTreeWidgetItem(m_symbols);
node->setText(0, stripped);
if (mclass == 4) node->setIcon(0, QIcon(mtd));
else node->setIcon(0, QIcon(cls));
node->setText(1, QString::number( tmpPos, 10));
node->setToolTip(0, strippedWithTypes);
}
stripped.clear();
//retry = 0;
block = 3;
}
if(cl.at(j)==QLatin1Char('{') && structure == true)
{
block = 3;
tmpPos = i;
}
if(cl.at(j)==QLatin1Char('(') && structure == true)
{
//retry = 1;
block = 0;
j = 0;
//qDebug(13000)<<"Restart from the beginning of line...";
stripped.clear();
break; // Avoid an infinite loop :(
}
if(structure == true && cl.at(j) >= 0x20) stripped += cl.at(j);
} // BLOCK 2
if (block == 3)
{
// A comment...there can be anything
if( ((j+1)isChecked())
{
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(sctNode, lastSctNode);
lastSctNode = node;
}
else node = new QTreeWidgetItem(m_symbols);
node->setText(0, stripped);
node->setIcon(0, QIcon(sct));
node->setText(1, QString::number( tmpPos, 10));
}
//qDebug(13000)<<"Structure -- Inserted : "<= 0x20) stripped += cl.at(j);
} // BLOCK 4
} // comment != 2
//qDebug(13000)<<"Stripped : "< 0
if (mclass == 4 && block == 0 && func_close == 0)
{
if (cl.indexOf(QLatin1Char('}')) >= 0)
{
cl = cl.mid(cl.indexOf(QLatin1Char('}')));
mclass = 0;
}
}
} // Comment != 1
} // for kv->numlines
//for (i= 0; i < (m_symbols->itemIndex(node) + 1); i++)
// qDebug(13000)<<"Symbol row :"<activeView()) return;
// the current line
QString cl;
// the current line stripped of all comments and strings
QString stripped;
// a parsed class/function identifier
QString identifier;
// temporary characters
QChar current, next, string_start = QLatin1Char('\0');
// whether we are in a multiline comment
bool in_comment = false;
// the current line index
int line = 0;
// indices into the string
int c, function_start = 0;
// the current depth of curly brace encapsulation
int brace_depth = 0;
// a list of inserted nodes with the index being the brace depth at insertion
QList nodes;
QPixmap cls( ( const char** ) class_xpm );
QPixmap mtd( ( const char** ) method_xpm );
QTreeWidgetItem *node = nullptr;
- if (m_plugin->treeOn) {
+ if (m_treeOn->isChecked()) {
m_symbols->setRootIsDecorated(1);
}
else {
m_symbols->setRootIsDecorated(0);
}
// read the document line by line
KTextEditor::Document *kv = m_mainWindow->activeView()->document();
for (line=0; line < kv->lines(); line++) {
// get a line to process, trimming off whitespace
cl = kv->line(line);
cl = cl.trimmed();
stripped.clear();
bool in_string = false;
for (c = 0; c < cl.length(); c++) {
// get the current character and the next
current = cl.at(c);
if ((c+1) < cl.length()) next = cl.at(c+1);
else next = QLatin1Char('\0');
// skip the rest of the line if we find a line comment
if ((! in_comment) && (current == QLatin1Char('/')) && (next == QLatin1Char('/'))) break;
// open/close multiline comments
if ((! in_string) && (current == QLatin1Char('/')) && (next == QLatin1Char('*'))) {
in_comment = true;
c++;
continue;
}
else if ((in_comment) && (current == QLatin1Char('*')) && (next == QLatin1Char('/'))) {
in_comment = false;
c++;
continue;
}
// open strings
if ((! in_comment) && (! in_string)) {
if ((current == QLatin1Char('\'')) || (current == QLatin1Char('"'))) {
string_start = current;
in_string = true;
continue;
}
}
// close strings
if (in_string) {
// skip escaped backslashes
if ((current == QLatin1Char('\\')) && (next == QLatin1Char('\\'))) {
c++;
continue;
}
// skip escaped string closures
if ((current == QLatin1Char('\\')) && (next == string_start)) {
c++;
continue;
}
else if (current == string_start) {
in_string = false;
continue;
}
}
// add anything outside strings and comments to the stripped line
if ((! in_comment) && (! in_string)) {
stripped += current;
}
}
// scan the stripped line
for (c = 0; c < stripped.length(); c++) {
current = stripped.at(c);
// look for class definitions (for ActionScript)
if ((current == QLatin1Char('c')) && (stripped.indexOf(QLatin1String("class"), c) == c)) {
identifier.clear();
c += 6;
for (c = c; c < stripped.length(); c++) {
current = stripped.at(c);
// look for the beginning of the class itself
if ((current == QLatin1Char('(')) || (current == QLatin1Char('{'))) {
c--;
break;
}
else {
identifier += current;
}
}
// trim whitespace
identifier = identifier.trimmed();
// get the node to add the class entry to
- if ((m_plugin->treeOn) && (! nodes.isEmpty())) {
+ if ((m_treeOn->isChecked()) && (! nodes.isEmpty())) {
node = new QTreeWidgetItem(nodes.last());
if (m_plugin->expandedOn) m_symbols->expandItem(node);
}
else {
node = new QTreeWidgetItem(m_symbols);
}
// add an entry for the class
node->setText(0, identifier);
node->setIcon(0, QIcon(cls));
node->setText(1, QString::number(line, 10));
if (m_plugin->expandedOn) m_symbols->expandItem(node);
} // (look for classes)
// look for function definitions
if ((current == QLatin1Char('f')) && (stripped.indexOf(QLatin1String("function"), c) == c)) {
function_start = c;
c += 8;
// look for the beginning of the parameters
identifier.clear();
for (c = c; c < stripped.length(); c++) {
current = stripped.at(c);
// look for the beginning of the function definition
if ((current == QLatin1Char('(')) || (current == QLatin1Char('{'))) {
c--;
break;
}
else {
identifier += current;
}
}
// trim off whitespace
identifier = identifier.trimmed();
// if we have an anonymous function, back up to see if it's assigned to anything
if (! (identifier.length() > 0)) {
QChar ch = QLatin1Char('\0');
for (int end = function_start - 1; end >= 0; end--) {
ch = stripped.at(end);
// skip whitespace
if ((ch == QLatin1Char(' ')) || (ch == QLatin1Char('\t'))) continue;
// if we hit an assignment or object property operator,
// get the preceding identifier
if ((ch == QLatin1Char('=')) || (ch == QLatin1Char(':'))) {
end--;
while (end >= 0) {
ch = stripped.at(end);
if ((ch != QLatin1Char(' ')) && (ch != QLatin1Char('\t'))) break;
end--;
}
int start = end;
while (start >= 0) {
ch = stripped.at(start);
if (((ch >= QLatin1Char('a')) && (ch <= QLatin1Char('z'))) ||
((ch >= QLatin1Char('A')) && (ch <= QLatin1Char('Z'))) ||
((ch >= QLatin1Char('0')) && (ch <= QLatin1Char('9'))) ||
(ch == QLatin1Char('_'))) start--;
else {
start++;
break;
}
}
identifier = stripped.mid(start, (end - start) + 1);
break;
}
// if we hit something else, we're not going to be able
// to read an assignment identifier
else break;
}
}
// if we have a function identifier, make a node
if (identifier.length() > 0) {
// make a node for the function
QTreeWidgetItem *parent = nullptr;
if (! nodes.isEmpty()) {
parent = nodes.last();
}
- if ((m_plugin->treeOn) && (parent != nullptr))
+ if ((m_treeOn->isChecked()) && (parent != nullptr))
node = new QTreeWidgetItem(parent);
else
node = new QTreeWidgetItem(m_symbols);
// mark the parent as a class (if it's not the root level)
if (parent != nullptr) {
parent->setIcon(0, QIcon(cls));
// mark this function as a method of the parent
node->setIcon(0, QIcon(mtd));
}
// mark root-level functions as classes
else {
node->setIcon(0, QIcon(cls));
}
// add the function
node->setText(0, identifier);
node->setText(1, QString::number(line, 10));
if (m_plugin->expandedOn) m_symbols->expandItem(node);
}
} // (look for functions)
// look for QML id: ....
if (stripped.midRef(c, 3) == QLatin1String("id:")) {
c += 3;
identifier.clear();
// parse the id name
for (c = c; c < stripped.length(); c++) {
current = stripped.at(c);
// look for the beginning of the id
if (current == QLatin1Char(';')) {
c--;
break;
}
else {
identifier += current;
}
}
identifier = identifier.trimmed();
// if we have an id, make a node
if (identifier.length() > 0) {
QTreeWidgetItem *parent = nullptr;
if (! nodes.isEmpty()) {
parent = nodes.last();
}
- if ((m_plugin->treeOn) && (parent != nullptr))
+ if ((m_treeOn->isChecked()) && (parent != nullptr))
node = new QTreeWidgetItem(parent);
else
node = new QTreeWidgetItem(m_symbols);
// mark the node as a class
node->setIcon(0, QIcon(cls));
// add the id
node->setText(0, identifier);
node->setText(1, QString::number(line, 10));
if (m_plugin->expandedOn) m_symbols->expandItem(node);
}
}
// keep track of brace depth
if (current == QLatin1Char('{')) {
brace_depth++;
// if a node has been added at this level or above,
// use it to extend the stack
if (node != nullptr)
nodes.append(node);
// if no node has been added, extend the last node to this depth
else if (! nodes.isEmpty())
nodes.append(nodes.last());
}
else if (current == QLatin1Char('}')) {
brace_depth--;
// pop the last node off the stack
node = nullptr;
if (! nodes.isEmpty()) nodes.removeLast();
}
} // (scan the stripped line)
} // (iterate through lines of the document)
}
diff --git a/addons/symbolviewer/fortran_parser.cpp b/addons/symbolviewer/fortran_parser.cpp
index 05e4ce50d..a7da05b2c 100644
--- a/addons/symbolviewer/fortran_parser.cpp
+++ b/addons/symbolviewer/fortran_parser.cpp
@@ -1,255 +1,255 @@
/***************************************************************************
fortran_parser.cpp - description
-------------------
begin : jul 10 2005
author : 2005 Roberto Quitiliani
email : roby(dot)q(AT)tiscali(dot)it
***************************************************************************/
/***************************************************************************
* *
* 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::parseFortranSymbols(void)
{
if (!m_mainWindow->activeView())
return;
QString currline;
QString subrStr(QLatin1String("subroutine "));
QString funcStr(QLatin1String("function "));
QString modStr(QLatin1String("module "));
QString stripped;
int i;
int fnd,block=0,blockend=0,paro=0,parc=0;
bool mainprog;
QTreeWidgetItem *node = nullptr;
QTreeWidgetItem *subrNode = nullptr, *funcNode = nullptr, *modNode = nullptr;
QTreeWidgetItem *lastSubrNode = nullptr, *lastFuncNode = nullptr, *lastModNode = nullptr;
QPixmap func( ( const char** ) class_xpm );
QPixmap subr( ( const char** ) macro_xpm );
QPixmap mod( ( const char** ) struct_xpm );
//It is necessary to change names
m_macro->setText(i18n("Show Subroutines"));
m_struct->setText(i18n("Show Modules"));
m_func->setText(i18n("Show Functions"));
- if(m_plugin->treeOn)
+ if(m_treeOn->isChecked())
{
funcNode = new QTreeWidgetItem(m_symbols, QStringList(i18n("Functions") ) );
subrNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Subroutines") ) );
modNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Modules") ) );
funcNode->setIcon(0, QIcon(func));
modNode->setIcon(0, QIcon(mod));
subrNode->setIcon(0, QIcon(subr));
if (m_plugin->expandedOn)
{
m_symbols->expandItem(funcNode);
m_symbols->expandItem(subrNode);
m_symbols->expandItem(modNode);
}
lastSubrNode = subrNode;
lastFuncNode = funcNode;
lastModNode = modNode;
m_symbols->setRootIsDecorated(1);
}
else
m_symbols->setRootIsDecorated(0);
KTextEditor::Document *kDoc = m_mainWindow->activeView()->document();
for (i = 0; i < kDoc->lines(); i++)
{
currline = kDoc->line(i);
currline = currline.trimmed();
//currline = currline.simplified(); is this really needed ?
//Fortran is case insensitive
currline = currline.toLower();
bool comment = false;
//kdDebug(13000)< 0) ||
currline.startsWith(funcStr)
)
{
block=3;
stripped.clear();
}
//Subroutines
if(block==1)
{
if(currline.startsWith(QLatin1String("program ")))
mainprog=true;
if (m_macro->isChecked()) // not really a macro, but a subroutines
{
stripped += currline.right(currline.length());
stripped = stripped.simplified();
stripped.remove(QLatin1Char('*'));
stripped.remove(QLatin1Char('+'));
stripped.remove(QLatin1Char('$'));
if(blockend==0)
{
fnd = stripped.indexOf(QLatin1Char(' '));
stripped = currline.right(currline.length()-fnd-1);
}
stripped.remove(QLatin1Char(' '));
fnd = stripped.indexOf(QLatin1Char('!'));
if(fnd>0)
{
stripped = stripped.left(fnd);
}
paro+=currline.count(QLatin1Char(')'), Qt::CaseSensitive);
parc+=currline.count(QLatin1Char('('), Qt::CaseSensitive);
if((paro==parc || mainprog) && stripped.endsWith(QLatin1Char('&'), Qt::CaseInsensitive)==false)
{
stripped.remove(QLatin1Char('&'));
if(mainprog && stripped.indexOf(QLatin1Char('('))<0 && stripped.indexOf(QLatin1Char(')'))<0)
stripped.prepend(QLatin1String("Main: "));
if(stripped.indexOf(QLatin1Char('='))==-1)
{
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(subrNode, lastSubrNode);
lastSubrNode = node;
}
else
node = new QTreeWidgetItem(m_symbols);
node->setText(0, stripped);
node->setIcon(0, QIcon(subr));
node->setText(1, QString::number( i, 10));
}
stripped.clear();
block=0;
blockend=0;
paro=0;
parc=0;
}
else
{
blockend=1;
}
}
}
//Modules
else if(block==2)
{
if (m_struct->isChecked()) // not really a struct, but a module
{
stripped = currline.right(currline.length());
stripped = stripped.simplified();
fnd = stripped.indexOf(QLatin1Char(' '));
stripped = currline.right(currline.length()-fnd-1);
fnd = stripped.indexOf(QLatin1Char('!'));
if(fnd>0)
{
stripped = stripped.left(fnd);
}
if(stripped.indexOf(QLatin1Char('='))==-1)
{
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(modNode, lastModNode);
lastModNode = node;
}
else
node = new QTreeWidgetItem(m_symbols);
node->setText(0, stripped);
node->setIcon(0, QIcon(mod));
node->setText(1, QString::number( i, 10));
}
stripped.clear();
}
block=0;
blockend=0;
}
//Functions
else if(block==3)
{
if (m_func->isChecked())
{
stripped += currline.right(currline.length());
stripped = stripped.trimmed();
stripped.remove( QLatin1String("function") );
stripped.remove(QLatin1Char('*'));
stripped.remove(QLatin1Char('+'));
stripped.remove(QLatin1Char('$'));
stripped = stripped.simplified();
fnd = stripped.indexOf(QLatin1Char('!'));
if(fnd>0)
{
stripped = stripped.left(fnd);
}
stripped = stripped.trimmed();
paro+=currline.count(QLatin1Char(')'), Qt::CaseSensitive);
parc+=currline.count(QLatin1Char('('), Qt::CaseSensitive);
if(paro==parc && stripped.endsWith(QLatin1Char('&'))==false)
{
stripped.remove(QLatin1Char('&'));
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(funcNode, lastFuncNode);
lastFuncNode = node;
}
else
node = new QTreeWidgetItem(m_symbols);
node->setText(0, stripped);
node->setIcon(0, QIcon(func));
node->setText(1, QString::number( i, 10));
stripped.clear();
block=0;
paro=0;
parc=0;
}
blockend=0;
}
}
}
} //for i loop
}
diff --git a/addons/symbolviewer/perl_parser.cpp b/addons/symbolviewer/perl_parser.cpp
index 67fdd8786..e425df775 100644
--- a/addons/symbolviewer/perl_parser.cpp
+++ b/addons/symbolviewer/perl_parser.cpp
@@ -1,142 +1,142 @@
/***************************************************************************
perl_parser.cpp - description
-------------------
begin : Apr 2 2003
author : 2003 Massimo Callegari
email : massimocallegari@yahoo.it
***************************************************************************/
/***************************************************************************
* *
* 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::parsePerlSymbols(void)
{
if (!m_mainWindow->activeView())
return;
m_macro->setText(i18n("Show Uses"));
m_struct->setText(i18n("Show Pragmas"));
m_func->setText(i18n("Show Subroutines"));
QString cl; // Current Line
QString stripped;
char comment = 0;
QPixmap cls( ( const char** ) class_xpm );
QPixmap sct( ( const char** ) struct_xpm );
QPixmap mcr( ( const char** ) macro_xpm );
QPixmap cls_int( ( const char** ) class_int_xpm );
QTreeWidgetItem *node = nullptr;
QTreeWidgetItem *mcrNode = nullptr, *sctNode = nullptr, *clsNode = nullptr;
QTreeWidgetItem *lastMcrNode = nullptr, *lastSctNode = nullptr, *lastClsNode = nullptr;
KTextEditor::Document *kv = m_mainWindow->activeView()->document();
//kdDebug(13000)<<"Lines counted :"<numLines()<treeOn)
+ if(m_treeOn->isChecked())
{
mcrNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Uses") ) );
sctNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Pragmas") ) );
clsNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Subroutines") ) );
mcrNode->setIcon(0, QIcon(mcr));
sctNode->setIcon(0, QIcon(sct));
clsNode->setIcon(0, QIcon(cls));
if (m_plugin->expandedOn)
{
m_symbols->expandItem(mcrNode);
m_symbols->expandItem(sctNode);
m_symbols->expandItem(clsNode);
}
lastMcrNode = mcrNode;
lastSctNode = sctNode;
lastClsNode = clsNode;
m_symbols->setRootIsDecorated(1);
}
else
m_symbols->setRootIsDecorated(0);
for (int i=0; ilines(); i++)
{
cl = kv->line(i);
//qDebug()<< "Line " << i << " : "<< cl;
if(cl.isEmpty() || cl.at(0) == QLatin1Char('#')) continue;
if(cl.indexOf(QRegExp(QLatin1String("^=[a-zA-Z]"))) >= 0) comment = 1;
if(cl.indexOf(QRegExp(QLatin1String("^=cut$"))) >= 0)
{
comment = 0;
continue;
}
if (comment==1)
continue;
cl = cl.trimmed();
//qDebug()<<"Trimmed line " << i << " : "<< cl;
if(cl.indexOf(QRegExp(QLatin1String("^use +[A-Z]"))) == 0 && m_macro->isChecked())
{
QString stripped=cl.remove( QRegExp(QLatin1String("^use +")) );
//stripped=stripped.replace( QRegExp(QLatin1String(";$")), "" ); // Doesn't work ??
stripped = stripped.left(stripped.indexOf(QLatin1Char(';')));
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(mcrNode, lastMcrNode);
lastMcrNode = node;
}
else
node = new QTreeWidgetItem(m_symbols);
node->setText(0, stripped);
node->setIcon(0, QIcon(mcr));
node->setText(1, QString::number( i, 10));
}
#if 1
if(cl.indexOf(QRegExp(QLatin1String("^use +[a-z]"))) == 0 && m_struct->isChecked())
{
QString stripped=cl.remove( QRegExp(QLatin1String("^use +")) );
stripped=stripped.remove( QRegExp(QLatin1String(";$")) );
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(sctNode, lastSctNode);
lastMcrNode = node;
}
else
node = new QTreeWidgetItem(m_symbols);
node->setText(0, stripped);
node->setIcon(0, QIcon(sct));
node->setText(1, QString::number( i, 10));
}
#endif
#if 1
if(cl.indexOf(QRegExp(QLatin1String("^sub +")))==0 && m_func->isChecked())
{
QString stripped=cl.remove( QRegExp(QLatin1String("^sub +")) );
stripped=stripped.remove( QRegExp(QLatin1String("[{;] *$")) );
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(clsNode, lastClsNode);
lastClsNode = node;
}
else
node = new QTreeWidgetItem(m_symbols);
node->setText(0, stripped);
if (!stripped.isEmpty() && stripped.at(0)==QLatin1Char('_'))
node->setIcon(0, QIcon(cls_int));
else
node->setIcon(0, QIcon(cls));
node->setText(1, QString::number( i, 10));
}
#endif
}
}
diff --git a/addons/symbolviewer/php_parser.cpp b/addons/symbolviewer/php_parser.cpp
index 9cd68013d..2ec2ebafa 100644
--- a/addons/symbolviewer/php_parser.cpp
+++ b/addons/symbolviewer/php_parser.cpp
@@ -1,335 +1,335 @@
/***************************************************************************
php_parser.cpp - description
-------------------
begin : Apr 1st 2007
last update : Sep 14th 2010
author(s) : 2007, Massimo Callegari
: 2010, Emmanuel Bouthenot
***************************************************************************/
/***************************************************************************
* *
* 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::parsePhpSymbols(void)
{
if (m_mainWindow->activeView())
{
QString line, lineWithliterals;
QPixmap namespacePix( ( const char** ) class_int_xpm );
QPixmap definePix( ( const char** ) macro_xpm );
QPixmap varPix( ( const char** ) struct_xpm );
QPixmap classPix( ( const char** ) class_xpm );
QPixmap constPix( ( const char** ) macro_xpm );
QPixmap functionPix( ( const char** ) method_xpm );
QTreeWidgetItem *node = nullptr;
QTreeWidgetItem *namespaceNode = nullptr, *defineNode = nullptr, \
*classNode = nullptr, *functionNode = nullptr;
QTreeWidgetItem *lastNamespaceNode = nullptr, *lastDefineNode = nullptr, \
*lastClassNode = nullptr, *lastFunctionNode = nullptr;
KTextEditor::Document *kv = m_mainWindow->activeView()->document();
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
namespaceNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Namespaces") ) );
defineNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Defines") ) );
classNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Classes") ) );
functionNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Functions") ) );
namespaceNode->setIcon(0, QIcon( namespacePix ) );
defineNode->setIcon(0, QIcon( definePix ) );
classNode->setIcon(0, QIcon( classPix ) );
functionNode->setIcon(0, QIcon( functionPix ) );
if (m_plugin->expandedOn)
{
m_symbols->expandItem(namespaceNode);
m_symbols->expandItem(defineNode);
m_symbols->expandItem(classNode);
m_symbols->expandItem(functionNode);
}
lastNamespaceNode = namespaceNode;
lastDefineNode = defineNode;
lastClassNode = classNode;
lastFunctionNode = functionNode;
m_symbols->setRootIsDecorated(1);
}
else
{
m_symbols->setRootIsDecorated(0);
}
// Namespaces: http://www.php.net/manual/en/language.namespaces.php
QRegExp namespaceRegExp(QLatin1String("^namespace\\s+([^;\\s]+)"), Qt::CaseInsensitive);
// defines: http://www.php.net/manual/en/function.define.php
QRegExp defineRegExp(QLatin1String("(^|\\W)define\\s*\\(\\s*['\"]([^'\"]+)['\"]"), Qt::CaseInsensitive);
// classes: http://www.php.net/manual/en/language.oop5.php
QRegExp classRegExp(QLatin1String("^((abstract\\s+|final\\s+)?)class\\s+([\\w_][\\w\\d_]*)\\s*(implements\\s+[\\w\\d_]*)?"), Qt::CaseInsensitive);
// interfaces: http://www.php.net/manual/en/language.oop5.php
QRegExp interfaceRegExp(QLatin1String("^interface\\s+([\\w_][\\w\\d_]*)"), Qt::CaseInsensitive);
// classes constants: http://www.php.net/manual/en/language.oop5.constants.php
QRegExp constantRegExp(QLatin1String("^const\\s+([\\w_][\\w\\d_]*)"), Qt::CaseInsensitive);
// functions: http://www.php.net/manual/en/language.oop5.constants.php
QRegExp functionRegExp(QLatin1String("^((public|protected|private)?(\\s*static)?\\s+)?function\\s+&?\\s*([\\w_][\\w\\d_]*)\\s*(.*)$"), Qt::CaseInsensitive);
// variables: http://www.php.net/manual/en/language.oop5.properties.php
QRegExp varRegExp(QLatin1String("^((var|public|protected|private)?(\\s*static)?\\s+)?\\$([\\w_][\\w\\d_]*)"), Qt::CaseInsensitive);
// function args detection: “function a($b, $c=null)” => “$b, $v”
QRegExp functionArgsRegExp(QLatin1String("(\\$[\\w_]+)"), Qt::CaseInsensitive);
QStringList functionArgsList;
QString functionArgs;
QString nameWithTypes;
// replace literals by empty strings: “function a($b='nothing', $c="pretty \"cool\" string")” => “function ($b='', $c="")”
QRegExp literalRegExp(QLatin1String("([\"'])(?:\\\\.|[^\\\\])*\\1"));
literalRegExp.setMinimal(true);
// remove useless comments: “public/* static */ function a($b, $c=null) /* test */” => “public function a($b, $c=null)”
QRegExp blockCommentInline(QLatin1String("/\\*.*\\*/"));
blockCommentInline.setMinimal(true);
int i, pos;
bool isClass, isInterface;
bool inBlockComment = false;
bool inClass = false, inFunction = false;
//QString debugBuffer("SymbolViewer(PHP), line %1 %2 → [%3]");
for (i=0; ilines(); i++)
{
//kdDebug(13000) << debugBuffer.arg(i, 4).arg("=origin", 10).arg(kv->line(i));
line = kv->line(i).simplified();
//kdDebug(13000) << debugBuffer.arg(i, 4).arg("+simplified", 10).arg(line);
// keeping a copy with literals for catching “defines()”
lineWithliterals = line;
// reduce literals to empty strings to not match comments separators in literals
line.replace(literalRegExp, QLatin1String("\\1\\1"));
//kdDebug(13000) << debugBuffer.arg(i, 4).arg("-literals", 10).arg(line);
line.remove(blockCommentInline);
//kdDebug(13000) << debugBuffer.arg(i, 4).arg("-comments", 10).arg(line);
// trying to find comments and to remove commented parts
pos = line.indexOf(QLatin1Char('#'));
if (pos >= 0)
{
line = line.left(pos);
}
pos = line.indexOf(QLatin1String("//"));
if (pos >= 0)
{
line = line.left(pos);
}
pos = line.indexOf(QLatin1String("/*"));
if (pos >= 0)
{
line = line.left(pos);
inBlockComment = true;
}
pos = line.indexOf(QLatin1String("*/"));
if (pos >= 0)
{
line = line.right(line.length() - pos - 2);
inBlockComment = false;
}
if (inBlockComment)
{
continue;
}
// trimming again after having removed the comments
line = line.simplified();
//kdDebug(13000) << debugBuffer.arg(i, 4).arg("+simplified", 10).arg(line);
// detect NameSpaces
if (namespaceRegExp.indexIn(line) != -1)
{
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(namespaceNode, lastNamespaceNode);
if (m_plugin->expandedOn)
{
m_symbols->expandItem(node);
}
lastNamespaceNode = node;
}
else
{
node = new QTreeWidgetItem(m_symbols);
}
node->setText(0, namespaceRegExp.cap(1));
node->setIcon(0, QIcon(namespacePix));
node->setText(1, QString::number( i, 10));
}
// detect defines
if (defineRegExp.indexIn(lineWithliterals) != -1)
{
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(defineNode, lastDefineNode);
lastDefineNode = node;
}
else
{
node = new QTreeWidgetItem(m_symbols);
}
node->setText(0, defineRegExp.cap(2));
node->setIcon(0, QIcon(definePix));
node->setText(1, QString::number( i, 10));
}
// detect classes, interfaces
isClass = classRegExp.indexIn(line) != -1;
isInterface = interfaceRegExp.indexIn(line) != -1;
if (isClass || isInterface)
{
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(classNode, lastClassNode);
if (m_plugin->expandedOn)
{
m_symbols->expandItem(node);
}
lastClassNode = node;
}
else
{
node = new QTreeWidgetItem(m_symbols);
}
if (isClass)
{
if (m_plugin->typesOn) {
if (!classRegExp.cap(1).trimmed().isEmpty() && !classRegExp.cap(4).trimmed().isEmpty())
{
nameWithTypes = classRegExp.cap(3)+QLatin1String(" [")+classRegExp.cap(1).trimmed()+QLatin1Char(',')+classRegExp.cap(4).trimmed()+QLatin1Char(']');
}
else if (!classRegExp.cap(1).trimmed().isEmpty())
{
nameWithTypes = classRegExp.cap(3)+QLatin1String(" [")+classRegExp.cap(1).trimmed()+QLatin1Char(']');
}
else if (!classRegExp.cap(4).trimmed().isEmpty())
{
nameWithTypes = classRegExp.cap(3)+QLatin1String(" [")+classRegExp.cap(4).trimmed()+QLatin1Char(']');
}
node->setText(0, nameWithTypes);
}
else
{
node->setText(0, classRegExp.cap(3));
}
}
else
{
if (m_plugin->typesOn)
{
nameWithTypes = interfaceRegExp.cap(1) + QLatin1String(" [interface]");
node->setText(0, nameWithTypes);
}
else
{
node->setText(0, interfaceRegExp.cap(1));
}
}
node->setIcon(0, QIcon(classPix));
node->setText(1, QString::number( i, 10));
node->setToolTip(0, nameWithTypes);
inClass = true;
inFunction = false;
}
// detect class constants
if (constantRegExp.indexIn(line) != -1)
{
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(lastClassNode);
}
else
{
node = new QTreeWidgetItem(m_symbols);
}
node->setText(0, constantRegExp.cap(1));
node->setIcon(0, QIcon(constPix));
node->setText(1, QString::number( i, 10));
}
// detect class variables
if (inClass && !inFunction)
{
if (varRegExp.indexIn(line) != -1)
{
- if (m_plugin->treeOn && inClass)
+ if (m_treeOn->isChecked() && inClass)
{
node = new QTreeWidgetItem(lastClassNode);
}
else
{
node = new QTreeWidgetItem(m_symbols);
}
node->setText(0, varRegExp.cap(4));
node->setIcon(0, QIcon(varPix));
node->setText(1, QString::number( i, 10));
}
}
// detect functions
if (functionRegExp.indexIn(line) != -1)
{
- if (m_plugin->treeOn && inClass)
+ if (m_treeOn->isChecked() && inClass)
{
node = new QTreeWidgetItem(lastClassNode);
}
- else if (m_plugin->treeOn)
+ else if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(lastFunctionNode);
}
else
{
node = new QTreeWidgetItem(m_symbols);
}
QString functionArgs(functionRegExp.cap(5));
pos = 0;
while (pos >= 0) {
pos = functionArgsRegExp.indexIn(functionArgs, pos);
if (pos >= 0) {
pos += functionArgsRegExp.matchedLength();
functionArgsList += functionArgsRegExp.cap(1);
}
}
nameWithTypes = functionRegExp.cap(4) + QLatin1Char('(') + functionArgsList.join(QLatin1String(", ")) + QLatin1Char(')');
if (m_plugin->typesOn)
{
node->setText(0, nameWithTypes);
}
else
{
node->setText(0, functionRegExp.cap(4));
}
node->setIcon(0, QIcon(functionPix));
node->setText(1, QString::number( i, 10));
node->setToolTip(0, nameWithTypes);
functionArgsList.clear();
inFunction = true;
}
}
}
}
diff --git a/addons/symbolviewer/plugin_katesymbolviewer.cpp b/addons/symbolviewer/plugin_katesymbolviewer.cpp
index 4b73b4a75..ef78ae3c4 100644
--- a/addons/symbolviewer/plugin_katesymbolviewer.cpp
+++ b/addons/symbolviewer/plugin_katesymbolviewer.cpp
@@ -1,463 +1,455 @@
/***************************************************************************
* plugin_katesymbolviewer.cpp - description
* -------------------
* Copyright (C) 2014 by Kåre Särs
*
* begin : Apr 2 2003
* author : 2003 Massimo Callegari
* email : massimocallegari@yahoo.it
*
* Changes:
* Nov 09 2004 v.1.3 - For changelog please refer to KDE CVS
* Nov 05 2004 v.1.2 - Choose parser from the current highlight. Minor i18n changes.
* Nov 28 2003 v.1.1 - Structured for multilanguage support
* Added preliminary Tcl/Tk parser (thanks Rohit). To be improved.
* Various bugfixing.
* Jun 19 2003 v.1.0 - Removed QTimer (polling is Evil(tm)... )
* - Captured documentChanged() event to refresh symbol list
* - Tooltips vanished into nowhere...sigh :(
* May 04 2003 v 0.6 - Symbol List becomes a K3ListView object. Removed Tooltip class.
* Added a QTimer that every 200ms checks:
* * if the list width has changed
* * if the document has changed
* Added an entry in the m_popup menu to switch between List and Tree mode
* Various bugfixing.
* Apr 24 2003 v 0.5 - Added three check buttons in m_popup menu to show/hide symbols
* Apr 23 2003 v 0.4 - "View Symbol" moved in Settings menu. "Refresh List" is no
* longer in Kate menu. Moved into a m_popup menu activated by a
* mouse right button click. + Bugfixing.
* Apr 22 2003 v 0.3 - Added macro extraction + several bugfixing
* Apr 19 2003 v 0.2 - Added to CVS. Extract functions and structures
* Apr 07 2003 v 0.1 - First version.
*
***************************************************************************/
/***************************************************************************
* *
* 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"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
K_PLUGIN_FACTORY_WITH_JSON (KatePluginSymbolViewerFactory, "katesymbolviewerplugin.json", registerPlugin();)
KatePluginSymbolViewerView::KatePluginSymbolViewerView(KatePluginSymbolViewer *plugin, KTextEditor::MainWindow *mw)
:QObject(mw)
,m_mainWindow(mw)
,m_plugin(plugin)
{
// FIXME KF5 KGlobal::locale()->insertCatalog("katesymbolviewerplugin");
KXMLGUIClient::setComponentName (QLatin1String("katesymbolviewer"), i18n ("SymbolViewer"));
setXMLFile(QLatin1String("ui.rc"));
mw->guiFactory()->addClient (this);
m_symbols = nullptr;
m_popup = new QMenu(m_symbols);
m_treeOn = m_popup->addAction(i18n("Tree Mode"), this, SLOT(slotChangeMode()));
m_treeOn->setCheckable(true);
m_sort = m_popup->addAction(i18n("Show Sorted"), this, SLOT(slotEnableSorting()));
m_sort->setCheckable(true);
m_popup->addSeparator();
m_macro = m_popup->addAction(i18n("Show Macros"), this, SLOT(toggleShowMacros()));
m_macro->setCheckable(true);
m_struct = m_popup->addAction(i18n("Show Structures"), this, SLOT(toggleShowStructures()));
m_struct->setCheckable(true);
m_func = m_popup->addAction(i18n("Show Functions"), this, SLOT(toggleShowFunctions()));
m_func->setCheckable(true);
KConfigGroup config(KSharedConfig::openConfig(), "PluginSymbolViewer");
m_plugin->typesOn = config.readEntry(QLatin1String("ViewTypes"), false);
m_plugin->expandedOn = config.readEntry(QLatin1String("ExpandTree"), false);
- m_plugin->treeOn = config.readEntry(QLatin1String("TreeView"), false);
- m_plugin->sortOn = config.readEntry(QLatin1String("SortSymbols"), false);
+ m_treeOn->setChecked(config.readEntry(QLatin1String("TreeView"), false));
+ m_sort->setChecked(config.readEntry(QLatin1String("SortSymbols"), false));
m_macro->setChecked(true);
m_struct->setChecked(true);
m_func->setChecked(true);
- m_treeOn->setChecked(m_plugin->treeOn);
- m_sort->setChecked(m_plugin->sortOn);
m_updateTimer.setSingleShot(true);
connect(&m_updateTimer, &QTimer::timeout, this, &KatePluginSymbolViewerView::slotRefreshSymbol);
m_currItemTimer.setSingleShot(true);
connect(&m_currItemTimer, &QTimer::timeout, this, &KatePluginSymbolViewerView::updateCurrTreeItem);
QPixmap cls( ( const char** ) class_xpm );
m_toolview = m_mainWindow->createToolView(plugin, QLatin1String("kate_plugin_symbolviewer"),
KTextEditor::MainWindow::Left,
cls,
i18n("Symbol List"));
QWidget *container = new QWidget(m_toolview);
QHBoxLayout *layout = new QHBoxLayout(container);
m_symbols = new QTreeWidget();
m_symbols->setFocusPolicy(Qt::NoFocus);
m_symbols->setLayoutDirection( Qt::LeftToRight );
layout->addWidget(m_symbols, 10);
layout->setContentsMargins(0,0,0,0);
connect(m_symbols, &QTreeWidget::itemClicked, this, &KatePluginSymbolViewerView::goToSymbol);
connect(m_symbols, &QTreeWidget::customContextMenuRequested, this, &KatePluginSymbolViewerView::slotShowContextMenu);
connect(m_mainWindow, &KTextEditor::MainWindow::viewChanged, this, &KatePluginSymbolViewerView::slotDocChanged);
QStringList titles;
titles << i18nc("@title:column", "Symbols") << i18nc("@title:column", "Position");
m_symbols->setColumnCount(2);
m_symbols->setHeaderLabels(titles);
m_symbols->setColumnHidden(1, true);
- m_symbols->setSortingEnabled(m_plugin->sortOn);
+ m_symbols->setSortingEnabled(m_sort->isChecked());
m_symbols->setRootIsDecorated(0);
m_symbols->setContextMenuPolicy(Qt::CustomContextMenu);
m_symbols->setIndentation(10);
m_toolview->installEventFilter(this);
}
KatePluginSymbolViewerView::~KatePluginSymbolViewerView()
{
m_mainWindow->guiFactory()->removeClient (this);
delete m_toolview;
delete m_popup;
}
void KatePluginSymbolViewerView::toggleShowMacros(void)
{
slotRefreshSymbol();
}
void KatePluginSymbolViewerView::toggleShowStructures(void)
{
slotRefreshSymbol();
}
void KatePluginSymbolViewerView::toggleShowFunctions(void)
{
slotRefreshSymbol();
}
void KatePluginSymbolViewerView::slotRefreshSymbol()
{
parseSymbols();
}
void KatePluginSymbolViewerView::slotChangeMode()
{
- m_plugin->treeOn = m_treeOn->isChecked();
parseSymbols();
}
void KatePluginSymbolViewerView::slotEnableSorting()
{
- m_plugin->sortOn = m_sort->isChecked();
- m_symbols->setSortingEnabled(m_sort->isChecked());
-
parseSymbols();
}
void KatePluginSymbolViewerView::slotDocChanged()
{
slotRefreshSymbol();
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);
}
}
}
void KatePluginSymbolViewerView::slotDocEdited()
{
m_currItemTimer.stop(); // Avoid unneeded update
m_updateTimer.start(500);
}
void KatePluginSymbolViewerView::cursorPositionChanged()
{
if (m_updateTimer.isActive()) {
// No need for update, will come anyway
return;
}
m_currItemTimer.start(100);
}
void KatePluginSymbolViewerView::updateCurrTreeItem()
{
if (!m_mainWindow) {
return;
}
KTextEditor::View* editView = m_mainWindow->activeView();
if (!editView) {
return;
}
KTextEditor::Document* doc = editView->document();
if (!doc) {
return;
}
int currLine = editView->cursorPositionVirtual().line();
if (currLine == m_oldCursorLine) {
// Nothing to do
return;
}
m_oldCursorLine = currLine;
int newItemLine = 0;
QTreeWidgetItem *newItem = nullptr;
QTreeWidgetItem *tmp = nullptr;
for (int i=0; itopLevelItemCount(); i++) {
tmp = newActveItem(newItemLine, currLine, m_symbols->topLevelItem(i));
if (tmp) newItem = tmp;
}
if (newItem) {
m_symbols->blockSignals(true);
m_symbols->setCurrentItem(newItem);
m_symbols->blockSignals(false);
}
}
QTreeWidgetItem *KatePluginSymbolViewerView::newActveItem(int &newItemLine, int currLine, QTreeWidgetItem *item)
{
QTreeWidgetItem *newItem = nullptr;
QTreeWidgetItem *tmp = nullptr;
int itemLine = item->data(1, Qt::DisplayRole).toInt();
if ((itemLine <= currLine) && (itemLine >= newItemLine)) {
newItemLine = itemLine;
newItem = item;
}
for (int i=0; ichildCount(); i++) {
tmp = newActveItem(newItemLine, currLine, item->child(i));
if (tmp) newItem = tmp;
}
return newItem;
}
bool KatePluginSymbolViewerView::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent *ke = static_cast(event);
if ((obj == m_toolview) && (ke->key() == Qt::Key_Escape)) {
m_mainWindow->activeView()->setFocus();
event->accept();
return true;
}
}
return QObject::eventFilter(obj, event);
}
void KatePluginSymbolViewerView::slotShowContextMenu(const QPoint&)
{
m_popup->popup(QCursor::pos(), m_treeOn);
}
void KatePluginSymbolViewerView::parseSymbols(void)
{
if (!m_symbols)
return;
m_symbols->clear();
// Qt docu recommends to populate view with disabled sorting
// https://doc.qt.io/qt-5/qtreeview.html#sortingEnabled-prop
m_symbols->setSortingEnabled(false);
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"))
parseCppSymbols();
else if (hlModeName == QLatin1String("PHP (HTML)"))
parsePhpSymbols();
else if (hlModeName == QLatin1String("Tcl/Tk"))
parseTclSymbols();
else if (hlModeName == QLatin1String("Fortran"))
parseFortranSymbols();
else if (hlModeName == QLatin1String("Perl"))
parsePerlSymbols();
else if (hlModeName == QLatin1String("Python"))
parsePythonSymbols();
else if (hlModeName == QLatin1String("Ruby"))
parseRubySymbols();
else if (hlModeName == QLatin1String("Java"))
parseCppSymbols();
else if (hlModeName == QLatin1String("xslt"))
parseXsltSymbols();
else if (hlModeName == QLatin1String("Bash"))
parseBashSymbols();
else if (hlModeName == QLatin1String("ActionScript 2.0") ||
hlModeName == QLatin1String("JavaScript") ||
hlModeName == QLatin1String("QML"))
parseEcmaSymbols();
else
new QTreeWidgetItem(m_symbols, QStringList(i18n("Sorry. Language not supported yet") ) );
m_oldCursorLine = -1;
updateCurrTreeItem();
if (m_sort->isChecked())
m_symbols->sortItems(0, Qt::AscendingOrder);
}
void KatePluginSymbolViewerView::goToSymbol(QTreeWidgetItem *it)
{
KTextEditor::View *kv = m_mainWindow->activeView();
// be sure we really have a view !
if (!kv)
return;
//qDebug()<<"Slot Activated at pos: "<indexOfTopLevelItem(it);
kv->setCursorPosition (KTextEditor::Cursor (it->text(1).toInt(nullptr, 10), 0));
}
KatePluginSymbolViewer::KatePluginSymbolViewer( QObject* parent, const QList& )
: KTextEditor::Plugin (parent)
{
//qDebug()<<"KatePluginSymbolViewer";
}
KatePluginSymbolViewer::~KatePluginSymbolViewer()
{
//qDebug()<<"~KatePluginSymbolViewer";
}
QObject *KatePluginSymbolViewer::createView (KTextEditor::MainWindow *mainWindow)
{
m_view = new KatePluginSymbolViewerView (this, mainWindow);
return m_view;
}
KTextEditor::ConfigPage* KatePluginSymbolViewer::configPage(int, QWidget *parent)
{
KatePluginSymbolViewerConfigPage* p = new KatePluginSymbolViewerConfigPage(this, parent);
KConfigGroup config(KSharedConfig::openConfig(), QStringLiteral("PluginSymbolViewer"));
p->viewReturns->setChecked(config.readEntry(QLatin1String("ViewTypes"), false));
p->expandTree->setChecked(config.readEntry(QLatin1String("ExpandTree"), false));
p->treeView->setChecked(config.readEntry(QLatin1String("TreeView"), false));
p->sortSymbols->setChecked(config.readEntry(QLatin1String("SortSymbols"), false));
connect(p, &KatePluginSymbolViewerConfigPage::configPageApplyRequest, this, &KatePluginSymbolViewer::applyConfig);
return (KTextEditor::ConfigPage*)p;
}
void KatePluginSymbolViewer::applyConfig( KatePluginSymbolViewerConfigPage* p )
{
KConfigGroup config(KSharedConfig::openConfig(), QStringLiteral("PluginSymbolViewer"));
config.writeEntry(QLatin1String("ViewTypes"), p->viewReturns->isChecked());
config.writeEntry(QLatin1String("ExpandTree"), p->expandTree->isChecked());
config.writeEntry(QLatin1String("TreeView"), p->treeView->isChecked());
config.writeEntry(QLatin1String("SortSymbols"), p->sortSymbols->isChecked());
typesOn = p->viewReturns->isChecked();
expandedOn = p->expandTree->isChecked();
- treeOn = p->treeView->isChecked();
- sortOn = p->sortSymbols->isChecked();
if (m_view) {
- m_view->m_treeOn->setChecked(treeOn);
- m_view->m_sort->setChecked(sortOn);
+ m_view->m_treeOn->setChecked(p->treeView->isChecked());
+ m_view->m_sort->setChecked(p->sortSymbols->isChecked());
}
}
// BEGIN KatePluginSymbolViewerConfigPage
KatePluginSymbolViewerConfigPage::KatePluginSymbolViewerConfigPage(
QObject* /*parent*/ /*= 0L*/, QWidget *parentWidget /*= 0L*/)
: KTextEditor::ConfigPage( parentWidget )
{
QVBoxLayout *lo = new QVBoxLayout( this );
//int spacing = KDialog::spacingHint();
//lo->setSpacing( spacing );
viewReturns = new QCheckBox(i18n("Display functions parameters"));
expandTree = new QCheckBox(i18n("Automatically expand nodes in tree mode"));
treeView = new QCheckBox(i18n("Always display symbols in tree mode"));
sortSymbols = new QCheckBox(i18n("Always sort symbols"));
QGroupBox* parserGBox = new QGroupBox( i18n("Parser Options"), this);
QVBoxLayout* top = new QVBoxLayout(parserGBox);
top->addWidget(viewReturns);
top->addWidget(expandTree);
top->addWidget(treeView);
top->addWidget(sortSymbols);
//QGroupBox* generalGBox = new QGroupBox( i18n("General Options"), this);
//QVBoxLayout* genLay = new QVBoxLayout(generalGBox);
//genLay->addWidget( );
lo->addWidget( parserGBox );
//lo->addWidget( generalGBox );
lo->addStretch( 1 );
// throw signal changed
connect(viewReturns, &QCheckBox::toggled, this, &KatePluginSymbolViewerConfigPage::changed);
connect(expandTree, &QCheckBox::toggled, this, &KatePluginSymbolViewerConfigPage::changed);
connect(treeView, &QCheckBox::toggled, this, &KatePluginSymbolViewerConfigPage::changed);
connect(sortSymbols, &QCheckBox::toggled, this, &KatePluginSymbolViewerConfigPage::changed);
}
KatePluginSymbolViewerConfigPage::~KatePluginSymbolViewerConfigPage() {}
QString KatePluginSymbolViewerConfigPage::name() const { return i18n("Symbol Viewer"); }
QString KatePluginSymbolViewerConfigPage::fullName() const { return i18n("Symbol Viewer Configuration Page"); }
QIcon KatePluginSymbolViewerConfigPage::icon() const { return QPixmap(( const char** ) class_xpm ); }
void KatePluginSymbolViewerConfigPage::apply()
{
emit configPageApplyRequest( this );
}
// END KatePluginSymbolViewerConfigPage
#include "plugin_katesymbolviewer.moc"
// kate: space-indent on; indent-width 2; replace-tabs on;
diff --git a/addons/symbolviewer/plugin_katesymbolviewer.h b/addons/symbolviewer/plugin_katesymbolviewer.h
index 4801c7ad0..b4b6dab23 100644
--- a/addons/symbolviewer/plugin_katesymbolviewer.h
+++ b/addons/symbolviewer/plugin_katesymbolviewer.h
@@ -1,321 +1,319 @@
/***************************************************************************
plugin_katesymbolviewer.h - description
-------------------
begin : Apr 2 2003
author : 2003 Massimo Callegari
email : massimocallegari@yahoo.it
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef _PLUGIN_KATE_SYMBOLVIEWER_H_
#define _PLUGIN_KATE_SYMBOLVIEWER_H_
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
/**
* Plugin's config page
*/
class KatePluginSymbolViewerConfigPage : public KTextEditor::ConfigPage
{
Q_OBJECT
friend class KatePluginSymbolViewer;
public:
explicit KatePluginSymbolViewerConfigPage (QObject* parent = nullptr, QWidget *parentWidget = nullptr);
~KatePluginSymbolViewerConfigPage () override;
/**
* Reimplemented from KTextEditor::ConfigPage
* just emits configPageApplyRequest( this ).
*/
QString name() const override;
QString fullName() const override;
QIcon icon() const override;
void apply() override;
void reset () override { ; }
void defaults () override { ; }
Q_SIGNALS:
/**
* Ask the plugin to set initial values
*/
void configPageApplyRequest( KatePluginSymbolViewerConfigPage* );
/**
* Ask the plugin to apply changes
*/
void configPageInitRequest( KatePluginSymbolViewerConfigPage* );
private:
QCheckBox* viewReturns;
QCheckBox* expandTree;
QCheckBox* treeView;
QCheckBox* sortSymbols;
};
class KatePluginSymbolViewer;
class KatePluginSymbolViewerView : public QObject, public KXMLGUIClient
{
Q_OBJECT
friend class KatePluginSymbolViewer;
public:
KatePluginSymbolViewerView (KatePluginSymbolViewer *plugin, KTextEditor::MainWindow *mw);
~KatePluginSymbolViewerView () override;
void parseSymbols(void);
public Q_SLOTS:
void slotRefreshSymbol();
void slotChangeMode();
void slotEnableSorting();
void slotDocChanged();
void goToSymbol(QTreeWidgetItem *);
void slotShowContextMenu(const QPoint&);
void toggleShowMacros(void);
void toggleShowStructures(void);
void toggleShowFunctions(void);
void cursorPositionChanged();
QTreeWidgetItem *newActveItem(int &currMinLine, int currLine, QTreeWidgetItem *item);
void updateCurrTreeItem();
void slotDocEdited();
protected:
bool eventFilter(QObject *obj, QEvent *ev) override;
private:
KTextEditor::MainWindow *m_mainWindow;
KatePluginSymbolViewer *m_plugin;
QMenu *m_popup;
QWidget *m_toolview;
QTreeWidget *m_symbols;
QAction *m_treeOn; // FIXME Rename other actions accordingly
QAction *m_sort; // m_sortOn etc
QAction *m_macro;
QAction *m_struct;
QAction *m_func;
QTimer m_updateTimer;
QTimer m_currItemTimer;
int m_oldCursorLine;
void updatePixmapScroll();
void parseCppSymbols(void);
void parseTclSymbols(void);
void parseFortranSymbols(void);
void parsePerlSymbols(void);
void parsePythonSymbols(void);
void parseRubySymbols(void);
void parseXsltSymbols(void);
void parsePhpSymbols(void);
void parseBashSymbols(void);
void parseEcmaSymbols(void);
};
class KatePluginSymbolViewer : public KTextEditor::Plugin
{
Q_OBJECT
public:
explicit KatePluginSymbolViewer(QObject* parent = nullptr, const QList& = QList());
~KatePluginSymbolViewer() override;
QObject *createView (KTextEditor::MainWindow *mainWindow) override;
int configPages () const override { return 1; }
KTextEditor::ConfigPage *configPage (int number = 0, QWidget *parent = nullptr) override;
public Q_SLOTS:
void applyConfig( KatePluginSymbolViewerConfigPage* p );
public:
bool typesOn;
bool expandedOn;
- bool treeOn;
- bool sortOn;
private:
KatePluginSymbolViewerView* m_view = nullptr;
};
/* XPM */
static const char* const class_xpm[] = {
"16 16 10 1",
" c None",
". c #000000",
"+ c #A4E8FC",
"@ c #24D0FC",
"# c #001CD0",
"$ c #0080E8",
"% c #C0FFFF",
"& c #00FFFF",
"* c #008080",
"= c #00C0C0",
" .. ",
" .++.. ",
" .+++@@. ",
" .@@@@@#... ",
" .$$@@##.%%.. ",
" .$$$##.%%%&&. ",
" .$$$#.&&&&&*. ",
" ...#.==&&**. ",
" .++..===***. ",
" .+++@@.==**. ",
" .@@@@@#..=*. ",
" .$$@@##. .. ",
" .$$$###. ",
" .$$$##. ",
" ..$#. ",
" .. "};
static const char * const class_int_xpm[] = {
"16 16 10 1",
" c None",
". c #000000",
"+ c #B8B8B8",
"@ c #8A8A8A",
"# c #212121",
"$ c #575757",
"% c #CCCCCC",
"& c #9A9A9A",
"* c #4D4D4D",
"= c #747474",
" .. ",
" .++.. ",
" .+++@@. ",
" .@@@@@#... ",
" .$$@@##.%%.. ",
" .$$$##.%%%&&. ",
" .$$$#.&&&&&*. ",
" ...#.==&&**. ",
" .++..===***. ",
" .+++@@.==**. ",
" .@@@@@#..=*. ",
" .$$@@##. .. ",
" .$$$###. ",
" .$$$##. ",
" ..$#. ",
" .. "};
static const char* const struct_xpm[] = {
"16 16 14 1",
" c None",
". c #000000",
"+ c #C0FFC0",
"@ c #00FF00",
"# c #008000",
"$ c #00C000",
"% c #C0FFFF",
"& c #00FFFF",
"* c #008080",
"= c #00C0C0",
"- c #FFFFC0",
"; c #FFFF00",
"> c #808000",
", c #C0C000",
" .. ",
" .++.. ",
" .+++@@. ",
" .@@@@@#... ",
" .$$@@##.%%.. ",
" .$$$##.%%%&&. ",
" .$$$#.&&&&&*. ",
" ...#.==&&**. ",
" .--..===***. ",
" .---;;.==**. ",
" .;;;;;>..=*. ",
" .,,;;>>. .. ",
" .,,,>>>. ",
" .,,,>>. ",
" ..,>. ",
" .. "};
static const char* const macro_xpm[] = {
"16 16 14 1",
" c None",
". c #000000",
"+ c #FF7FE5",
"@ c #FF00C7",
"# c #7F0066",
"$ c #BC0096",
"% c #C0FFFF",
"& c #00FFFF",
"* c #008080",
"= c #00C0C0",
"- c #D493FF",
"; c #A100FF",
"> c #470082",
", c #6B00B7",
" .. ",
" .++.. ",
" .+++@@. ",
" .@@@@@#... ",
" .$$@@##.%%.. ",
" .$$$##.%%%&&. ",
" .$$$#.&&&&&*. ",
" ...#.==&&**. ",
" .--..===***. ",
" .---;;.==**. ",
" .;;;;;>..=*. ",
" .,,;;>>. .. ",
" .,,,>>>. ",
" .,,,>>. ",
" ..,>. ",
" .. "};
static const char* const method_xpm[] = {
"16 16 5 1",
" c None",
". c #000000",
"+ c #FCFC80",
"@ c #E0BC38",
"# c #F0DC5C",
" ",
" ",
" ",
" .. ",
" .++.. ",
" .+++++. ",
" .+++++@. ",
" .. .##++@@. ",
" .++..###@@@. ",
" .+++++.##@@. ",
" .+++++@..#@. ",
" .##++@@. .. ",
" .###@@@. ",
" .###@@. ",
" ..#@. ",
" .. "
};
#endif
diff --git a/addons/symbolviewer/python_parser.cpp b/addons/symbolviewer/python_parser.cpp
index 074f6e55a..b9448bbe5 100644
--- a/addons/symbolviewer/python_parser.cpp
+++ b/addons/symbolviewer/python_parser.cpp
@@ -1,165 +1,165 @@
/***************************************************************************
python_parser.cpp - description
-------------------
begin : Apr 2 2003
author : 2003 Massimo Callegari
email : massimocallegari@yahoo.it
***************************************************************************/
/***************************************************************************
* *
* 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::parsePythonSymbols(void)
{
if (!m_mainWindow->activeView())
return;
m_macro->setText(i18n("Show Globals"));
m_struct->setText(i18n("Show Methods"));
m_func->setText(i18n("Show Classes"));
QString cl; // Current Line
QPixmap cls( ( const char** ) class_xpm );
QPixmap mtd( ( const char** ) method_xpm );
QPixmap mcr( ( const char** ) macro_xpm );
int in_class = 0, state = 0, j;
QString name;
QTreeWidgetItem *node = nullptr;
QTreeWidgetItem *mcrNode = nullptr, *mtdNode = nullptr, *clsNode = nullptr;
QTreeWidgetItem *lastMcrNode = nullptr, *lastMtdNode = nullptr, *lastClsNode = nullptr;
KTextEditor::Document *kv = m_mainWindow->activeView()->document();
//kdDebug(13000)<<"Lines counted :"<numLines()<treeOn)
+ if(m_treeOn->isChecked())
{
clsNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Classes") ) );
mcrNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Globals") ) );
mcrNode->setIcon(0, QIcon(mcr));
clsNode->setIcon(0, QIcon(cls));
if (m_plugin->expandedOn)
{
m_symbols->expandItem(mcrNode);
m_symbols->expandItem(clsNode);
}
lastClsNode = clsNode;
lastMcrNode = mcrNode;
mtdNode = clsNode;
lastMtdNode = clsNode;
m_symbols->setRootIsDecorated(1);
}
else
m_symbols->setRootIsDecorated(0);
for (int i=0; ilines(); i++)
{
int line=i;
cl = kv->line(i);
// concatenate continued lines and remove continuation marker
if (cl.length()==0) continue;
while (cl[cl.length()-1]==QLatin1Char('\\'))
{
cl=cl.left(cl.length()-1);
i++;
if (ilines())
cl+=kv->line(i);
else
break;
}
if(cl.indexOf( QRegExp(QLatin1String("^class [a-zA-Z0-9_,\\s\\(\\).]+:")) ) >= 0) in_class = 1;
//if(cl.find( QRegExp(QLatin1String("[\\s]+def [a-zA-Z_]+[^#]*:")) ) >= 0) in_class = 2;
if(cl.indexOf( QRegExp(QLatin1String("^def\\s+[a-zA-Z_]+[^#]*:")) ) >= 0 ) in_class = 0;
if (cl.indexOf(QLatin1String("def ")) >= 0 || (cl.indexOf(QLatin1String("class ")) >= 0 && in_class == 1))
{
if (cl.indexOf(QLatin1String("def ")) >= 0 && in_class == 1) in_class = 2;
state = 1;
if (cl.indexOf(QLatin1Char(':')) >= 0) state = 3; // found in the same line. Done
else if (cl.indexOf(QLatin1Char('(')) >= 0) state = 2;
if (state == 2 || state == 3) name = cl.left (cl.indexOf (QLatin1Char('(')));
}
if (state > 0 && state < 3)
{
for (j = 0; j < cl.length(); j++)
{
if (cl.at(j) == QLatin1Char('(')) state = 2;
else if (cl.at(j) == QLatin1Char(':')) { state = 3; break; }
if (state == 1) name += cl.at(j);
}
}
if (state == 3)
{
//qDebug(13000)<<"Function -- Inserted : "<isChecked() && in_class == 1)
{
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(clsNode, lastClsNode);
if (m_plugin->expandedOn) m_symbols->expandItem(node);
lastClsNode = node;
mtdNode = lastClsNode;
lastMtdNode = lastClsNode;
}
else node = new QTreeWidgetItem(m_symbols);
node->setText(0, name);
node->setIcon(0, QIcon(cls));
node->setText(1, QString::number( line, 10));
}
if (m_struct->isChecked() && in_class == 2)
{
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(mtdNode, lastMtdNode);
lastMtdNode = node;
}
else node = new QTreeWidgetItem(m_symbols);
node->setText(0, name);
node->setIcon(0, QIcon(mtd));
node->setText(1, QString::number( line, 10));
}
if (m_macro->isChecked() && in_class == 0)
{
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(mcrNode, lastMcrNode);
lastMcrNode = node;
}
else node = new QTreeWidgetItem(m_symbols);
node->setText(0, name);
node->setIcon(0, QIcon(mcr));
node->setText(1, QString::number( line, 10));
}
state = 0;
name.clear();
}
}
}
// kate: space-indent on; indent-width 2; replace-tabs on;
diff --git a/addons/symbolviewer/ruby_parser.cpp b/addons/symbolviewer/ruby_parser.cpp
index 53d26d73a..9e494b018 100644
--- a/addons/symbolviewer/ruby_parser.cpp
+++ b/addons/symbolviewer/ruby_parser.cpp
@@ -1,106 +1,106 @@
/***************************************************************************
ruby_parser.cpp - description
-------------------
begin : May 9th 2007
author : 2007 Massimo Callegari
email : massimocallegari@yahoo.it
***************************************************************************/
/***************************************************************************
* *
* 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::parseRubySymbols(void)
{
if (!m_mainWindow->activeView())
return;
m_macro->setText(i18n("Show Globals"));
m_struct->setText(i18n("Show Methods"));
m_func->setText(i18n("Show Classes"));
QString cl; // Current Line
QPixmap cls( ( const char** ) class_xpm );
QPixmap mtd( ( const char** ) method_xpm );
QPixmap mcr( ( const char** ) macro_xpm );
int i;
QString name;
QTreeWidgetItem *node = nullptr;
QTreeWidgetItem *mtdNode = nullptr, *clsNode = nullptr;
QTreeWidgetItem *lastMtdNode = nullptr, *lastClsNode = nullptr;
KTextEditor::Document *kv = m_mainWindow->activeView()->document();
//kdDebug(13000)<<"Lines counted :"<numLines()<treeOn)
+ if(m_treeOn->isChecked())
{
clsNode = new QTreeWidgetItem(m_symbols);
clsNode->setText(0, i18n("Classes"));
clsNode->setIcon(0, QIcon(cls));
if (m_plugin->expandedOn) m_symbols->expandItem(clsNode);
lastClsNode = clsNode;
mtdNode = clsNode;
lastMtdNode = clsNode;
m_symbols->setRootIsDecorated(1);
}
else
m_symbols->setRootIsDecorated(0);
for (i=0; ilines(); i++)
{
cl = kv->line(i);
cl = cl.trimmed();
if (cl.indexOf( QRegExp(QLatin1String("^class [a-zA-Z0-9]+[^#]")) ) >= 0)
{
if (m_func->isChecked())
{
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(clsNode, lastClsNode);
if (m_plugin->expandedOn) m_symbols->expandItem(node);
lastClsNode = node;
mtdNode = lastClsNode;
lastMtdNode = lastClsNode;
}
else node = new QTreeWidgetItem(m_symbols);
node->setText(0, cl.mid(6));
node->setIcon(0, QIcon(cls));
node->setText(1, QString::number( i, 10));
}
}
if (cl.indexOf( QRegExp(QLatin1String("^def [a-zA-Z_]+[^#]")) ) >= 0 )
{
if (m_struct->isChecked())
{
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(mtdNode, lastMtdNode);
lastMtdNode = node;
}
else node = new QTreeWidgetItem(m_symbols);
name = cl.mid(4);
node->setToolTip(0, name);
if (m_plugin->typesOn == false)
{
name = name.left(name.indexOf(QLatin1Char('(')));
}
node->setText(0, name);
node->setIcon(0, QIcon(mtd));
node->setText(1, QString::number( i, 10));
}
}
}
}
diff --git a/addons/symbolviewer/tcl_parser.cpp b/addons/symbolviewer/tcl_parser.cpp
index 2aaa26732..e18de1767 100644
--- a/addons/symbolviewer/tcl_parser.cpp
+++ b/addons/symbolviewer/tcl_parser.cpp
@@ -1,157 +1,157 @@
/***************************************************************************
tcl_parser.cpp - description
-------------------
begin : Apr 2 2003
author : 2003 Massimo Callegari
email : massimocallegari@yahoo.it
***************************************************************************/
/***************************************************************************
* *
* 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"
#include
void KatePluginSymbolViewerView::parseTclSymbols(void)
{
if (!m_mainWindow->activeView())
return;
QString currline, prevline;
bool prevComment = false;
QString varStr(QLatin1String("set "));
QString procStr(QLatin1String("proc"));
QString stripped;
int i, j, args_par = 0, graph = 0;
char block = 0, parse_func = 0;
QTreeWidgetItem *node = nullptr;
QTreeWidgetItem *mcrNode = nullptr, *clsNode = nullptr;
QTreeWidgetItem *lastMcrNode = nullptr, *lastClsNode = nullptr;
QPixmap mcr( ( const char** ) macro_xpm );
QPixmap cls( ( const char** ) class_xpm );
- if(m_plugin->treeOn)
+ if(m_treeOn->isChecked())
{
clsNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Functions") ) );
mcrNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Globals") ) );
clsNode->setIcon(0, QIcon(cls));
mcrNode->setIcon(0, QIcon(mcr));
lastMcrNode = mcrNode;
lastClsNode = clsNode;
if (m_plugin->expandedOn)
{
m_symbols->expandItem(clsNode);
m_symbols->expandItem(mcrNode);
}
m_symbols->setRootIsDecorated(1);
}
else
m_symbols->setRootIsDecorated(0);
KTextEditor::Document *kDoc = m_mainWindow->activeView()->document();
//positions.resize(kDoc->numLines() + 3); // Maximum m_symbols number o.O
//positions.fill(0);
for (i = 0; ilines(); i++)
{
currline = kDoc->line(i);
currline = currline.trimmed();
bool comment = false;
//qDebug(13000)< 0)
{
prevline = kDoc->line(i-1);
if(prevline.endsWith(QLatin1String("\\")) && prevComment) comment = true;
}
prevComment = comment;
if(!comment)
{
if(currline.startsWith(varStr) && block == 0)
{
if (m_macro->isChecked()) // not really a macro, but a variable
{
stripped = currline.right(currline.length() - 3);
stripped = stripped.simplified();
int fnd = stripped.indexOf(QLatin1Char(' '));
//fnd = stripped.indexOf(QLatin1Char(';'));
if(fnd > 0) stripped = stripped.left(fnd);
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(mcrNode, lastMcrNode);
lastMcrNode = node;
}
else
node = new QTreeWidgetItem(m_symbols);
node->setText(0, stripped);
node->setIcon(0, QIcon(mcr));
node->setText(1, QString::number( i, 10));
stripped.clear();
}//macro
} // starts with "set"
else if(currline.startsWith(procStr)) { parse_func = 1; }
if (parse_func == 1)
{
for (j = 0; j < currline.length(); j++)
{
if (block == 1)
{
if(currline.at(j)==QLatin1Char('{')) graph++;
if(currline.at(j)==QLatin1Char('}'))
{
graph--;
if (graph == 0) { block = 0; parse_func = 0; continue; }
}
}
if (block == 0)
{
stripped += currline.at(j);
if(currline.at(j) == QLatin1Char('{')) args_par++;
if(currline.at(j) == QLatin1Char('}'))
{
args_par--;
if (args_par == 0)
{
//stripped = stripped.simplified();
if(m_func->isChecked())
{
- if (m_plugin->treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(clsNode, lastClsNode);
lastClsNode = node;
}
else
node = new QTreeWidgetItem(m_symbols);
node->setText(0, stripped);
node->setIcon(0, QIcon(cls));
node->setText(1, QString::number( i, 10));
}
stripped.clear();
block = 1;
}
}
} // block = 0
} // for j loop
}//m_func->isChecked()
} // not a comment
} //for i loop
//positions.resize(m_symbols->itemIndex(node) + 1);
}
diff --git a/addons/symbolviewer/xslt_parser.cpp b/addons/symbolviewer/xslt_parser.cpp
index 15db7fc53..9acdb7431 100644
--- a/addons/symbolviewer/xslt_parser.cpp
+++ b/addons/symbolviewer/xslt_parser.cpp
@@ -1,158 +1,158 @@
/***************************************************************************
xslt_parser.cpp - description
-------------------
begin : Mar 28 2007
author : 2007 jiri Tyr
email : jiri.tyr@vslib.cz
***************************************************************************/
/***************************************************************************
* *
* 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::parseXsltSymbols(void)
{
if (!m_mainWindow->activeView())
return;
m_macro->setText(i18n("Show Params"));
m_struct->setText(i18n("Show Variables"));
m_func->setText(i18n("Show Templates"));
QString cl; // Current Line
QString stripped;
char comment = 0;
char templ = 0;
int i;
QPixmap cls( ( const char** ) class_xpm );
QPixmap sct( ( const char** ) struct_xpm );
QPixmap mcr( ( const char** ) macro_xpm );
QPixmap cls_int( ( const char** ) class_int_xpm );
QTreeWidgetItem *node = nullptr;
QTreeWidgetItem *mcrNode = nullptr, *sctNode = nullptr, *clsNode = nullptr;
QTreeWidgetItem *lastMcrNode = nullptr, *lastSctNode = nullptr, *lastClsNode = nullptr;
KTextEditor::Document *kv = m_mainWindow->activeView()->document();
//kdDebug(13000)<<"Lines counted :"<numLines()<treeOn)
+ if(m_treeOn->isChecked())
{
mcrNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Params") ) );
sctNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Variables") ) );
clsNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Templates") ) );
mcrNode->setIcon(0, QIcon(mcr));
sctNode->setIcon(0, QIcon(sct));
clsNode->setIcon(0, QIcon(cls));
if (m_plugin->expandedOn)
{
m_symbols->expandItem(mcrNode);
m_symbols->expandItem(sctNode);
m_symbols->expandItem(clsNode);
}
lastMcrNode = mcrNode;
lastSctNode = sctNode;
lastClsNode = clsNode;
m_symbols->setRootIsDecorated(1);
}
else
{
m_symbols->setRootIsDecorated(0);
}
for (i=0; ilines(); i++)
{
cl = kv->line(i);
cl = cl.trimmed();
if(cl.indexOf(QRegExp(QLatin1String(""))) >= 0) { comment = 0; continue; }
if(cl.indexOf(QRegExp(QLatin1String("^"))) >= 0) { templ = 0; continue; }
if (comment==1) { continue; }
if (templ==1) { continue; }
if(cl.indexOf(QRegExp(QLatin1String("^isChecked())
{
QString stripped = cl.remove(QRegExp(QLatin1String("^treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(mcrNode, lastMcrNode);
lastMcrNode = node;
}
else node = new QTreeWidgetItem(m_symbols);
node->setText(0, stripped);
node->setIcon(0, QIcon(mcr));
node->setText(1, QString::number( i, 10));
}
if(cl.indexOf(QRegExp(QLatin1String("^isChecked())
{
QString stripped = cl.remove(QRegExp(QLatin1String("^treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(sctNode, lastSctNode);
lastSctNode = node;
}
else node = new QTreeWidgetItem(m_symbols);
node->setText(0, stripped);
node->setIcon(0, QIcon(sct));
node->setText(1, QString::number( i, 10));
}
if(cl.indexOf(QRegExp(QLatin1String("^isChecked())
{
QString stripped = cl.remove(QRegExp(QLatin1String("^treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(clsNode, lastClsNode);
lastClsNode = node;
}
else node = new QTreeWidgetItem(m_symbols);
node->setText(0, stripped);
node->setIcon(0, QIcon(cls_int));
node->setText(1, QString::number( i, 10));
}
if(cl.indexOf(QRegExp(QLatin1String("^isChecked())
{
QString stripped = cl.remove(QRegExp(QLatin1String("^treeOn)
+ if (m_treeOn->isChecked())
{
node = new QTreeWidgetItem(clsNode, lastClsNode);
lastClsNode = node;
}
else node = new QTreeWidgetItem(m_symbols);
node->setText(0, stripped);
node->setIcon(0, QIcon(cls));
node->setText(1, QString::number( i, 10));
}
if(cl.indexOf(QRegExp(QLatin1String("= 0)
{
templ = 1;
}
}
}