author | jowenn <jowenn> | 2002-11-11 20:37:06 (UTC) |
---|---|---|
committer | jowenn <jowenn> | 2002-11-11 20:37:06 (UTC) |
commit | da541da2e5cec28acb36cbd6e9c04a76375b4ac7 (patch) (unidiff) | |
tree | f016ecc7faaeb45f03674e7239982645da42e8cc | |
parent | 6a0fc9de7e89357095b9efc3dace5c92042291ac (diff) | |
download | opie-da541da2e5cec28acb36cbd6e9c04a76375b4ac7.zip opie-da541da2e5cec28acb36cbd6e9c04a76375b4ac7.tar.gz opie-da541da2e5cec28acb36cbd6e9c04a76375b4ac7.tar.bz2 |
Read keyword lists again
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp b/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp index 3390bdb..e45daa4 100644 --- a/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp +++ b/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp | |||
@@ -1,310 +1,311 @@ | |||
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 | #include <qpe/qpeapplication.h> | 27 | #include <qpe/qpeapplication.h> |
28 | #include <qdir.h> | 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/"; | 58 | QString path=QPEApplication::qpeDir() +"share/tinykate/syntax/"; |
59 | 59 | ||
60 | QDir dir(path); | 60 | QDir dir(path); |
61 | QStringList list=dir.entryList("*.xml"); | 61 | QStringList list=dir.entryList("*.xml"); |
62 | 62 | ||
63 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) | 63 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) |
64 | { | 64 | { |
65 | QString Group="Highlighting_Cache"+path+*it; | 65 | QString Group="Highlighting_Cache"+path+*it; |
66 | 66 | ||
67 | if ((config->hasGroup(Group)) && (!force)) | 67 | if ((config->hasGroup(Group)) && (!force)) |
68 | { | 68 | { |
69 | config->setGroup(Group); | 69 | config->setGroup(Group); |
70 | syntaxModeListItem *mli=new syntaxModeListItem; | 70 | syntaxModeListItem *mli=new syntaxModeListItem; |
71 | mli->name = config->readEntry("name",""); | 71 | mli->name = config->readEntry("name",""); |
72 | mli->section = config->readEntry("section",""); | 72 | mli->section = config->readEntry("section",""); |
73 | mli->mimetype = config->readEntry("mimetype",""); | 73 | mli->mimetype = config->readEntry("mimetype",""); |
74 | mli->extension = config->readEntry("extension",""); | 74 | mli->extension = config->readEntry("extension",""); |
75 | mli->identifier = *it; | 75 | mli->identifier = *it; |
76 | myModeList.append(mli); | 76 | myModeList.append(mli); |
77 | } | 77 | } |
78 | else | 78 | else |
79 | { | 79 | { |
80 | qDebug("Found a description file:"+path+(*it)); | 80 | qDebug("Found a description file:"+path+(*it)); |
81 | setIdentifier(path+(*it)); | 81 | setIdentifier(path+(*it)); |
82 | Opie::XMLElement *e=m_root; | 82 | Opie::XMLElement *e=m_root; |
83 | if (e) | 83 | if (e) |
84 | { | 84 | { |
85 | e=e->firstChild(); | 85 | e=e->firstChild(); |
86 | qDebug(e->tagName()); | 86 | qDebug(e->tagName()); |
87 | if (e->tagName()=="language") | 87 | if (e->tagName()=="language") |
88 | { | 88 | { |
89 | syntaxModeListItem *mli=new syntaxModeListItem; | 89 | syntaxModeListItem *mli=new syntaxModeListItem; |
90 | mli->name = e->attribute("name"); | 90 | mli->name = e->attribute("name"); |
91 | mli->section = e->attribute("section"); | 91 | mli->section = e->attribute("section"); |
92 | mli->mimetype = e->attribute("mimetype"); | 92 | mli->mimetype = e->attribute("mimetype"); |
93 | mli->extension = e->attribute("extensions"); | 93 | mli->extension = e->attribute("extensions"); |
94 | 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)); |
95 | if (mli->section.isEmpty()) | 95 | if (mli->section.isEmpty()) |
96 | mli->section=i18n("Other"); | 96 | mli->section=i18n("Other"); |
97 | 97 | ||
98 | mli->identifier = path+(*it); | 98 | mli->identifier = path+(*it); |
99 | #warning fixme | 99 | #warning fixme |
100 | /* | 100 | /* |
101 | config->setGroup(Group); | 101 | config->setGroup(Group); |
102 | config->writeEntry("name",mli->name); | 102 | config->writeEntry("name",mli->name); |
103 | config->writeEntry("section",mli->section); | 103 | config->writeEntry("section",mli->section); |
104 | config->writeEntry("mimetype",mli->mimetype); | 104 | config->writeEntry("mimetype",mli->mimetype); |
105 | config->writeEntry("extension",mli->extension); | 105 | config->writeEntry("extension",mli->extension); |
106 | */ | 106 | */ |
107 | myModeList.append(mli); | 107 | myModeList.append(mli); |
108 | } | 108 | } |
109 | } | 109 | } |
110 | } | 110 | } |
111 | } | 111 | } |
112 | // } | 112 | // } |
113 | 113 | ||
114 | // config->sync(); | 114 | // config->sync(); |
115 | } | 115 | } |
116 | 116 | ||
117 | SyntaxModeList SyntaxDocument::modeList() | 117 | SyntaxModeList SyntaxDocument::modeList() |
118 | { | 118 | { |
119 | return myModeList; | 119 | return myModeList; |
120 | } | 120 | } |
121 | 121 | ||
122 | bool SyntaxDocument::nextGroup( syntaxContextData* data) | 122 | bool SyntaxDocument::nextGroup( syntaxContextData* data) |
123 | { | 123 | { |
124 | if(!data) return false; | 124 | if(!data) return false; |
125 | 125 | ||
126 | if (!data->currentGroup) | 126 | if (!data->currentGroup) |
127 | data->currentGroup=data->parent->firstChild(); | 127 | data->currentGroup=data->parent->firstChild(); |
128 | else | 128 | else |
129 | data->currentGroup=data->currentGroup->nextChild(); | 129 | data->currentGroup=data->currentGroup->nextChild(); |
130 | 130 | ||
131 | data->item=0; | 131 | data->item=0; |
132 | 132 | ||
133 | if (!data->currentGroup) | 133 | if (!data->currentGroup) |
134 | return false; | 134 | return false; |
135 | else | 135 | else |
136 | return true; | 136 | return true; |
137 | } | 137 | } |
138 | 138 | ||
139 | bool SyntaxDocument::nextItem( syntaxContextData* data) | 139 | bool SyntaxDocument::nextItem( syntaxContextData* data) |
140 | { | 140 | { |
141 | if(!data) return false; | 141 | if(!data) return false; |
142 | 142 | ||
143 | if (!data->item) | 143 | if (!data->item) |
144 | data->item=data->currentGroup->firstChild(); | 144 | data->item=data->currentGroup->firstChild(); |
145 | else | 145 | else |
146 | data->item=data->item->nextChild(); | 146 | data->item=data->item->nextChild(); |
147 | 147 | ||
148 | if (!data->item) | 148 | if (!data->item) |
149 | return false; | 149 | return false; |
150 | else | 150 | else |
151 | return true; | 151 | return true; |
152 | } | 152 | } |
153 | 153 | ||
154 | QString SyntaxDocument::groupItemData( syntaxContextData* data,QString name) | 154 | QString SyntaxDocument::groupItemData( syntaxContextData* data,QString name) |
155 | { | 155 | { |
156 | if(!data) | 156 | if(!data) |
157 | return QString::null; | 157 | return QString::null; |
158 | 158 | ||
159 | if ( (data->item) && (name.isEmpty())) | 159 | if ( (data->item) && (name.isEmpty())) |
160 | return data->item->tagName(); | 160 | return data->item->tagName(); |
161 | 161 | ||
162 | if (data->item) | 162 | if (data->item) |
163 | return data->item->attribute(name); | 163 | return data->item->attribute(name); |
164 | else | 164 | else |
165 | return QString(); | 165 | return QString(); |
166 | } | 166 | } |
167 | 167 | ||
168 | QString SyntaxDocument::groupData( syntaxContextData* data,QString name) | 168 | QString SyntaxDocument::groupData( syntaxContextData* data,QString name) |
169 | { | 169 | { |
170 | if(!data) | 170 | if(!data) |
171 | return QString::null; | 171 | return QString::null; |
172 | 172 | ||
173 | if (data->currentGroup) | 173 | if (data->currentGroup) |
174 | return data->currentGroup->attribute(name); | 174 | return data->currentGroup->attribute(name); |
175 | else | 175 | else |
176 | return QString(); | 176 | return QString(); |
177 | } | 177 | } |
178 | 178 | ||
179 | void SyntaxDocument::freeGroupInfo( syntaxContextData* data) | 179 | void SyntaxDocument::freeGroupInfo( syntaxContextData* data) |
180 | { | 180 | { |
181 | if (data) | 181 | if (data) |
182 | delete data; | 182 | delete data; |
183 | } | 183 | } |
184 | 184 | ||
185 | syntaxContextData* SyntaxDocument::getSubItems(syntaxContextData* data) | 185 | syntaxContextData* SyntaxDocument::getSubItems(syntaxContextData* data) |
186 | { | 186 | { |
187 | syntaxContextData *retval=new syntaxContextData; | 187 | syntaxContextData *retval=new syntaxContextData; |
188 | retval->parent=0; | 188 | retval->parent=0; |
189 | retval->currentGroup=0; | 189 | retval->currentGroup=0; |
190 | retval->item=0; | 190 | retval->item=0; |
191 | if (data != 0) | 191 | if (data != 0) |
192 | { | 192 | { |
193 | retval->parent=data->currentGroup; | 193 | retval->parent=data->currentGroup; |
194 | retval->currentGroup=data->item; | 194 | retval->currentGroup=data->item; |
195 | retval->item=0; | 195 | retval->item=0; |
196 | } | 196 | } |
197 | 197 | ||
198 | return retval; | 198 | return retval; |
199 | } | 199 | } |
200 | 200 | ||
201 | syntaxContextData* SyntaxDocument::getConfig(const QString& mainGroupName, const QString &Config) | 201 | syntaxContextData* SyntaxDocument::getConfig(const QString& mainGroupName, const QString &Config) |
202 | { | 202 | { |
203 | Opie::XMLElement *e = m_root->firstChild()->firstChild(); | 203 | Opie::XMLElement *e = m_root->firstChild()->firstChild(); |
204 | 204 | ||
205 | while (e) | 205 | while (e) |
206 | { | 206 | { |
207 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl; | 207 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl; |
208 | 208 | ||
209 | if (e->tagName().compare(mainGroupName)==0 ) | 209 | if (e->tagName().compare(mainGroupName)==0 ) |
210 | { | 210 | { |
211 | Opie::XMLElement *e1=e->firstChild(); | 211 | Opie::XMLElement *e1=e->firstChild(); |
212 | 212 | ||
213 | while (e1) | 213 | while (e1) |
214 | { | 214 | { |
215 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl; | 215 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl; |
216 | 216 | ||
217 | if (e1->tagName()==Config) | 217 | if (e1->tagName()==Config) |
218 | { | 218 | { |
219 | syntaxContextData *data=new ( syntaxContextData); | 219 | syntaxContextData *data=new ( syntaxContextData); |
220 | data->currentGroup=0; | 220 | data->currentGroup=0; |
221 | data->parent=0; | 221 | data->parent=0; |
222 | data->item=e1; | 222 | data->item=e1; |
223 | return data; | 223 | return data; |
224 | } | 224 | } |
225 | 225 | ||
226 | e1=e1->nextChild(); | 226 | e1=e1->nextChild(); |
227 | } | 227 | } |
228 | 228 | ||
229 | kdDebug(13010) << "WARNING :returning null 3"<< endl; | 229 | kdDebug(13010) << "WARNING :returning null 3"<< endl; |
230 | return 0; | 230 | return 0; |
231 | } | 231 | } |
232 | 232 | ||
233 | e=e->nextChild(); | 233 | e=e->nextChild(); |
234 | } | 234 | } |
235 | 235 | ||
236 | kdDebug(13010) << "WARNING :returning null 4" << endl; | 236 | kdDebug(13010) << "WARNING :returning null 4" << endl; |
237 | return 0; | 237 | return 0; |
238 | } | 238 | } |
239 | 239 | ||
240 | 240 | ||
241 | 241 | ||
242 | syntaxContextData* SyntaxDocument::getGroupInfo(const QString& mainGroupName, const QString &group) | 242 | syntaxContextData* SyntaxDocument::getGroupInfo(const QString& mainGroupName, const QString &group) |
243 | { | 243 | { |
244 | 244 | ||
245 | Opie::XMLElement *e=m_root->firstChild()->firstChild(); | 245 | Opie::XMLElement *e=m_root->firstChild()->firstChild(); |
246 | 246 | ||
247 | while (e) | 247 | while (e) |
248 | { | 248 | { |
249 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl; | 249 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl; |
250 | 250 | ||
251 | if (e->tagName().compare(mainGroupName)==0 ) | 251 | if (e->tagName().compare(mainGroupName)==0 ) |
252 | { | 252 | { |
253 | Opie::XMLElement *e1=e->firstChild(); | 253 | Opie::XMLElement *e1=e->firstChild(); |
254 | 254 | ||
255 | while (e1) | 255 | while (e1) |
256 | { | 256 | { |
257 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl; | 257 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl; |
258 | if (e1->tagName()==group+"s") | 258 | if (e1->tagName()==group+"s") |
259 | { | 259 | { |
260 | syntaxContextData *data=new ( syntaxContextData); | 260 | syntaxContextData *data=new ( syntaxContextData); |
261 | data->parent=e1; | 261 | data->parent=e1; |
262 | data->currentGroup=0; | 262 | data->currentGroup=0; |
263 | data->item=0; | 263 | data->item=0; |
264 | return data; | 264 | return data; |
265 | } | 265 | } |
266 | 266 | ||
267 | e1=e1->nextChild(); | 267 | e1=e1->nextChild(); |
268 | } | 268 | } |
269 | 269 | ||
270 | kdDebug(13010) << "WARNING : getGroupInfo returning null :1 " << endl; | 270 | kdDebug(13010) << "WARNING : getGroupInfo returning null :1 " << endl; |
271 | return 0; | 271 | return 0; |
272 | } | 272 | } |
273 | 273 | ||
274 | e=e->nextChild(); | 274 | e=e->nextChild(); |
275 | } | 275 | } |
276 | 276 | ||
277 | kdDebug(13010) << "WARNING : getGroupInfo returning null :2" << endl; | 277 | kdDebug(13010) << "WARNING : getGroupInfo returning null :2" << endl; |
278 | return 0; | 278 | return 0; |
279 | } | 279 | } |
280 | 280 | ||
281 | 281 | ||
282 | QStringList& SyntaxDocument::finddata(const QString& mainGroup,const QString& type,bool clearList) | 282 | QStringList& SyntaxDocument::finddata(const QString& mainGroup,const QString& type,bool clearList) |
283 | { | 283 | { |
284 | Opie::XMLElement *e = m_root->firstChild(); | 284 | Opie::XMLElement *e = m_root->firstChild(); |
285 | if (clearList) | 285 | if (clearList) |
286 | m_data.clear(); | 286 | m_data.clear(); |
287 | 287 | ||
288 | for(e=e->firstChild(); e; e=e->nextChild()) | 288 | for(e=e->firstChild(); e; e=e->nextChild()) |
289 | { | 289 | { |
290 | if (e->tagName()==mainGroup) | 290 | if (e->tagName()==mainGroup) |
291 | { | 291 | { |
292 | for (Opie::XMLElement *e1=e->firstChild();e1;e1=e1->nextChild()) | 292 | for (Opie::XMLElement *e1=e->firstChild();e1;e1=e1->nextChild()) |
293 | { | 293 | { |
294 | if (e1->tagName()!="list") continue; | 294 | if (e1->tagName()!="list") continue; |
295 | 295 | ||
296 | if (e1->attribute("name")==type) | 296 | if (e1->attribute("name")==type) |
297 | { | 297 | { |
298 | for (Opie::XMLElement *e2=e1->firstChild();e2;e2=e2->nextChild()) | 298 | for (Opie::XMLElement *e2=e1->firstChild();e2;e2=e2->nextChild()) |
299 | qDebug("FOUND A LIST ENTRY("+e2->tagName()+"):"+e2->value()); | 299 | { |
300 | m_data+="TEST";//e2->value().stripWhiteSpace(); | 300 | qDebug("FOUND A LIST ENTRY("+e2->tagName()+"):"+e2->firstChild()->value()); |
301 | 301 | m_data+=e2->firstChild()->value().stripWhiteSpace(); | |
302 | } | ||
302 | break; | 303 | break; |
303 | } | 304 | } |
304 | } | 305 | } |
305 | break; | 306 | break; |
306 | } | 307 | } |
307 | } | 308 | } |
308 | 309 | ||
309 | return m_data; | 310 | return m_data; |
310 | } | 311 | } |