Git commit 0c97728f5e0bfaa1d521588daa27d31cdb629635 by Christoph Cullmann. Committed on 31/07/2018 at 20:21. Pushed by cullmann into branch 'syntax-highlighting'. delete massive amounts of old code, we can later see how to fill the member= s with info M +0 -1 src/CMakeLists.txt M +0 -1 src/mode/katemodeconfigpage.cpp M +0 -1 src/mode/katemodemanager.cpp M +0 -1 src/mode/katemodemenu.cpp M +0 -1 src/syntax/katehighlight.cpp M +0 -1 src/syntax/katehighlighthelpers.cpp M +0 -1 src/syntax/katehighlightmenu.cpp D +0 -336 src/syntax/katesyntaxdocument.cpp D +0 -133 src/syntax/katesyntaxdocument.h M +0 -1 src/syntax/katesyntaxmanager.cpp https://commits.kde.org/ktexteditor/0c97728f5e0bfaa1d521588daa27d31cdb629635 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d4f60453..ab4b2ff3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -141,7 +141,6 @@ syntax/katesyntaxmanager.cpp syntax/katehighlight.cpp syntax/katehighlighthelpers.cpp syntax/katehighlightmenu.cpp -syntax/katesyntaxdocument.cpp syntax/katehighlightingcmds.cpp = # view stuff (THE view and its helpers) diff --git a/src/mode/katemodeconfigpage.cpp b/src/mode/katemodeconfigpage.= cpp index 14ee9168..cc2c4e1a 100644 --- a/src/mode/katemodeconfigpage.cpp +++ b/src/mode/katemodeconfigpage.cpp @@ -27,7 +27,6 @@ #include "kateglobal.h" #include "kateautoindent.h" #include "katesyntaxmanager.h" -#include "katesyntaxdocument.h" = #include "ui_filetypeconfigwidget.h" = diff --git a/src/mode/katemodemanager.cpp b/src/mode/katemodemanager.cpp index bb8f2acc..ff82f791 100644 --- a/src/mode/katemodemanager.cpp +++ b/src/mode/katemodemanager.cpp @@ -27,7 +27,6 @@ #include "kateview.h" #include "kateglobal.h" #include "katesyntaxmanager.h" -#include "katesyntaxdocument.h" #include "katepartdebug.h" = #include diff --git a/src/mode/katemodemenu.cpp b/src/mode/katemodemenu.cpp index a44d1b1d..995d5f8d 100644 --- a/src/mode/katemodemenu.cpp +++ b/src/mode/katemodemenu.cpp @@ -26,7 +26,6 @@ #include "kateview.h" #include "kateglobal.h" #include "katesyntaxmanager.h" -#include "katesyntaxdocument.h" #include "katepartdebug.h" //END Includes = diff --git a/src/syntax/katehighlight.cpp b/src/syntax/katehighlight.cpp index 1257e404..8da5bcd8 100644 --- a/src/syntax/katehighlight.cpp +++ b/src/syntax/katehighlight.cpp @@ -28,7 +28,6 @@ #include "katehighlighthelpers.h" #include "katetextline.h" #include "katedocument.h" -#include "katesyntaxdocument.h" #include "katerenderer.h" #include "kateglobal.h" #include "kateschema.h" diff --git a/src/syntax/katehighlighthelpers.cpp b/src/syntax/katehighlight= helpers.cpp index fff189aa..214fda71 100644 --- a/src/syntax/katehighlighthelpers.cpp +++ b/src/syntax/katehighlighthelpers.cpp @@ -26,7 +26,6 @@ = #include "katetextline.h" #include "katedocument.h" -#include "katesyntaxdocument.h" #include "katerenderer.h" #include "kateglobal.h" #include "kateschema.h" diff --git a/src/syntax/katehighlightmenu.cpp b/src/syntax/katehighlightmen= u.cpp index 589e7927..17a0396c 100644 --- a/src/syntax/katehighlightmenu.cpp +++ b/src/syntax/katehighlightmenu.cpp @@ -25,7 +25,6 @@ #include "kateview.h" #include "kateglobal.h" #include "katesyntaxmanager.h" -#include "katesyntaxdocument.h" #include "katepartdebug.h" //END Includes = diff --git a/src/syntax/katesyntaxdocument.cpp b/src/syntax/katesyntaxdocum= ent.cpp deleted file mode 100644 index 3a4ae058..00000000 --- a/src/syntax/katesyntaxdocument.cpp +++ /dev/null @@ -1,336 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2001 Joseph Wenninger - Copyright (C) 2000 Scott Manson - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public Licen= se - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "katesyntaxdocument.h" - -#include "katepartdebug.h" -#include "kateglobal.h" - -#include - -#include -#include -#include -#include - -#include -#include - -// use this to turn on over verbose debug output... -#undef KSD_OVER_VERBOSE - -KateSyntaxDocument::KateSyntaxDocument() -{ -} - -KateSyntaxDocument::~KateSyntaxDocument() -{ - // cleanup, else we have a memory leak! - clearCache(); -} - -/** If the open hl file is different from the one needed, it opens - the new one and assign some other things. - identifier =3D File name and path of the new xml needed -*/ -bool KateSyntaxDocument::setIdentifier(const QString &identifier) -{ - // already existing in cache? be done - if (m_domDocuments.contains(identifier)) { - currentFile =3D identifier; - return true; - } - - // else: try to open - QFile f(identifier); - if (!f.open(QIODevice::ReadOnly)) { - // Oh o, we couldn't open the file. - KMessageBox::error(QApplication::activeWindow(), i18n("Unable to o= pen %1", identifier)); - return false; - } - - // try to parse - QDomDocument *document =3D new QDomDocument(); - QString errorMsg; - int line, col; - if (!document->setContent(&f, &errorMsg, &line, &col)) { - KMessageBox::error(QApplication::activeWindow(), i18n("The err= or %4
has been detected in the file %1 at %2/%3
", identif= ier, - line, col, i18nc("QXml", errorMsg.toUtf= 8().data()))); - delete document; - return false; - } - - // cache and be done - currentFile =3D identifier; - m_domDocuments[currentFile] =3D document; - return true; -} - -void KateSyntaxDocument::clearCache() -{ - qDeleteAll(m_domDocuments); - m_domDocuments.clear(); - currentFile.clear(); - m_data.clear(); -} - -/** - * Jump to the next group, KateSyntaxContextData::currentGroup will point = to the next group - */ -bool KateSyntaxDocument::nextGroup(KateSyntaxContextData *data) -{ - if (!data) { - return false; - } - - // No group yet so go to first child - if (data->currentGroup.isNull()) { - // Skip over non-elements. So far non-elements are just comments - QDomNode node =3D data->parent.firstChild(); - while (node.isComment()) { - node =3D node.nextSibling(); - } - - data->currentGroup =3D node.toElement(); - } else { - // common case, iterate over siblings, skipping comments as we go - QDomNode node =3D data->currentGroup.nextSibling(); - while (node.isComment()) { - node =3D node.nextSibling(); - } - - data->currentGroup =3D node.toElement(); - } - - return !data->currentGroup.isNull(); -} - -/** - * Jump to the next item, KateSyntaxContextData::item will point to the ne= xt item - */ -bool KateSyntaxDocument::nextItem(KateSyntaxContextData *data) -{ - if (!data) { - return false; - } - - if (data->item.isNull()) { - QDomNode node =3D data->currentGroup.firstChild(); - while (node.isComment()) { - node =3D node.nextSibling(); - } - - data->item =3D node.toElement(); - } else { - QDomNode node =3D data->item.nextSibling(); - while (node.isComment()) { - node =3D node.nextSibling(); - } - - data->item =3D node.toElement(); - } - - return !data->item.isNull(); -} - -/** - * This function is used to fetch the atributes of the tags of the item in= a KateSyntaxContextData. - */ -QString KateSyntaxDocument::groupItemData(const KateSyntaxContextData *dat= a, const QString &name) -{ - if (!data) { - return QString(); - } - - // If there's no name just return the tag name of data->item - if ((!data->item.isNull()) && (name.isEmpty())) { - return data->item.tagName(); - } - - // if name is not empty return the value of the attribute name - if (!data->item.isNull()) { - return data->item.attribute(name); - } - - return QString(); - -} - -QString KateSyntaxDocument::groupData(const KateSyntaxContextData *data, c= onst QString &name) -{ - if (!data) { - return QString(); - } - - if (!data->currentGroup.isNull()) { - return data->currentGroup.attribute(name); - } else { - return QString(); - } -} - -void KateSyntaxDocument::freeGroupInfo(KateSyntaxContextData *data) -{ - delete data; -} - -KateSyntaxContextData *KateSyntaxDocument::getSubItems(KateSyntaxContextDa= ta *data) -{ - KateSyntaxContextData *retval =3D new KateSyntaxContextData; - - if (data !=3D nullptr) { - retval->parent =3D data->currentGroup; - retval->currentGroup =3D data->item; - } - - return retval; -} - -bool KateSyntaxDocument::getElement(QDomElement &element, const QString &m= ainGroupName, const QString &config) -{ -#ifdef KSD_OVER_VERBOSE - qCDebug(LOG_KTE) << "Looking for \"" << mainGroupName << "\" -> \"" <<= config << "\"."; -#endif - - QDomNodeList nodes; - if (m_domDocuments.contains(currentFile)) - nodes =3D m_domDocuments[currentFile]->documentElement().childNode= s(); - - // Loop over all these child nodes looking for mainGroupName - for (int i =3D 0; i < nodes.count(); i++) { - QDomElement elem =3D nodes.item(i).toElement(); - if (elem.tagName() =3D=3D mainGroupName) { - // Found mainGroupName ... - QDomNodeList subNodes =3D elem.childNodes(); - - // ... so now loop looking for config - for (int j =3D 0; j < subNodes.count(); j++) { - QDomElement subElem =3D subNodes.item(j).toElement(); - if (subElem.tagName() =3D=3D config) { - // Found it! - element =3D subElem; - return true; - } - } - -#ifdef KSD_OVER_VERBOSE - qCDebug(LOG_KTE) << "WARNING: \"" << config << "\" wasn't foun= d!"; -#endif - - return false; - } - } - -#ifdef KSD_OVER_VERBOSE - qCDebug(LOG_KTE) << "WARNING: \"" << mainGroupName << "\" wasn't found= !"; -#endif - - return false; -} - -/** - * Get the KateSyntaxContextData of the QDomElement Config inside mainGrou= pName - * KateSyntaxContextData::item will contain the QDomElement found - */ -KateSyntaxContextData *KateSyntaxDocument::getConfig(const QString &mainGr= oupName, const QString &config) -{ - QDomElement element; - if (getElement(element, mainGroupName, config)) { - KateSyntaxContextData *data =3D new KateSyntaxContextData; - data->item =3D element; - return data; - } - return nullptr; -} - -/** - * Get the KateSyntaxContextData of the QDomElement Config inside mainGrou= pName - * KateSyntaxContextData::parent will contain the QDomElement found - */ -KateSyntaxContextData *KateSyntaxDocument::getGroupInfo(const QString &mai= nGroupName, const QString &group) -{ - QDomElement element; - if (getElement(element, mainGroupName, group + QLatin1Char('s'))) { - KateSyntaxContextData *data =3D new KateSyntaxContextData; - data->parent =3D element; - return data; - } - return nullptr; -} - -/** - * Returns a list with all the keywords inside the list type - */ -QStringList &KateSyntaxDocument::finddata(const QString &mainGroup, const = QString &type, bool clearList) -{ -#ifdef KSD_OVER_VERBOSE - qCDebug(LOG_KTE) << "Create a list of keywords \"" << type << "\" from= \"" << mainGroup << "\"."; -#endif - - if (clearList) { - m_data.clear(); - } - - if (!m_domDocuments.contains(currentFile)) - return m_data; - - for (QDomNode node =3D m_domDocuments[currentFile]->documentElement().= firstChild(); !node.isNull(); node =3D node.nextSibling()) { - QDomElement elem =3D node.toElement(); - if (elem.tagName() =3D=3D mainGroup) { -#ifdef KSD_OVER_VERBOSE - qCDebug(LOG_KTE) << "\"" << mainGroup << "\" found."; -#endif - - QDomNodeList nodelist1 =3D elem.elementsByTagName(QStringLiter= al("list")); - - for (int l =3D 0; l < nodelist1.count(); l++) { - if (nodelist1.item(l).toElement().attribute(QStringLiteral= ("name")) =3D=3D type) { -#ifdef KSD_OVER_VERBOSE - qCDebug(LOG_KTE) << "List with attribute name=3D\"" <<= type << "\" found."; -#endif - - QDomNodeList childlist =3D nodelist1.item(l).toElement= ().childNodes(); - - for (int i =3D 0; i < childlist.count(); i++) { - QString element =3D childlist.item(i).toElement().= text().trimmed(); - if (element.isEmpty()) { - continue; - } - -#ifdef KSD_OVER_VERBOSE - if (i < 6) { - qCDebug(LOG_KTE) << "\"" << element << "\" add= ed to the list \"" << type << "\""; - } else if (i =3D=3D 6) { - qCDebug(LOG_KTE) << "... The list continues ..= ."; - } -#endif - - m_data +=3D element; - } - - break; - } - } - break; - } - } - - return m_data; -} diff --git a/src/syntax/katesyntaxdocument.h b/src/syntax/katesyntaxdocumen= t.h deleted file mode 100644 index 26a79182..00000000 --- a/src/syntax/katesyntaxdocument.h +++ /dev/null @@ -1,133 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2001 Joseph Wenninger - Copyright (C) 2000 Scott Manson - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public Licen= se - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __KATE_SYNTAXDOCUMENT_H__ -#define __KATE_SYNTAXDOCUMENT_H__ - -#include -#include -#include -#include - -/** - * Class holding the data around the current QDomElement - */ -class KateSyntaxContextData -{ -public: - QDomElement parent; - QDomElement currentGroup; - QDomElement item; -}; - -/** - * Store and manage the information about Syntax Highlighting. - */ -class KateSyntaxDocument -{ -public: - /** - * Constructor - */ - KateSyntaxDocument(); - - /** - * Destructor - */ - ~KateSyntaxDocument(); - - /** - * If the open hl file is different from the one needed, it opens - * the new one and assign some other things. - * @param identifier file name and path of the new xml needed - * @return success - */ - bool setIdentifier(const QString &identifier); - = - /** - * Clear internal QDomDocument cache - */ - void clearCache(); - - /** - * Jump to the next group, KateSyntaxContextData::currentGroup will po= int to the next group - * @param data context - * @return success - */ - bool nextGroup(KateSyntaxContextData *data); - - /** - * Jump to the next item, KateSyntaxContextData::item will point to th= e next item - * @param data context - * @return success - */ - bool nextItem(KateSyntaxContextData *data); - - /** - * This function is used to fetch the atributes of the tags. - */ - QString groupItemData(const KateSyntaxContextData *data, const QString= &name); - QString groupData(const KateSyntaxContextData *data, const QString &na= me); - - void freeGroupInfo(KateSyntaxContextData *data); - KateSyntaxContextData *getSubItems(KateSyntaxContextData *data); - - /** - * Get the KateSyntaxContextData of the DomElement Config inside mainG= roupName - * It just fills KateSyntaxContextData::item - */ - KateSyntaxContextData *getConfig(const QString &mainGroupName, const Q= String &config); - - /** - * Get the KateSyntaxContextData of the QDomElement Config inside main= GroupName - * KateSyntaxContextData::parent will contain the QDomElement found - */ - KateSyntaxContextData *getGroupInfo(const QString &mainGroupName, cons= t QString &group); - - /** - * Returns a list with all the keywords inside the list type - */ - QStringList &finddata(const QString &mainGroup, const QString &type, b= ool clearList =3D true); - -private: - /** - * Used by getConfig and getGroupInfo to traverse the xml nodes and - * evenually return the found element - */ - bool getElement(QDomElement &element, const QString &mainGroupName, co= nst QString &config); - - /** - * current parsed filename - */ - QString currentFile; - - /** - * last found data out of the xml - */ - QStringList m_data; - = - /** - * internal cache for domdocuments - */ - QHash m_domDocuments; -}; - -#endif - diff --git a/src/syntax/katesyntaxmanager.cpp b/src/syntax/katesyntaxmanage= r.cpp index 7d1149e8..e164936e 100644 --- a/src/syntax/katesyntaxmanager.cpp +++ b/src/syntax/katesyntaxmanager.cpp @@ -27,7 +27,6 @@ = #include "katetextline.h" #include "katedocument.h" -#include "katesyntaxdocument.h" #include "katerenderer.h" #include "kateglobal.h" #include "kateschema.h"