20 #include "katesyntaxdocument.h" 22 #include <sys/types.h> 27 #include <tdestandarddirs.h> 29 #include <tdemessagebox.h> 30 #include <tdeconfig.h> 43 for (uint i=0; i < myModeList.size(); i++)
54 if(currentFile != identifier)
57 TQFile f( identifier );
59 if ( f.open(IO_ReadOnly) )
66 bool success=setContent(&f,&errorMsg,&line,&col);
69 currentFile = identifier;
76 KMessageBox::error(0L,i18n(
"<qt>The error <b>%4</b><br> has been detected in the file %1 at %2/%3</qt>").arg(identifier)
77 .arg(line).arg(col).arg(i18n(
"TQXml",errorMsg.utf8())));
100 if (data->currentGroup.isNull())
103 TQDomNode node = data->parent.firstChild();
104 while (node.isComment())
105 node = node.nextSibling();
107 data->currentGroup = node.toElement();
112 TQDomNode node = data->currentGroup.nextSibling();
113 while (node.isComment())
114 node = node.nextSibling();
116 data->currentGroup = node.toElement();
119 return !data->currentGroup.isNull();
130 if (data->item.isNull())
132 TQDomNode node = data->currentGroup.firstChild();
133 while (node.isComment())
134 node = node.nextSibling();
136 data->item = node.toElement();
140 TQDomNode node = data->item.nextSibling();
141 while (node.isComment())
142 node = node.nextSibling();
144 data->item = node.toElement();
147 return !data->item.isNull();
155 return TQString::null;
158 if ( (!data->item.isNull()) && (name.isEmpty()))
160 return data->item.tagName();
164 if (!data->item.isNull())
166 return data->item.attribute(name);
169 return TQString::null;
176 return TQString::null;
178 if (!data->currentGroup.isNull())
180 return data->currentGroup.attribute(name);
184 return TQString::null;
200 retval->parent = data->currentGroup;
201 retval->currentGroup = data->item;
207 bool KateSyntaxDocument::getElement (TQDomElement &element,
const TQString &mainGroupName,
const TQString &config)
209 kdDebug(13010) <<
"Looking for \"" << mainGroupName <<
"\" -> \"" << config <<
"\"." <<
endl;
211 TQDomNodeList nodes = documentElement().childNodes();
214 for (
unsigned int i=0; i<nodes.count(); i++)
216 TQDomElement elem = nodes.item(i).toElement();
217 if (elem.tagName() == mainGroupName)
220 TQDomNodeList subNodes = elem.childNodes();
223 for (
unsigned int j=0; j<subNodes.count(); j++)
225 TQDomElement subElem = subNodes.item(j).toElement();
226 if (subElem.tagName() == config)
234 kdDebug(13010) <<
"WARNING: \""<< config <<
"\" wasn't found!" <<
endl;
239 kdDebug(13010) <<
"WARNING: \""<< mainGroupName <<
"\" wasn't found!" <<
endl;
249 TQDomElement element;
250 if (getElement(element, mainGroupName, config))
253 data->item = element;
265 TQDomElement element;
266 if (getElement(element, mainGroupName, group+
"s"))
269 data->parent = element;
280 kdDebug(13010)<<
"Create a list of keywords \""<<type<<
"\" from \""<<mainGroup<<
"\"."<<
endl;
284 for(TQDomNode node = documentElement().firstChild(); !node.isNull(); node = node.nextSibling())
286 TQDomElement elem = node.toElement();
287 if (elem.tagName() == mainGroup)
289 kdDebug(13010)<<
"\""<<mainGroup<<
"\" found."<<
endl;
290 TQDomNodeList nodelist1 = elem.elementsByTagName(
"list");
292 for (uint l=0; l<nodelist1.count(); l++)
294 if (nodelist1.item(l).toElement().attribute(
"name") == type)
296 kdDebug(13010)<<
"List with attribute name=\""<<type<<
"\" found."<<
endl;
297 TQDomNodeList childlist = nodelist1.item(l).toElement().childNodes();
299 for (uint i=0; i<childlist.count(); i++)
301 TQString element = childlist.item(i).toElement().text().stripWhiteSpace();
302 if (element.isEmpty())
307 kdDebug(13010)<<
"\""<<element<<
"\" added to the list \""<<type<<
"\""<<
endl;
311 kdDebug(13010)<<
"... The list continues ..."<<
endl;
331 void KateSyntaxDocument::setupModeList (
bool force)
334 if (!myModeList.isEmpty())
338 TDEConfig config(
"katesyntaxhighlightingrc",
false,
false);
352 for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it )
355 TQString Group=
"Cache "+ *it;
362 memset (&sbuf, 0,
sizeof(sbuf));
363 stat(TQFile::encodeName(*it), &sbuf);
371 mli->nameTranslated = i18n(
"Language",mli->name.utf8());
372 mli->section = i18n(
"Language Section",config.
readEntry(
"section").utf8());
373 mli->mimetype = config.
readEntry(
"mimetype");
374 mli->extension = config.
readEntry(
"extension");
375 mli->version = config.
readEntry(
"version");
376 mli->priority = config.
readEntry(
"priority");
377 mli->author = config.
readEntry(
"author");
378 mli->license = config.
readEntry(
"license");
380 mli->identifier = *it;
383 myModeList.append(mli);
387 kdDebug (13010) <<
"UPDATE hl cache for: " << *it <<
endl;
392 if (f.open(IO_ReadOnly))
399 bool success = setContent(&f,&errMsg,&line,&col);
405 TQDomElement root = documentElement();
410 if (root.tagName()==
"language")
415 mli->name = root.attribute(
"name");
416 mli->section = root.attribute(
"section");
417 mli->mimetype = root.attribute(
"mimetype");
418 mli->extension = root.attribute(
"extensions");
419 mli->version = root.attribute(
"version");
420 mli->priority = root.attribute(
"priority");
421 mli->author = root.attribute(
"author");
422 mli->license = root.attribute(
"license");
424 TQString hidden = root.attribute(
"hidden");
425 mli->hidden = (hidden ==
"true" || hidden ==
"TRUE");
427 mli->identifier = *it;
434 config.
writeEntry(
"extension",mli->extension);
442 config.
writeEntry(
"lastModified", sbuf.st_mtime);
445 mli->section = i18n(
"Language Section",mli->section.utf8());
446 mli->nameTranslated = i18n(
"Language",mli->name.utf8());
449 myModeList.append(mli);
457 emli->section=i18n(
"Errors!");
458 emli->mimetype=
"invalid_file/invalid_file";
459 emli->extension=
"invalid_file.invalid_file";
461 emli->name=TQString (
"Error: %1").arg(*it);
462 emli->nameTranslated=i18n(
"Error: %1").arg(*it);
463 emli->identifier=(*it);
465 myModeList.append(emli);
TQStringList findAllResources(const char *type, const TQString &filter=TQString::null, bool recursive=false, bool unique=false) const
static void error(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
KateSyntaxDocument(bool force=false)
Constructor Sets the current file to nothing and build the ModeList (katesyntaxhighlightingrc) ...
void setGroup(const TQString &group)
KateSyntaxContextData * getGroupInfo(const TQString &mainGroupName, const TQString &group)
Get the KateSyntaxContextData of the TQDomElement Config inside mainGroupName KateSyntaxContextData::...
kdbgstream kdDebug(int area=0)
bool nextGroup(KateSyntaxContextData *data)
Jump to the next group, KateSyntaxContextData::currentGroup will point to the next group...
~KateSyntaxDocument()
Desctructor.
static TDEStandardDirs * dirs()
bool nextItem(KateSyntaxContextData *data)
Jump to the next item, KateSyntaxContextData::item will point to the next item.
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
bool setIdentifier(const TQString &identifier)
If the open hl file is different from the one needed, it opens the new one and assign some other thin...
TQStringList & finddata(const TQString &mainGroup, const TQString &type, bool clearList=true)
Returns a list with all the keywords inside the list type.
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
KateSyntaxContextData * getConfig(const TQString &mainGroupName, const TQString &config)
Get the KateSyntaxContextData of the DomElement Config inside mainGroupName It just fills KateSyntaxC...
bool hasGroup(const TQString &group) const
Information about each syntax hl Mode.
kndbgstream & endl(kndbgstream &s)
int readNumEntry(const TQString &pKey, int nDefault=0) const
TQString groupItemData(const KateSyntaxContextData *data, const TQString &name)
This function is used to fetch the atributes of the tags.
Class holding the data around the current QDomElement.