-rw-r--r-- | noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp b/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp index c51221b..3390bdb 100644 --- a/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp +++ b/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp | |||
@@ -1,306 +1,310 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | katesyntaxdocument.cpp - description | 2 | katesyntaxdocument.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Sat 31 March 2001 | 4 | begin : Sat 31 March 2001 |
5 | copyright : (C) 2001,2002 by Joseph Wenninger | 5 | copyright : (C) 2001,2002 by Joseph Wenninger |
6 | email : jowenn@kde.org | 6 | email : jowenn@kde.org |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | 17 | ||
18 | #include "katesyntaxdocument.h" | 18 | #include "katesyntaxdocument.h" |
19 | #include <qfile.h> | 19 | #include <qfile.h> |
20 | #include <kdebug.h> | 20 | #include <kdebug.h> |
21 | #include <kstddirs.h> | 21 | #include <kstddirs.h> |
22 | #include <klocale.h> | 22 | #include <klocale.h> |
23 | #include <kmessagebox.h> | 23 | #include <kmessagebox.h> |
24 | #include <qstringlist.h> | 24 | #include <qstringlist.h> |
25 | #include <kconfig.h> | 25 | #include <kconfig.h> |
26 | #include <kglobal.h> | 26 | #include <kglobal.h> |
27 | 27 | #include <qpe/qpeapplication.h> | |
28 | 28 | #include <qdir.h> | |
29 | 29 | ||
30 | SyntaxDocument::SyntaxDocument() | 30 | SyntaxDocument::SyntaxDocument() |
31 | { | 31 | { |
32 | m_root=0; | 32 | m_root=0; |
33 | currentFile=""; | 33 | currentFile=""; |
34 | setupModeList(); | 34 | setupModeList(); |
35 | } | 35 | } |
36 | 36 | ||
37 | void SyntaxDocument::setIdentifier(const QString& identifier) | 37 | void SyntaxDocument::setIdentifier(const QString& identifier) |
38 | { | 38 | { |
39 | #warning FIXME delete m_root; | 39 | #warning FIXME delete m_root; |
40 | m_root=Opie::XMLElement::load(identifier); | 40 | m_root=Opie::XMLElement::load(identifier); |
41 | if (!m_root) KMessageBox::error( 0L, i18n("Can't open %1").arg(identifier) ); | 41 | if (!m_root) KMessageBox::error( 0L, i18n("Can't open %1").arg(identifier) ); |
42 | 42 | ||
43 | } | 43 | } |
44 | 44 | ||
45 | SyntaxDocument::~SyntaxDocument() | 45 | SyntaxDocument::~SyntaxDocument() |
46 | { | 46 | { |
47 | } | 47 | } |
48 | 48 | ||
49 | void SyntaxDocument::setupModeList(bool force) | 49 | void SyntaxDocument::setupModeList(bool force) |
50 | { | 50 | { |
51 | 51 | ||
52 | if (myModeList.count() > 0) return; | 52 | if (myModeList.count() > 0) return; |
53 | 53 | ||
54 | KConfig *config=KGlobal::config(); | 54 | KConfig *config=KGlobal::config(); |
55 | KStandardDirs *dirs = KGlobal::dirs(); | 55 | KStandardDirs *dirs = KGlobal::dirs(); |
56 | 56 | ||
57 | QStringList list=dirs->findAllResources("data","kate/syntax/*.xml",false,true); | 57 | // QStringList list=dirs->findAllResources("data","kate/syntax/*.xml",false,true); |
58 | QString path=QPEApplication::qpeDir() +"share/tinykate/syntax/"; | ||
59 | |||
60 | QDir dir(path); | ||
61 | QStringList list=dir.entryList("*.xml"); | ||
58 | 62 | ||
59 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) | 63 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) |
60 | { | 64 | { |
61 | QString Group="Highlighting_Cache"+*it; | 65 | QString Group="Highlighting_Cache"+path+*it; |
62 | 66 | ||
63 | if ((config->hasGroup(Group)) && (!force)) | 67 | if ((config->hasGroup(Group)) && (!force)) |
64 | { | 68 | { |
65 | config->setGroup(Group); | 69 | config->setGroup(Group); |
66 | syntaxModeListItem *mli=new syntaxModeListItem; | 70 | syntaxModeListItem *mli=new syntaxModeListItem; |
67 | mli->name = config->readEntry("name",""); | 71 | mli->name = config->readEntry("name",""); |
68 | mli->section = config->readEntry("section",""); | 72 | mli->section = config->readEntry("section",""); |
69 | mli->mimetype = config->readEntry("mimetype",""); | 73 | mli->mimetype = config->readEntry("mimetype",""); |
70 | mli->extension = config->readEntry("extension",""); | 74 | mli->extension = config->readEntry("extension",""); |
71 | mli->identifier = *it; | 75 | mli->identifier = *it; |
72 | myModeList.append(mli); | 76 | myModeList.append(mli); |
73 | } | 77 | } |
74 | else | 78 | else |
75 | { | 79 | { |
76 | qDebug("Found a description file:"+(*it)); | 80 | qDebug("Found a description file:"+path+(*it)); |
77 | setIdentifier(*it); | 81 | setIdentifier(path+(*it)); |
78 | Opie::XMLElement *e=m_root; | 82 | Opie::XMLElement *e=m_root; |
79 | if (e) | 83 | if (e) |
80 | { | 84 | { |
81 | e=e->firstChild(); | 85 | e=e->firstChild(); |
82 | qDebug(e->tagName()); | 86 | qDebug(e->tagName()); |
83 | if (e->tagName()=="language") | 87 | if (e->tagName()=="language") |
84 | { | 88 | { |
85 | syntaxModeListItem *mli=new syntaxModeListItem; | 89 | syntaxModeListItem *mli=new syntaxModeListItem; |
86 | mli->name = e->attribute("name"); | 90 | mli->name = e->attribute("name"); |
87 | mli->section = e->attribute("section"); | 91 | mli->section = e->attribute("section"); |
88 | mli->mimetype = e->attribute("mimetype"); | 92 | mli->mimetype = e->attribute("mimetype"); |
89 | mli->extension = e->attribute("extensions"); | 93 | mli->extension = e->attribute("extensions"); |
90 | qDebug(QString("valid description for: %1/%2").arg(mli->section).arg(mli->name)); | 94 | qDebug(QString("valid description for: %1/%2").arg(mli->section).arg(mli->name)); |
91 | if (mli->section.isEmpty()) | 95 | if (mli->section.isEmpty()) |
92 | mli->section=i18n("Other"); | 96 | mli->section=i18n("Other"); |
93 | 97 | ||
94 | mli->identifier = *it; | 98 | mli->identifier = path+(*it); |
95 | #warning fixme | 99 | #warning fixme |
96 | /* | 100 | /* |
97 | config->setGroup(Group); | 101 | config->setGroup(Group); |
98 | config->writeEntry("name",mli->name); | 102 | config->writeEntry("name",mli->name); |
99 | config->writeEntry("section",mli->section); | 103 | config->writeEntry("section",mli->section); |
100 | config->writeEntry("mimetype",mli->mimetype); | 104 | config->writeEntry("mimetype",mli->mimetype); |
101 | config->writeEntry("extension",mli->extension); | 105 | config->writeEntry("extension",mli->extension); |
102 | */ | 106 | */ |
103 | myModeList.append(mli); | 107 | myModeList.append(mli); |
104 | } | 108 | } |
105 | } | 109 | } |
106 | } | 110 | } |
107 | } | 111 | } |
108 | // } | 112 | // } |
109 | 113 | ||
110 | // config->sync(); | 114 | // config->sync(); |
111 | } | 115 | } |
112 | 116 | ||
113 | SyntaxModeList SyntaxDocument::modeList() | 117 | SyntaxModeList SyntaxDocument::modeList() |
114 | { | 118 | { |
115 | return myModeList; | 119 | return myModeList; |
116 | } | 120 | } |
117 | 121 | ||
118 | bool SyntaxDocument::nextGroup( syntaxContextData* data) | 122 | bool SyntaxDocument::nextGroup( syntaxContextData* data) |
119 | { | 123 | { |
120 | if(!data) return false; | 124 | if(!data) return false; |
121 | 125 | ||
122 | if (!data->currentGroup) | 126 | if (!data->currentGroup) |
123 | data->currentGroup=data->parent->firstChild(); | 127 | data->currentGroup=data->parent->firstChild(); |
124 | else | 128 | else |
125 | data->currentGroup=data->currentGroup->nextChild(); | 129 | data->currentGroup=data->currentGroup->nextChild(); |
126 | 130 | ||
127 | data->item=0; | 131 | data->item=0; |
128 | 132 | ||
129 | if (!data->currentGroup) | 133 | if (!data->currentGroup) |
130 | return false; | 134 | return false; |
131 | else | 135 | else |
132 | return true; | 136 | return true; |
133 | } | 137 | } |
134 | 138 | ||
135 | bool SyntaxDocument::nextItem( syntaxContextData* data) | 139 | bool SyntaxDocument::nextItem( syntaxContextData* data) |
136 | { | 140 | { |
137 | if(!data) return false; | 141 | if(!data) return false; |
138 | 142 | ||
139 | if (!data->item) | 143 | if (!data->item) |
140 | data->item=data->currentGroup->firstChild(); | 144 | data->item=data->currentGroup->firstChild(); |
141 | else | 145 | else |
142 | data->item=data->item->nextChild(); | 146 | data->item=data->item->nextChild(); |
143 | 147 | ||
144 | if (!data->item) | 148 | if (!data->item) |
145 | return false; | 149 | return false; |
146 | else | 150 | else |
147 | return true; | 151 | return true; |
148 | } | 152 | } |
149 | 153 | ||
150 | QString SyntaxDocument::groupItemData( syntaxContextData* data,QString name) | 154 | QString SyntaxDocument::groupItemData( syntaxContextData* data,QString name) |
151 | { | 155 | { |
152 | if(!data) | 156 | if(!data) |
153 | return QString::null; | 157 | return QString::null; |
154 | 158 | ||
155 | if ( (data->item) && (name.isEmpty())) | 159 | if ( (data->item) && (name.isEmpty())) |
156 | return data->item->tagName(); | 160 | return data->item->tagName(); |
157 | 161 | ||
158 | if (data->item) | 162 | if (data->item) |
159 | return data->item->attribute(name); | 163 | return data->item->attribute(name); |
160 | else | 164 | else |
161 | return QString(); | 165 | return QString(); |
162 | } | 166 | } |
163 | 167 | ||
164 | QString SyntaxDocument::groupData( syntaxContextData* data,QString name) | 168 | QString SyntaxDocument::groupData( syntaxContextData* data,QString name) |
165 | { | 169 | { |
166 | if(!data) | 170 | if(!data) |
167 | return QString::null; | 171 | return QString::null; |
168 | 172 | ||
169 | if (data->currentGroup) | 173 | if (data->currentGroup) |
170 | return data->currentGroup->attribute(name); | 174 | return data->currentGroup->attribute(name); |
171 | else | 175 | else |
172 | return QString(); | 176 | return QString(); |
173 | } | 177 | } |
174 | 178 | ||
175 | void SyntaxDocument::freeGroupInfo( syntaxContextData* data) | 179 | void SyntaxDocument::freeGroupInfo( syntaxContextData* data) |
176 | { | 180 | { |
177 | if (data) | 181 | if (data) |
178 | delete data; | 182 | delete data; |
179 | } | 183 | } |
180 | 184 | ||
181 | syntaxContextData* SyntaxDocument::getSubItems(syntaxContextData* data) | 185 | syntaxContextData* SyntaxDocument::getSubItems(syntaxContextData* data) |
182 | { | 186 | { |
183 | syntaxContextData *retval=new syntaxContextData; | 187 | syntaxContextData *retval=new syntaxContextData; |
184 | retval->parent=0; | 188 | retval->parent=0; |
185 | retval->currentGroup=0; | 189 | retval->currentGroup=0; |
186 | retval->item=0; | 190 | retval->item=0; |
187 | if (data != 0) | 191 | if (data != 0) |
188 | { | 192 | { |
189 | retval->parent=data->currentGroup; | 193 | retval->parent=data->currentGroup; |
190 | retval->currentGroup=data->item; | 194 | retval->currentGroup=data->item; |
191 | retval->item=0; | 195 | retval->item=0; |
192 | } | 196 | } |
193 | 197 | ||
194 | return retval; | 198 | return retval; |
195 | } | 199 | } |
196 | 200 | ||
197 | syntaxContextData* SyntaxDocument::getConfig(const QString& mainGroupName, const QString &Config) | 201 | syntaxContextData* SyntaxDocument::getConfig(const QString& mainGroupName, const QString &Config) |
198 | { | 202 | { |
199 | Opie::XMLElement *e = m_root->firstChild()->firstChild(); | 203 | Opie::XMLElement *e = m_root->firstChild()->firstChild(); |
200 | 204 | ||
201 | while (e) | 205 | while (e) |
202 | { | 206 | { |
203 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl; | 207 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl; |
204 | 208 | ||
205 | if (e->tagName().compare(mainGroupName)==0 ) | 209 | if (e->tagName().compare(mainGroupName)==0 ) |
206 | { | 210 | { |
207 | Opie::XMLElement *e1=e->firstChild(); | 211 | Opie::XMLElement *e1=e->firstChild(); |
208 | 212 | ||
209 | while (e1) | 213 | while (e1) |
210 | { | 214 | { |
211 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl; | 215 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl; |
212 | 216 | ||
213 | if (e1->tagName()==Config) | 217 | if (e1->tagName()==Config) |
214 | { | 218 | { |
215 | syntaxContextData *data=new ( syntaxContextData); | 219 | syntaxContextData *data=new ( syntaxContextData); |
216 | data->currentGroup=0; | 220 | data->currentGroup=0; |
217 | data->parent=0; | 221 | data->parent=0; |
218 | data->item=e1; | 222 | data->item=e1; |
219 | return data; | 223 | return data; |
220 | } | 224 | } |
221 | 225 | ||
222 | e1=e1->nextChild(); | 226 | e1=e1->nextChild(); |
223 | } | 227 | } |
224 | 228 | ||
225 | kdDebug(13010) << "WARNING :returning null 3"<< endl; | 229 | kdDebug(13010) << "WARNING :returning null 3"<< endl; |
226 | return 0; | 230 | return 0; |
227 | } | 231 | } |
228 | 232 | ||
229 | e=e->nextChild(); | 233 | e=e->nextChild(); |
230 | } | 234 | } |
231 | 235 | ||
232 | kdDebug(13010) << "WARNING :returning null 4" << endl; | 236 | kdDebug(13010) << "WARNING :returning null 4" << endl; |
233 | return 0; | 237 | return 0; |
234 | } | 238 | } |
235 | 239 | ||
236 | 240 | ||
237 | 241 | ||
238 | syntaxContextData* SyntaxDocument::getGroupInfo(const QString& mainGroupName, const QString &group) | 242 | syntaxContextData* SyntaxDocument::getGroupInfo(const QString& mainGroupName, const QString &group) |
239 | { | 243 | { |
240 | 244 | ||
241 | Opie::XMLElement *e=m_root->firstChild()->firstChild(); | 245 | Opie::XMLElement *e=m_root->firstChild()->firstChild(); |
242 | 246 | ||
243 | while (e) | 247 | while (e) |
244 | { | 248 | { |
245 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl; | 249 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl; |
246 | 250 | ||
247 | if (e->tagName().compare(mainGroupName)==0 ) | 251 | if (e->tagName().compare(mainGroupName)==0 ) |
248 | { | 252 | { |
249 | Opie::XMLElement *e1=e->firstChild(); | 253 | Opie::XMLElement *e1=e->firstChild(); |
250 | 254 | ||
251 | while (e1) | 255 | while (e1) |
252 | { | 256 | { |
253 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl; | 257 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl; |
254 | if (e1->tagName()==group+"s") | 258 | if (e1->tagName()==group+"s") |
255 | { | 259 | { |
256 | syntaxContextData *data=new ( syntaxContextData); | 260 | syntaxContextData *data=new ( syntaxContextData); |
257 | data->parent=e1; | 261 | data->parent=e1; |
258 | data->currentGroup=0; | 262 | data->currentGroup=0; |
259 | data->item=0; | 263 | data->item=0; |
260 | return data; | 264 | return data; |
261 | } | 265 | } |
262 | 266 | ||
263 | e1=e1->nextChild(); | 267 | e1=e1->nextChild(); |
264 | } | 268 | } |
265 | 269 | ||
266 | kdDebug(13010) << "WARNING : getGroupInfo returning null :1 " << endl; | 270 | kdDebug(13010) << "WARNING : getGroupInfo returning null :1 " << endl; |
267 | return 0; | 271 | return 0; |
268 | } | 272 | } |
269 | 273 | ||
270 | e=e->nextChild(); | 274 | e=e->nextChild(); |
271 | } | 275 | } |
272 | 276 | ||
273 | kdDebug(13010) << "WARNING : getGroupInfo returning null :2" << endl; | 277 | kdDebug(13010) << "WARNING : getGroupInfo returning null :2" << endl; |
274 | return 0; | 278 | return 0; |
275 | } | 279 | } |
276 | 280 | ||
277 | 281 | ||
278 | QStringList& SyntaxDocument::finddata(const QString& mainGroup,const QString& type,bool clearList) | 282 | QStringList& SyntaxDocument::finddata(const QString& mainGroup,const QString& type,bool clearList) |
279 | { | 283 | { |
280 | Opie::XMLElement *e = m_root->firstChild(); | 284 | Opie::XMLElement *e = m_root->firstChild(); |
281 | if (clearList) | 285 | if (clearList) |
282 | m_data.clear(); | 286 | m_data.clear(); |
283 | 287 | ||
284 | for(e=e->firstChild(); e; e=e->nextChild()) | 288 | for(e=e->firstChild(); e; e=e->nextChild()) |
285 | { | 289 | { |
286 | if (e->tagName()==mainGroup) | 290 | if (e->tagName()==mainGroup) |
287 | { | 291 | { |
288 | for (Opie::XMLElement *e1=e->firstChild();e1;e1=e1->nextChild()) | 292 | for (Opie::XMLElement *e1=e->firstChild();e1;e1=e1->nextChild()) |
289 | { | 293 | { |
290 | if (e1->tagName()!="list") continue; | 294 | if (e1->tagName()!="list") continue; |
291 | 295 | ||
292 | if (e1->attribute("name")==type) | 296 | if (e1->attribute("name")==type) |
293 | { | 297 | { |
294 | for (Opie::XMLElement *e2=e1->firstChild();e2;e2=e2->nextChild()) | 298 | for (Opie::XMLElement *e2=e1->firstChild();e2;e2=e2->nextChild()) |
295 | qDebug("FOUND A LIST ENTRY("+e2->tagName()+"):"+e2->value()); | 299 | qDebug("FOUND A LIST ENTRY("+e2->tagName()+"):"+e2->value()); |
296 | m_data+="TEST";//e2->value().stripWhiteSpace(); | 300 | m_data+="TEST";//e2->value().stripWhiteSpace(); |
297 | 301 | ||
298 | break; | 302 | break; |
299 | } | 303 | } |
300 | } | 304 | } |
301 | break; | 305 | break; |
302 | } | 306 | } |
303 | } | 307 | } |
304 | 308 | ||
305 | return m_data; | 309 | return m_data; |
306 | } | 310 | } |