19 files changed, 835 insertions, 308 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.cpp b/noncore/apps/tinykate/libkate/document/katedocument.cpp index df1de8d..6807544 100644 --- a/noncore/apps/tinykate/libkate/document/katedocument.cpp +++ b/noncore/apps/tinykate/libkate/document/katedocument.cpp | |||
@@ -1,3177 +1,3176 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | katedocument.cpp - description | 2 | katedocument.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Jan 15 2001 | 4 | begin : Mon Jan 15 2001 |
5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann | 5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann |
6 | (C) 2002 by Joseph Wenninger | 6 | (C) 2002 by Joseph Wenninger |
7 | email : crossfire@babylon2k.de | 7 | email : crossfire@babylon2k.de |
8 | jowenn@kde.org | 8 | jowenn@kde.org |
9 | 9 | ||
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * * | 13 | * * |
14 | * This program is free software; you can redistribute it and/or modify * | 14 | * This program is free software; you can redistribute it and/or modify * |
15 | * it under the terms of the GNU General Public License as published by * | 15 | * it under the terms of the GNU General Public License as published by * |
16 | * the Free Software Foundation; either version 2 of the License, or * | 16 | * the Free Software Foundation; either version 2 of the License, or * |
17 | * (at your option) any later version. * | 17 | * (at your option) any later version. * |
18 | * * | 18 | * * |
19 | ***************************************************************************/ | 19 | ***************************************************************************/ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Copyright (C) 1998, 1999 Jochen Wilhelmy | 22 | Copyright (C) 1998, 1999 Jochen Wilhelmy |
23 | digisnap@cs.tu-berlin.de | 23 | digisnap@cs.tu-berlin.de |
24 | 24 | ||
25 | This library is free software; you can redistribute it and/or | 25 | This library is free software; you can redistribute it and/or |
26 | modify it under the terms of the GNU Library General Public | 26 | modify it under the terms of the GNU Library General Public |
27 | License as published by the Free Software Foundation; either | 27 | License as published by the Free Software Foundation; either |
28 | version 2 of the License, or (at your option) any later version. | 28 | version 2 of the License, or (at your option) any later version. |
29 | 29 | ||
30 | This library is distributed in the hope that it will be useful, | 30 | This library is distributed in the hope that it will be useful, |
31 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 31 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
33 | Library General Public License for more details. | 33 | Library General Public License for more details. |
34 | 34 | ||
35 | You should have received a copy of the GNU Library General Public License | 35 | You should have received a copy of the GNU Library General Public License |
36 | along with this library; see the file COPYING.LIB. If not, write to | 36 | along with this library; see the file COPYING.LIB. If not, write to |
37 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 37 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
38 | Boston, MA 02111-1307, USA. | 38 | Boston, MA 02111-1307, USA. |
39 | */ | 39 | */ |
40 | 40 | ||
41 | #include "katedocument.h" | 41 | #include "katedocument.h" |
42 | 42 | ||
43 | 43 | ||
44 | #include <qfileinfo.h> | 44 | #include <qfileinfo.h> |
45 | #include <qdatetime.h> | 45 | #include <qdatetime.h> |
46 | 46 | ||
47 | #include <kmessagebox.h> | 47 | #include <kmessagebox.h> |
48 | #include <klocale.h> | 48 | #include <klocale.h> |
49 | #include <qpe/config.h> | 49 | #include <qpe/config.h> |
50 | #include <qstring.h> | 50 | #include <qstring.h> |
51 | 51 | ||
52 | #include <sys/time.h> | 52 | #include <sys/time.h> |
53 | #include <unistd.h> | 53 | #include <unistd.h> |
54 | 54 | ||
55 | #include <stdio.h> | 55 | #include <stdio.h> |
56 | 56 | ||
57 | #include <qtimer.h> | 57 | #include <qtimer.h> |
58 | #include <qobject.h> | 58 | #include <qobject.h> |
59 | #include <qapplication.h> | 59 | #include <qapplication.h> |
60 | #include <qclipboard.h> | 60 | #include <qclipboard.h> |
61 | #include <qfont.h> | 61 | #include <qfont.h> |
62 | #include <qpainter.h> | 62 | #include <qpainter.h> |
63 | #include <qfile.h> | 63 | #include <qfile.h> |
64 | #include <qtextstream.h> | 64 | #include <qtextstream.h> |
65 | #include <qtextcodec.h> | 65 | #include <qtextcodec.h> |
66 | #include <kglobal.h> | 66 | #include <kglobal.h> |
67 | 67 | ||
68 | #include <klocale.h> | 68 | #include <klocale.h> |
69 | //#include <kcharsets.h> | 69 | //#include <kcharsets.h> |
70 | #include <kdebug.h> | 70 | #include <kdebug.h> |
71 | //#include <kinstance.h> | 71 | //#include <kinstance.h> |
72 | 72 | ||
73 | #include <kglobalsettings.h> | 73 | #include <kglobalsettings.h> |
74 | //#include <kaction.h> | 74 | //#include <kaction.h> |
75 | //#include <kstdaction.h> | 75 | //#include <kstdaction.h> |
76 | 76 | ||
77 | #include "../view/kateview.h" | 77 | #include "../view/kateview.h" |
78 | #include "katebuffer.h" | 78 | #include "katebuffer.h" |
79 | #include "katetextline.h" | 79 | #include "katetextline.h" |
80 | 80 | ||
81 | #include "katecmd.h" | 81 | #include "katecmd.h" |
82 | 82 | ||
83 | KateAction::KateAction(Action a, PointStruc &cursor, int len, const QString &text) | 83 | KateAction::KateAction(Action a, PointStruc &cursor, int len, const QString &text) |
84 | : action(a), cursor(cursor), len(len), text(text) { | 84 | : action(a), cursor(cursor), len(len), text(text) { |
85 | } | 85 | } |
86 | 86 | ||
87 | KateActionGroup::KateActionGroup(PointStruc &aStart, int type) | 87 | KateActionGroup::KateActionGroup(PointStruc &aStart, int type) |
88 | : start(aStart), action(0L), undoType(type) { | 88 | : start(aStart), action(0L), undoType(type) { |
89 | } | 89 | } |
90 | 90 | ||
91 | KateActionGroup::~KateActionGroup() { | 91 | KateActionGroup::~KateActionGroup() { |
92 | KateAction *current, *next; | 92 | KateAction *current, *next; |
93 | 93 | ||
94 | current = action; | 94 | current = action; |
95 | while (current) { | 95 | while (current) { |
96 | next = current->next; | 96 | next = current->next; |
97 | delete current; | 97 | delete current; |
98 | current = next; | 98 | current = next; |
99 | } | 99 | } |
100 | } | 100 | } |
101 | 101 | ||
102 | void KateActionGroup::insertAction(KateAction *a) { | 102 | void KateActionGroup::insertAction(KateAction *a) { |
103 | a->next = action; | 103 | a->next = action; |
104 | action = a; | 104 | action = a; |
105 | } | 105 | } |
106 | 106 | ||
107 | const char * KateActionGroup::typeName(int type) | 107 | const char * KateActionGroup::typeName(int type) |
108 | { | 108 | { |
109 | // return a short text description of the given undo group type suitable for a menu | 109 | // return a short text description of the given undo group type suitable for a menu |
110 | // not the lack of i18n's, the caller is expected to handle translation | 110 | // not the lack of i18n's, the caller is expected to handle translation |
111 | switch (type) { | 111 | switch (type) { |
112 | case ugPaste : return "Paste Text"; | 112 | case ugPaste : return "Paste Text"; |
113 | case ugDelBlock : return "Selection Overwrite"; | 113 | case ugDelBlock : return "Selection Overwrite"; |
114 | case ugIndent : return "Indent"; | 114 | case ugIndent : return "Indent"; |
115 | case ugUnindent : return "Unindent"; | 115 | case ugUnindent : return "Unindent"; |
116 | case ugComment : return "Comment"; | 116 | case ugComment : return "Comment"; |
117 | case ugUncomment : return "Uncomment"; | 117 | case ugUncomment : return "Uncomment"; |
118 | case ugReplace : return "Text Replace"; | 118 | case ugReplace : return "Text Replace"; |
119 | case ugSpell : return "Spell Check"; | 119 | case ugSpell : return "Spell Check"; |
120 | case ugInsChar : return "Typing"; | 120 | case ugInsChar : return "Typing"; |
121 | case ugDelChar : return "Delete Text"; | 121 | case ugDelChar : return "Delete Text"; |
122 | case ugInsLine : return "New Line"; | 122 | case ugInsLine : return "New Line"; |
123 | case ugDelLine : return "Delete Line"; | 123 | case ugDelLine : return "Delete Line"; |
124 | } | 124 | } |
125 | return ""; | 125 | return ""; |
126 | } | 126 | } |
127 | 127 | ||
128 | const int KateDocument::maxAttribs = 32; | 128 | const int KateDocument::maxAttribs = 32; |
129 | 129 | ||
130 | QStringList KateDocument::searchForList = QStringList(); | 130 | QStringList KateDocument::searchForList = QStringList(); |
131 | QStringList KateDocument::replaceWithList = QStringList(); | 131 | QStringList KateDocument::replaceWithList = QStringList(); |
132 | 132 | ||
133 | uint KateDocument::uniqueID = 0; | 133 | uint KateDocument::uniqueID = 0; |
134 | 134 | ||
135 | QPtrDict<KateDocument::KateDocPrivate>* KateDocument::d_ptr = 0; | 135 | QPtrDict<KateDocument::KateDocPrivate>* KateDocument::d_ptr = 0; |
136 | 136 | ||
137 | 137 | ||
138 | KateDocument::KateDocument(bool bSingleViewMode, bool bBrowserView, | 138 | KateDocument::KateDocument(bool bSingleViewMode, bool bBrowserView, |
139 | QWidget *parentWidget, const char *widgetName, | 139 | QWidget *parentWidget, const char *widgetName, |
140 | QObject *, const char *) | 140 | QObject *, const char *) |
141 | : Kate::Document (), | 141 | : Kate::Document (), |
142 | myFont(KGlobalSettings::generalFont()), myFontBold(KGlobalSettings::generalFont()), myFontItalic(KGlobalSettings::generalFont()), myFontBI(KGlobalSettings::generalFont()), | 142 | myFont(KGlobalSettings::generalFont()), myFontBold(KGlobalSettings::generalFont()), myFontItalic(KGlobalSettings::generalFont()), myFontBI(KGlobalSettings::generalFont()), |
143 | myFontMetrics (myFont), myFontMetricsBold (myFontBold), myFontMetricsItalic (myFontItalic), myFontMetricsBI (myFontBI), | 143 | myFontMetrics (myFont), myFontMetricsBold (myFontBold), myFontMetricsItalic (myFontItalic), myFontMetricsBI (myFontBI), |
144 | hlManager(HlManager::self ()) | 144 | hlManager(HlManager::self ()) |
145 | { | 145 | { |
146 | 146 | ||
147 | d(this)->hlSetByUser = false; | 147 | d(this)->hlSetByUser = false; |
148 | PreHighlightedTill=0; | 148 | PreHighlightedTill=0; |
149 | RequestPreHighlightTill=0; | 149 | RequestPreHighlightTill=0; |
150 | 150 | ||
151 | m_bSingleViewMode=bSingleViewMode; | 151 | m_bSingleViewMode=bSingleViewMode; |
152 | m_bBrowserView = bBrowserView; | 152 | m_bBrowserView = bBrowserView; |
153 | 153 | ||
154 | m_url = QString::null; | 154 | m_url = QString::null; |
155 | 155 | ||
156 | // NOTE: QFont::CharSet doesn't provide all the charsets KDE supports | 156 | // NOTE: QFont::CharSet doesn't provide all the charsets KDE supports |
157 | // (esp. it doesn't distinguish between UTF-8 and iso10646-1) | 157 | // (esp. it doesn't distinguish between UTF-8 and iso10646-1) |
158 | 158 | ||
159 | myEncoding = QString::fromLatin1(QTextCodec::codecForLocale()->name()); | 159 | myEncoding = QString::fromLatin1(QTextCodec::codecForLocale()->name()); |
160 | 160 | ||
161 | maxLength = -1; | 161 | maxLength = -1; |
162 | 162 | ||
163 | setFont (KGlobalSettings::generalFont()); | 163 | setFont (KGlobalSettings::generalFont()); |
164 | 164 | ||
165 | myDocID = uniqueID; | 165 | myDocID = uniqueID; |
166 | uniqueID++; | 166 | uniqueID++; |
167 | 167 | ||
168 | myDocName = QString (""); | 168 | myDocName = QString (""); |
169 | fileInfo = new QFileInfo (); | 169 | fileInfo = new QFileInfo (); |
170 | 170 | ||
171 | myCmd = new KateCmd (this); | 171 | myCmd = new KateCmd (this); |
172 | 172 | ||
173 | connect(this,SIGNAL(modifiedChanged ()),this,SLOT(slotModChanged ())); | 173 | connect(this,SIGNAL(modifiedChanged ()),this,SLOT(slotModChanged ())); |
174 | 174 | ||
175 | buffer = new KWBuffer; | 175 | buffer = new KWBuffer; |
176 | connect(buffer, SIGNAL(linesChanged(int)), this, SLOT(slotBufferChanged())); | 176 | connect(buffer, SIGNAL(linesChanged(int)), this, SLOT(slotBufferChanged())); |
177 | // connect(buffer, SIGNAL(textChanged()), this, SIGNAL(textChanged())); | 177 | // connect(buffer, SIGNAL(textChanged()), this, SIGNAL(textChanged())); |
178 | connect(buffer, SIGNAL(needHighlight(long,long)),this,SLOT(slotBufferHighlight(long,long))); | 178 | connect(buffer, SIGNAL(needHighlight(long,long)),this,SLOT(slotBufferHighlight(long,long))); |
179 | 179 | ||
180 | colors[0] = KGlobalSettings::baseColor(); | 180 | colors[0] = KGlobalSettings::baseColor(); |
181 | colors[1] = KGlobalSettings::highlightColor(); | 181 | colors[1] = KGlobalSettings::highlightColor(); |
182 | 182 | ||
183 | m_attribs = new Attribute[maxAttribs]; | 183 | m_attribs = new Attribute[maxAttribs]; |
184 | 184 | ||
185 | m_highlight = 0L; | 185 | m_highlight = 0L; |
186 | tabChars = 8; | 186 | tabChars = 8; |
187 | 187 | ||
188 | m_singleSelection = false; | 188 | m_singleSelection = false; |
189 | 189 | ||
190 | newDocGeometry = false; | 190 | newDocGeometry = false; |
191 | readOnly = false; | 191 | readOnly = false; |
192 | newDoc = false; | 192 | newDoc = false; |
193 | 193 | ||
194 | modified = false; | 194 | modified = false; |
195 | 195 | ||
196 | undoList.setAutoDelete(true); | 196 | undoList.setAutoDelete(true); |
197 | undoState = 0; | 197 | undoState = 0; |
198 | undoSteps = 50; | 198 | undoSteps = 50; |
199 | 199 | ||
200 | pseudoModal = 0L; | 200 | pseudoModal = 0L; |
201 | clear(); | 201 | clear(); |
202 | 202 | ||
203 | setHighlight(0); //calls updateFontData() | 203 | setHighlight(0); //calls updateFontData() |
204 | // if the user changes the highlight with the dialog, notify the doc | 204 | // if the user changes the highlight with the dialog, notify the doc |
205 | connect(hlManager,SIGNAL(changed()),SLOT(hlChanged())); | 205 | connect(hlManager,SIGNAL(changed()),SLOT(hlChanged())); |
206 | 206 | ||
207 | newDocGeometry = false; | 207 | newDocGeometry = false; |
208 | 208 | ||
209 | readConfig(); | 209 | readConfig(); |
210 | 210 | ||
211 | setReadOnly(false); | 211 | setReadOnly(false); |
212 | } | 212 | } |
213 | 213 | ||
214 | void KateDocument::setDontChangeHlOnSave() | 214 | void KateDocument::setDontChangeHlOnSave() |
215 | { | 215 | { |
216 | d(this)->hlSetByUser = true; | 216 | d(this)->hlSetByUser = true; |
217 | } | 217 | } |
218 | 218 | ||
219 | void KateDocument::setFont (QFont font) | 219 | void KateDocument::setFont (QFont font) |
220 | { | 220 | { |
221 | kdDebug()<<"Kate:: setFont"<<endl; | 221 | kdDebug()<<"Kate:: setFont"<<endl; |
222 | int oldwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 | 222 | int oldwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 |
223 | myFont = font; | 223 | myFont = font; |
224 | myFontBold = QFont (font); | 224 | myFontBold = QFont (font); |
225 | myFontBold.setBold (true); | 225 | myFontBold.setBold (true); |
226 | 226 | ||
227 | myFontItalic = QFont (font); | 227 | myFontItalic = QFont (font); |
228 | myFontItalic.setItalic (true); | 228 | myFontItalic.setItalic (true); |
229 | 229 | ||
230 | myFontBI = QFont (font); | 230 | myFontBI = QFont (font); |
231 | myFontBI.setBold (true); | 231 | myFontBI.setBold (true); |
232 | myFontBI.setItalic (true); | 232 | myFontBI.setItalic (true); |
233 | 233 | ||
234 | myFontMetrics = CachedFontMetrics (myFont); | 234 | myFontMetrics = CachedFontMetrics (myFont); |
235 | myFontMetricsBold = CachedFontMetrics (myFontBold); | 235 | myFontMetricsBold = CachedFontMetrics (myFontBold); |
236 | myFontMetricsItalic = CachedFontMetrics (myFontItalic); | 236 | myFontMetricsItalic = CachedFontMetrics (myFontItalic); |
237 | myFontMetricsBI = CachedFontMetrics (myFontBI); | 237 | myFontMetricsBI = CachedFontMetrics (myFontBI); |
238 | int newwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 | 238 | int newwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 |
239 | maxLength=maxLength*(float)newwidth/(float)oldwidth; //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 | 239 | maxLength=maxLength*(float)newwidth/(float)oldwidth; //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 |
240 | 240 | ||
241 | updateFontData(); | 241 | updateFontData(); |
242 | updateViews(); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 | 242 | updateViews(); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 |
243 | 243 | ||
244 | } | 244 | } |
245 | 245 | ||
246 | long KateDocument::needPreHighlight(long till) | 246 | long KateDocument::needPreHighlight(long till) |
247 | { | 247 | { |
248 | int max=numLines()-1; | 248 | int max=numLines()-1; |
249 | if (till>max) | 249 | if (till>max) |
250 | { | 250 | { |
251 | till=max; | 251 | till=max; |
252 | } | 252 | } |
253 | if (PreHighlightedTill>=till) return -1; | 253 | if (PreHighlightedTill>=till) return -1; |
254 | 254 | ||
255 | long tmp=RequestPreHighlightTill; | 255 | long tmp=RequestPreHighlightTill; |
256 | if (RequestPreHighlightTill<till) | 256 | if (RequestPreHighlightTill<till) |
257 | { | 257 | { |
258 | RequestPreHighlightTill=till; | 258 | RequestPreHighlightTill=till; |
259 | if (tmp<=PreHighlightedTill) QTimer::singleShot(10,this,SLOT(doPreHighlight())); | 259 | if (tmp<=PreHighlightedTill) QTimer::singleShot(10,this,SLOT(doPreHighlight())); |
260 | } | 260 | } |
261 | return RequestPreHighlightTill; | 261 | return RequestPreHighlightTill; |
262 | } | 262 | } |
263 | 263 | ||
264 | void KateDocument::doPreHighlight() | 264 | void KateDocument::doPreHighlight() |
265 | { | 265 | { |
266 | int from = PreHighlightedTill; | 266 | int from = PreHighlightedTill; |
267 | int till = PreHighlightedTill+200; | 267 | int till = PreHighlightedTill+200; |
268 | int max = numLines()-1; | 268 | int max = numLines()-1; |
269 | if (till > max) | 269 | if (till > max) |
270 | { | 270 | { |
271 | till = max; | 271 | till = max; |
272 | } | 272 | } |
273 | PreHighlightedTill = till; | 273 | PreHighlightedTill = till; |
274 | updateLines(from,till); | 274 | updateLines(from,till); |
275 | emit preHighlightChanged(PreHighlightedTill); | 275 | emit preHighlightChanged(PreHighlightedTill); |
276 | if (PreHighlightedTill<RequestPreHighlightTill) | 276 | if (PreHighlightedTill<RequestPreHighlightTill) |
277 | QTimer::singleShot(10,this,SLOT(doPreHighlight())); | 277 | QTimer::singleShot(10,this,SLOT(doPreHighlight())); |
278 | } | 278 | } |
279 | 279 | ||
280 | KateDocument::~KateDocument() | 280 | KateDocument::~KateDocument() |
281 | { | 281 | { |
282 | m_highlight->release(); | 282 | m_highlight->release(); |
283 | writeConfig(); | ||
283 | 284 | ||
284 | if ( !m_bSingleViewMode ) | 285 | if ( !m_bSingleViewMode ) |
285 | { | 286 | { |
286 | m_views.setAutoDelete( true ); | 287 | m_views.setAutoDelete( true ); |
287 | m_views.clear(); | 288 | m_views.clear(); |
288 | m_views.setAutoDelete( false ); | 289 | m_views.setAutoDelete( false ); |
289 | } | 290 | } |
290 | delete_d(this); | 291 | delete_d(this); |
291 | } | 292 | } |
292 | 293 | ||
293 | void KateDocument::openURL(const QString &filename) | 294 | void KateDocument::openURL(const QString &filename) |
294 | { | 295 | { |
295 | 296 | ||
296 | m_file=filename; | 297 | m_file=filename; |
297 | fileInfo->setFile (m_file); | 298 | fileInfo->setFile (m_file); |
298 | setMTime(); | 299 | setMTime(); |
299 | 300 | ||
300 | if (!fileInfo->exists() || !fileInfo->isReadable()) | 301 | if (!fileInfo->exists() || !fileInfo->isReadable()) |
301 | { | 302 | { |
302 | qDebug("File doesn't exit or couldn't be read"); | 303 | qDebug("File doesn't exit or couldn't be read"); |
303 | return ; | 304 | return ; |
304 | } | 305 | } |
305 | 306 | ||
306 | buffer->clear(); | 307 | buffer->clear(); |
307 | #warning fixme | 308 | #warning fixme |
308 | // buffer->insertFile(0, m_file, KGlobal::charsets()->codecForName(myEncoding)); | 309 | // buffer->insertFile(0, m_file, KGlobal::charsets()->codecForName(myEncoding)); |
309 | qDebug("Telling buffer to open file"); | 310 | qDebug("Telling buffer to open file"); |
310 | buffer->insertFile(0, m_file, QTextCodec::codecForLocale()); | 311 | buffer->insertFile(0, m_file, QTextCodec::codecForLocale()); |
311 | 312 | ||
312 | setMTime(); | 313 | setMTime(); |
313 | 314 | ||
314 | if (myWordWrap) | 315 | if (myWordWrap) |
315 | wrapText (myWordWrapAt); | 316 | wrapText (myWordWrapAt); |
316 | 317 | ||
317 | int hl = hlManager->wildcardFind( m_file ); | 318 | int hl = hlManager->wildcardFind( m_file ); |
318 | 319 | ||
319 | setHighlight(hl); | 320 | setHighlight(hl); |
320 | 321 | ||
321 | updateLines(); | 322 | updateLines(); |
322 | updateViews(); | 323 | updateViews(); |
323 | 324 | ||
324 | emit fileNameChanged(); | 325 | emit fileNameChanged(); |
325 | 326 | ||
326 | return ; | 327 | return ; |
327 | } | 328 | } |
328 | 329 | ||
329 | bool KateDocument::saveFile() | 330 | bool KateDocument::saveFile() |
330 | { | 331 | { |
331 | 332 | ||
332 | QFile f( m_file ); | 333 | QFile f( m_file ); |
333 | if ( !f.open( IO_WriteOnly ) ) | 334 | if ( !f.open( IO_WriteOnly ) ) |
334 | return false; // Error | 335 | return false; // Error |
335 | 336 | ||
336 | QTextStream stream(&f); | 337 | QTextStream stream(&f); |
337 | 338 | ||
338 | stream.setEncoding(QTextStream::RawUnicode); // disable Unicode headers | 339 | stream.setEncoding(QTextStream::RawUnicode); // disable Unicode headers |
339 | #warning fixme | 340 | #warning fixme |
340 | // stream.setCodec(KGlobal::charsets()->codecForName(myEncoding)); | 341 | // stream.setCodec(KGlobal::charsets()->codecForName(myEncoding)); |
341 | stream.setCodec(QTextCodec::codecForLocale()); // this line sets the mapper to the correct codec | 342 | stream.setCodec(QTextCodec::codecForLocale()); // this line sets the mapper to the correct codec |
342 | 343 | ||
343 | int maxLine = numLines(); | 344 | int maxLine = numLines(); |
344 | int line = 0; | 345 | int line = 0; |
345 | while(true) | 346 | while(true) |
346 | { | 347 | { |
347 | stream << getTextLine(line)->getString(); | 348 | stream << getTextLine(line)->getString(); |
348 | line++; | 349 | line++; |
349 | if (line >= maxLine) break; | 350 | if (line >= maxLine) break; |
350 | 351 | ||
351 | if (eolMode == KateDocument::eolUnix) stream << "\n"; | 352 | if (eolMode == KateDocument::eolUnix) stream << "\n"; |
352 | else if (eolMode == KateDocument::eolDos) stream << "\r\n"; | 353 | else if (eolMode == KateDocument::eolDos) stream << "\r\n"; |
353 | else if (eolMode == KateDocument::eolMacintosh) stream << '\r'; | 354 | else if (eolMode == KateDocument::eolMacintosh) stream << '\r'; |
354 | }; | 355 | }; |
355 | f.close(); | 356 | f.close(); |
356 | 357 | ||
357 | fileInfo->setFile (m_file); | 358 | fileInfo->setFile (m_file); |
358 | setMTime(); | 359 | setMTime(); |
359 | 360 | ||
360 | if (!(d(this)->hlSetByUser)) | 361 | if (!(d(this)->hlSetByUser)) |
361 | { | 362 | { |
362 | int hl = hlManager->wildcardFind( m_file ); | 363 | int hl = hlManager->wildcardFind( m_file ); |
363 | 364 | ||
364 | setHighlight(hl); | 365 | setHighlight(hl); |
365 | } | 366 | } |
366 | emit fileNameChanged (); | 367 | emit fileNameChanged (); |
367 | 368 | ||
368 | return (f.status() == IO_Ok); | 369 | return (f.status() == IO_Ok); |
369 | } | 370 | } |
370 | 371 | ||
371 | KTextEditor::View *KateDocument::createView( QWidget *parent, const char *name ) | 372 | KTextEditor::View *KateDocument::createView( QWidget *parent, const char *name ) |
372 | { | 373 | { |
373 | return new KateView( this, parent, name); | 374 | return new KateView( this, parent, name); |
374 | } | 375 | } |
375 | 376 | ||
376 | QString KateDocument::textLine( int line ) const | 377 | QString KateDocument::textLine( int line ) const |
377 | { | 378 | { |
378 | TextLine::Ptr l = getTextLine( line ); | 379 | TextLine::Ptr l = getTextLine( line ); |
379 | if ( !l ) | 380 | if ( !l ) |
380 | return QString(); | 381 | return QString(); |
381 | 382 | ||
382 | return l->getString(); | 383 | return l->getString(); |
383 | } | 384 | } |
384 | 385 | ||
385 | void KateDocument::replaceLine(const QString& s,int line) | 386 | void KateDocument::replaceLine(const QString& s,int line) |
386 | { | 387 | { |
387 | remove_Line(line,false); | 388 | remove_Line(line,false); |
388 | insert_Line(s,line,true); | 389 | insert_Line(s,line,true); |
389 | } | 390 | } |
390 | 391 | ||
391 | void KateDocument::insertLine( const QString &str, int l ) { | 392 | void KateDocument::insertLine( const QString &str, int l ) { |
392 | insert_Line(str,l,true); | 393 | insert_Line(str,l,true); |
393 | } | 394 | } |
394 | 395 | ||
395 | void KateDocument::insert_Line(const QString& s,int line, bool update) | 396 | void KateDocument::insert_Line(const QString& s,int line, bool update) |
396 | { | 397 | { |
397 | kdDebug(13020)<<"KateDocument::insertLine "<<s<<QString(" %1").arg(line)<<endl; | 398 | kdDebug(13020)<<"KateDocument::insertLine "<<s<<QString(" %1").arg(line)<<endl; |
398 | TextLine::Ptr TL=new TextLine(); | 399 | TextLine::Ptr TL=new TextLine(); |
399 | TL->append(s.unicode(),s.length()); | 400 | TL->append(s.unicode(),s.length()); |
400 | buffer->insertLine(line,TL); | 401 | buffer->insertLine(line,TL); |
401 | if (update) | 402 | if (update) |
402 | { | 403 | { |
403 | newDocGeometry=true; | 404 | newDocGeometry=true; |
404 | updateLines(line); | 405 | updateLines(line); |
405 | updateViews(); | 406 | updateViews(); |
406 | } | 407 | } |
407 | } | 408 | } |
408 | 409 | ||
409 | void KateDocument::insertAt( const QString &s, int line, int col, bool ) | 410 | void KateDocument::insertAt( const QString &s, int line, int col, bool ) |
410 | { | 411 | { |
411 | VConfig c; | 412 | VConfig c; |
412 | c.view = 0; // ### FIXME | 413 | c.view = 0; // ### FIXME |
413 | c.cursor.x = col; | 414 | c.cursor.x = col; |
414 | c.cursor.y = line; | 415 | c.cursor.y = line; |
415 | c.cXPos = 0; // ### FIXME | 416 | c.cXPos = 0; // ### FIXME |
416 | c.flags = 0; // ### FIXME | 417 | c.flags = 0; // ### FIXME |
417 | insert( c, s ); | 418 | insert( c, s ); |
418 | } | 419 | } |
419 | 420 | ||
420 | void KateDocument::removeLine( int line ) { | 421 | void KateDocument::removeLine( int line ) { |
421 | remove_Line(line,true); | 422 | remove_Line(line,true); |
422 | } | 423 | } |
423 | 424 | ||
424 | void KateDocument::remove_Line(int line,bool update) | 425 | void KateDocument::remove_Line(int line,bool update) |
425 | { | 426 | { |
426 | kdDebug(13020)<<"KateDocument::removeLine "<<QString("%1").arg(line)<<endl; | 427 | kdDebug(13020)<<"KateDocument::removeLine "<<QString("%1").arg(line)<<endl; |
427 | buffer->removeLine(line); | 428 | buffer->removeLine(line); |
428 | // newDocGeometry=true; | 429 | // newDocGeometry=true; |
429 | // if line==0) | 430 | // if line==0) |
430 | if (update) | 431 | if (update) |
431 | { | 432 | { |
432 | updateLines(line); | 433 | updateLines(line); |
433 | updateViews(); | 434 | updateViews(); |
434 | } | 435 | } |
435 | } | 436 | } |
436 | 437 | ||
437 | int KateDocument::length() const | 438 | int KateDocument::length() const |
438 | { | 439 | { |
439 | return text().length(); | 440 | return text().length(); |
440 | } | 441 | } |
441 | 442 | ||
442 | void KateDocument::setSelection( int , int , int , int ) | 443 | void KateDocument::setSelection( int , int , int , int ) |
443 | { | 444 | { |
444 | } | 445 | } |
445 | 446 | ||
446 | bool KateDocument::hasSelection() const | 447 | bool KateDocument::hasSelection() const |
447 | { | 448 | { |
448 | return (selectEnd >= selectStart); | 449 | return (selectEnd >= selectStart); |
449 | } | 450 | } |
450 | 451 | ||
451 | QString KateDocument::selection() const | 452 | QString KateDocument::selection() const |
452 | { | 453 | { |
453 | uint flags = 0; | 454 | uint flags = 0; |
454 | TextLine::Ptr textLine; | 455 | TextLine::Ptr textLine; |
455 | int len, z, start, end, i; | 456 | int len, z, start, end, i; |
456 | 457 | ||
457 | len = 1; | 458 | len = 1; |
458 | if (!(flags & KateView::cfVerticalSelect)) { | 459 | if (!(flags & KateView::cfVerticalSelect)) { |
459 | for (z = selectStart; z <= selectEnd; z++) { | 460 | for (z = selectStart; z <= selectEnd; z++) { |
460 | textLine = getTextLine(z); | 461 | textLine = getTextLine(z); |
461 | len += textLine->numSelected(); | 462 | len += textLine->numSelected(); |
462 | if (textLine->isSelected()) len++; | 463 | if (textLine->isSelected()) len++; |
463 | } | 464 | } |
464 | QString s; | 465 | QString s; |
465 | len = 0; | 466 | len = 0; |
466 | for (z = selectStart; z <= selectEnd; z++) { | 467 | for (z = selectStart; z <= selectEnd; z++) { |
467 | textLine = getTextLine(z); | 468 | textLine = getTextLine(z); |
468 | end = 0; | 469 | end = 0; |
469 | do { | 470 | do { |
470 | start = textLine->findUnselected(end); | 471 | start = textLine->findUnselected(end); |
471 | end = textLine->findSelected(start); | 472 | end = textLine->findSelected(start); |
472 | for (i = start; i < end; i++) { | 473 | for (i = start; i < end; i++) { |
473 | s[len] = textLine->getChar(i); | 474 | s[len] = textLine->getChar(i); |
474 | len++; | 475 | len++; |
475 | } | 476 | } |
476 | } while (start < end); | 477 | } while (start < end); |
477 | if (textLine->isSelected()) { | 478 | if (textLine->isSelected()) { |
478 | s[len] = '\n'; | 479 | s[len] = '\n'; |
479 | len++; | 480 | len++; |
480 | } | 481 | } |
481 | } | 482 | } |
482 | // s[len] = '\0'; | 483 | // s[len] = '\0'; |
483 | return s; | 484 | return s; |
484 | } else { | 485 | } else { |
485 | for (z = selectStart; z <= selectEnd; z++) { | 486 | for (z = selectStart; z <= selectEnd; z++) { |
486 | textLine = getTextLine(z); | 487 | textLine = getTextLine(z); |
487 | len += textLine->numSelected() + 1; | 488 | len += textLine->numSelected() + 1; |
488 | } | 489 | } |
489 | QString s; | 490 | QString s; |
490 | len = 0; | 491 | len = 0; |
491 | for (z = selectStart; z <= selectEnd; z++) { | 492 | for (z = selectStart; z <= selectEnd; z++) { |
492 | textLine = getTextLine(z); | 493 | textLine = getTextLine(z); |
493 | end = 0; | 494 | end = 0; |
494 | do { | 495 | do { |
495 | start = textLine->findUnselected(end); | 496 | start = textLine->findUnselected(end); |
496 | end = textLine->findSelected(start); | 497 | end = textLine->findSelected(start); |
497 | for (i = start; i < end; i++) { | 498 | for (i = start; i < end; i++) { |
498 | s[len] = textLine->getChar(i); | 499 | s[len] = textLine->getChar(i); |
499 | len++; | 500 | len++; |
500 | } | 501 | } |
501 | } while (start < end); | 502 | } while (start < end); |
502 | s[len] = '\n'; | 503 | s[len] = '\n'; |
503 | len++; | 504 | len++; |
504 | } | 505 | } |
505 | // s[len] = '\0'; // the final \0 is not counted in length() | 506 | // s[len] = '\0'; // the final \0 is not counted in length() |
506 | return s; | 507 | return s; |
507 | } | 508 | } |
508 | } | 509 | } |
509 | 510 | ||
510 | int KateDocument::numLines() const | 511 | int KateDocument::numLines() const |
511 | { | 512 | { |
512 | return buffer->count(); | 513 | return buffer->count(); |
513 | } | 514 | } |
514 | 515 | ||
515 | 516 | ||
516 | TextLine::Ptr KateDocument::getTextLine(int line) const | 517 | TextLine::Ptr KateDocument::getTextLine(int line) const |
517 | { | 518 | { |
518 | // This is a hack to get this stuff working. | 519 | // This is a hack to get this stuff working. |
519 | return buffer->line(line); | 520 | return buffer->line(line); |
520 | } | 521 | } |
521 | 522 | ||
522 | int KateDocument::textLength(int line) { | 523 | int KateDocument::textLength(int line) { |
523 | TextLine::Ptr textLine = getTextLine(line); | 524 | TextLine::Ptr textLine = getTextLine(line); |
524 | if (!textLine) return 0; | 525 | if (!textLine) return 0; |
525 | return textLine->length(); | 526 | return textLine->length(); |
526 | } | 527 | } |
527 | 528 | ||
528 | void KateDocument::setTabWidth(int chars) { | 529 | void KateDocument::setTabWidth(int chars) { |
529 | if (tabChars == chars) return; | 530 | if (tabChars == chars) return; |
530 | if (chars < 1) chars = 1; | 531 | if (chars < 1) chars = 1; |
531 | if (chars > 16) chars = 16; | 532 | if (chars > 16) chars = 16; |
532 | tabChars = chars; | 533 | tabChars = chars; |
533 | updateFontData(); | 534 | updateFontData(); |
534 | 535 | ||
535 | maxLength = -1; | 536 | maxLength = -1; |
536 | for (int i=0; i < buffer->count(); i++) | 537 | for (int i=0; i < buffer->count(); i++) |
537 | { | 538 | { |
538 | TextLine::Ptr textLine = buffer->line(i); | 539 | TextLine::Ptr textLine = buffer->line(i); |
539 | int len = textWidth(textLine,textLine->length()); | 540 | int len = textWidth(textLine,textLine->length()); |
540 | if (len > maxLength) { | 541 | if (len > maxLength) { |
541 | maxLength = len; | 542 | maxLength = len; |
542 | longestLine = textLine; | 543 | longestLine = textLine; |
543 | } | 544 | } |
544 | } | 545 | } |
545 | } | 546 | } |
546 | 547 | ||
547 | void KateDocument::setReadOnly(bool m) { | 548 | void KateDocument::setReadOnly(bool m) { |
548 | KTextEditor::View *view; | 549 | KTextEditor::View *view; |
549 | 550 | ||
550 | if (m != readOnly) { | 551 | if (m != readOnly) { |
551 | readOnly = m; | 552 | readOnly = m; |
552 | // if (readOnly) recordReset(); | 553 | // if (readOnly) recordReset(); |
553 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { | 554 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { |
554 | emit static_cast<KateView *>( view )->newStatus(); | 555 | emit static_cast<KateView *>( view )->newStatus(); |
555 | } | 556 | } |
556 | } | 557 | } |
557 | } | 558 | } |
558 | 559 | ||
559 | bool KateDocument::isReadOnly() const { | 560 | bool KateDocument::isReadOnly() const { |
560 | return readOnly; | 561 | return readOnly; |
561 | } | 562 | } |
562 | 563 | ||
563 | void KateDocument::setNewDoc( bool m ) | 564 | void KateDocument::setNewDoc( bool m ) |
564 | { | 565 | { |
565 | // KTextEditor::View *view; | 566 | // KTextEditor::View *view; |
566 | 567 | ||
567 | if ( m != newDoc ) | 568 | if ( m != newDoc ) |
568 | { | 569 | { |
569 | newDoc = m; | 570 | newDoc = m; |
570 | //// if (readOnly) recordReset(); | 571 | //// if (readOnly) recordReset(); |
571 | // for (view = m_views.first(); view != 0L; view = m_views.next() ) { | 572 | // for (view = m_views.first(); view != 0L; view = m_views.next() ) { |
572 | // emit static_cast<KateView *>( view )->newStatus(); | 573 | // emit static_cast<KateView *>( view )->newStatus(); |
573 | // } | 574 | // } |
574 | } | 575 | } |
575 | } | 576 | } |
576 | 577 | ||
577 | bool KateDocument::isNewDoc() const { | 578 | bool KateDocument::isNewDoc() const { |
578 | return newDoc; | 579 | return newDoc; |
579 | } | 580 | } |
580 | 581 | ||
581 | void KateDocument::setModified(bool m) { | 582 | void KateDocument::setModified(bool m) { |
582 | KTextEditor::View *view; | 583 | KTextEditor::View *view; |
583 | 584 | ||
584 | if (m != modified) { | 585 | if (m != modified) { |
585 | modified = m; | 586 | modified = m; |
586 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { | 587 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { |
587 | emit static_cast<KateView *>( view )->newStatus(); | 588 | emit static_cast<KateView *>( view )->newStatus(); |
588 | } | 589 | } |
589 | emit modifiedChanged (); | 590 | emit modifiedChanged (); |
590 | } | 591 | } |
591 | } | 592 | } |
592 | 593 | ||
593 | bool KateDocument::isModified() const { | 594 | bool KateDocument::isModified() const { |
594 | return modified; | 595 | return modified; |
595 | } | 596 | } |
596 | 597 | ||
597 | void KateDocument::readConfig() | 598 | void KateDocument::readConfig() |
598 | { | 599 | { |
599 | KConfig *config = KGlobal::config(); | 600 | KateConfig *config = KGlobal::config(); |
600 | config->setGroup("Kate Document"); | 601 | config->setGroup("Kate Document"); |
601 | 602 | ||
602 | myWordWrap = config->readBoolEntry("Word Wrap On", false); | 603 | myWordWrap = config->readBoolEntry("Word Wrap On", false); |
603 | myWordWrapAt = config->readNumEntry("Word Wrap At", 80); | 604 | myWordWrapAt = config->readNumEntry("Word Wrap At", 80); |
604 | if (myWordWrap) | 605 | if (myWordWrap) |
605 | wrapText (myWordWrapAt); | 606 | wrapText (myWordWrapAt); |
606 | 607 | ||
607 | setTabWidth(config->readNumEntry("TabWidth", 8)); | 608 | setTabWidth(config->readNumEntry("TabWidth", 8)); |
608 | setUndoSteps(config->readNumEntry("UndoSteps", 50)); | 609 | setUndoSteps(config->readNumEntry("UndoSteps", 50)); |
609 | m_singleSelection = config->readBoolEntry("SingleSelection", false); | 610 | m_singleSelection = config->readBoolEntry("SingleSelection", false); |
610 | myEncoding = config->readEntry("Encoding", QString::fromLatin1(QTextCodec::codecForLocale()->name())); | 611 | myEncoding = config->readEntry("Encoding", QString::fromLatin1(QTextCodec::codecForLocale()->name())); |
611 | setFont (config->readFontEntry("Font", &myFont)); | 612 | setFont (config->readFontEntry("Font", myFont)); |
612 | 613 | ||
613 | colors[0] = config->readColorEntry("Color Background", &colors[0]); | 614 | colors[0] = config->readColorEntry("Color Background", colors[0]); |
614 | colors[1] = config->readColorEntry("Color Selected", &colors[1]); | 615 | colors[1] = config->readColorEntry("Color Selected", colors[1]); |
615 | 616 | ||
616 | config->sync(); | 617 | // config->sync(); |
617 | } | 618 | } |
618 | 619 | ||
619 | void KateDocument::writeConfig() | 620 | void KateDocument::writeConfig() |
620 | { | 621 | { |
621 | KConfig *config = KGlobal::config(); | 622 | KateConfig *config = KGlobal::config(); |
622 | config->setGroup("Kate Document"); | 623 | config->setGroup("Kate Document"); |
623 | #if 0 | 624 | config->writeEntry("Word Wrap On", myWordWrap); |
624 | cofig->writeEntry("Word Wrap On", myWordWrap); | ||
625 | config->writeEntry("Word Wrap At", myWordWrapAt); | 625 | config->writeEntry("Word Wrap At", myWordWrapAt); |
626 | config->writeEntry("TabWidth", tabChars); | 626 | config->writeEntry("TabWidth", tabChars); |
627 | config->writeEntry("UndoSteps", undoSteps); | 627 | config->writeEntry("UndoSteps", undoSteps); |
628 | config->writeEntry("SingleSelection", m_singleSelection); | 628 | config->writeEntry("SingleSelection", m_singleSelection); |
629 | config->writeEntry("Encoding", myEncoding); | 629 | config->writeEntry("Encoding", myEncoding); |
630 | config->writeEntry("Font", myFont); | 630 | config->writeEntry("Font", myFont); |
631 | config->writeEntry("Color Background", colors[0]); | 631 | config->writeEntry("Color Background", colors[0]); |
632 | config->writeEntry("Color Selected", colors[1]); | 632 | config->writeEntry("Color Selected", colors[1]); |
633 | #endif | 633 | // config->sync(); |
634 | config->sync(); | ||
635 | } | 634 | } |
636 | 635 | ||
637 | void KateDocument::readSessionConfig(KConfig *config) | 636 | void KateDocument::readSessionConfig(KateConfig *config) |
638 | { | 637 | { |
639 | m_url = config->readEntry("URL"); // ### doesn't this break the encoding? (Simon) | 638 | m_url = config->readEntry("URL"); // ### doesn't this break the encoding? (Simon) |
640 | setHighlight(hlManager->nameFind(config->readEntry("Highlight"))); | 639 | setHighlight(hlManager->nameFind(config->readEntry("Highlight"))); |
641 | // anders: restore bookmarks if possible | 640 | // anders: restore bookmarks if possible |
642 | QValueList<int> l = config->readIntListEntry("Bookmarks"); | 641 | QValueList<int> l = config->readIntListEntry("Bookmarks"); |
643 | if ( l.count() ) { | 642 | if ( l.count() ) { |
644 | for (uint i=0; i < l.count(); i++) { | 643 | for (uint i=0; i < l.count(); i++) { |
645 | if ( numLines() < l[i] ) break; | 644 | if ( numLines() < l[i] ) break; |
646 | getTextLine( l[i] )->addMark( Bookmark ); | 645 | getTextLine( l[i] )->addMark( Bookmark ); |
647 | } | 646 | } |
648 | } | 647 | } |
649 | } | 648 | } |
650 | 649 | ||
651 | void KateDocument::writeSessionConfig(KConfig *config) | 650 | void KateDocument::writeSessionConfig(KateConfig *config) |
652 | { | 651 | { |
653 | #if 0 | 652 | #if 0 |
654 | config->writeEntry("URL", m_url); // ### encoding?? (Simon) | 653 | config->writeEntry("URL", m_url); // ### encoding?? (Simon) |
655 | config->writeEntry("Highlight", m_highlight->name()); | 654 | config->writeEntry("Highlight", m_highlight->name()); |
656 | // anders: save bookmarks | 655 | // anders: save bookmarks |
657 | QList<Kate::Mark> l = marks(); | 656 | QList<Kate::Mark> l = marks(); |
658 | QValueList<int> ml; | 657 | QValueList<int> ml; |
659 | for (uint i=0; i < l.count(); i++) { | 658 | for (uint i=0; i < l.count(); i++) { |
660 | if ( l.at(i)->type == 1) // only save bookmarks | 659 | if ( l.at(i)->type == 1) // only save bookmarks |
661 | ml << l.at(i)->line; | 660 | ml << l.at(i)->line; |
662 | } | 661 | } |
663 | if ( ml.count() ) | 662 | if ( ml.count() ) |
664 | config->writeEntry("Bookmarks", ml); | 663 | config->writeEntry("Bookmarks", ml); |
665 | #endif | 664 | #endif |
666 | } | 665 | } |
667 | 666 | ||
668 | 667 | ||
669 | void KateDocument::setHighlight(int n) { | 668 | void KateDocument::setHighlight(int n) { |
670 | Highlight *h; | 669 | Highlight *h; |
671 | 670 | ||
672 | // hlNumber = n; | 671 | // hlNumber = n; |
673 | 672 | ||
674 | h = hlManager->getHl(n); | 673 | h = hlManager->getHl(n); |
675 | if (h == m_highlight) { | 674 | if (h == m_highlight) { |
676 | updateLines(); | 675 | updateLines(); |
677 | } else { | 676 | } else { |
678 | if (m_highlight != 0L) m_highlight->release(); | 677 | if (m_highlight != 0L) m_highlight->release(); |
679 | h->use(); | 678 | h->use(); |
680 | m_highlight = h; | 679 | m_highlight = h; |
681 | makeAttribs(); | 680 | makeAttribs(); |
682 | } | 681 | } |
683 | PreHighlightedTill=0; | 682 | PreHighlightedTill=0; |
684 | RequestPreHighlightTill=0; | 683 | RequestPreHighlightTill=0; |
685 | emit(highlightChanged()); | 684 | emit(highlightChanged()); |
686 | } | 685 | } |
687 | 686 | ||
688 | void KateDocument::makeAttribs() { | 687 | void KateDocument::makeAttribs() { |
689 | qDebug("KateDocument::makeAttribs()"); | 688 | qDebug("KateDocument::makeAttribs()"); |
690 | m_numAttribs = hlManager->makeAttribs(m_highlight, m_attribs, maxAttribs); | 689 | m_numAttribs = hlManager->makeAttribs(m_highlight, m_attribs, maxAttribs); |
691 | updateFontData(); | 690 | updateFontData(); |
692 | updateLines(); | 691 | updateLines(); |
693 | } | 692 | } |
694 | 693 | ||
695 | void KateDocument::updateFontData() { | 694 | void KateDocument::updateFontData() { |
696 | int maxAscent, maxDescent; | 695 | int maxAscent, maxDescent; |
697 | int tabWidth; | 696 | int tabWidth; |
698 | KateView *view; | 697 | KateView *view; |
699 | 698 | ||
700 | maxAscent = myFontMetrics.ascent(); | 699 | maxAscent = myFontMetrics.ascent(); |
701 | maxDescent = myFontMetrics.descent(); | 700 | maxDescent = myFontMetrics.descent(); |
702 | tabWidth = myFontMetrics.width(' '); | 701 | tabWidth = myFontMetrics.width(' '); |
703 | 702 | ||
704 | fontHeight = maxAscent + maxDescent + 1; | 703 | fontHeight = maxAscent + maxDescent + 1; |
705 | fontAscent = maxAscent; | 704 | fontAscent = maxAscent; |
706 | m_tabWidth = tabChars*tabWidth; | 705 | m_tabWidth = tabChars*tabWidth; |
707 | 706 | ||
708 | for (view = views.first(); view != 0L; view = views.next() ) { | 707 | for (view = views.first(); view != 0L; view = views.next() ) { |
709 | view->myViewInternal->drawBuffer->resize(view->width(),fontHeight); | 708 | view->myViewInternal->drawBuffer->resize(view->width(),fontHeight); |
710 | view->tagAll(); | 709 | view->tagAll(); |
711 | view->updateCursor(); | 710 | view->updateCursor(); |
712 | } | 711 | } |
713 | } | 712 | } |
714 | 713 | ||
715 | void KateDocument::hlChanged() { //slot | 714 | void KateDocument::hlChanged() { //slot |
716 | makeAttribs(); | 715 | makeAttribs(); |
717 | updateViews(); | 716 | updateViews(); |
718 | } | 717 | } |
719 | 718 | ||
720 | 719 | ||
721 | void KateDocument::addView(KTextEditor::View *view) { | 720 | void KateDocument::addView(KTextEditor::View *view) { |
722 | views.append( static_cast<KateView *>( view ) ); | 721 | views.append( static_cast<KateView *>( view ) ); |
723 | KTextEditor::Document::addView( view ); | 722 | KTextEditor::Document::addView( view ); |
724 | connect( static_cast<KateView *>( view ), SIGNAL( destroyed() ), this, SLOT( slotViewDestroyed() ) ); | 723 | connect( static_cast<KateView *>( view ), SIGNAL( destroyed() ), this, SLOT( slotViewDestroyed() ) ); |
725 | } | 724 | } |
726 | 725 | ||
727 | void KateDocument::removeView(KTextEditor::View *view) { | 726 | void KateDocument::removeView(KTextEditor::View *view) { |
728 | // if (undoView == view) recordReset(); | 727 | // if (undoView == view) recordReset(); |
729 | disconnect( static_cast<KateView *>( view ), SIGNAL( destroyed() ), this, SLOT( slotViewDestroyed() ) ); | 728 | disconnect( static_cast<KateView *>( view ), SIGNAL( destroyed() ), this, SLOT( slotViewDestroyed() ) ); |
730 | views.removeRef( static_cast<KateView *>( view ) ); | 729 | views.removeRef( static_cast<KateView *>( view ) ); |
731 | KTextEditor::Document::removeView( view ); | 730 | KTextEditor::Document::removeView( view ); |
732 | } | 731 | } |
733 | 732 | ||
734 | void KateDocument::slotViewDestroyed() | 733 | void KateDocument::slotViewDestroyed() |
735 | { | 734 | { |
736 | views.removeRef( static_cast<const KateView *>( sender() ) ); | 735 | views.removeRef( static_cast<const KateView *>( sender() ) ); |
737 | } | 736 | } |
738 | 737 | ||
739 | bool KateDocument::ownedView(KateView *view) { | 738 | bool KateDocument::ownedView(KateView *view) { |
740 | // do we own the given view? | 739 | // do we own the given view? |
741 | return (views.containsRef(view) > 0); | 740 | return (views.containsRef(view) > 0); |
742 | } | 741 | } |
743 | 742 | ||
744 | bool KateDocument::isLastView(int numViews) { | 743 | bool KateDocument::isLastView(int numViews) { |
745 | return ((int) views.count() == numViews); | 744 | return ((int) views.count() == numViews); |
746 | } | 745 | } |
747 | 746 | ||
748 | int KateDocument::textWidth(const TextLine::Ptr &textLine, int cursorX) { | 747 | int KateDocument::textWidth(const TextLine::Ptr &textLine, int cursorX) { |
749 | int x; | 748 | int x; |
750 | int z; | 749 | int z; |
751 | QChar ch; | 750 | QChar ch; |
752 | Attribute *a; | 751 | Attribute *a; |
753 | 752 | ||
754 | x = 0; | 753 | x = 0; |
755 | for (z = 0; z < cursorX; z++) { | 754 | for (z = 0; z < cursorX; z++) { |
756 | ch = textLine->getChar(z); | 755 | ch = textLine->getChar(z); |
757 | a = &m_attribs[textLine->getAttr(z)]; | 756 | a = &m_attribs[textLine->getAttr(z)]; |
758 | 757 | ||
759 | if (ch == '\t') | 758 | if (ch == '\t') |
760 | x += m_tabWidth - (x % m_tabWidth); | 759 | x += m_tabWidth - (x % m_tabWidth); |
761 | else if (a->bold && a->italic) | 760 | else if (a->bold && a->italic) |
762 | x += myFontMetricsBI.width(ch); | 761 | x += myFontMetricsBI.width(ch); |
763 | else if (a->bold) | 762 | else if (a->bold) |
764 | x += myFontMetricsBold.width(ch); | 763 | x += myFontMetricsBold.width(ch); |
765 | else if (a->italic) | 764 | else if (a->italic) |
766 | x += myFontMetricsItalic.width(ch); | 765 | x += myFontMetricsItalic.width(ch); |
767 | else | 766 | else |
768 | x += myFontMetrics.width(ch); | 767 | x += myFontMetrics.width(ch); |
769 | } | 768 | } |
770 | return x; | 769 | return x; |
771 | } | 770 | } |
772 | 771 | ||
773 | int KateDocument::textWidth(PointStruc &cursor) { | 772 | int KateDocument::textWidth(PointStruc &cursor) { |
774 | if (cursor.x < 0) | 773 | if (cursor.x < 0) |
775 | cursor.x = 0; | 774 | cursor.x = 0; |
776 | if (cursor.y < 0) | 775 | if (cursor.y < 0) |
777 | cursor.y = 0; | 776 | cursor.y = 0; |
778 | if (cursor.y >= numLines()) | 777 | if (cursor.y >= numLines()) |
779 | cursor.y = lastLine(); | 778 | cursor.y = lastLine(); |
780 | return textWidth(getTextLine(cursor.y),cursor.x); | 779 | return textWidth(getTextLine(cursor.y),cursor.x); |
781 | } | 780 | } |
782 | 781 | ||
783 | int KateDocument::textWidth(bool wrapCursor, PointStruc &cursor, int xPos) { | 782 | int KateDocument::textWidth(bool wrapCursor, PointStruc &cursor, int xPos) { |
784 | int len; | 783 | int len; |
785 | int x, oldX; | 784 | int x, oldX; |
786 | int z; | 785 | int z; |
787 | QChar ch; | 786 | QChar ch; |
788 | Attribute *a; | 787 | Attribute *a; |
789 | 788 | ||
790 | if (cursor.y < 0) cursor.y = 0; | 789 | if (cursor.y < 0) cursor.y = 0; |
791 | if (cursor.y > lastLine()) cursor.y = lastLine(); | 790 | if (cursor.y > lastLine()) cursor.y = lastLine(); |
792 | TextLine::Ptr textLine = getTextLine(cursor.y); | 791 | TextLine::Ptr textLine = getTextLine(cursor.y); |
793 | len = textLine->length(); | 792 | len = textLine->length(); |
794 | 793 | ||
795 | x = oldX = z = 0; | 794 | x = oldX = z = 0; |
796 | while (x < xPos && (!wrapCursor || z < len)) { | 795 | while (x < xPos && (!wrapCursor || z < len)) { |
797 | oldX = x; | 796 | oldX = x; |
798 | ch = textLine->getChar(z); | 797 | ch = textLine->getChar(z); |
799 | a = &m_attribs[textLine->getAttr(z)]; | 798 | a = &m_attribs[textLine->getAttr(z)]; |
800 | 799 | ||
801 | if (ch == '\t') | 800 | if (ch == '\t') |
802 | x += m_tabWidth - (x % m_tabWidth); | 801 | x += m_tabWidth - (x % m_tabWidth); |
803 | else if (a->bold && a->italic) | 802 | else if (a->bold && a->italic) |
804 | x += myFontMetricsBI.width(ch); | 803 | x += myFontMetricsBI.width(ch); |
805 | else if (a->bold) | 804 | else if (a->bold) |
806 | x += myFontMetricsBold.width(ch); | 805 | x += myFontMetricsBold.width(ch); |
807 | else if (a->italic) | 806 | else if (a->italic) |
808 | x += myFontMetricsItalic.width(ch); | 807 | x += myFontMetricsItalic.width(ch); |
809 | else | 808 | else |
810 | x += myFontMetrics.width(ch); | 809 | x += myFontMetrics.width(ch); |
811 | 810 | ||
812 | z++; | 811 | z++; |
813 | } | 812 | } |
814 | if (xPos - oldX < x - xPos && z > 0) { | 813 | if (xPos - oldX < x - xPos && z > 0) { |
815 | z--; | 814 | z--; |
816 | x = oldX; | 815 | x = oldX; |
817 | } | 816 | } |
818 | cursor.x = z; | 817 | cursor.x = z; |
819 | return x; | 818 | return x; |
820 | } | 819 | } |
821 | 820 | ||
822 | 821 | ||
823 | int KateDocument::textPos(const TextLine::Ptr &textLine, int xPos) { | 822 | int KateDocument::textPos(const TextLine::Ptr &textLine, int xPos) { |
824 | int x, oldX; | 823 | int x, oldX; |
825 | int z; | 824 | int z; |
826 | QChar ch; | 825 | QChar ch; |
827 | Attribute *a; | 826 | Attribute *a; |
828 | 827 | ||
829 | x = oldX = z = 0; | 828 | x = oldX = z = 0; |
830 | while (x < xPos) { // && z < len) { | 829 | while (x < xPos) { // && z < len) { |
831 | oldX = x; | 830 | oldX = x; |
832 | ch = textLine->getChar(z); | 831 | ch = textLine->getChar(z); |
833 | a = &m_attribs[textLine->getAttr(z)]; | 832 | a = &m_attribs[textLine->getAttr(z)]; |
834 | 833 | ||
835 | if (ch == '\t') | 834 | if (ch == '\t') |
836 | x += m_tabWidth - (x % m_tabWidth); | 835 | x += m_tabWidth - (x % m_tabWidth); |
837 | else if (a->bold && a->italic) | 836 | else if (a->bold && a->italic) |
838 | x += myFontMetricsBI.width(ch); | 837 | x += myFontMetricsBI.width(ch); |
839 | else if (a->bold) | 838 | else if (a->bold) |
840 | x += myFontMetricsBold.width(ch); | 839 | x += myFontMetricsBold.width(ch); |
841 | else if (a->italic) | 840 | else if (a->italic) |
842 | x += myFontMetricsItalic.width(ch); | 841 | x += myFontMetricsItalic.width(ch); |
843 | else | 842 | else |
844 | x += myFontMetrics.width(ch); | 843 | x += myFontMetrics.width(ch); |
845 | 844 | ||
846 | z++; | 845 | z++; |
847 | } | 846 | } |
848 | if (xPos - oldX < x - xPos && z > 0) { | 847 | if (xPos - oldX < x - xPos && z > 0) { |
849 | z--; | 848 | z--; |
850 | // newXPos = oldX; | 849 | // newXPos = oldX; |
851 | }// else newXPos = x; | 850 | }// else newXPos = x; |
852 | return z; | 851 | return z; |
853 | } | 852 | } |
854 | 853 | ||
855 | int KateDocument::textWidth() { | 854 | int KateDocument::textWidth() { |
856 | return int(maxLength + 8); | 855 | return int(maxLength + 8); |
857 | } | 856 | } |
858 | 857 | ||
859 | int KateDocument::textHeight() { | 858 | int KateDocument::textHeight() { |
860 | return numLines()*fontHeight; | 859 | return numLines()*fontHeight; |
861 | } | 860 | } |
862 | 861 | ||
863 | void KateDocument::insert(VConfig &c, const QString &s) { | 862 | void KateDocument::insert(VConfig &c, const QString &s) { |
864 | int pos; | 863 | int pos; |
865 | QChar ch; | 864 | QChar ch; |
866 | QString buf; | 865 | QString buf; |
867 | 866 | ||
868 | if (s.isEmpty()) return; | 867 | if (s.isEmpty()) return; |
869 | 868 | ||
870 | recordStart(c, KateActionGroup::ugPaste); | 869 | recordStart(c, KateActionGroup::ugPaste); |
871 | 870 | ||
872 | pos = 0; | 871 | pos = 0; |
873 | if (!(c.flags & KateView::cfVerticalSelect)) { | 872 | if (!(c.flags & KateView::cfVerticalSelect)) { |
874 | do { | 873 | do { |
875 | ch = s[pos]; | 874 | ch = s[pos]; |
876 | if (ch.isPrint() || ch == '\t') { | 875 | if (ch.isPrint() || ch == '\t') { |
877 | buf += ch; // append char to buffer | 876 | buf += ch; // append char to buffer |
878 | } else if (ch == '\n') { | 877 | } else if (ch == '\n') { |
879 | recordAction(KateAction::newLine, c.cursor); // wrap contents behind cursor to new line | 878 | recordAction(KateAction::newLine, c.cursor); // wrap contents behind cursor to new line |
880 | recordInsert(c, buf); // append to old line | 879 | recordInsert(c, buf); // append to old line |
881 | // c.cursor.x += buf.length(); | 880 | // c.cursor.x += buf.length(); |
882 | buf.truncate(0); // clear buffer | 881 | buf.truncate(0); // clear buffer |
883 | c.cursor.y++; | 882 | c.cursor.y++; |
884 | c.cursor.x = 0; | 883 | c.cursor.x = 0; |
885 | } | 884 | } |
886 | pos++; | 885 | pos++; |
887 | } while (pos < (int) s.length()); | 886 | } while (pos < (int) s.length()); |
888 | } else { | 887 | } else { |
889 | int xPos; | 888 | int xPos; |
890 | 889 | ||
891 | xPos = textWidth(c.cursor); | 890 | xPos = textWidth(c.cursor); |
892 | do { | 891 | do { |
893 | ch = s[pos]; | 892 | ch = s[pos]; |
894 | if (ch.isPrint() || ch == '\t') { | 893 | if (ch.isPrint() || ch == '\t') { |
895 | buf += ch; | 894 | buf += ch; |
896 | } else if (ch == '\n') { | 895 | } else if (ch == '\n') { |
897 | recordInsert(c, buf); | 896 | recordInsert(c, buf); |
898 | c.cursor.x += buf.length(); | 897 | c.cursor.x += buf.length(); |
899 | buf.truncate(0); | 898 | buf.truncate(0); |
900 | c.cursor.y++; | 899 | c.cursor.y++; |
901 | if (c.cursor.y >= numLines()) | 900 | if (c.cursor.y >= numLines()) |
902 | recordAction(KateAction::insLine, c.cursor); | 901 | recordAction(KateAction::insLine, c.cursor); |
903 | c.cursor.x = textPos(getTextLine(c.cursor.y), xPos); | 902 | c.cursor.x = textPos(getTextLine(c.cursor.y), xPos); |
904 | } | 903 | } |
905 | pos++; | 904 | pos++; |
906 | } while (pos < (int) s.length()); | 905 | } while (pos < (int) s.length()); |
907 | } | 906 | } |
908 | recordInsert(c, buf); | 907 | recordInsert(c, buf); |
909 | c.cursor.x += buf.length(); | 908 | c.cursor.x += buf.length(); |
910 | recordEnd(c); | 909 | recordEnd(c); |
911 | } | 910 | } |
912 | 911 | ||
913 | void KateDocument::insertFile(VConfig &c, QIODevice &dev) | 912 | void KateDocument::insertFile(VConfig &c, QIODevice &dev) |
914 | { | 913 | { |
915 | recordStart(c, KateActionGroup::ugPaste); | 914 | recordStart(c, KateActionGroup::ugPaste); |
916 | 915 | ||
917 | QString buf; | 916 | QString buf; |
918 | QChar ch, last; | 917 | QChar ch, last; |
919 | 918 | ||
920 | QTextStream stream( &dev ); | 919 | QTextStream stream( &dev ); |
921 | 920 | ||
922 | while ( !stream.atEnd() ) { | 921 | while ( !stream.atEnd() ) { |
923 | stream >> ch; | 922 | stream >> ch; |
924 | 923 | ||
925 | if (ch.isPrint() || ch == '\t') { | 924 | if (ch.isPrint() || ch == '\t') { |
926 | buf += ch; | 925 | buf += ch; |
927 | } else if (ch == '\n' || ch == '\r') { | 926 | } else if (ch == '\n' || ch == '\r') { |
928 | if (last != '\r' || ch != '\n') { | 927 | if (last != '\r' || ch != '\n') { |
929 | recordAction(KateAction::newLine, c.cursor); | 928 | recordAction(KateAction::newLine, c.cursor); |
930 | recordInsert(c, buf); | 929 | recordInsert(c, buf); |
931 | buf.truncate(0); | 930 | buf.truncate(0); |
932 | c.cursor.y++; | 931 | c.cursor.y++; |
933 | c.cursor.x = 0; | 932 | c.cursor.x = 0; |
934 | } | 933 | } |
935 | last = ch; | 934 | last = ch; |
936 | } | 935 | } |
937 | } | 936 | } |
938 | 937 | ||
939 | recordInsert(c, buf); | 938 | recordInsert(c, buf); |
940 | recordEnd(c); | 939 | recordEnd(c); |
941 | } | 940 | } |
942 | 941 | ||
943 | int KateDocument::currentColumn(PointStruc &cursor) { | 942 | int KateDocument::currentColumn(PointStruc &cursor) { |
944 | return getTextLine(cursor.y)->cursorX(cursor.x,tabChars); | 943 | return getTextLine(cursor.y)->cursorX(cursor.x,tabChars); |
945 | } | 944 | } |
946 | 945 | ||
947 | bool KateDocument::insertChars(VConfig &c, const QString &chars) { | 946 | bool KateDocument::insertChars(VConfig &c, const QString &chars) { |
948 | int z, pos, l; | 947 | int z, pos, l; |
949 | bool onlySpaces; | 948 | bool onlySpaces; |
950 | QChar ch; | 949 | QChar ch; |
951 | QString buf; | 950 | QString buf; |
952 | 951 | ||
953 | TextLine::Ptr textLine = getTextLine(c.cursor.y); | 952 | TextLine::Ptr textLine = getTextLine(c.cursor.y); |
954 | 953 | ||
955 | pos = 0; | 954 | pos = 0; |
956 | onlySpaces = true; | 955 | onlySpaces = true; |
957 | for (z = 0; z < (int) chars.length(); z++) { | 956 | for (z = 0; z < (int) chars.length(); z++) { |
958 | ch = chars[z]; | 957 | ch = chars[z]; |
959 | if (ch == '\t' && c.flags & KateView::cfReplaceTabs) { | 958 | if (ch == '\t' && c.flags & KateView::cfReplaceTabs) { |
960 | l = tabChars - (textLine->cursorX(c.cursor.x, tabChars) % tabChars); | 959 | l = tabChars - (textLine->cursorX(c.cursor.x, tabChars) % tabChars); |
961 | while (l > 0) { | 960 | while (l > 0) { |
962 | buf.insert(pos, ' '); | 961 | buf.insert(pos, ' '); |
963 | pos++; | 962 | pos++; |
964 | l--; | 963 | l--; |
965 | } | 964 | } |
966 | } else if (ch.isPrint() || ch == '\t') { | 965 | } else if (ch.isPrint() || ch == '\t') { |
967 | buf.insert(pos, ch); | 966 | buf.insert(pos, ch); |
968 | pos++; | 967 | pos++; |
969 | if (ch != ' ') onlySpaces = false; | 968 | if (ch != ' ') onlySpaces = false; |
970 | if (c.flags & KateView::cfAutoBrackets) { | 969 | if (c.flags & KateView::cfAutoBrackets) { |
971 | if (ch == '(') buf.insert(pos, ')'); | 970 | if (ch == '(') buf.insert(pos, ')'); |
972 | if (ch == '[') buf.insert(pos, ']'); | 971 | if (ch == '[') buf.insert(pos, ']'); |
973 | if (ch == '{') buf.insert(pos, '}'); | 972 | if (ch == '{') buf.insert(pos, '}'); |
974 | } | 973 | } |
975 | } | 974 | } |
976 | } | 975 | } |
977 | //pos = cursor increment | 976 | //pos = cursor increment |
978 | 977 | ||
979 | //return false if nothing has to be inserted | 978 | //return false if nothing has to be inserted |
980 | if (buf.isEmpty()) return false; | 979 | if (buf.isEmpty()) return false; |
981 | 980 | ||
982 | //auto deletion of the marked text occurs not very often and can therefore | 981 | //auto deletion of the marked text occurs not very often and can therefore |
983 | // be recorded separately | 982 | // be recorded separately |
984 | if (c.flags &KateView:: cfDelOnInput) delMarkedText(c); | 983 | if (c.flags &KateView:: cfDelOnInput) delMarkedText(c); |
985 | 984 | ||
986 | recordStart(c, KateActionGroup::ugInsChar); | 985 | recordStart(c, KateActionGroup::ugInsChar); |
987 | recordReplace(c/*.cursor*/, (c.flags & KateView::cfOvr) ? buf.length() : 0, buf); | 986 | recordReplace(c/*.cursor*/, (c.flags & KateView::cfOvr) ? buf.length() : 0, buf); |
988 | c.cursor.x += pos; | 987 | c.cursor.x += pos; |
989 | 988 | ||
990 | if (myWordWrap && myWordWrapAt > 0) { | 989 | if (myWordWrap && myWordWrapAt > 0) { |
991 | int line; | 990 | int line; |
992 | const QChar *s; | 991 | const QChar *s; |
993 | // int pos; | 992 | // int pos; |
994 | PointStruc actionCursor; | 993 | PointStruc actionCursor; |
995 | 994 | ||
996 | line = c.cursor.y; | 995 | line = c.cursor.y; |
997 | do { | 996 | do { |
998 | textLine = getTextLine(line); | 997 | textLine = getTextLine(line); |
999 | s = textLine->getText(); | 998 | s = textLine->getText(); |
1000 | l = textLine->length(); | 999 | l = textLine->length(); |
1001 | for (z = myWordWrapAt; z < l; z++) if (!s[z].isSpace()) break; //search for text to wrap | 1000 | for (z = myWordWrapAt; z < l; z++) if (!s[z].isSpace()) break; //search for text to wrap |
1002 | if (z >= l) break; // nothing more to wrap | 1001 | if (z >= l) break; // nothing more to wrap |
1003 | pos = myWordWrapAt; | 1002 | pos = myWordWrapAt; |
1004 | for (; z >= 0; z--) { //find wrap position | 1003 | for (; z >= 0; z--) { //find wrap position |
1005 | if (s[z].isSpace()) { | 1004 | if (s[z].isSpace()) { |
1006 | pos = z + 1; | 1005 | pos = z + 1; |
1007 | break; | 1006 | break; |
1008 | } | 1007 | } |
1009 | } | 1008 | } |
1010 | //pos = wrap position | 1009 | //pos = wrap position |
1011 | 1010 | ||
1012 | if (line == c.cursor.y && pos <= c.cursor.x) { | 1011 | if (line == c.cursor.y && pos <= c.cursor.x) { |
1013 | //wrap cursor | 1012 | //wrap cursor |
1014 | c.cursor.y++; | 1013 | c.cursor.y++; |
1015 | c.cursor.x -= pos; | 1014 | c.cursor.x -= pos; |
1016 | } | 1015 | } |
1017 | 1016 | ||
1018 | if (line == lastLine() || (getTextLine(line+1)->length() == 0) ) { | 1017 | if (line == lastLine() || (getTextLine(line+1)->length() == 0) ) { |
1019 | //at end of doc: create new line | 1018 | //at end of doc: create new line |
1020 | actionCursor.x = pos; | 1019 | actionCursor.x = pos; |
1021 | actionCursor.y = line; | 1020 | actionCursor.y = line; |
1022 | recordAction(KateAction::newLine,actionCursor); | 1021 | recordAction(KateAction::newLine,actionCursor); |
1023 | } else { | 1022 | } else { |
1024 | //wrap | 1023 | //wrap |
1025 | actionCursor.y = line + 1; | 1024 | actionCursor.y = line + 1; |
1026 | if (!s[l - 1].isSpace()) { //add space in next line if necessary | 1025 | if (!s[l - 1].isSpace()) { //add space in next line if necessary |
1027 | actionCursor.x = 0; | 1026 | actionCursor.x = 0; |
1028 | recordInsert(actionCursor, " "); | 1027 | recordInsert(actionCursor, " "); |
1029 | } | 1028 | } |
1030 | actionCursor.x = textLine->length() - pos; | 1029 | actionCursor.x = textLine->length() - pos; |
1031 | recordAction(KateAction::wordWrap, actionCursor); | 1030 | recordAction(KateAction::wordWrap, actionCursor); |
1032 | } | 1031 | } |
1033 | line++; | 1032 | line++; |
1034 | } while (true); | 1033 | } while (true); |
1035 | } | 1034 | } |
1036 | recordEnd(c); | 1035 | recordEnd(c); |
1037 | return true; | 1036 | return true; |
1038 | } | 1037 | } |
1039 | 1038 | ||
1040 | QString tabString(int pos, int tabChars) { | 1039 | QString tabString(int pos, int tabChars) { |
1041 | QString s; | 1040 | QString s; |
1042 | while (pos >= tabChars) { | 1041 | while (pos >= tabChars) { |
1043 | s += '\t'; | 1042 | s += '\t'; |
1044 | pos -= tabChars; | 1043 | pos -= tabChars; |
1045 | } | 1044 | } |
1046 | while (pos > 0) { | 1045 | while (pos > 0) { |
1047 | s += ' '; | 1046 | s += ' '; |
1048 | pos--; | 1047 | pos--; |
1049 | } | 1048 | } |
1050 | return s; | 1049 | return s; |
1051 | } | 1050 | } |
1052 | 1051 | ||
1053 | void KateDocument::newLine(VConfig &c) { | 1052 | void KateDocument::newLine(VConfig &c) { |
1054 | 1053 | ||
1055 | //auto deletion of marked text is done by the view to have a more | 1054 | //auto deletion of marked text is done by the view to have a more |
1056 | // "low level" KateDocument::newLine method | 1055 | // "low level" KateDocument::newLine method |
1057 | recordStart(c, KateActionGroup::ugInsLine); | 1056 | recordStart(c, KateActionGroup::ugInsLine); |
1058 | 1057 | ||
1059 | if (!(c.flags & KateView::cfAutoIndent)) { | 1058 | if (!(c.flags & KateView::cfAutoIndent)) { |
1060 | recordAction(KateAction::newLine,c.cursor); | 1059 | recordAction(KateAction::newLine,c.cursor); |
1061 | c.cursor.y++; | 1060 | c.cursor.y++; |
1062 | c.cursor.x = 0; | 1061 | c.cursor.x = 0; |
1063 | } else { | 1062 | } else { |
1064 | TextLine::Ptr textLine = getTextLine(c.cursor.y); | 1063 | TextLine::Ptr textLine = getTextLine(c.cursor.y); |
1065 | int pos = textLine->firstChar(); | 1064 | int pos = textLine->firstChar(); |
1066 | if (c.cursor.x < pos) c.cursor.x = pos; // place cursor on first char if before | 1065 | if (c.cursor.x < pos) c.cursor.x = pos; // place cursor on first char if before |
1067 | 1066 | ||
1068 | int y = c.cursor.y; | 1067 | int y = c.cursor.y; |
1069 | while ((y > 0) && (pos < 0)) { // search a not empty text line | 1068 | while ((y > 0) && (pos < 0)) { // search a not empty text line |
1070 | textLine = getTextLine(--y); | 1069 | textLine = getTextLine(--y); |
1071 | pos = textLine->firstChar(); | 1070 | pos = textLine->firstChar(); |
1072 | } | 1071 | } |
1073 | recordAction(KateAction::newLine, c.cursor); | 1072 | recordAction(KateAction::newLine, c.cursor); |
1074 | c.cursor.y++; | 1073 | c.cursor.y++; |
1075 | c.cursor.x = 0; | 1074 | c.cursor.x = 0; |
1076 | if (pos > 0) { | 1075 | if (pos > 0) { |
1077 | pos = textLine->cursorX(pos, tabChars); | 1076 | pos = textLine->cursorX(pos, tabChars); |
1078 | // if (getTextLine(c.cursor.y)->length() > 0) { | 1077 | // if (getTextLine(c.cursor.y)->length() > 0) { |
1079 | QString s = tabString(pos, (c.flags & KateView::cfSpaceIndent) ? 0xffffff : tabChars); | 1078 | QString s = tabString(pos, (c.flags & KateView::cfSpaceIndent) ? 0xffffff : tabChars); |
1080 | recordInsert(c.cursor, s); | 1079 | recordInsert(c.cursor, s); |
1081 | pos = s.length(); | 1080 | pos = s.length(); |
1082 | // } | 1081 | // } |
1083 | // recordInsert(c.cursor, QString(textLine->getText(), pos)); | 1082 | // recordInsert(c.cursor, QString(textLine->getText(), pos)); |
1084 | c.cursor.x = pos; | 1083 | c.cursor.x = pos; |
1085 | } | 1084 | } |
1086 | } | 1085 | } |
1087 | 1086 | ||
1088 | recordEnd(c); | 1087 | recordEnd(c); |
1089 | } | 1088 | } |
1090 | 1089 | ||
1091 | void KateDocument::killLine(VConfig &c) { | 1090 | void KateDocument::killLine(VConfig &c) { |
1092 | 1091 | ||
1093 | recordStart(c, KateActionGroup::ugDelLine); | 1092 | recordStart(c, KateActionGroup::ugDelLine); |
1094 | c.cursor.x = 0; | 1093 | c.cursor.x = 0; |
1095 | recordDelete(c.cursor, 0xffffff); | 1094 | recordDelete(c.cursor, 0xffffff); |
1096 | if (c.cursor.y < lastLine()) { | 1095 | if (c.cursor.y < lastLine()) { |
1097 | recordAction(KateAction::killLine, c.cursor); | 1096 | recordAction(KateAction::killLine, c.cursor); |
1098 | } | 1097 | } |
1099 | recordEnd(c); | 1098 | recordEnd(c); |
1100 | } | 1099 | } |
1101 | 1100 | ||
1102 | void KateDocument::backspace(VConfig &c) { | 1101 | void KateDocument::backspace(VConfig &c) { |
1103 | 1102 | ||
1104 | if (c.cursor.x <= 0 && c.cursor.y <= 0) return; | 1103 | if (c.cursor.x <= 0 && c.cursor.y <= 0) return; |
1105 | 1104 | ||
1106 | if (c.cursor.x > 0) { | 1105 | if (c.cursor.x > 0) { |
1107 | recordStart(c, KateActionGroup::ugDelChar); | 1106 | recordStart(c, KateActionGroup::ugDelChar); |
1108 | if (!(c.flags & KateView::cfBackspaceIndents)) { | 1107 | if (!(c.flags & KateView::cfBackspaceIndents)) { |
1109 | // ordinary backspace | 1108 | // ordinary backspace |
1110 | c.cursor.x--; | 1109 | c.cursor.x--; |
1111 | recordDelete(c.cursor, 1); | 1110 | recordDelete(c.cursor, 1); |
1112 | } else { | 1111 | } else { |
1113 | // backspace indents: erase to next indent position | 1112 | // backspace indents: erase to next indent position |
1114 | int l = 1; // del one char | 1113 | int l = 1; // del one char |
1115 | 1114 | ||
1116 | TextLine::Ptr textLine = getTextLine(c.cursor.y); | 1115 | TextLine::Ptr textLine = getTextLine(c.cursor.y); |
1117 | int pos = textLine->firstChar(); | 1116 | int pos = textLine->firstChar(); |
1118 | if (pos < 0 || pos >= c.cursor.x) { | 1117 | if (pos < 0 || pos >= c.cursor.x) { |
1119 | // only spaces on left side of cursor | 1118 | // only spaces on left side of cursor |
1120 | // search a line with less spaces | 1119 | // search a line with less spaces |
1121 | int y = c.cursor.y; | 1120 | int y = c.cursor.y; |
1122 | while (y > 0) { | 1121 | while (y > 0) { |
1123 | textLine = getTextLine(--y); | 1122 | textLine = getTextLine(--y); |
1124 | pos = textLine->firstChar(); | 1123 | pos = textLine->firstChar(); |
1125 | if (pos >= 0 && pos < c.cursor.x) { | 1124 | if (pos >= 0 && pos < c.cursor.x) { |
1126 | l = c.cursor.x - pos; // del more chars | 1125 | l = c.cursor.x - pos; // del more chars |
1127 | break; | 1126 | break; |
1128 | } | 1127 | } |
1129 | } | 1128 | } |
1130 | } | 1129 | } |
1131 | // break effectively jumps here | 1130 | // break effectively jumps here |
1132 | c.cursor.x -= l; | 1131 | c.cursor.x -= l; |
1133 | recordDelete(c.cursor, l); | 1132 | recordDelete(c.cursor, l); |
1134 | } | 1133 | } |
1135 | } else { | 1134 | } else { |
1136 | // c.cursor.x == 0: wrap to previous line | 1135 | // c.cursor.x == 0: wrap to previous line |
1137 | recordStart(c, KateActionGroup::ugDelLine); | 1136 | recordStart(c, KateActionGroup::ugDelLine); |
1138 | c.cursor.y--; | 1137 | c.cursor.y--; |
1139 | c.cursor.x = getTextLine(c.cursor.y)->length(); | 1138 | c.cursor.x = getTextLine(c.cursor.y)->length(); |
1140 | recordAction(KateAction::delLine,c.cursor); | 1139 | recordAction(KateAction::delLine,c.cursor); |
1141 | } | 1140 | } |
1142 | recordEnd(c); | 1141 | recordEnd(c); |
1143 | } | 1142 | } |
1144 | 1143 | ||
1145 | 1144 | ||
1146 | void KateDocument::del(VConfig &c) { | 1145 | void KateDocument::del(VConfig &c) { |
1147 | TextLine::Ptr textLine = getTextLine(c.cursor.y); | 1146 | TextLine::Ptr textLine = getTextLine(c.cursor.y); |
1148 | int len = (c.flags & KateView::cfRemoveSpaces) ? textLine->lastChar() : textLine->length(); | 1147 | int len = (c.flags & KateView::cfRemoveSpaces) ? textLine->lastChar() : textLine->length(); |
1149 | if (c.cursor.x < len/*getTextLine(c.cursor.y)->length()*/) { | 1148 | if (c.cursor.x < len/*getTextLine(c.cursor.y)->length()*/) { |
1150 | // delete one character | 1149 | // delete one character |
1151 | recordStart(c, KateActionGroup::ugDelChar); | 1150 | recordStart(c, KateActionGroup::ugDelChar); |
1152 | recordDelete(c.cursor, 1); | 1151 | recordDelete(c.cursor, 1); |
1153 | recordEnd(c); | 1152 | recordEnd(c); |
1154 | } else { | 1153 | } else { |
1155 | if (c.cursor.y < lastLine()) { | 1154 | if (c.cursor.y < lastLine()) { |
1156 | // wrap next line to this line | 1155 | // wrap next line to this line |
1157 | textLine->truncate(c.cursor.x); // truncate spaces | 1156 | textLine->truncate(c.cursor.x); // truncate spaces |
1158 | recordStart(c, KateActionGroup::ugDelLine); | 1157 | recordStart(c, KateActionGroup::ugDelLine); |
1159 | recordAction(KateAction::delLine,c.cursor); | 1158 | recordAction(KateAction::delLine,c.cursor); |
1160 | recordEnd(c); | 1159 | recordEnd(c); |
1161 | } | 1160 | } |
1162 | } | 1161 | } |
1163 | } | 1162 | } |
1164 | 1163 | ||
1165 | void KateDocument::clear() { | 1164 | void KateDocument::clear() { |
1166 | PointStruc cursor; | 1165 | PointStruc cursor; |
1167 | KateView *view; | 1166 | KateView *view; |
1168 | 1167 | ||
1169 | setPseudoModal(0L); | 1168 | setPseudoModal(0L); |
1170 | cursor.x = cursor.y = 0; | 1169 | cursor.x = cursor.y = 0; |
1171 | for (view = views.first(); view != 0L; view = views.next() ) { | 1170 | for (view = views.first(); view != 0L; view = views.next() ) { |
1172 | view->updateCursor(cursor); | 1171 | view->updateCursor(cursor); |
1173 | view->tagAll(); | 1172 | view->tagAll(); |
1174 | } | 1173 | } |
1175 | 1174 | ||
1176 | eolMode = KateDocument::eolUnix; | 1175 | eolMode = KateDocument::eolUnix; |
1177 | 1176 | ||
1178 | buffer->clear(); | 1177 | buffer->clear(); |
1179 | longestLine = buffer->line(0); | 1178 | longestLine = buffer->line(0); |
1180 | 1179 | ||
1181 | maxLength = 0; | 1180 | maxLength = 0; |
1182 | 1181 | ||
1183 | select.x = -1; | 1182 | select.x = -1; |
1184 | 1183 | ||
1185 | selectStart = 0xffffff; | 1184 | selectStart = 0xffffff; |
1186 | selectEnd = 0; | 1185 | selectEnd = 0; |
1187 | oldMarkState = false; | 1186 | oldMarkState = false; |
1188 | 1187 | ||
1189 | setModified(false); | 1188 | setModified(false); |
1190 | 1189 | ||
1191 | undoList.clear(); | 1190 | undoList.clear(); |
1192 | currentUndo = 0; | 1191 | currentUndo = 0; |
1193 | newUndo(); | 1192 | newUndo(); |
1194 | } | 1193 | } |
1195 | 1194 | ||
1196 | void KateDocument::cut(VConfig &c) { | 1195 | void KateDocument::cut(VConfig &c) { |
1197 | 1196 | ||
1198 | if (selectEnd < selectStart) return; | 1197 | if (selectEnd < selectStart) return; |
1199 | 1198 | ||
1200 | copy(c.flags); | 1199 | copy(c.flags); |
1201 | delMarkedText(c); | 1200 | delMarkedText(c); |
1202 | } | 1201 | } |
1203 | 1202 | ||
1204 | void KateDocument::copy(int flags) { | 1203 | void KateDocument::copy(int flags) { |
1205 | 1204 | ||
1206 | if (selectEnd < selectStart) return; | 1205 | if (selectEnd < selectStart) return; |
1207 | 1206 | ||
1208 | QString s = markedText(flags); | 1207 | QString s = markedText(flags); |
1209 | if (!s.isEmpty()) { | 1208 | if (!s.isEmpty()) { |
1210 | //#if defined(_WS_X11_) | 1209 | //#if defined(_WS_X11_) |
1211 | if (m_singleSelection) | 1210 | if (m_singleSelection) |
1212 | disconnect(QApplication::clipboard(), SIGNAL(dataChanged()), this, 0); | 1211 | disconnect(QApplication::clipboard(), SIGNAL(dataChanged()), this, 0); |
1213 | //#endif | 1212 | //#endif |
1214 | QApplication::clipboard()->setText(s); | 1213 | QApplication::clipboard()->setText(s); |
1215 | //#if defined(_WS_X11_) | 1214 | //#if defined(_WS_X11_) |
1216 | if (m_singleSelection) { | 1215 | if (m_singleSelection) { |
1217 | connect(QApplication::clipboard(), SIGNAL(dataChanged()), | 1216 | connect(QApplication::clipboard(), SIGNAL(dataChanged()), |
1218 | this, SLOT(clipboardChanged())); | 1217 | this, SLOT(clipboardChanged())); |
1219 | } | 1218 | } |
1220 | //#endif | 1219 | //#endif |
1221 | } | 1220 | } |
1222 | } | 1221 | } |
1223 | 1222 | ||
1224 | void KateDocument::paste(VConfig &c) { | 1223 | void KateDocument::paste(VConfig &c) { |
1225 | QString s = QApplication::clipboard()->text(); | 1224 | QString s = QApplication::clipboard()->text(); |
1226 | if (!s.isEmpty()) { | 1225 | if (!s.isEmpty()) { |
1227 | insert(c, s); | 1226 | insert(c, s); |
1228 | } | 1227 | } |
1229 | } | 1228 | } |
1230 | 1229 | ||
1231 | void KateDocument::toggleRect(int start, int end, int x1, int x2) { | 1230 | void KateDocument::toggleRect(int start, int end, int x1, int x2) { |
1232 | int z, line; | 1231 | int z, line; |
1233 | bool t; | 1232 | bool t; |
1234 | 1233 | ||
1235 | if (x1 > x2) { | 1234 | if (x1 > x2) { |
1236 | z = x1; | 1235 | z = x1; |
1237 | x1 = x2; | 1236 | x1 = x2; |
1238 | x2 = z; | 1237 | x2 = z; |
1239 | } | 1238 | } |
1240 | if (start > end) { | 1239 | if (start > end) { |
1241 | z = start; | 1240 | z = start; |
1242 | start = end; | 1241 | start = end; |
1243 | end = z; | 1242 | end = z; |
1244 | } | 1243 | } |
1245 | 1244 | ||
1246 | t = false; | 1245 | t = false; |
1247 | for (line = start; line < end; line++) { | 1246 | for (line = start; line < end; line++) { |
1248 | int x, oldX, s, e, newX1, newX2; | 1247 | int x, oldX, s, e, newX1, newX2; |
1249 | QChar ch; | 1248 | QChar ch; |
1250 | Attribute *a; | 1249 | Attribute *a; |
1251 | 1250 | ||
1252 | TextLine::Ptr textLine = getTextLine(line); | 1251 | TextLine::Ptr textLine = getTextLine(line); |
1253 | 1252 | ||
1254 | //--- speed optimization | 1253 | //--- speed optimization |
1255 | //s = textPos(textLine, x1, newX1); | 1254 | //s = textPos(textLine, x1, newX1); |
1256 | x = oldX = z = 0; | 1255 | x = oldX = z = 0; |
1257 | while (x < x1) { // && z < len) { | 1256 | while (x < x1) { // && z < len) { |
1258 | oldX = x; | 1257 | oldX = x; |
1259 | ch = textLine->getChar(z); | 1258 | ch = textLine->getChar(z); |
1260 | a = &m_attribs[textLine->getAttr(z)]; | 1259 | a = &m_attribs[textLine->getAttr(z)]; |
1261 | 1260 | ||
1262 | if (ch == '\t') | 1261 | if (ch == '\t') |
1263 | x += m_tabWidth - (x % m_tabWidth); | 1262 | x += m_tabWidth - (x % m_tabWidth); |
1264 | else if (a->bold && a->italic) | 1263 | else if (a->bold && a->italic) |
1265 | x += myFontMetricsBI.width(ch); | 1264 | x += myFontMetricsBI.width(ch); |
1266 | else if (a->bold) | 1265 | else if (a->bold) |
1267 | x += myFontMetricsBold.width(ch); | 1266 | x += myFontMetricsBold.width(ch); |
1268 | else if (a->italic) | 1267 | else if (a->italic) |
1269 | x += myFontMetricsItalic.width(ch); | 1268 | x += myFontMetricsItalic.width(ch); |
1270 | else | 1269 | else |
1271 | x += myFontMetrics.width(ch); | 1270 | x += myFontMetrics.width(ch); |
1272 | 1271 | ||
1273 | z++; | 1272 | z++; |
1274 | } | 1273 | } |
1275 | s = z; | 1274 | s = z; |
1276 | if (x1 - oldX < x - x1 && z > 0) { | 1275 | if (x1 - oldX < x - x1 && z > 0) { |
1277 | s--; | 1276 | s--; |
1278 | newX1 = oldX; | 1277 | newX1 = oldX; |
1279 | } else newX1 = x; | 1278 | } else newX1 = x; |
1280 | //e = textPos(textLine, x2, newX2); | 1279 | //e = textPos(textLine, x2, newX2); |
1281 | while (x < x2) { // && z < len) { | 1280 | while (x < x2) { // && z < len) { |
1282 | oldX = x; | 1281 | oldX = x; |
1283 | ch = textLine->getChar(z); | 1282 | ch = textLine->getChar(z); |
1284 | a = &m_attribs[textLine->getAttr(z)]; | 1283 | a = &m_attribs[textLine->getAttr(z)]; |
1285 | 1284 | ||
1286 | if (ch == '\t') | 1285 | if (ch == '\t') |
1287 | x += m_tabWidth - (x % m_tabWidth); | 1286 | x += m_tabWidth - (x % m_tabWidth); |
1288 | else if (a->bold && a->italic) | 1287 | else if (a->bold && a->italic) |
1289 | x += myFontMetricsBI.width(ch); | 1288 | x += myFontMetricsBI.width(ch); |
1290 | else if (a->bold) | 1289 | else if (a->bold) |
1291 | x += myFontMetricsBold.width(ch); | 1290 | x += myFontMetricsBold.width(ch); |
1292 | else if (a->italic) | 1291 | else if (a->italic) |
1293 | x += myFontMetricsItalic.width(ch); | 1292 | x += myFontMetricsItalic.width(ch); |
1294 | else | 1293 | else |
1295 | x += myFontMetrics.width(ch); | 1294 | x += myFontMetrics.width(ch); |
1296 | 1295 | ||
1297 | z++; | 1296 | z++; |
1298 | } | 1297 | } |
1299 | e = z; | 1298 | e = z; |
1300 | if (x2 - oldX < x - x2 && z > 0) { | 1299 | if (x2 - oldX < x - x2 && z > 0) { |
1301 | e--; | 1300 | e--; |
1302 | newX2 = oldX; | 1301 | newX2 = oldX; |
1303 | } else newX2 = x; | 1302 | } else newX2 = x; |
1304 | //--- | 1303 | //--- |
1305 | 1304 | ||
1306 | if (e > s) { | 1305 | if (e > s) { |
1307 | textLine->toggleSelect(s, e); | 1306 | textLine->toggleSelect(s, e); |
1308 | tagLineRange(line, newX1, newX2); | 1307 | tagLineRange(line, newX1, newX2); |
1309 | t = true; | 1308 | t = true; |
1310 | } | 1309 | } |
1311 | } | 1310 | } |
1312 | if (t) { | 1311 | if (t) { |
1313 | end--; | 1312 | end--; |
1314 | // tagLines(start, end); | 1313 | // tagLines(start, end); |
1315 | 1314 | ||
1316 | if (start < selectStart) selectStart = start; | 1315 | if (start < selectStart) selectStart = start; |
1317 | if (end > selectEnd) selectEnd = end; | 1316 | if (end > selectEnd) selectEnd = end; |
1318 | emit selectionChanged(); | 1317 | emit selectionChanged(); |
1319 | } | 1318 | } |
1320 | } | 1319 | } |
1321 | 1320 | ||
1322 | void KateDocument::selectTo(VConfig &c, PointStruc &cursor, int cXPos) { | 1321 | void KateDocument::selectTo(VConfig &c, PointStruc &cursor, int cXPos) { |
1323 | //c.cursor = old cursor position | 1322 | //c.cursor = old cursor position |
1324 | //cursor = new cursor position | 1323 | //cursor = new cursor position |
1325 | 1324 | ||
1326 | if (c.cursor.x != select.x || c.cursor.y != select.y) { | 1325 | if (c.cursor.x != select.x || c.cursor.y != select.y) { |
1327 | //new selection | 1326 | //new selection |
1328 | 1327 | ||
1329 | if (!(c.flags & KateView::cfKeepSelection)) deselectAll(); | 1328 | if (!(c.flags & KateView::cfKeepSelection)) deselectAll(); |
1330 | // else recordReset(); | 1329 | // else recordReset(); |
1331 | 1330 | ||
1332 | anchor = c.cursor; | 1331 | anchor = c.cursor; |
1333 | aXPos = c.cXPos; | 1332 | aXPos = c.cXPos; |
1334 | } | 1333 | } |
1335 | 1334 | ||
1336 | if (!(c.flags & KateView::cfVerticalSelect)) { | 1335 | if (!(c.flags & KateView::cfVerticalSelect)) { |
1337 | //horizontal selections | 1336 | //horizontal selections |
1338 | int x, y, sXPos; | 1337 | int x, y, sXPos; |
1339 | int ex, ey, eXPos; | 1338 | int ex, ey, eXPos; |
1340 | bool sel; | 1339 | bool sel; |
1341 | 1340 | ||
1342 | if (cursor.y > c.cursor.y || (cursor.y == c.cursor.y && cursor.x > c.cursor.x)) { | 1341 | if (cursor.y > c.cursor.y || (cursor.y == c.cursor.y && cursor.x > c.cursor.x)) { |
1343 | x = c.cursor.x; | 1342 | x = c.cursor.x; |
1344 | y = c.cursor.y; | 1343 | y = c.cursor.y; |
1345 | sXPos = c.cXPos; | 1344 | sXPos = c.cXPos; |
1346 | ex = cursor.x; | 1345 | ex = cursor.x; |
1347 | ey = cursor.y; | 1346 | ey = cursor.y; |
1348 | eXPos = cXPos; | 1347 | eXPos = cXPos; |
1349 | sel = true; | 1348 | sel = true; |
1350 | } else { | 1349 | } else { |
1351 | x = cursor.x; | 1350 | x = cursor.x; |
1352 | y = cursor.y; | 1351 | y = cursor.y; |
1353 | sXPos = cXPos; | 1352 | sXPos = cXPos; |
1354 | ex = c.cursor.x; | 1353 | ex = c.cursor.x; |
1355 | ey = c.cursor.y; | 1354 | ey = c.cursor.y; |
1356 | eXPos = c.cXPos; | 1355 | eXPos = c.cXPos; |
1357 | sel = false; | 1356 | sel = false; |
1358 | } | 1357 | } |
1359 | 1358 | ||
1360 | // tagLines(y, ye); | 1359 | // tagLines(y, ye); |
1361 | if (y < ey) { | 1360 | if (y < ey) { |
1362 | //tagLineRange(y, sXPos, 0xffffff); | 1361 | //tagLineRange(y, sXPos, 0xffffff); |
1363 | tagLines(y, ey -1); | 1362 | tagLines(y, ey -1); |
1364 | tagLineRange(ey, 0, eXPos); | 1363 | tagLineRange(ey, 0, eXPos); |
1365 | } else tagLineRange(y, sXPos, eXPos); | 1364 | } else tagLineRange(y, sXPos, eXPos); |
1366 | 1365 | ||
1367 | if (y < selectStart) selectStart = y; | 1366 | if (y < selectStart) selectStart = y; |
1368 | if (ey > selectEnd) selectEnd = ey; | 1367 | if (ey > selectEnd) selectEnd = ey; |
1369 | 1368 | ||
1370 | TextLine::Ptr textLine = getTextLine(y); | 1369 | TextLine::Ptr textLine = getTextLine(y); |
1371 | 1370 | ||
1372 | if (c.flags & KateView::cfXorSelect) { | 1371 | if (c.flags & KateView::cfXorSelect) { |
1373 | //xor selection with old selection | 1372 | //xor selection with old selection |
1374 | while (y < ey) { | 1373 | while (y < ey) { |
1375 | textLine->toggleSelectEol(x); | 1374 | textLine->toggleSelectEol(x); |
1376 | x = 0; | 1375 | x = 0; |
1377 | y++; | 1376 | y++; |
1378 | textLine = getTextLine(y); | 1377 | textLine = getTextLine(y); |
1379 | } | 1378 | } |
1380 | textLine->toggleSelect(x, ex); | 1379 | textLine->toggleSelect(x, ex); |
1381 | } else { | 1380 | } else { |
1382 | //set selection over old selection | 1381 | //set selection over old selection |
1383 | 1382 | ||
1384 | if (anchor.y > y || (anchor.y == y && anchor.x > x)) { | 1383 | if (anchor.y > y || (anchor.y == y && anchor.x > x)) { |
1385 | if (anchor.y < ey || (anchor.y == ey && anchor.x < ex)) { | 1384 | if (anchor.y < ey || (anchor.y == ey && anchor.x < ex)) { |
1386 | sel = !sel; | 1385 | sel = !sel; |
1387 | while (y < anchor.y) { | 1386 | while (y < anchor.y) { |
1388 | textLine->selectEol(sel, x); | 1387 | textLine->selectEol(sel, x); |
1389 | x = 0; | 1388 | x = 0; |
1390 | y++; | 1389 | y++; |
1391 | textLine = getTextLine(y); | 1390 | textLine = getTextLine(y); |
1392 | } | 1391 | } |
1393 | textLine->select(sel, x, anchor.x); | 1392 | textLine->select(sel, x, anchor.x); |
1394 | x = anchor.x; | 1393 | x = anchor.x; |
1395 | } | 1394 | } |
1396 | sel = !sel; | 1395 | sel = !sel; |
1397 | } | 1396 | } |
1398 | while (y < ey) { | 1397 | while (y < ey) { |
1399 | textLine->selectEol(sel, x); | 1398 | textLine->selectEol(sel, x); |
1400 | x = 0; | 1399 | x = 0; |
1401 | y++; | 1400 | y++; |
1402 | textLine = getTextLine(y); | 1401 | textLine = getTextLine(y); |
1403 | } | 1402 | } |
1404 | textLine->select(sel, x, ex); | 1403 | textLine->select(sel, x, ex); |
1405 | } | 1404 | } |
1406 | } else { | 1405 | } else { |
1407 | //vertical (block) selections | 1406 | //vertical (block) selections |
1408 | // int ax, sx, ex; | 1407 | // int ax, sx, ex; |
1409 | 1408 | ||
1410 | // ax = textWidth(anchor); | 1409 | // ax = textWidth(anchor); |
1411 | // sx = textWidth(start); | 1410 | // sx = textWidth(start); |
1412 | // ex = textWidth(end); | 1411 | // ex = textWidth(end); |
1413 | 1412 | ||
1414 | toggleRect(c.cursor.y + 1, cursor.y + 1, aXPos, c.cXPos); | 1413 | toggleRect(c.cursor.y + 1, cursor.y + 1, aXPos, c.cXPos); |
1415 | toggleRect(anchor.y, cursor.y + 1, c.cXPos, cXPos); | 1414 | toggleRect(anchor.y, cursor.y + 1, c.cXPos, cXPos); |
1416 | } | 1415 | } |
1417 | select = cursor; | 1416 | select = cursor; |
1418 | optimizeSelection(); | 1417 | optimizeSelection(); |
1419 | emit selectionChanged(); | 1418 | emit selectionChanged(); |
1420 | } | 1419 | } |
1421 | 1420 | ||
1422 | 1421 | ||
1423 | void KateDocument::selectAll() { | 1422 | void KateDocument::selectAll() { |
1424 | int z; | 1423 | int z; |
1425 | TextLine::Ptr textLine; | 1424 | TextLine::Ptr textLine; |
1426 | 1425 | ||
1427 | select.x = -1; | 1426 | select.x = -1; |
1428 | 1427 | ||
1429 | // if (selectStart != 0 || selectEnd != lastLine()) recordReset(); | 1428 | // if (selectStart != 0 || selectEnd != lastLine()) recordReset(); |
1430 | 1429 | ||
1431 | selectStart = 0; | 1430 | selectStart = 0; |
1432 | selectEnd = lastLine(); | 1431 | selectEnd = lastLine(); |
1433 | 1432 | ||
1434 | tagLines(selectStart,selectEnd); | 1433 | tagLines(selectStart,selectEnd); |
1435 | 1434 | ||
1436 | for (z = selectStart; z < selectEnd; z++) { | 1435 | for (z = selectStart; z < selectEnd; z++) { |
1437 | textLine = getTextLine(z); | 1436 | textLine = getTextLine(z); |
1438 | textLine->selectEol(true,0); | 1437 | textLine->selectEol(true,0); |
1439 | } | 1438 | } |
1440 | textLine = getTextLine(z); | 1439 | textLine = getTextLine(z); |
1441 | textLine->select(true,0,textLine->length()); | 1440 | textLine->select(true,0,textLine->length()); |
1442 | emit selectionChanged(); | 1441 | emit selectionChanged(); |
1443 | } | 1442 | } |
1444 | 1443 | ||
1445 | void KateDocument::deselectAll() { | 1444 | void KateDocument::deselectAll() { |
1446 | select.x = -1; | 1445 | select.x = -1; |
1447 | if (selectEnd < selectStart) return; | 1446 | if (selectEnd < selectStart) return; |
1448 | 1447 | ||
1449 | // recordReset(); | 1448 | // recordReset(); |
1450 | 1449 | ||
1451 | tagLines(selectStart,selectEnd); | 1450 | tagLines(selectStart,selectEnd); |
1452 | 1451 | ||
1453 | for (int z = selectStart; z <= selectEnd; z++) { | 1452 | for (int z = selectStart; z <= selectEnd; z++) { |
1454 | TextLine::Ptr textLine = getTextLine(z); | 1453 | TextLine::Ptr textLine = getTextLine(z); |
1455 | textLine->selectEol(false,0); | 1454 | textLine->selectEol(false,0); |
1456 | } | 1455 | } |
1457 | selectStart = 0xffffff; | 1456 | selectStart = 0xffffff; |
1458 | selectEnd = 0; | 1457 | selectEnd = 0; |
1459 | emit selectionChanged(); | 1458 | emit selectionChanged(); |
1460 | } | 1459 | } |
1461 | 1460 | ||
1462 | void KateDocument::invertSelection() { | 1461 | void KateDocument::invertSelection() { |
1463 | TextLine::Ptr textLine; | 1462 | TextLine::Ptr textLine; |
1464 | 1463 | ||
1465 | select.x = -1; | 1464 | select.x = -1; |
1466 | 1465 | ||
1467 | // if (selectStart != 0 || selectEnd != lastLine()) recordReset(); | 1466 | // if (selectStart != 0 || selectEnd != lastLine()) recordReset(); |
1468 | 1467 | ||
1469 | selectStart = 0; | 1468 | selectStart = 0; |
1470 | selectEnd = lastLine(); | 1469 | selectEnd = lastLine(); |
1471 | 1470 | ||
1472 | tagLines(selectStart,selectEnd); | 1471 | tagLines(selectStart,selectEnd); |
1473 | 1472 | ||
1474 | for (int z = selectStart; z < selectEnd; z++) { | 1473 | for (int z = selectStart; z < selectEnd; z++) { |
1475 | textLine = getTextLine(z); | 1474 | textLine = getTextLine(z); |
1476 | textLine->toggleSelectEol(0); | 1475 | textLine->toggleSelectEol(0); |
1477 | } | 1476 | } |
1478 | textLine = getTextLine(selectEnd); | 1477 | textLine = getTextLine(selectEnd); |
1479 | textLine->toggleSelect(0,textLine->length()); | 1478 | textLine->toggleSelect(0,textLine->length()); |
1480 | optimizeSelection(); | 1479 | optimizeSelection(); |
1481 | emit selectionChanged(); | 1480 | emit selectionChanged(); |
1482 | } | 1481 | } |
1483 | 1482 | ||
1484 | void KateDocument::selectWord(PointStruc &cursor, int flags) { | 1483 | void KateDocument::selectWord(PointStruc &cursor, int flags) { |
1485 | int start, end, len; | 1484 | int start, end, len; |
1486 | 1485 | ||
1487 | TextLine::Ptr textLine = getTextLine(cursor.y); | 1486 | TextLine::Ptr textLine = getTextLine(cursor.y); |
1488 | len = textLine->length(); | 1487 | len = textLine->length(); |
1489 | start = end = cursor.x; | 1488 | start = end = cursor.x; |
1490 | while (start > 0 && m_highlight->isInWord(textLine->getChar(start - 1))) start--; | 1489 | while (start > 0 && m_highlight->isInWord(textLine->getChar(start - 1))) start--; |
1491 | while (end < len && m_highlight->isInWord(textLine->getChar(end))) end++; | 1490 | while (end < len && m_highlight->isInWord(textLine->getChar(end))) end++; |
1492 | if (end <= start) return; | 1491 | if (end <= start) return; |
1493 | if (!(flags & KateView::cfKeepSelection)) deselectAll(); | 1492 | if (!(flags & KateView::cfKeepSelection)) deselectAll(); |
1494 | // else recordReset(); | 1493 | // else recordReset(); |
1495 | 1494 | ||
1496 | textLine->select(true, start, end); | 1495 | textLine->select(true, start, end); |
1497 | 1496 | ||
1498 | anchor.x = start; | 1497 | anchor.x = start; |
1499 | select.x = end; | 1498 | select.x = end; |
1500 | anchor.y = select.y = cursor.y; | 1499 | anchor.y = select.y = cursor.y; |
1501 | tagLines(cursor.y, cursor.y); | 1500 | tagLines(cursor.y, cursor.y); |
1502 | if (cursor.y < selectStart) selectStart = cursor.y; | 1501 | if (cursor.y < selectStart) selectStart = cursor.y; |
1503 | if (cursor.y > selectEnd) selectEnd = cursor.y; | 1502 | if (cursor.y > selectEnd) selectEnd = cursor.y; |
1504 | emit selectionChanged(); | 1503 | emit selectionChanged(); |
1505 | } | 1504 | } |
1506 | 1505 | ||
1507 | void KateDocument::selectLength(PointStruc &cursor, int length, int flags) { | 1506 | void KateDocument::selectLength(PointStruc &cursor, int length, int flags) { |
1508 | int start, end; | 1507 | int start, end; |
1509 | 1508 | ||
1510 | TextLine::Ptr textLine = getTextLine(cursor.y); | 1509 | TextLine::Ptr textLine = getTextLine(cursor.y); |
1511 | start = cursor.x; | 1510 | start = cursor.x; |
1512 | end = start + length; | 1511 | end = start + length; |
1513 | if (end <= start) return; | 1512 | if (end <= start) return; |
1514 | if (!(flags & KateView::cfKeepSelection)) deselectAll(); | 1513 | if (!(flags & KateView::cfKeepSelection)) deselectAll(); |
1515 | 1514 | ||
1516 | textLine->select(true, start, end); | 1515 | textLine->select(true, start, end); |
1517 | 1516 | ||
1518 | anchor.x = start; | 1517 | anchor.x = start; |
1519 | select.x = end; | 1518 | select.x = end; |
1520 | anchor.y = select.y = cursor.y; | 1519 | anchor.y = select.y = cursor.y; |
1521 | tagLines(cursor.y, cursor.y); | 1520 | tagLines(cursor.y, cursor.y); |
1522 | if (cursor.y < selectStart) selectStart = cursor.y; | 1521 | if (cursor.y < selectStart) selectStart = cursor.y; |
1523 | if (cursor.y > selectEnd) selectEnd = cursor.y; | 1522 | if (cursor.y > selectEnd) selectEnd = cursor.y; |
1524 | emit selectionChanged(); | 1523 | emit selectionChanged(); |
1525 | } | 1524 | } |
1526 | 1525 | ||
1527 | void KateDocument::doIndent(VConfig &c, int change) { | 1526 | void KateDocument::doIndent(VConfig &c, int change) { |
1528 | 1527 | ||
1529 | c.cursor.x = 0; | 1528 | c.cursor.x = 0; |
1530 | 1529 | ||
1531 | recordStart(c, (change < 0) ? KateActionGroup::ugUnindent | 1530 | recordStart(c, (change < 0) ? KateActionGroup::ugUnindent |
1532 | : KateActionGroup::ugIndent); | 1531 | : KateActionGroup::ugIndent); |
1533 | 1532 | ||
1534 | if (selectEnd < selectStart) { | 1533 | if (selectEnd < selectStart) { |
1535 | // single line | 1534 | // single line |
1536 | optimizeLeadingSpace(c.cursor.y, c.flags, change); | 1535 | optimizeLeadingSpace(c.cursor.y, c.flags, change); |
1537 | } else { | 1536 | } else { |
1538 | // entire selection | 1537 | // entire selection |
1539 | TextLine::Ptr textLine; | 1538 | TextLine::Ptr textLine; |
1540 | int line, z; | 1539 | int line, z; |
1541 | QChar ch; | 1540 | QChar ch; |
1542 | 1541 | ||
1543 | if (c.flags & KateView::cfKeepIndentProfile && change < 0) { | 1542 | if (c.flags & KateView::cfKeepIndentProfile && change < 0) { |
1544 | // unindent so that the existing indent profile doesn´t get screwed | 1543 | // unindent so that the existing indent profile doesn´t get screwed |
1545 | // if any line we may unindent is already full left, don't do anything | 1544 | // if any line we may unindent is already full left, don't do anything |
1546 | for (line = selectStart; line <= selectEnd; line++) { | 1545 | for (line = selectStart; line <= selectEnd; line++) { |
1547 | textLine = getTextLine(line); | 1546 | textLine = getTextLine(line); |
1548 | if (textLine->isSelected() || textLine->numSelected()) { | 1547 | if (textLine->isSelected() || textLine->numSelected()) { |
1549 | for (z = 0; z < tabChars; z++) { | 1548 | for (z = 0; z < tabChars; z++) { |
1550 | ch = textLine->getChar(z); | 1549 | ch = textLine->getChar(z); |
1551 | if (ch == '\t') break; | 1550 | if (ch == '\t') break; |
1552 | if (ch != ' ') { | 1551 | if (ch != ' ') { |
1553 | change = 0; | 1552 | change = 0; |
1554 | goto jumpOut; | 1553 | goto jumpOut; |
1555 | } | 1554 | } |
1556 | } | 1555 | } |
1557 | } | 1556 | } |
1558 | } | 1557 | } |
1559 | jumpOut:; | 1558 | jumpOut:; |
1560 | } | 1559 | } |
1561 | 1560 | ||
1562 | for (line = selectStart; line <= selectEnd; line++) { | 1561 | for (line = selectStart; line <= selectEnd; line++) { |
1563 | textLine = getTextLine(line); | 1562 | textLine = getTextLine(line); |
1564 | if (textLine->isSelected() || textLine->numSelected()) { | 1563 | if (textLine->isSelected() || textLine->numSelected()) { |
1565 | optimizeLeadingSpace(line, c.flags, change); | 1564 | optimizeLeadingSpace(line, c.flags, change); |
1566 | } | 1565 | } |
1567 | } | 1566 | } |
1568 | } | 1567 | } |
1569 | // recordEnd now removes empty undo records | 1568 | // recordEnd now removes empty undo records |
1570 | recordEnd(c.view, c.cursor, c.flags | KateView::cfPersistent); | 1569 | recordEnd(c.view, c.cursor, c.flags | KateView::cfPersistent); |
1571 | } | 1570 | } |
1572 | 1571 | ||
1573 | /* | 1572 | /* |
1574 | Optimize the leading whitespace for a single line. | 1573 | Optimize the leading whitespace for a single line. |
1575 | If change is > 0, it adds indentation units (tabChars) | 1574 | If change is > 0, it adds indentation units (tabChars) |
1576 | if change is == 0, it only optimizes | 1575 | if change is == 0, it only optimizes |
1577 | If change is < 0, it removes indentation units | 1576 | If change is < 0, it removes indentation units |
1578 | This will be used to indent, unindent, and optimal-fill a line. | 1577 | This will be used to indent, unindent, and optimal-fill a line. |
1579 | If excess space is removed depends on the flag cfKeepExtraSpaces | 1578 | If excess space is removed depends on the flag cfKeepExtraSpaces |
1580 | which has to be set by the user | 1579 | which has to be set by the user |
1581 | */ | 1580 | */ |
1582 | void KateDocument::optimizeLeadingSpace(int line, int flags, int change) { | 1581 | void KateDocument::optimizeLeadingSpace(int line, int flags, int change) { |
1583 | int len; | 1582 | int len; |
1584 | int chars, space, okLen; | 1583 | int chars, space, okLen; |
1585 | QChar ch; | 1584 | QChar ch; |
1586 | int extra; | 1585 | int extra; |
1587 | QString s; | 1586 | QString s; |
1588 | PointStruc cursor; | 1587 | PointStruc cursor; |
1589 | 1588 | ||
1590 | TextLine::Ptr textLine = getTextLine(line); | 1589 | TextLine::Ptr textLine = getTextLine(line); |
1591 | len = textLine->length(); | 1590 | len = textLine->length(); |
1592 | space = 0; // length of space at the beginning of the textline | 1591 | space = 0; // length of space at the beginning of the textline |
1593 | okLen = 0; // length of space which does not have to be replaced | 1592 | okLen = 0; // length of space which does not have to be replaced |
1594 | for (chars = 0; chars < len; chars++) { | 1593 | for (chars = 0; chars < len; chars++) { |
1595 | ch = textLine->getChar(chars); | 1594 | ch = textLine->getChar(chars); |
1596 | if (ch == ' ') { | 1595 | if (ch == ' ') { |
1597 | space++; | 1596 | space++; |
1598 | if (flags & KateView::cfSpaceIndent && okLen == chars) okLen++; | 1597 | if (flags & KateView::cfSpaceIndent && okLen == chars) okLen++; |
1599 | } else if (ch == '\t') { | 1598 | } else if (ch == '\t') { |
1600 | space += tabChars - space % tabChars; | 1599 | space += tabChars - space % tabChars; |
1601 | if (!(flags & KateView::cfSpaceIndent) && okLen == chars) okLen++; | 1600 | if (!(flags & KateView::cfSpaceIndent) && okLen == chars) okLen++; |
1602 | } else break; | 1601 | } else break; |
1603 | } | 1602 | } |
1604 | 1603 | ||
1605 | space += change*tabChars; // modify space width | 1604 | space += change*tabChars; // modify space width |
1606 | // if line contains only spaces it will be cleared | 1605 | // if line contains only spaces it will be cleared |
1607 | if (space < 0 || chars == len) space = 0; | 1606 | if (space < 0 || chars == len) space = 0; |
1608 | 1607 | ||
1609 | extra = space % tabChars; // extra spaces which don´t fit the indentation pattern | 1608 | extra = space % tabChars; // extra spaces which don´t fit the indentation pattern |
1610 | if (flags & KateView::cfKeepExtraSpaces) chars -= extra; | 1609 | if (flags & KateView::cfKeepExtraSpaces) chars -= extra; |
1611 | 1610 | ||
1612 | if (flags & KateView::cfSpaceIndent) { | 1611 | if (flags & KateView::cfSpaceIndent) { |
1613 | space -= extra; | 1612 | space -= extra; |
1614 | ch = ' '; | 1613 | ch = ' '; |
1615 | } else { | 1614 | } else { |
1616 | space /= tabChars; | 1615 | space /= tabChars; |
1617 | ch = '\t'; | 1616 | ch = '\t'; |
1618 | } | 1617 | } |
1619 | 1618 | ||
1620 | // don´t replace chars which are already ok | 1619 | // don´t replace chars which are already ok |
1621 | cursor.x = QMIN(okLen, QMIN(chars, space)); | 1620 | cursor.x = QMIN(okLen, QMIN(chars, space)); |
1622 | chars -= cursor.x; | 1621 | chars -= cursor.x; |
1623 | space -= cursor.x; | 1622 | space -= cursor.x; |
1624 | if (chars == 0 && space == 0) return; //nothing to do | 1623 | if (chars == 0 && space == 0) return; //nothing to do |
1625 | 1624 | ||
1626 | s.fill(ch, space); | 1625 | s.fill(ch, space); |
1627 | 1626 | ||
1628 | //printf("chars %d insert %d cursor.x %d\n", chars, insert, cursor.x); | 1627 | //printf("chars %d insert %d cursor.x %d\n", chars, insert, cursor.x); |
1629 | cursor.y = line; | 1628 | cursor.y = line; |
1630 | recordReplace(cursor, chars, s); | 1629 | recordReplace(cursor, chars, s); |
1631 | } | 1630 | } |
1632 | 1631 | ||
1633 | void KateDocument::doComment(VConfig &c, int change) | 1632 | void KateDocument::doComment(VConfig &c, int change) |
1634 | { | 1633 | { |
1635 | c.flags |=KateView:: cfPersistent; | 1634 | c.flags |=KateView:: cfPersistent; |
1636 | 1635 | ||
1637 | recordStart(c, (change < 0) ? KateActionGroup::ugUncomment | 1636 | recordStart(c, (change < 0) ? KateActionGroup::ugUncomment |
1638 | : KateActionGroup::ugComment); | 1637 | : KateActionGroup::ugComment); |
1639 | 1638 | ||
1640 | QString startComment = m_highlight->getCommentStart(); | 1639 | QString startComment = m_highlight->getCommentStart(); |
1641 | QString startLineComment = m_highlight->getCommentSingleLineStart(); | 1640 | QString startLineComment = m_highlight->getCommentSingleLineStart(); |
1642 | QString endComment = m_highlight->getCommentEnd(); | 1641 | QString endComment = m_highlight->getCommentEnd(); |
1643 | 1642 | ||
1644 | int startCommentLen = startComment.length(); | 1643 | int startCommentLen = startComment.length(); |
1645 | int startLineCommentLen = startLineComment.length(); | 1644 | int startLineCommentLen = startLineComment.length(); |
1646 | int endCommentLen = endComment.length(); | 1645 | int endCommentLen = endComment.length(); |
1647 | 1646 | ||
1648 | if (change > 0) | 1647 | if (change > 0) |
1649 | { | 1648 | { |
1650 | if ( !hasMarkedText() ) | 1649 | if ( !hasMarkedText() ) |
1651 | { | 1650 | { |
1652 | if (startLineComment != "") | 1651 | if (startLineComment != "") |
1653 | { | 1652 | { |
1654 | // Add a start comment mark | 1653 | // Add a start comment mark |
1655 | c.cursor.x = 0; | 1654 | c.cursor.x = 0; |
1656 | recordReplace(c.cursor, 0, startLineComment); | 1655 | recordReplace(c.cursor, 0, startLineComment); |
1657 | } | 1656 | } |
1658 | else if ((startComment != "") && (endComment != "")) | 1657 | else if ((startComment != "") && (endComment != "")) |
1659 | { | 1658 | { |
1660 | // Add a start comment mark | 1659 | // Add a start comment mark |
1661 | c.cursor.x = 0; | 1660 | c.cursor.x = 0; |
1662 | recordReplace(c.cursor, 0, startComment); | 1661 | recordReplace(c.cursor, 0, startComment); |
1663 | 1662 | ||
1664 | // Add an end comment mark | 1663 | // Add an end comment mark |
1665 | TextLine* textline = getTextLine(c.cursor.y); | 1664 | TextLine* textline = getTextLine(c.cursor.y); |
1666 | c.cursor.x = textline->length(); | 1665 | c.cursor.x = textline->length(); |
1667 | recordReplace(c.cursor, 0, endComment); | 1666 | recordReplace(c.cursor, 0, endComment); |
1668 | c.cursor.x = 0; | 1667 | c.cursor.x = 0; |
1669 | } | 1668 | } |
1670 | } | 1669 | } |
1671 | else if ((startComment != "") && (endComment != "")) | 1670 | else if ((startComment != "") && (endComment != "")) |
1672 | { | 1671 | { |
1673 | QString marked (c.view->markedText ()); | 1672 | QString marked (c.view->markedText ()); |
1674 | int preDeleteLine = -1, preDeleteCol = -1; | 1673 | int preDeleteLine = -1, preDeleteCol = -1; |
1675 | c.view->getCursorPosition (&preDeleteLine, &preDeleteCol); | 1674 | c.view->getCursorPosition (&preDeleteLine, &preDeleteCol); |
1676 | 1675 | ||
1677 | if (marked.length() > 0) | 1676 | if (marked.length() > 0) |
1678 | c.view->keyDelete (); | 1677 | c.view->keyDelete (); |
1679 | 1678 | ||
1680 | int line = -1, col = -1; | 1679 | int line = -1, col = -1; |
1681 | c.view->getCursorPosition (&line, &col); | 1680 | c.view->getCursorPosition (&line, &col); |
1682 | 1681 | ||
1683 | c.view->insertText (startComment + marked + endComment); | 1682 | c.view->insertText (startComment + marked + endComment); |
1684 | } | 1683 | } |
1685 | } | 1684 | } |
1686 | else | 1685 | else |
1687 | { | 1686 | { |
1688 | if ( !hasMarkedText() ) | 1687 | if ( !hasMarkedText() ) |
1689 | { | 1688 | { |
1690 | TextLine* textline = getTextLine(c.cursor.y); | 1689 | TextLine* textline = getTextLine(c.cursor.y); |
1691 | 1690 | ||
1692 | if(textline->startingWith(startLineComment)) | 1691 | if(textline->startingWith(startLineComment)) |
1693 | { | 1692 | { |
1694 | // Remove start comment mark | 1693 | // Remove start comment mark |
1695 | c.cursor.x = 0; | 1694 | c.cursor.x = 0; |
1696 | recordReplace(c.cursor, startLineCommentLen, ""); | 1695 | recordReplace(c.cursor, startLineCommentLen, ""); |
1697 | } | 1696 | } |
1698 | else if (textline->startingWith(startComment) && textline->endingWith(endComment)) | 1697 | else if (textline->startingWith(startComment) && textline->endingWith(endComment)) |
1699 | { | 1698 | { |
1700 | // Remove start comment mark | 1699 | // Remove start comment mark |
1701 | c.cursor.x = 0; | 1700 | c.cursor.x = 0; |
1702 | recordReplace(c.cursor, startCommentLen, ""); | 1701 | recordReplace(c.cursor, startCommentLen, ""); |
1703 | 1702 | ||
1704 | // Remove end comment mark | 1703 | // Remove end comment mark |
1705 | if(endComment != "") | 1704 | if(endComment != "") |
1706 | { | 1705 | { |
1707 | c.cursor.x = textline->length() - endCommentLen; | 1706 | c.cursor.x = textline->length() - endCommentLen; |
1708 | recordReplace(c.cursor, endCommentLen, ""); | 1707 | recordReplace(c.cursor, endCommentLen, ""); |
1709 | c.cursor.x = 0; | 1708 | c.cursor.x = 0; |
1710 | } | 1709 | } |
1711 | } | 1710 | } |
1712 | } | 1711 | } |
1713 | else | 1712 | else |
1714 | { | 1713 | { |
1715 | QString marked (c.view->markedText ()); | 1714 | QString marked (c.view->markedText ()); |
1716 | int preDeleteLine = -1, preDeleteCol = -1; | 1715 | int preDeleteLine = -1, preDeleteCol = -1; |
1717 | c.view->getCursorPosition (&preDeleteLine, &preDeleteCol); | 1716 | c.view->getCursorPosition (&preDeleteLine, &preDeleteCol); |
1718 | 1717 | ||
1719 | int start = marked.find (startComment); | 1718 | int start = marked.find (startComment); |
1720 | int end = marked.findRev (endComment); | 1719 | int end = marked.findRev (endComment); |
1721 | 1720 | ||
1722 | if ((start > -1) && (end > -1)) | 1721 | if ((start > -1) && (end > -1)) |
1723 | { | 1722 | { |
1724 | marked.remove (start, startCommentLen); | 1723 | marked.remove (start, startCommentLen); |
1725 | marked.remove (end-startCommentLen, endCommentLen); | 1724 | marked.remove (end-startCommentLen, endCommentLen); |
1726 | 1725 | ||
1727 | c.view->keyDelete (); | 1726 | c.view->keyDelete (); |
1728 | 1727 | ||
1729 | int line = -1, col = -1; | 1728 | int line = -1, col = -1; |
1730 | c.view->getCursorPosition (&line, &col); | 1729 | c.view->getCursorPosition (&line, &col); |
1731 | c.view->insertText (marked); | 1730 | c.view->insertText (marked); |
1732 | } | 1731 | } |
1733 | } | 1732 | } |
1734 | } | 1733 | } |
1735 | 1734 | ||
1736 | recordEnd(c.view, c.cursor, c.flags | KateView::cfPersistent); | 1735 | recordEnd(c.view, c.cursor, c.flags | KateView::cfPersistent); |
1737 | } | 1736 | } |
1738 | 1737 | ||
1739 | 1738 | ||
1740 | QString KateDocument::text() const | 1739 | QString KateDocument::text() const |
1741 | { | 1740 | { |
1742 | QString s; | 1741 | QString s; |
1743 | 1742 | ||
1744 | for (int i=0; i < buffer->count(); i++) | 1743 | for (int i=0; i < buffer->count(); i++) |
1745 | { | 1744 | { |
1746 | TextLine::Ptr textLine = buffer->line(i); | 1745 | TextLine::Ptr textLine = buffer->line(i); |
1747 | s.insert(s.length(), textLine->getText(), textLine->length()); | 1746 | s.insert(s.length(), textLine->getText(), textLine->length()); |
1748 | if ( (i < (buffer->count()-1)) ) | 1747 | if ( (i < (buffer->count()-1)) ) |
1749 | s.append('\n'); | 1748 | s.append('\n'); |
1750 | } | 1749 | } |
1751 | 1750 | ||
1752 | return s; | 1751 | return s; |
1753 | } | 1752 | } |
1754 | 1753 | ||
1755 | QString KateDocument::getWord(PointStruc &cursor) { | 1754 | QString KateDocument::getWord(PointStruc &cursor) { |
1756 | int start, end, len; | 1755 | int start, end, len; |
1757 | 1756 | ||
1758 | TextLine::Ptr textLine = getTextLine(cursor.y); | 1757 | TextLine::Ptr textLine = getTextLine(cursor.y); |
1759 | len = textLine->length(); | 1758 | len = textLine->length(); |
1760 | start = end = cursor.x; | 1759 | start = end = cursor.x; |
1761 | while (start > 0 && m_highlight->isInWord(textLine->getChar(start - 1))) start--; | 1760 | while (start > 0 && m_highlight->isInWord(textLine->getChar(start - 1))) start--; |
1762 | while (end < len && m_highlight->isInWord(textLine->getChar(end))) end++; | 1761 | while (end < len && m_highlight->isInWord(textLine->getChar(end))) end++; |
1763 | len = end - start; | 1762 | len = end - start; |
1764 | return QString(&textLine->getText()[start], len); | 1763 | return QString(&textLine->getText()[start], len); |
1765 | } | 1764 | } |
1766 | 1765 | ||
1767 | void KateDocument::setText(const QString &s) { | 1766 | void KateDocument::setText(const QString &s) { |
1768 | int pos; | 1767 | int pos; |
1769 | QChar ch; | 1768 | QChar ch; |
1770 | 1769 | ||
1771 | clear(); | 1770 | clear(); |
1772 | 1771 | ||
1773 | int line=1; | 1772 | int line=1; |
1774 | 1773 | ||
1775 | TextLine::Ptr textLine = buffer->line(0); | 1774 | TextLine::Ptr textLine = buffer->line(0); |
1776 | for (pos = 0; pos <= (int) s.length(); pos++) { | 1775 | for (pos = 0; pos <= (int) s.length(); pos++) { |
1777 | ch = s[pos]; | 1776 | ch = s[pos]; |
1778 | if (ch.isPrint() || ch == '\t') { | 1777 | if (ch.isPrint() || ch == '\t') { |
1779 | textLine->append(&ch, 1); | 1778 | textLine->append(&ch, 1); |
1780 | } else if (ch == '\n') | 1779 | } else if (ch == '\n') |
1781 | { | 1780 | { |
1782 | textLine = new TextLine(); | 1781 | textLine = new TextLine(); |
1783 | buffer->insertLine (line, textLine); | 1782 | buffer->insertLine (line, textLine); |
1784 | line++; | 1783 | line++; |
1785 | } | 1784 | } |
1786 | } | 1785 | } |
1787 | updateLines(); | 1786 | updateLines(); |
1788 | } | 1787 | } |
1789 | 1788 | ||
1790 | 1789 | ||
1791 | QString KateDocument::markedText(int flags) { | 1790 | QString KateDocument::markedText(int flags) { |
1792 | TextLine::Ptr textLine; | 1791 | TextLine::Ptr textLine; |
1793 | int len, z, start, end, i; | 1792 | int len, z, start, end, i; |
1794 | 1793 | ||
1795 | len = 1; | 1794 | len = 1; |
1796 | if (!(flags & KateView::cfVerticalSelect)) { | 1795 | if (!(flags & KateView::cfVerticalSelect)) { |
1797 | for (z = selectStart; z <= selectEnd; z++) { | 1796 | for (z = selectStart; z <= selectEnd; z++) { |
1798 | textLine = getTextLine(z); | 1797 | textLine = getTextLine(z); |
1799 | len += textLine->numSelected(); | 1798 | len += textLine->numSelected(); |
1800 | if (textLine->isSelected()) len++; | 1799 | if (textLine->isSelected()) len++; |
1801 | } | 1800 | } |
1802 | QString s; | 1801 | QString s; |
1803 | len = 0; | 1802 | len = 0; |
1804 | for (z = selectStart; z <= selectEnd; z++) { | 1803 | for (z = selectStart; z <= selectEnd; z++) { |
1805 | textLine = getTextLine(z); | 1804 | textLine = getTextLine(z); |
1806 | end = 0; | 1805 | end = 0; |
1807 | do { | 1806 | do { |
1808 | start = textLine->findUnselected(end); | 1807 | start = textLine->findUnselected(end); |
1809 | end = textLine->findSelected(start); | 1808 | end = textLine->findSelected(start); |
1810 | for (i = start; i < end; i++) { | 1809 | for (i = start; i < end; i++) { |
1811 | s[len] = textLine->getChar(i); | 1810 | s[len] = textLine->getChar(i); |
1812 | len++; | 1811 | len++; |
1813 | } | 1812 | } |
1814 | } while (start < end); | 1813 | } while (start < end); |
1815 | if (textLine->isSelected()) { | 1814 | if (textLine->isSelected()) { |
1816 | s[len] = '\n'; | 1815 | s[len] = '\n'; |
1817 | len++; | 1816 | len++; |
1818 | } | 1817 | } |
1819 | } | 1818 | } |
1820 | // s[len] = '\0'; | 1819 | // s[len] = '\0'; |
1821 | return s; | 1820 | return s; |
1822 | } else { | 1821 | } else { |
1823 | for (z = selectStart; z <= selectEnd; z++) { | 1822 | for (z = selectStart; z <= selectEnd; z++) { |
1824 | textLine = getTextLine(z); | 1823 | textLine = getTextLine(z); |
1825 | len += textLine->numSelected() + 1; | 1824 | len += textLine->numSelected() + 1; |
1826 | } | 1825 | } |
1827 | QString s; | 1826 | QString s; |
1828 | len = 0; | 1827 | len = 0; |
1829 | for (z = selectStart; z <= selectEnd; z++) { | 1828 | for (z = selectStart; z <= selectEnd; z++) { |
1830 | textLine = getTextLine(z); | 1829 | textLine = getTextLine(z); |
1831 | end = 0; | 1830 | end = 0; |
1832 | do { | 1831 | do { |
1833 | start = textLine->findUnselected(end); | 1832 | start = textLine->findUnselected(end); |
1834 | end = textLine->findSelected(start); | 1833 | end = textLine->findSelected(start); |
1835 | for (i = start; i < end; i++) { | 1834 | for (i = start; i < end; i++) { |
1836 | s[len] = textLine->getChar(i); | 1835 | s[len] = textLine->getChar(i); |
1837 | len++; | 1836 | len++; |
1838 | } | 1837 | } |
1839 | } while (start < end); | 1838 | } while (start < end); |
1840 | s[len] = '\n'; | 1839 | s[len] = '\n'; |
1841 | len++; | 1840 | len++; |
1842 | } | 1841 | } |
1843 | // s[len] = '\0'; // the final \0 is not counted in length() | 1842 | // s[len] = '\0'; // the final \0 is not counted in length() |
1844 | return s; | 1843 | return s; |
1845 | } | 1844 | } |
1846 | } | 1845 | } |
1847 | 1846 | ||
1848 | void KateDocument::delMarkedText(VConfig &c/*, bool undo*/) { | 1847 | void KateDocument::delMarkedText(VConfig &c/*, bool undo*/) { |
1849 | int end = 0; | 1848 | int end = 0; |
1850 | 1849 | ||
1851 | if (selectEnd < selectStart) return; | 1850 | if (selectEnd < selectStart) return; |
1852 | 1851 | ||
1853 | // the caller may have already started an undo record for the current action | 1852 | // the caller may have already started an undo record for the current action |
1854 | // if (undo) | 1853 | // if (undo) |
1855 | 1854 | ||
1856 | //auto deletion of the marked text occurs not very often and can therefore | 1855 | //auto deletion of the marked text occurs not very often and can therefore |
1857 | // be recorded separately | 1856 | // be recorded separately |
1858 | recordStart(c, KateActionGroup::ugDelBlock); | 1857 | recordStart(c, KateActionGroup::ugDelBlock); |
1859 | 1858 | ||
1860 | for (c.cursor.y = selectEnd; c.cursor.y >= selectStart; c.cursor.y--) { | 1859 | for (c.cursor.y = selectEnd; c.cursor.y >= selectStart; c.cursor.y--) { |
1861 | TextLine::Ptr textLine = getTextLine(c.cursor.y); | 1860 | TextLine::Ptr textLine = getTextLine(c.cursor.y); |
1862 | 1861 | ||
1863 | c.cursor.x = textLine->length(); | 1862 | c.cursor.x = textLine->length(); |
1864 | do { | 1863 | do { |
1865 | end = textLine->findRevUnselected(c.cursor.x); | 1864 | end = textLine->findRevUnselected(c.cursor.x); |
1866 | if (end == 0) break; | 1865 | if (end == 0) break; |
1867 | c.cursor.x = textLine->findRevSelected(end); | 1866 | c.cursor.x = textLine->findRevSelected(end); |
1868 | recordDelete(c.cursor, end - c.cursor.x); | 1867 | recordDelete(c.cursor, end - c.cursor.x); |
1869 | } while (true); | 1868 | } while (true); |
1870 | end = c.cursor.x; | 1869 | end = c.cursor.x; |
1871 | c.cursor.x = textLine->length(); | 1870 | c.cursor.x = textLine->length(); |
1872 | if (textLine->isSelected()) recordAction(KateAction::delLine,c.cursor); | 1871 | if (textLine->isSelected()) recordAction(KateAction::delLine,c.cursor); |
1873 | } | 1872 | } |
1874 | c.cursor.y++; | 1873 | c.cursor.y++; |
1875 | /*if (end < c.cursor.x)*/ c.cursor.x = end; | 1874 | /*if (end < c.cursor.x)*/ c.cursor.x = end; |
1876 | 1875 | ||
1877 | selectEnd = -1; | 1876 | selectEnd = -1; |
1878 | select.x = -1; | 1877 | select.x = -1; |
1879 | 1878 | ||
1880 | /*if (undo)*/ recordEnd(c); | 1879 | /*if (undo)*/ recordEnd(c); |
1881 | } | 1880 | } |
1882 | 1881 | ||
1883 | void KateDocument::tagLineRange(int line, int x1, int x2) { | 1882 | void KateDocument::tagLineRange(int line, int x1, int x2) { |
1884 | int z; | 1883 | int z; |
1885 | 1884 | ||
1886 | for (z = 0; z < (int) views.count(); z++) { | 1885 | for (z = 0; z < (int) views.count(); z++) { |
1887 | views.at(z)->tagLines(line, line, x1, x2); | 1886 | views.at(z)->tagLines(line, line, x1, x2); |
1888 | } | 1887 | } |
1889 | } | 1888 | } |
1890 | 1889 | ||
1891 | void KateDocument::tagLines(int start, int end) { | 1890 | void KateDocument::tagLines(int start, int end) { |
1892 | int z; | 1891 | int z; |
1893 | 1892 | ||
1894 | for (z = 0; z < (int) views.count(); z++) { | 1893 | for (z = 0; z < (int) views.count(); z++) { |
1895 | views.at(z)->tagLines(start, end, 0, 0xffffff); | 1894 | views.at(z)->tagLines(start, end, 0, 0xffffff); |
1896 | } | 1895 | } |
1897 | } | 1896 | } |
1898 | 1897 | ||
1899 | void KateDocument::tagAll() { | 1898 | void KateDocument::tagAll() { |
1900 | int z; | 1899 | int z; |
1901 | 1900 | ||
1902 | for (z = 0; z < (int) views.count(); z++) { | 1901 | for (z = 0; z < (int) views.count(); z++) { |
1903 | views.at(z)->tagAll(); | 1902 | views.at(z)->tagAll(); |
1904 | } | 1903 | } |
1905 | } | 1904 | } |
1906 | 1905 | ||
1907 | void KateDocument::updateLines(int startLine, int endLine, int flags, int cursorY) { | 1906 | void KateDocument::updateLines(int startLine, int endLine, int flags, int cursorY) { |
1908 | TextLine::Ptr textLine; | 1907 | TextLine::Ptr textLine; |
1909 | int line, last_line; | 1908 | int line, last_line; |
1910 | int ctxNum, endCtx; | 1909 | int ctxNum, endCtx; |
1911 | // kdDebug(13020)<<"******************KateDocument::updateLines Checkpoint 1"<<endl; | 1910 | // kdDebug(13020)<<"******************KateDocument::updateLines Checkpoint 1"<<endl; |
1912 | if (buffer->line(startLine)==0) {kdDebug(13020)<<"********************No buffer for line " << startLine << " found**************"<<endl; return;}; | 1911 | if (buffer->line(startLine)==0) {kdDebug(13020)<<"********************No buffer for line " << startLine << " found**************"<<endl; return;}; |
1913 | // kdDebug(13020)<<"KateDocument::updateLines Checkpoint 2"<<endl; | 1912 | // kdDebug(13020)<<"KateDocument::updateLines Checkpoint 2"<<endl; |
1914 | last_line = lastLine(); | 1913 | last_line = lastLine(); |
1915 | // if (endLine >= last_line) endLine = last_line; | 1914 | // if (endLine >= last_line) endLine = last_line; |
1916 | 1915 | ||
1917 | line = startLine; | 1916 | line = startLine; |
1918 | ctxNum = 0; | 1917 | ctxNum = 0; |
1919 | if (line > 0) ctxNum = getTextLine(line - 1)->getContext(); | 1918 | if (line > 0) ctxNum = getTextLine(line - 1)->getContext(); |
1920 | do { | 1919 | do { |
1921 | // kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl; | 1920 | // kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl; |
1922 | textLine = getTextLine(line); | 1921 | textLine = getTextLine(line); |
1923 | if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl; | 1922 | if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl; |
1924 | if (line <= endLine && line != cursorY) { | 1923 | if (line <= endLine && line != cursorY) { |
1925 | if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces(); | 1924 | if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces(); |
1926 | updateMaxLength(textLine); | 1925 | updateMaxLength(textLine); |
1927 | } | 1926 | } |
1928 | endCtx = textLine->getContext(); | 1927 | endCtx = textLine->getContext(); |
1929 | // qDebug("DOHIGHLIGHT"); | 1928 | // qDebug("DOHIGHLIGHT"); |
1930 | 1929 | ||
1931 | ctxNum = m_highlight->doHighlight(ctxNum,textLine); | 1930 | ctxNum = m_highlight->doHighlight(ctxNum,textLine); |
1932 | textLine->setContext(ctxNum); | 1931 | textLine->setContext(ctxNum); |
1933 | line++; | 1932 | line++; |
1934 | } while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum)); | 1933 | } while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum)); |
1935 | // kdDebug(13020)<<"updateLines :: while loop left"<<endl; | 1934 | // kdDebug(13020)<<"updateLines :: while loop left"<<endl; |
1936 | tagLines(startLine, line - 1); | 1935 | tagLines(startLine, line - 1); |
1937 | } | 1936 | } |
1938 | 1937 | ||
1939 | 1938 | ||
1940 | void KateDocument::updateMaxLength(TextLine::Ptr &textLine) { | 1939 | void KateDocument::updateMaxLength(TextLine::Ptr &textLine) { |
1941 | int len; | 1940 | int len; |
1942 | 1941 | ||
1943 | len = textWidth(textLine,textLine->length()); | 1942 | len = textWidth(textLine,textLine->length()); |
1944 | 1943 | ||
1945 | if (len > maxLength) { | 1944 | if (len > maxLength) { |
1946 | longestLine = textLine; | 1945 | longestLine = textLine; |
1947 | maxLength = len; | 1946 | maxLength = len; |
1948 | newDocGeometry = true; | 1947 | newDocGeometry = true; |
1949 | } else { | 1948 | } else { |
1950 | if (!longestLine || (textLine == longestLine && len <= maxLength*3/4)) { | 1949 | if (!longestLine || (textLine == longestLine && len <= maxLength*3/4)) { |
1951 | maxLength = -1; | 1950 | maxLength = -1; |
1952 | for (int i = 0; i < numLines();i++) { | 1951 | for (int i = 0; i < numLines();i++) { |
1953 | textLine = getTextLine(i); | 1952 | textLine = getTextLine(i); |
1954 | len = textWidth(textLine,textLine->length()); | 1953 | len = textWidth(textLine,textLine->length()); |
1955 | if (len > maxLength) { | 1954 | if (len > maxLength) { |
1956 | maxLength = len; | 1955 | maxLength = len; |
1957 | longestLine = textLine; | 1956 | longestLine = textLine; |
1958 | } | 1957 | } |
1959 | } | 1958 | } |
1960 | newDocGeometry = true; | 1959 | newDocGeometry = true; |
1961 | } | 1960 | } |
1962 | } | 1961 | } |
1963 | } | 1962 | } |
1964 | 1963 | ||
1965 | void KateDocument::slotBufferChanged() { | 1964 | void KateDocument::slotBufferChanged() { |
1966 | newDocGeometry = true; | 1965 | newDocGeometry = true; |
1967 | //updateLines();//JW | 1966 | //updateLines();//JW |
1968 | updateViews(); | 1967 | updateViews(); |
1969 | } | 1968 | } |
1970 | 1969 | ||
1971 | void KateDocument::slotBufferHighlight(long start,long stop) { | 1970 | void KateDocument::slotBufferHighlight(long start,long stop) { |
1972 | kdDebug(13020)<<"KateDocument::slotBufferHighlight"<<QString("%1-%2").arg(start).arg(stop)<<endl; | 1971 | kdDebug(13020)<<"KateDocument::slotBufferHighlight"<<QString("%1-%2").arg(start).arg(stop)<<endl; |
1973 | updateLines(start,stop); | 1972 | updateLines(start,stop); |
1974 | // buffer->startLoadTimer(); | 1973 | // buffer->startLoadTimer(); |
1975 | } | 1974 | } |
1976 | 1975 | ||
1977 | void KateDocument::updateViews(KateView *exclude) { | 1976 | void KateDocument::updateViews(KateView *exclude) { |
1978 | KateView *view; | 1977 | KateView *view; |
1979 | int flags; | 1978 | int flags; |
1980 | bool markState = hasMarkedText(); | 1979 | bool markState = hasMarkedText(); |
1981 | 1980 | ||
1982 | flags = (newDocGeometry) ? KateView::ufDocGeometry : 0; | 1981 | flags = (newDocGeometry) ? KateView::ufDocGeometry : 0; |
1983 | for (view = views.first(); view != 0L; view = views.next() ) { | 1982 | for (view = views.first(); view != 0L; view = views.next() ) { |
1984 | if (view != exclude) view->updateView(flags); | 1983 | if (view != exclude) view->updateView(flags); |
1985 | 1984 | ||
1986 | // notify every view about the changed mark state.... | 1985 | // notify every view about the changed mark state.... |
1987 | if (oldMarkState != markState) emit view->newMarkStatus(); | 1986 | if (oldMarkState != markState) emit view->newMarkStatus(); |
1988 | } | 1987 | } |
1989 | oldMarkState = markState; | 1988 | oldMarkState = markState; |
1990 | newDocGeometry = false; | 1989 | newDocGeometry = false; |
1991 | } | 1990 | } |
1992 | 1991 | ||
1993 | QColor &KateDocument::cursorCol(int x, int y) { | 1992 | QColor &KateDocument::cursorCol(int x, int y) { |
1994 | int attr; | 1993 | int attr; |
1995 | Attribute *a; | 1994 | Attribute *a; |
1996 | 1995 | ||
1997 | TextLine::Ptr textLine = getTextLine(y); | 1996 | TextLine::Ptr textLine = getTextLine(y); |
1998 | attr = textLine->getRawAttr(x); | 1997 | attr = textLine->getRawAttr(x); |
1999 | a = &m_attribs[attr & taAttrMask]; | 1998 | a = &m_attribs[attr & taAttrMask]; |
2000 | if (attr & taSelected) return a->selCol; else return a->col; | 1999 | if (attr & taSelected) return a->selCol; else return a->col; |
2001 | } | 2000 | } |
2002 | 2001 | ||
2003 | void KateDocument::paintTextLine(QPainter &paint, int line, int xStart, int xEnd, bool showTabs) | 2002 | void KateDocument::paintTextLine(QPainter &paint, int line, int xStart, int xEnd, bool showTabs) |
2004 | { | 2003 | { |
2005 | paintTextLine (paint, line, 0, xStart, xEnd, showTabs); | 2004 | paintTextLine (paint, line, 0, xStart, xEnd, showTabs); |
2006 | } | 2005 | } |
2007 | 2006 | ||
2008 | void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, int xEnd, bool showTabs) | 2007 | void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, int xEnd, bool showTabs) |
2009 | { | 2008 | { |
2010 | TextLine::Ptr textLine; | 2009 | TextLine::Ptr textLine; |
2011 | int len; | 2010 | int len; |
2012 | const QChar *s; | 2011 | const QChar *s; |
2013 | int z, x; | 2012 | int z, x; |
2014 | QChar ch; | 2013 | QChar ch; |
2015 | Attribute *a = 0L; | 2014 | Attribute *a = 0L; |
2016 | int attr, nextAttr; | 2015 | int attr, nextAttr; |
2017 | int xs; | 2016 | int xs; |
2018 | int xc, zc; | 2017 | int xc, zc; |
2019 | 2018 | ||
2020 | if (line > lastLine()) { | 2019 | if (line > lastLine()) { |
2021 | paint.fillRect(0, y, xEnd - xStart,fontHeight, colors[0]); | 2020 | paint.fillRect(0, y, xEnd - xStart,fontHeight, colors[0]); |
2022 | return; | 2021 | return; |
2023 | } | 2022 | } |
2024 | 2023 | ||
2025 | textLine = getTextLine(line); | 2024 | textLine = getTextLine(line); |
2026 | len = textLine->length(); | 2025 | len = textLine->length(); |
2027 | s = textLine->getText(); | 2026 | s = textLine->getText(); |
2028 | 2027 | ||
2029 | // skip to first visible character | 2028 | // skip to first visible character |
2030 | x = 0; | 2029 | x = 0; |
2031 | z = 0; | 2030 | z = 0; |
2032 | do { | 2031 | do { |
2033 | xc = x; | 2032 | xc = x; |
2034 | zc = z; | 2033 | zc = z; |
2035 | if (z == len) break; | 2034 | if (z == len) break; |
2036 | ch = s[z];//textLine->getChar(z); | 2035 | ch = s[z];//textLine->getChar(z); |
2037 | if (ch == '\t') { | 2036 | if (ch == '\t') { |
2038 | x += m_tabWidth - (x % m_tabWidth); | 2037 | x += m_tabWidth - (x % m_tabWidth); |
2039 | } else { | 2038 | } else { |
2040 | a = &m_attribs[textLine->getAttr(z)]; | 2039 | a = &m_attribs[textLine->getAttr(z)]; |
2041 | 2040 | ||
2042 | if (a->bold && a->italic) | 2041 | if (a->bold && a->italic) |
2043 | x += myFontMetricsBI.width(ch); | 2042 | x += myFontMetricsBI.width(ch); |
2044 | else if (a->bold) | 2043 | else if (a->bold) |
2045 | x += myFontMetricsBold.width(ch); | 2044 | x += myFontMetricsBold.width(ch); |
2046 | else if (a->italic) | 2045 | else if (a->italic) |
2047 | x += myFontMetricsItalic.width(ch); | 2046 | x += myFontMetricsItalic.width(ch); |
2048 | else | 2047 | else |
2049 | x += myFontMetrics.width(ch); | 2048 | x += myFontMetrics.width(ch); |
2050 | } | 2049 | } |
2051 | z++; | 2050 | z++; |
2052 | } while (x <= xStart); | 2051 | } while (x <= xStart); |
2053 | 2052 | ||
2054 | // draw background | 2053 | // draw background |
2055 | xs = xStart; | 2054 | xs = xStart; |
2056 | attr = textLine->getRawAttr(zc); | 2055 | attr = textLine->getRawAttr(zc); |
2057 | while (x < xEnd) | 2056 | while (x < xEnd) |
2058 | { | 2057 | { |
2059 | nextAttr = textLine->getRawAttr(z); | 2058 | nextAttr = textLine->getRawAttr(z); |
2060 | if ((nextAttr ^ attr) & taSelected) | 2059 | if ((nextAttr ^ attr) & taSelected) |
2061 | { | 2060 | { |
2062 | if (attr & taSelected) | 2061 | if (attr & taSelected) |
2063 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[1]); | 2062 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[1]); |
2064 | else | 2063 | else |
2065 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[0]); | 2064 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[0]); |
2066 | 2065 | ||
2067 | xs = x; | 2066 | xs = x; |
2068 | attr = nextAttr; | 2067 | attr = nextAttr; |
2069 | } | 2068 | } |
2070 | 2069 | ||
2071 | if (z == len) break; | 2070 | if (z == len) break; |
2072 | 2071 | ||
2073 | ch = s[z];//textLine->getChar(z); | 2072 | ch = s[z];//textLine->getChar(z); |
2074 | 2073 | ||
2075 | if (ch == '\t') | 2074 | if (ch == '\t') |
2076 | x += m_tabWidth - (x % m_tabWidth); | 2075 | x += m_tabWidth - (x % m_tabWidth); |
2077 | else | 2076 | else |
2078 | { | 2077 | { |
2079 | a = &m_attribs[textLine->getAttr(z)]; | 2078 | a = &m_attribs[textLine->getAttr(z)]; |
2080 | 2079 | ||
2081 | if (a->bold && a->italic) | 2080 | if (a->bold && a->italic) |
2082 | x += myFontMetricsBI.width(ch); | 2081 | x += myFontMetricsBI.width(ch); |
2083 | else if (a->bold) | 2082 | else if (a->bold) |
2084 | x += myFontMetricsBold.width(ch); | 2083 | x += myFontMetricsBold.width(ch); |
2085 | else if (a->italic) | 2084 | else if (a->italic) |
2086 | x += myFontMetricsItalic.width(ch); | 2085 | x += myFontMetricsItalic.width(ch); |
2087 | else | 2086 | else |
2088 | x += myFontMetrics.width(ch); | 2087 | x += myFontMetrics.width(ch); |
2089 | } | 2088 | } |
2090 | z++; | 2089 | z++; |
2091 | } | 2090 | } |
2092 | 2091 | ||
2093 | if (attr & taSelected) | 2092 | if (attr & taSelected) |
2094 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[1]); | 2093 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[1]); |
2095 | else | 2094 | else |
2096 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[0]); | 2095 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[0]); |
2097 | 2096 | ||
2098 | len = z; //reduce length to visible length | 2097 | len = z; //reduce length to visible length |
2099 | 2098 | ||
2100 | // draw text | 2099 | // draw text |
2101 | x = xc; | 2100 | x = xc; |
2102 | z = zc; | 2101 | z = zc; |
2103 | y += fontAscent;// -1; | 2102 | y += fontAscent;// -1; |
2104 | attr = -1; | 2103 | attr = -1; |
2105 | while (z < len) { | 2104 | while (z < len) { |
2106 | ch = s[z];//textLine->getChar(z); | 2105 | ch = s[z];//textLine->getChar(z); |
2107 | if (ch == '\t') { | 2106 | if (ch == '\t') { |
2108 | if (z > zc) { | 2107 | if (z > zc) { |
2109 | //this should cause no copy at all | 2108 | //this should cause no copy at all |
2110 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2109 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2111 | QString s = str.string(); | 2110 | QString s = str.string(); |
2112 | paint.drawText(x - xStart, y, s); | 2111 | paint.drawText(x - xStart, y, s); |
2113 | 2112 | ||
2114 | if (a->bold && a->italic) | 2113 | if (a->bold && a->italic) |
2115 | x += myFontMetricsBI.width(s); | 2114 | x += myFontMetricsBI.width(s); |
2116 | else if (a->bold) | 2115 | else if (a->bold) |
2117 | x += myFontMetricsBold.width(s); | 2116 | x += myFontMetricsBold.width(s); |
2118 | else if (a->italic) | 2117 | else if (a->italic) |
2119 | x += myFontMetricsItalic.width(s); | 2118 | x += myFontMetricsItalic.width(s); |
2120 | else | 2119 | else |
2121 | x += myFontMetrics.width(s); | 2120 | x += myFontMetrics.width(s); |
2122 | } | 2121 | } |
2123 | zc = z +1; | 2122 | zc = z +1; |
2124 | 2123 | ||
2125 | if (showTabs) { | 2124 | if (showTabs) { |
2126 | nextAttr = textLine->getRawAttr(z); | 2125 | nextAttr = textLine->getRawAttr(z); |
2127 | if (nextAttr != attr) { | 2126 | if (nextAttr != attr) { |
2128 | attr = nextAttr; | 2127 | attr = nextAttr; |
2129 | a = &m_attribs[attr & taAttrMask]; | 2128 | a = &m_attribs[attr & taAttrMask]; |
2130 | 2129 | ||
2131 | if (attr & taSelected) paint.setPen(a->selCol); | 2130 | if (attr & taSelected) paint.setPen(a->selCol); |
2132 | else paint.setPen(a->col); | 2131 | else paint.setPen(a->col); |
2133 | 2132 | ||
2134 | if (a->bold && a->italic) | 2133 | if (a->bold && a->italic) |
2135 | paint.setFont(myFontBI); | 2134 | paint.setFont(myFontBI); |
2136 | else if (a->bold) | 2135 | else if (a->bold) |
2137 | paint.setFont(myFontBold); | 2136 | paint.setFont(myFontBold); |
2138 | else if (a->italic) | 2137 | else if (a->italic) |
2139 | paint.setFont(myFontItalic); | 2138 | paint.setFont(myFontItalic); |
2140 | else | 2139 | else |
2141 | paint.setFont(myFont); | 2140 | paint.setFont(myFont); |
2142 | } | 2141 | } |
2143 | 2142 | ||
2144 | // paint.drawLine(x - xStart, y -2, x - xStart, y); | 2143 | // paint.drawLine(x - xStart, y -2, x - xStart, y); |
2145 | // paint.drawLine(x - xStart, y, x - xStart + 2, y); | 2144 | // paint.drawLine(x - xStart, y, x - xStart + 2, y); |
2146 | paint.drawPoint(x - xStart, y); | 2145 | paint.drawPoint(x - xStart, y); |
2147 | paint.drawPoint(x - xStart +1, y); | 2146 | paint.drawPoint(x - xStart +1, y); |
2148 | paint.drawPoint(x - xStart, y -1); | 2147 | paint.drawPoint(x - xStart, y -1); |
2149 | } | 2148 | } |
2150 | x += m_tabWidth - (x % m_tabWidth); | 2149 | x += m_tabWidth - (x % m_tabWidth); |
2151 | } else { | 2150 | } else { |
2152 | nextAttr = textLine->getRawAttr(z); | 2151 | nextAttr = textLine->getRawAttr(z); |
2153 | if (nextAttr != attr) { | 2152 | if (nextAttr != attr) { |
2154 | if (z > zc) { | 2153 | if (z > zc) { |
2155 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2154 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2156 | QString s = str.string(); | 2155 | QString s = str.string(); |
2157 | paint.drawText(x - xStart, y, s); | 2156 | paint.drawText(x - xStart, y, s); |
2158 | 2157 | ||
2159 | if (a->bold && a->italic) | 2158 | if (a->bold && a->italic) |
2160 | x += myFontMetricsBI.width(s); | 2159 | x += myFontMetricsBI.width(s); |
2161 | else if (a->bold) | 2160 | else if (a->bold) |
2162 | x += myFontMetricsBold.width(s); | 2161 | x += myFontMetricsBold.width(s); |
2163 | else if (a->italic) | 2162 | else if (a->italic) |
2164 | x += myFontMetricsItalic.width(s); | 2163 | x += myFontMetricsItalic.width(s); |
2165 | else | 2164 | else |
2166 | x += myFontMetrics.width(s); | 2165 | x += myFontMetrics.width(s); |
2167 | zc = z; | 2166 | zc = z; |
2168 | } | 2167 | } |
2169 | attr = nextAttr; | 2168 | attr = nextAttr; |
2170 | a = &m_attribs[attr & taAttrMask]; | 2169 | a = &m_attribs[attr & taAttrMask]; |
2171 | 2170 | ||
2172 | if (attr & taSelected) paint.setPen(a->selCol); | 2171 | if (attr & taSelected) paint.setPen(a->selCol); |
2173 | else paint.setPen(a->col); | 2172 | else paint.setPen(a->col); |
2174 | 2173 | ||
2175 | if (a->bold && a->italic) | 2174 | if (a->bold && a->italic) |
2176 | paint.setFont(myFontBI); | 2175 | paint.setFont(myFontBI); |
2177 | else if (a->bold) | 2176 | else if (a->bold) |
2178 | paint.setFont(myFontBold); | 2177 | paint.setFont(myFontBold); |
2179 | else if (a->italic) | 2178 | else if (a->italic) |
2180 | paint.setFont(myFontItalic); | 2179 | paint.setFont(myFontItalic); |
2181 | else | 2180 | else |
2182 | paint.setFont(myFont); | 2181 | paint.setFont(myFont); |
2183 | } | 2182 | } |
2184 | } | 2183 | } |
2185 | z++; | 2184 | z++; |
2186 | } | 2185 | } |
2187 | if (z > zc) { | 2186 | if (z > zc) { |
2188 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2187 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2189 | paint.drawText(x - xStart, y, str.string()); | 2188 | paint.drawText(x - xStart, y, str.string()); |
2190 | } | 2189 | } |
2191 | } | 2190 | } |
2192 | 2191 | ||
2193 | // Applies the search context, and returns whether a match was found. If one is, | 2192 | // Applies the search context, and returns whether a match was found. If one is, |
2194 | // the length of the string matched is also returned. | 2193 | // the length of the string matched is also returned. |
2195 | bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) { | 2194 | bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) { |
2196 | int line, col; | 2195 | int line, col; |
2197 | int searchEnd; | 2196 | int searchEnd; |
2198 | int bufLen, tlen; | 2197 | int bufLen, tlen; |
2199 | QChar *t; | 2198 | QChar *t; |
2200 | TextLine::Ptr textLine; | 2199 | TextLine::Ptr textLine; |
2201 | int pos, newPos; | 2200 | int pos, newPos; |
2202 | 2201 | ||
2203 | if (searchFor.isEmpty()) return false; | 2202 | if (searchFor.isEmpty()) return false; |
2204 | 2203 | ||
2205 | bufLen = 0; | 2204 | bufLen = 0; |
2206 | t = 0L; | 2205 | t = 0L; |
2207 | 2206 | ||
2208 | line = sc.cursor.y; | 2207 | line = sc.cursor.y; |
2209 | col = sc.cursor.x; | 2208 | col = sc.cursor.x; |
2210 | if (!(sc.flags & KateView::sfBackward)) { | 2209 | if (!(sc.flags & KateView::sfBackward)) { |
2211 | //forward search | 2210 | //forward search |
2212 | if (sc.flags & KateView::sfSelected) { | 2211 | if (sc.flags & KateView::sfSelected) { |
2213 | if (line < selectStart) { | 2212 | if (line < selectStart) { |
2214 | line = selectStart; | 2213 | line = selectStart; |
2215 | col = 0; | 2214 | col = 0; |
2216 | } | 2215 | } |
2217 | searchEnd = selectEnd; | 2216 | searchEnd = selectEnd; |
2218 | } else searchEnd = lastLine(); | 2217 | } else searchEnd = lastLine(); |
2219 | 2218 | ||
2220 | while (line <= searchEnd) { | 2219 | while (line <= searchEnd) { |
2221 | textLine = getTextLine(line); | 2220 | textLine = getTextLine(line); |
2222 | tlen = textLine->length(); | 2221 | tlen = textLine->length(); |
2223 | if (tlen > bufLen) { | 2222 | if (tlen > bufLen) { |
2224 | delete t; | 2223 | delete t; |
2225 | bufLen = (tlen + 255) & (~255); | 2224 | bufLen = (tlen + 255) & (~255); |
2226 | t = new QChar[bufLen]; | 2225 | t = new QChar[bufLen]; |
2227 | } | 2226 | } |
2228 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); | 2227 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); |
2229 | if (sc.flags & KateView::sfSelected) { | 2228 | if (sc.flags & KateView::sfSelected) { |
2230 | pos = 0; | 2229 | pos = 0; |
2231 | do { | 2230 | do { |
2232 | pos = textLine->findSelected(pos); | 2231 | pos = textLine->findSelected(pos); |
2233 | newPos = textLine->findUnselected(pos); | 2232 | newPos = textLine->findUnselected(pos); |
2234 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); | 2233 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); |
2235 | pos = newPos; | 2234 | pos = newPos; |
2236 | } while (pos < tlen); | 2235 | } while (pos < tlen); |
2237 | } | 2236 | } |
2238 | 2237 | ||
2239 | QString text(t, tlen); | 2238 | QString text(t, tlen); |
2240 | if (sc.flags & KateView::sfWholeWords) { | 2239 | if (sc.flags & KateView::sfWholeWords) { |
2241 | // Until the end of the line... | 2240 | // Until the end of the line... |
2242 | while (col < tlen) { | 2241 | while (col < tlen) { |
2243 | // ...find the next match. | 2242 | // ...find the next match. |
2244 | col = sc.search(text, col); | 2243 | col = sc.search(text, col); |
2245 | if (col != -1) { | 2244 | if (col != -1) { |
2246 | // Is the match delimited correctly? | 2245 | // Is the match delimited correctly? |
2247 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && | 2246 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && |
2248 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { | 2247 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { |
2249 | goto found; | 2248 | goto found; |
2250 | } | 2249 | } |
2251 | else { | 2250 | else { |
2252 | // Start again from the next character. | 2251 | // Start again from the next character. |
2253 | col++; | 2252 | col++; |
2254 | } | 2253 | } |
2255 | } | 2254 | } |
2256 | else { | 2255 | else { |
2257 | // No match. | 2256 | // No match. |
2258 | break; | 2257 | break; |
2259 | } | 2258 | } |
2260 | } | 2259 | } |
2261 | } | 2260 | } |
2262 | else { | 2261 | else { |
2263 | // Non-whole-word search. | 2262 | // Non-whole-word search. |
2264 | col = sc.search(text, col); | 2263 | col = sc.search(text, col); |
2265 | if (col != -1) | 2264 | if (col != -1) |
2266 | goto found; | 2265 | goto found; |
2267 | } | 2266 | } |
2268 | col = 0; | 2267 | col = 0; |
2269 | line++; | 2268 | line++; |
2270 | } | 2269 | } |
2271 | } else { | 2270 | } else { |
2272 | // backward search | 2271 | // backward search |
2273 | if (sc.flags & KateView::sfSelected) { | 2272 | if (sc.flags & KateView::sfSelected) { |
2274 | if (line > selectEnd) { | 2273 | if (line > selectEnd) { |
2275 | line = selectEnd; | 2274 | line = selectEnd; |
2276 | col = -1; | 2275 | col = -1; |
2277 | } | 2276 | } |
2278 | searchEnd = selectStart; | 2277 | searchEnd = selectStart; |
2279 | } else searchEnd = 0; | 2278 | } else searchEnd = 0; |
2280 | 2279 | ||
2281 | while (line >= searchEnd) { | 2280 | while (line >= searchEnd) { |
2282 | textLine = getTextLine(line); | 2281 | textLine = getTextLine(line); |
2283 | tlen = textLine->length(); | 2282 | tlen = textLine->length(); |
2284 | if (tlen > bufLen) { | 2283 | if (tlen > bufLen) { |
2285 | delete t; | 2284 | delete t; |
2286 | bufLen = (tlen + 255) & (~255); | 2285 | bufLen = (tlen + 255) & (~255); |
2287 | t = new QChar[bufLen]; | 2286 | t = new QChar[bufLen]; |
2288 | } | 2287 | } |
2289 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); | 2288 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); |
2290 | if (sc.flags & KateView::sfSelected) { | 2289 | if (sc.flags & KateView::sfSelected) { |
2291 | pos = 0; | 2290 | pos = 0; |
2292 | do { | 2291 | do { |
2293 | pos = textLine->findSelected(pos); | 2292 | pos = textLine->findSelected(pos); |
2294 | newPos = textLine->findUnselected(pos); | 2293 | newPos = textLine->findUnselected(pos); |
2295 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); | 2294 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); |
2296 | pos = newPos; | 2295 | pos = newPos; |
2297 | } while (pos < tlen); | 2296 | } while (pos < tlen); |
2298 | } | 2297 | } |
2299 | 2298 | ||
2300 | if (col < 0 || col > tlen) col = tlen; | 2299 | if (col < 0 || col > tlen) col = tlen; |
2301 | 2300 | ||
2302 | QString text(t, tlen); | 2301 | QString text(t, tlen); |
2303 | if (sc.flags & KateView::sfWholeWords) { | 2302 | if (sc.flags & KateView::sfWholeWords) { |
2304 | // Until the beginning of the line... | 2303 | // Until the beginning of the line... |
2305 | while (col >= 0) { | 2304 | while (col >= 0) { |
2306 | // ...find the next match. | 2305 | // ...find the next match. |
2307 | col = sc.search(text, col); | 2306 | col = sc.search(text, col); |
2308 | if (col != -1) { | 2307 | if (col != -1) { |
2309 | // Is the match delimited correctly? | 2308 | // Is the match delimited correctly? |
2310 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && | 2309 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && |
2311 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { | 2310 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { |
2312 | goto found; | 2311 | goto found; |
2313 | } | 2312 | } |
2314 | else { | 2313 | else { |
2315 | // Start again from the previous character. | 2314 | // Start again from the previous character. |
2316 | col--; | 2315 | col--; |
2317 | } | 2316 | } |
2318 | } | 2317 | } |
2319 | else { | 2318 | else { |
2320 | // No match. | 2319 | // No match. |
2321 | break; | 2320 | break; |
2322 | } | 2321 | } |
2323 | } | 2322 | } |
2324 | } | 2323 | } |
2325 | else { | 2324 | else { |
2326 | // Non-whole-word search. | 2325 | // Non-whole-word search. |
2327 | col = sc.search(text, col); | 2326 | col = sc.search(text, col); |
2328 | if (col != -1) | 2327 | if (col != -1) |
2329 | goto found; | 2328 | goto found; |
2330 | } | 2329 | } |
2331 | col = -1; | 2330 | col = -1; |
2332 | line--; | 2331 | line--; |
2333 | } | 2332 | } |
2334 | } | 2333 | } |
2335 | sc.flags |= KateView::sfWrapped; | 2334 | sc.flags |= KateView::sfWrapped; |
2336 | return false; | 2335 | return false; |
2337 | found: | 2336 | found: |
2338 | if (sc.flags & KateView::sfWrapped) { | 2337 | if (sc.flags & KateView::sfWrapped) { |
2339 | if ((line > sc.startCursor.y || (line == sc.startCursor.y && col >= sc.startCursor.x)) | 2338 | if ((line > sc.startCursor.y || (line == sc.startCursor.y && col >= sc.startCursor.x)) |
2340 | ^ ((sc.flags & KateView::sfBackward) != 0)) return false; | 2339 | ^ ((sc.flags & KateView::sfBackward) != 0)) return false; |
2341 | } | 2340 | } |
2342 | sc.cursor.x = col; | 2341 | sc.cursor.x = col; |
2343 | sc.cursor.y = line; | 2342 | sc.cursor.y = line; |
2344 | return true; | 2343 | return true; |
2345 | } | 2344 | } |
2346 | 2345 | ||
2347 | void KateDocument::tagLine(int line) { | 2346 | void KateDocument::tagLine(int line) { |
2348 | 2347 | ||
2349 | if (tagStart > line) tagStart = line; | 2348 | if (tagStart > line) tagStart = line; |
2350 | if (tagEnd < line) tagEnd = line; | 2349 | if (tagEnd < line) tagEnd = line; |
2351 | } | 2350 | } |
2352 | 2351 | ||
2353 | void KateDocument::insLine(int line) { | 2352 | void KateDocument::insLine(int line) { |
2354 | KateView *view; | 2353 | KateView *view; |
2355 | 2354 | ||
2356 | if (selectStart >= line) selectStart++; | 2355 | if (selectStart >= line) selectStart++; |
2357 | if (selectEnd >= line) selectEnd++; | 2356 | if (selectEnd >= line) selectEnd++; |
2358 | if (tagStart >= line) tagStart++; | 2357 | if (tagStart >= line) tagStart++; |
2359 | if (tagEnd >= line) tagEnd++; | 2358 | if (tagEnd >= line) tagEnd++; |
2360 | 2359 | ||
2361 | newDocGeometry = true; | 2360 | newDocGeometry = true; |
2362 | for (view = views.first(); view != 0L; view = views.next() ) { | 2361 | for (view = views.first(); view != 0L; view = views.next() ) { |
2363 | view->insLine(line); | 2362 | view->insLine(line); |
2364 | } | 2363 | } |
2365 | } | 2364 | } |
2366 | 2365 | ||
2367 | void KateDocument::delLine(int line) { | 2366 | void KateDocument::delLine(int line) { |
2368 | KateView *view; | 2367 | KateView *view; |
2369 | 2368 | ||
2370 | if (selectStart >= line && selectStart > 0) selectStart--; | 2369 | if (selectStart >= line && selectStart > 0) selectStart--; |
2371 | if (selectEnd >= line) selectEnd--; | 2370 | if (selectEnd >= line) selectEnd--; |
2372 | if (tagStart >= line && tagStart > 0) tagStart--; | 2371 | if (tagStart >= line && tagStart > 0) tagStart--; |
2373 | if (tagEnd >= line) tagEnd--; | 2372 | if (tagEnd >= line) tagEnd--; |
2374 | 2373 | ||
2375 | newDocGeometry = true; | 2374 | newDocGeometry = true; |
2376 | for (view = views.first(); view != 0L; view = views.next() ) { | 2375 | for (view = views.first(); view != 0L; view = views.next() ) { |
2377 | view->delLine(line); | 2376 | view->delLine(line); |
2378 | } | 2377 | } |
2379 | } | 2378 | } |
2380 | 2379 | ||
2381 | void KateDocument::optimizeSelection() { | 2380 | void KateDocument::optimizeSelection() { |
2382 | TextLine::Ptr textLine; | 2381 | TextLine::Ptr textLine; |
2383 | 2382 | ||
2384 | while (selectStart <= selectEnd) { | 2383 | while (selectStart <= selectEnd) { |
2385 | textLine = getTextLine(selectStart); | 2384 | textLine = getTextLine(selectStart); |
2386 | if (textLine->isSelected() || textLine->numSelected() > 0) break; | 2385 | if (textLine->isSelected() || textLine->numSelected() > 0) break; |
2387 | selectStart++; | 2386 | selectStart++; |
2388 | } | 2387 | } |
2389 | while (selectEnd >= selectStart) { | 2388 | while (selectEnd >= selectStart) { |
2390 | textLine = getTextLine(selectEnd); | 2389 | textLine = getTextLine(selectEnd); |
2391 | if (textLine->isSelected() || textLine->numSelected() > 0) break; | 2390 | if (textLine->isSelected() || textLine->numSelected() > 0) break; |
2392 | selectEnd--; | 2391 | selectEnd--; |
2393 | } | 2392 | } |
2394 | if (selectStart > selectEnd) { | 2393 | if (selectStart > selectEnd) { |
2395 | selectStart = 0xffffff; | 2394 | selectStart = 0xffffff; |
2396 | selectEnd = 0; | 2395 | selectEnd = 0; |
2397 | } | 2396 | } |
2398 | } | 2397 | } |
2399 | 2398 | ||
2400 | void KateDocument::doAction(KateAction *a) { | 2399 | void KateDocument::doAction(KateAction *a) { |
2401 | 2400 | ||
2402 | switch (a->action) { | 2401 | switch (a->action) { |
2403 | case KateAction::replace: | 2402 | case KateAction::replace: |
2404 | doReplace(a); | 2403 | doReplace(a); |
2405 | break; | 2404 | break; |
2406 | case KateAction::wordWrap: | 2405 | case KateAction::wordWrap: |
2407 | doWordWrap(a); | 2406 | doWordWrap(a); |
2408 | break; | 2407 | break; |
2409 | case KateAction::wordUnWrap: | 2408 | case KateAction::wordUnWrap: |
2410 | doWordUnWrap(a); | 2409 | doWordUnWrap(a); |
2411 | break; | 2410 | break; |
2412 | case KateAction::newLine: | 2411 | case KateAction::newLine: |
2413 | doNewLine(a); | 2412 | doNewLine(a); |
2414 | break; | 2413 | break; |
2415 | case KateAction::delLine: | 2414 | case KateAction::delLine: |
2416 | doDelLine(a); | 2415 | doDelLine(a); |
2417 | break; | 2416 | break; |
2418 | case KateAction::insLine: | 2417 | case KateAction::insLine: |
2419 | doInsLine(a); | 2418 | doInsLine(a); |
2420 | break; | 2419 | break; |
2421 | case KateAction::killLine: | 2420 | case KateAction::killLine: |
2422 | doKillLine(a); | 2421 | doKillLine(a); |
2423 | break; | 2422 | break; |
2424 | /* case KateAction::doubleLine: | 2423 | /* case KateAction::doubleLine: |
2425 | break; | 2424 | break; |
2426 | case KateAction::removeLine: | 2425 | case KateAction::removeLine: |
2427 | break;*/ | 2426 | break;*/ |
2428 | } | 2427 | } |
2429 | } | 2428 | } |
2430 | 2429 | ||
2431 | void KateDocument::doReplace(KateAction *a) { | 2430 | void KateDocument::doReplace(KateAction *a) { |
2432 | TextLine::Ptr textLine; | 2431 | TextLine::Ptr textLine; |
2433 | int l; | 2432 | int l; |
2434 | 2433 | ||
2435 | //exchange current text with stored text in KateAction *a | 2434 | //exchange current text with stored text in KateAction *a |
2436 | 2435 | ||
2437 | textLine = getTextLine(a->cursor.y); | 2436 | textLine = getTextLine(a->cursor.y); |
2438 | l = textLine->length() - a->cursor.x; | 2437 | l = textLine->length() - a->cursor.x; |
2439 | if (l > a->len) l = a->len; | 2438 | if (l > a->len) l = a->len; |
2440 | 2439 | ||
2441 | QString oldText(&textLine->getText()[a->cursor.x], (l < 0) ? 0 : l); | 2440 | QString oldText(&textLine->getText()[a->cursor.x], (l < 0) ? 0 : l); |
2442 | textLine->replace(a->cursor.x, a->len, a->text.unicode(), a->text.length()); | 2441 | textLine->replace(a->cursor.x, a->len, a->text.unicode(), a->text.length()); |
2443 | 2442 | ||
2444 | a->len = a->text.length(); | 2443 | a->len = a->text.length(); |
2445 | a->text = oldText; | 2444 | a->text = oldText; |
2446 | 2445 | ||
2447 | buffer->changeLine(a->cursor.y); | 2446 | buffer->changeLine(a->cursor.y); |
2448 | 2447 | ||
2449 | tagLine(a->cursor.y); | 2448 | tagLine(a->cursor.y); |
2450 | } | 2449 | } |
2451 | 2450 | ||
2452 | void KateDocument::doWordWrap(KateAction *a) { | 2451 | void KateDocument::doWordWrap(KateAction *a) { |
2453 | TextLine::Ptr textLine; | 2452 | TextLine::Ptr textLine; |
2454 | 2453 | ||
2455 | textLine = getTextLine(a->cursor.y - 1); | 2454 | textLine = getTextLine(a->cursor.y - 1); |
2456 | a->len = textLine->length() - a->cursor.x; | 2455 | a->len = textLine->length() - a->cursor.x; |
2457 | textLine->wrap(getTextLine(a->cursor.y),a->len); | 2456 | textLine->wrap(getTextLine(a->cursor.y),a->len); |
2458 | 2457 | ||
2459 | buffer->changeLine(a->cursor.y - 1); | 2458 | buffer->changeLine(a->cursor.y - 1); |
2460 | buffer->changeLine(a->cursor.y); | 2459 | buffer->changeLine(a->cursor.y); |
2461 | 2460 | ||
2462 | tagLine(a->cursor.y - 1); | 2461 | tagLine(a->cursor.y - 1); |
2463 | tagLine(a->cursor.y); | 2462 | tagLine(a->cursor.y); |
2464 | if (selectEnd == a->cursor.y - 1) selectEnd++; | 2463 | if (selectEnd == a->cursor.y - 1) selectEnd++; |
2465 | 2464 | ||
2466 | a->action = KateAction::wordUnWrap; | 2465 | a->action = KateAction::wordUnWrap; |
2467 | } | 2466 | } |
2468 | 2467 | ||
2469 | void KateDocument::doWordUnWrap(KateAction *a) { | 2468 | void KateDocument::doWordUnWrap(KateAction *a) { |
2470 | TextLine::Ptr textLine; | 2469 | TextLine::Ptr textLine; |
2471 | 2470 | ||
2472 | textLine = getTextLine(a->cursor.y - 1); | 2471 | textLine = getTextLine(a->cursor.y - 1); |
2473 | // textLine->setLength(a->len); | 2472 | // textLine->setLength(a->len); |
2474 | textLine->unWrap(a->len, getTextLine(a->cursor.y),a->cursor.x); | 2473 | textLine->unWrap(a->len, getTextLine(a->cursor.y),a->cursor.x); |
2475 | 2474 | ||
2476 | buffer->changeLine(a->cursor.y - 1); | 2475 | buffer->changeLine(a->cursor.y - 1); |
2477 | buffer->changeLine(a->cursor.y); | 2476 | buffer->changeLine(a->cursor.y); |
2478 | 2477 | ||
2479 | tagLine(a->cursor.y - 1); | 2478 | tagLine(a->cursor.y - 1); |
2480 | tagLine(a->cursor.y); | 2479 | tagLine(a->cursor.y); |
2481 | 2480 | ||
2482 | a->action = KateAction::wordWrap; | 2481 | a->action = KateAction::wordWrap; |
2483 | } | 2482 | } |
2484 | 2483 | ||
2485 | void KateDocument::doNewLine(KateAction *a) { | 2484 | void KateDocument::doNewLine(KateAction *a) { |
2486 | TextLine::Ptr textLine, newLine; | 2485 | TextLine::Ptr textLine, newLine; |
2487 | 2486 | ||
2488 | textLine = getTextLine(a->cursor.y); | 2487 | textLine = getTextLine(a->cursor.y); |
2489 | newLine = new TextLine(textLine->getRawAttr(), textLine->getContext()); | 2488 | newLine = new TextLine(textLine->getRawAttr(), textLine->getContext()); |
2490 | textLine->wrap(newLine,a->cursor.x); | 2489 | textLine->wrap(newLine,a->cursor.x); |
2491 | 2490 | ||
2492 | buffer->insertLine(a->cursor.y + 1, newLine); | 2491 | buffer->insertLine(a->cursor.y + 1, newLine); |
2493 | buffer->changeLine(a->cursor.y); | 2492 | buffer->changeLine(a->cursor.y); |
2494 | 2493 | ||
2495 | insLine(a->cursor.y + 1); | 2494 | insLine(a->cursor.y + 1); |
2496 | tagLine(a->cursor.y); | 2495 | tagLine(a->cursor.y); |
2497 | tagLine(a->cursor.y + 1); | 2496 | tagLine(a->cursor.y + 1); |
2498 | if (selectEnd == a->cursor.y) selectEnd++;//addSelection(a->cursor.y + 1); | 2497 | if (selectEnd == a->cursor.y) selectEnd++;//addSelection(a->cursor.y + 1); |
2499 | 2498 | ||
2500 | a->action = KateAction::delLine; | 2499 | a->action = KateAction::delLine; |
2501 | } | 2500 | } |
2502 | 2501 | ||
2503 | void KateDocument::doDelLine(KateAction *a) { | 2502 | void KateDocument::doDelLine(KateAction *a) { |
2504 | TextLine::Ptr textLine, nextLine; | 2503 | TextLine::Ptr textLine, nextLine; |
2505 | 2504 | ||
2506 | textLine = getTextLine(a->cursor.y); | 2505 | textLine = getTextLine(a->cursor.y); |
2507 | nextLine = getTextLine(a->cursor.y+1); | 2506 | nextLine = getTextLine(a->cursor.y+1); |
2508 | // textLine->setLength(a->cursor.x); | 2507 | // textLine->setLength(a->cursor.x); |
2509 | textLine->unWrap(a->cursor.x, nextLine,nextLine->length()); | 2508 | textLine->unWrap(a->cursor.x, nextLine,nextLine->length()); |
2510 | textLine->setContext(nextLine->getContext()); | 2509 | textLine->setContext(nextLine->getContext()); |
2511 | if (longestLine == nextLine) longestLine = 0L; | 2510 | if (longestLine == nextLine) longestLine = 0L; |
2512 | 2511 | ||
2513 | buffer->changeLine(a->cursor.y); | 2512 | buffer->changeLine(a->cursor.y); |
2514 | buffer->removeLine(a->cursor.y+1); | 2513 | buffer->removeLine(a->cursor.y+1); |
2515 | 2514 | ||
2516 | tagLine(a->cursor.y); | 2515 | tagLine(a->cursor.y); |
2517 | delLine(a->cursor.y + 1); | 2516 | delLine(a->cursor.y + 1); |
2518 | 2517 | ||
2519 | a->action = KateAction::newLine; | 2518 | a->action = KateAction::newLine; |
2520 | } | 2519 | } |
2521 | 2520 | ||
2522 | void KateDocument::doInsLine(KateAction *a) { | 2521 | void KateDocument::doInsLine(KateAction *a) { |
2523 | 2522 | ||
2524 | buffer->insertLine(a->cursor.y, new TextLine()); | 2523 | buffer->insertLine(a->cursor.y, new TextLine()); |
2525 | 2524 | ||
2526 | insLine(a->cursor.y); | 2525 | insLine(a->cursor.y); |
2527 | 2526 | ||
2528 | a->action = KateAction::killLine; | 2527 | a->action = KateAction::killLine; |
2529 | } | 2528 | } |
2530 | 2529 | ||
2531 | void KateDocument::doKillLine(KateAction *a) { | 2530 | void KateDocument::doKillLine(KateAction *a) { |
2532 | TextLine::Ptr textLine = getTextLine(a->cursor.y); | 2531 | TextLine::Ptr textLine = getTextLine(a->cursor.y); |
2533 | if (longestLine == textLine) longestLine = 0L; | 2532 | if (longestLine == textLine) longestLine = 0L; |
2534 | 2533 | ||
2535 | buffer->removeLine(a->cursor.y); | 2534 | buffer->removeLine(a->cursor.y); |
2536 | 2535 | ||
2537 | delLine(a->cursor.y); | 2536 | delLine(a->cursor.y); |
2538 | tagLine(a->cursor.y); | 2537 | tagLine(a->cursor.y); |
2539 | 2538 | ||
2540 | a->action = KateAction::insLine; | 2539 | a->action = KateAction::insLine; |
2541 | } | 2540 | } |
2542 | 2541 | ||
2543 | void KateDocument::newUndo() { | 2542 | void KateDocument::newUndo() { |
2544 | KTextEditor::View *view; | 2543 | KTextEditor::View *view; |
2545 | int state; | 2544 | int state; |
2546 | 2545 | ||
2547 | state = 0; | 2546 | state = 0; |
2548 | if (currentUndo > 0) state |= 1; | 2547 | if (currentUndo > 0) state |= 1; |
2549 | if (currentUndo < (int) undoList.count()) state |= 2; | 2548 | if (currentUndo < (int) undoList.count()) state |= 2; |
2550 | undoState = state; | 2549 | undoState = state; |
2551 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { | 2550 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { |
2552 | emit static_cast<KateView *>( view )->newUndo(); | 2551 | emit static_cast<KateView *>( view )->newUndo(); |
2553 | } | 2552 | } |
2554 | } | 2553 | } |
2555 | 2554 | ||
2556 | void KateDocument::recordStart(VConfig &c, int newUndoType) { | 2555 | void KateDocument::recordStart(VConfig &c, int newUndoType) { |
2557 | recordStart(c.view, c.cursor, c.flags, newUndoType); | 2556 | recordStart(c.view, c.cursor, c.flags, newUndoType); |
2558 | } | 2557 | } |
2559 | 2558 | ||
2560 | void KateDocument::recordStart(KateView *, PointStruc &cursor, int flags, | 2559 | void KateDocument::recordStart(KateView *, PointStruc &cursor, int flags, |
2561 | int newUndoType, bool keepModal, bool mergeUndo) { | 2560 | int newUndoType, bool keepModal, bool mergeUndo) { |
2562 | 2561 | ||
2563 | KateActionGroup *g; | 2562 | KateActionGroup *g; |
2564 | 2563 | ||
2565 | // if (newUndoType == KateActionGroup::ugNone) { | 2564 | // if (newUndoType == KateActionGroup::ugNone) { |
2566 | // only a bug would cause this | 2565 | // only a bug would cause this |
2567 | //why should someone do this? we can't prevent all programming errors :) (jochen whilhelmy) | 2566 | //why should someone do this? we can't prevent all programming errors :) (jochen whilhelmy) |
2568 | // debug("KateDocument::recordStart() called with no undo group type!"); | 2567 | // debug("KateDocument::recordStart() called with no undo group type!"); |
2569 | // return; | 2568 | // return; |
2570 | // } | 2569 | // } |
2571 | 2570 | ||
2572 | if (!keepModal) setPseudoModal(0L); | 2571 | if (!keepModal) setPseudoModal(0L); |
2573 | 2572 | ||
2574 | //i optimized the group undo stuff a bit (jochen wilhelmy) | 2573 | //i optimized the group undo stuff a bit (jochen wilhelmy) |
2575 | // recordReset() is not needed any more | 2574 | // recordReset() is not needed any more |
2576 | g = undoList.getLast(); | 2575 | g = undoList.getLast(); |
2577 | if (g != 0L && ((undoCount < 1024 && flags & KateView::cfGroupUndo | 2576 | if (g != 0L && ((undoCount < 1024 && flags & KateView::cfGroupUndo |
2578 | && g->end.x == cursor.x && g->end.y == cursor.y) || mergeUndo)) { | 2577 | && g->end.x == cursor.x && g->end.y == cursor.y) || mergeUndo)) { |
2579 | 2578 | ||
2580 | //undo grouping : same actions are put into one undo step | 2579 | //undo grouping : same actions are put into one undo step |
2581 | //precondition : new action starts where old stops or mergeUndo flag | 2580 | //precondition : new action starts where old stops or mergeUndo flag |
2582 | if (g->undoType == newUndoType | 2581 | if (g->undoType == newUndoType |
2583 | || (g->undoType == KateActionGroup::ugInsChar | 2582 | || (g->undoType == KateActionGroup::ugInsChar |
2584 | && newUndoType == KateActionGroup::ugInsLine) | 2583 | && newUndoType == KateActionGroup::ugInsLine) |
2585 | || (g->undoType == KateActionGroup::ugDelChar | 2584 | || (g->undoType == KateActionGroup::ugDelChar |
2586 | && newUndoType == KateActionGroup::ugDelLine)) { | 2585 | && newUndoType == KateActionGroup::ugDelLine)) { |
2587 | 2586 | ||
2588 | undoCount++; | 2587 | undoCount++; |
2589 | if (g->undoType != newUndoType) undoCount = 0xffffff; | 2588 | if (g->undoType != newUndoType) undoCount = 0xffffff; |
2590 | return; | 2589 | return; |
2591 | } | 2590 | } |
2592 | } | 2591 | } |
2593 | undoCount = 0; | 2592 | undoCount = 0; |
2594 | /* | 2593 | /* |
2595 | if (undoView != view) { | 2594 | if (undoView != view) { |
2596 | // always kill the current undo group if the editing view changes | 2595 | // always kill the current undo group if the editing view changes |
2597 | recordReset(); | 2596 | recordReset(); |
2598 | undoType = newUndoType; | 2597 | undoType = newUndoType; |
2599 | } else if (newUndoType == undoType) { | 2598 | } else if (newUndoType == undoType) { |
2600 | printf("bla!!!\n"); | 2599 | printf("bla!!!\n"); |
2601 | // same as current type, keep using it | 2600 | // same as current type, keep using it |
2602 | return; | 2601 | return; |
2603 | } else if ( (undoType == KateActionGroup::ugInsChar && newUndoType == KateActionGroup::ugInsLine) || | 2602 | } else if ( (undoType == KateActionGroup::ugInsChar && newUndoType == KateActionGroup::ugInsLine) || |
2604 | (undoType == KateActionGroup::ugDelChar && newUndoType == KateActionGroup::ugDelLine) ) { | 2603 | (undoType == KateActionGroup::ugDelChar && newUndoType == KateActionGroup::ugDelLine) ) { |
2605 | // some type combinations can run together... | 2604 | // some type combinations can run together... |
2606 | undoType += 1000; | 2605 | undoType += 1000; |
2607 | return; | 2606 | return; |
2608 | } else { | 2607 | } else { |
2609 | recordReset(); | 2608 | recordReset(); |
2610 | undoType = newUndoType; | 2609 | undoType = newUndoType; |
2611 | } | 2610 | } |
2612 | 2611 | ||
2613 | undoView = view; | 2612 | undoView = view; |
2614 | */ | 2613 | */ |
2615 | while ((int) undoList.count() > currentUndo) undoList.removeLast(); | 2614 | while ((int) undoList.count() > currentUndo) undoList.removeLast(); |
2616 | while ((int) undoList.count() > undoSteps) { | 2615 | while ((int) undoList.count() > undoSteps) { |
2617 | undoList.removeFirst(); | 2616 | undoList.removeFirst(); |
2618 | currentUndo--; | 2617 | currentUndo--; |
2619 | } | 2618 | } |
2620 | 2619 | ||
2621 | g = new KateActionGroup(cursor, newUndoType); | 2620 | g = new KateActionGroup(cursor, newUndoType); |
2622 | undoList.append(g); | 2621 | undoList.append(g); |
2623 | // currentUndo++; | 2622 | // currentUndo++; |
2624 | 2623 | ||
2625 | tagEnd = 0; | 2624 | tagEnd = 0; |
2626 | tagStart = 0xffffff; | 2625 | tagStart = 0xffffff; |
2627 | } | 2626 | } |
2628 | 2627 | ||
2629 | void KateDocument::recordAction(KateAction::Action action, PointStruc &cursor) { | 2628 | void KateDocument::recordAction(KateAction::Action action, PointStruc &cursor) { |
2630 | KateAction *a; | 2629 | KateAction *a; |
2631 | 2630 | ||
2632 | a = new KateAction(action, cursor); | 2631 | a = new KateAction(action, cursor); |
2633 | doAction(a); | 2632 | doAction(a); |
2634 | undoList.getLast()->insertAction(a); | 2633 | undoList.getLast()->insertAction(a); |
2635 | } | 2634 | } |
2636 | 2635 | ||
2637 | void KateDocument::recordInsert(VConfig &c, const QString &text) { | 2636 | void KateDocument::recordInsert(VConfig &c, const QString &text) { |
2638 | recordReplace(c, 0, text); | 2637 | recordReplace(c, 0, text); |
2639 | } | 2638 | } |
2640 | 2639 | ||
2641 | void KateDocument::recordReplace(VConfig &c, int len, const QString &text) { | 2640 | void KateDocument::recordReplace(VConfig &c, int len, const QString &text) { |
2642 | if (c.cursor.x > 0 && !(c.flags & KateView::cfSpaceIndent)) { | 2641 | if (c.cursor.x > 0 && !(c.flags & KateView::cfSpaceIndent)) { |
2643 | TextLine::Ptr textLine = getTextLine(c.cursor.y); | 2642 | TextLine::Ptr textLine = getTextLine(c.cursor.y); |
2644 | if (textLine->length() == 0) { | 2643 | if (textLine->length() == 0) { |
2645 | QString s = tabString(c.cursor.x, tabChars); | 2644 | QString s = tabString(c.cursor.x, tabChars); |
2646 | int len = s.length(); | 2645 | int len = s.length(); |
2647 | s += text; | 2646 | s += text; |
2648 | c.cursor.x = 0; | 2647 | c.cursor.x = 0; |
2649 | recordReplace(c.cursor, len, s); | 2648 | recordReplace(c.cursor, len, s); |
2650 | c.cursor.x = len; | 2649 | c.cursor.x = len; |
2651 | return; | 2650 | return; |
2652 | } | 2651 | } |
2653 | } | 2652 | } |
2654 | recordReplace(c.cursor, len, text); | 2653 | recordReplace(c.cursor, len, text); |
2655 | } | 2654 | } |
2656 | 2655 | ||
2657 | void KateDocument::recordInsert(PointStruc &cursor, const QString &text) { | 2656 | void KateDocument::recordInsert(PointStruc &cursor, const QString &text) { |
2658 | recordReplace(cursor, 0, text); | 2657 | recordReplace(cursor, 0, text); |
2659 | } | 2658 | } |
2660 | 2659 | ||
2661 | void KateDocument::recordDelete(PointStruc &cursor, int len) { | 2660 | void KateDocument::recordDelete(PointStruc &cursor, int len) { |
2662 | recordReplace(cursor, len, QString::null); | 2661 | recordReplace(cursor, len, QString::null); |
2663 | } | 2662 | } |
2664 | 2663 | ||
2665 | void KateDocument::recordReplace(PointStruc &cursor, int len, const QString &text) { | 2664 | void KateDocument::recordReplace(PointStruc &cursor, int len, const QString &text) { |
2666 | KateAction *a; | 2665 | KateAction *a; |
2667 | TextLine::Ptr textLine; | 2666 | TextLine::Ptr textLine; |
2668 | int l; | 2667 | int l; |
2669 | 2668 | ||
2670 | if (len == 0 && text.isEmpty()) return; | 2669 | if (len == 0 && text.isEmpty()) return; |
2671 | 2670 | ||
2672 | //try to append to last replace action | 2671 | //try to append to last replace action |
2673 | a = undoList.getLast()->action; | 2672 | a = undoList.getLast()->action; |
2674 | if (a == 0L || a->action != KateAction::replace | 2673 | if (a == 0L || a->action != KateAction::replace |
2675 | || a->cursor.x + a->len != cursor.x || a->cursor.y != cursor.y) { | 2674 | || a->cursor.x + a->len != cursor.x || a->cursor.y != cursor.y) { |
2676 | 2675 | ||
2677 | //if (a != 0L) printf("new %d %d\n", a->cursor.x + a->len, cursor.x); | 2676 | //if (a != 0L) printf("new %d %d\n", a->cursor.x + a->len, cursor.x); |
2678 | a = new KateAction(KateAction::replace, cursor); | 2677 | a = new KateAction(KateAction::replace, cursor); |
2679 | undoList.getLast()->insertAction(a); | 2678 | undoList.getLast()->insertAction(a); |
2680 | } | 2679 | } |
2681 | 2680 | ||
2682 | //replace | 2681 | //replace |
2683 | textLine = getTextLine(cursor.y); | 2682 | textLine = getTextLine(cursor.y); |
2684 | l = textLine->length() - cursor.x; | 2683 | l = textLine->length() - cursor.x; |
2685 | if (l > len) l = len; | 2684 | if (l > len) l = len; |
2686 | a->text.insert(a->text.length(), &textLine->getText()[cursor.x], (l < 0) ? 0 : l); | 2685 | a->text.insert(a->text.length(), &textLine->getText()[cursor.x], (l < 0) ? 0 : l); |
2687 | textLine->replace(cursor.x, len, text.unicode(), text.length()); | 2686 | textLine->replace(cursor.x, len, text.unicode(), text.length()); |
2688 | a->len += text.length(); | 2687 | a->len += text.length(); |
2689 | 2688 | ||
2690 | buffer->changeLine(a->cursor.y); | 2689 | buffer->changeLine(a->cursor.y); |
2691 | updateMaxLength(textLine); | 2690 | updateMaxLength(textLine); |
2692 | tagLine(a->cursor.y); | 2691 | tagLine(a->cursor.y); |
2693 | } | 2692 | } |
2694 | 2693 | ||
2695 | void KateDocument::recordEnd(VConfig &c) { | 2694 | void KateDocument::recordEnd(VConfig &c) { |
2696 | recordEnd(c.view, c.cursor, c.flags); | 2695 | recordEnd(c.view, c.cursor, c.flags); |
2697 | } | 2696 | } |
2698 | 2697 | ||
2699 | void KateDocument::recordEnd(KateView *view, PointStruc &cursor, int flags) { | 2698 | void KateDocument::recordEnd(KateView *view, PointStruc &cursor, int flags) { |
2700 | KateActionGroup *g; | 2699 | KateActionGroup *g; |
2701 | 2700 | ||
2702 | // clear selection if option "persistent selections" is off | 2701 | // clear selection if option "persistent selections" is off |
2703 | // if (!(flags & cfPersistent)) deselectAll(); | 2702 | // if (!(flags & cfPersistent)) deselectAll(); |
2704 | 2703 | ||
2705 | g = undoList.getLast(); | 2704 | g = undoList.getLast(); |
2706 | if (g->action == 0L) { | 2705 | if (g->action == 0L) { |
2707 | // no action has been done: remove empty undo record | 2706 | // no action has been done: remove empty undo record |
2708 | undoList.removeLast(); | 2707 | undoList.removeLast(); |
2709 | return; | 2708 | return; |
2710 | } | 2709 | } |
2711 | // store end cursor position for redo | 2710 | // store end cursor position for redo |
2712 | g->end = cursor; | 2711 | g->end = cursor; |
2713 | currentUndo = undoList.count(); | 2712 | currentUndo = undoList.count(); |
2714 | 2713 | ||
2715 | if (tagStart <= tagEnd) { | 2714 | if (tagStart <= tagEnd) { |
2716 | optimizeSelection(); | 2715 | optimizeSelection(); |
2717 | updateLines(tagStart, tagEnd, flags, cursor.y); | 2716 | updateLines(tagStart, tagEnd, flags, cursor.y); |
2718 | setModified(true); | 2717 | setModified(true); |
2719 | } | 2718 | } |
2720 | 2719 | ||
2721 | view->updateCursor(cursor, flags); | 2720 | view->updateCursor(cursor, flags); |
2722 | 2721 | ||
2723 | // newUndo(); | 2722 | // newUndo(); |
2724 | /* | 2723 | /* |
2725 | undoCount++; | 2724 | undoCount++; |
2726 | // we limit the number of individual undo operations for sanity - is 1K reasonable? | 2725 | // we limit the number of individual undo operations for sanity - is 1K reasonable? |
2727 | // this is also where we handle non-group undo preference | 2726 | // this is also where we handle non-group undo preference |
2728 | // if the undo type is singlular, we always finish it now | 2727 | // if the undo type is singlular, we always finish it now |
2729 | if ( undoType == KateActionGroup::ugPaste || | 2728 | if ( undoType == KateActionGroup::ugPaste || |
2730 | undoType == KateActionGroup::ugDelBlock || | 2729 | undoType == KateActionGroup::ugDelBlock || |
2731 | undoType > 1000 || | 2730 | undoType > 1000 || |
2732 | undoCount > 1024 || !(flags & cfGroupUndo) ) { | 2731 | undoCount > 1024 || !(flags & cfGroupUndo) ) { |
2733 | printf("recordend %d %d\n", undoType, undoCount); | 2732 | printf("recordend %d %d\n", undoType, undoCount); |
2734 | recordReset(); | 2733 | recordReset(); |
2735 | } | 2734 | } |
2736 | */ | 2735 | */ |
2737 | 2736 | ||
2738 | // this should keep the flood of signals down a little... | 2737 | // this should keep the flood of signals down a little... |
2739 | if (undoCount == 0) newUndo(); | 2738 | if (undoCount == 0) newUndo(); |
2740 | emit textChanged(); | 2739 | emit textChanged(); |
2741 | } | 2740 | } |
2742 | /* | 2741 | /* |
2743 | void KateDocument::recordReset() | 2742 | void KateDocument::recordReset() |
2744 | { | 2743 | { |
2745 | if (pseudoModal) | 2744 | if (pseudoModal) |
2746 | return; | 2745 | return; |
2747 | 2746 | ||
2748 | // forces the next call of recordStart() to begin a new undo group | 2747 | // forces the next call of recordStart() to begin a new undo group |
2749 | // not used in normal editing, but used by markFound(), etc. | 2748 | // not used in normal editing, but used by markFound(), etc. |
2750 | undoType = KateActionGroup::ugNone; | 2749 | undoType = KateActionGroup::ugNone; |
2751 | undoCount = 0; | 2750 | undoCount = 0; |
2752 | undoView = NULL; | 2751 | undoView = NULL; |
2753 | undoReported = false; | 2752 | undoReported = false; |
2754 | printf("recordreset\n"); | 2753 | printf("recordreset\n"); |
2755 | } | 2754 | } |
2756 | */ | 2755 | */ |
2757 | 2756 | ||
2758 | /* | 2757 | /* |
2759 | void KateDocument::recordDel(PointStruc &cursor, TextLine::Ptr &textLine, int l) { | 2758 | void KateDocument::recordDel(PointStruc &cursor, TextLine::Ptr &textLine, int l) { |
2760 | int len; | 2759 | int len; |
2761 | 2760 | ||
2762 | len = textLine->length() - cursor.x; | 2761 | len = textLine->length() - cursor.x; |
2763 | if (len > l) len = l; | 2762 | if (len > l) len = l; |
2764 | if (len > 0) { | 2763 | if (len > 0) { |
2765 | insertUndo(new KateAction(KateAction::replace,cursor,&textLine->getText()[cursor.x],len)); | 2764 | insertUndo(new KateAction(KateAction::replace,cursor,&textLine->getText()[cursor.x],len)); |
2766 | } | 2765 | } |
2767 | } | 2766 | } |
2768 | */ | 2767 | */ |
2769 | 2768 | ||
2770 | 2769 | ||
2771 | void KateDocument::doActionGroup(KateActionGroup *g, int flags, bool undo) { | 2770 | void KateDocument::doActionGroup(KateActionGroup *g, int flags, bool undo) { |
2772 | KateAction *a, *next; | 2771 | KateAction *a, *next; |
2773 | 2772 | ||
2774 | setPseudoModal(0L); | 2773 | setPseudoModal(0L); |
2775 | if (!(flags & KateView::cfPersistent)) deselectAll(); | 2774 | if (!(flags & KateView::cfPersistent)) deselectAll(); |
2776 | tagEnd = 0; | 2775 | tagEnd = 0; |
2777 | tagStart = 0xffffff; | 2776 | tagStart = 0xffffff; |
2778 | 2777 | ||
2779 | a = g->action; | 2778 | a = g->action; |
2780 | g->action = 0L; | 2779 | g->action = 0L; |
2781 | while (a) { | 2780 | while (a) { |
2782 | doAction(a); | 2781 | doAction(a); |
2783 | next = a->next; | 2782 | next = a->next; |
2784 | g->insertAction(a); | 2783 | g->insertAction(a); |
2785 | a = next; | 2784 | a = next; |
2786 | } | 2785 | } |
2787 | optimizeSelection(); | 2786 | optimizeSelection(); |
2788 | if (tagStart <= tagEnd) updateLines(tagStart, tagEnd, flags); | 2787 | if (tagStart <= tagEnd) updateLines(tagStart, tagEnd, flags); |
2789 | 2788 | ||
2790 | // the undo/redo functions set undo to true, all others should leave it | 2789 | // the undo/redo functions set undo to true, all others should leave it |
2791 | // alone (default) | 2790 | // alone (default) |
2792 | if (!undo) { | 2791 | if (!undo) { |
2793 | setModified(true); | 2792 | setModified(true); |
2794 | newUndo(); | 2793 | newUndo(); |
2795 | } | 2794 | } |
2796 | } | 2795 | } |
2797 | 2796 | ||
2798 | int KateDocument::nextUndoType() | 2797 | int KateDocument::nextUndoType() |
2799 | { | 2798 | { |
2800 | KateActionGroup *g; | 2799 | KateActionGroup *g; |
2801 | 2800 | ||
2802 | if (currentUndo <= 0) return KateActionGroup::ugNone; | 2801 | if (currentUndo <= 0) return KateActionGroup::ugNone; |
2803 | g = undoList.at(currentUndo - 1); | 2802 | g = undoList.at(currentUndo - 1); |
2804 | return g->undoType; | 2803 | return g->undoType; |
2805 | } | 2804 | } |
2806 | 2805 | ||
2807 | int KateDocument::nextRedoType() | 2806 | int KateDocument::nextRedoType() |
2808 | { | 2807 | { |
2809 | KateActionGroup *g; | 2808 | KateActionGroup *g; |
2810 | 2809 | ||
2811 | if (currentUndo >= (int) undoList.count()) return KateActionGroup::ugNone; | 2810 | if (currentUndo >= (int) undoList.count()) return KateActionGroup::ugNone; |
2812 | g = undoList.at(currentUndo); | 2811 | g = undoList.at(currentUndo); |
2813 | // if (!g) return KateActionGroup::ugNone; | 2812 | // if (!g) return KateActionGroup::ugNone; |
2814 | return g->undoType; | 2813 | return g->undoType; |
2815 | } | 2814 | } |
2816 | 2815 | ||
2817 | void KateDocument::undoTypeList(QValueList<int> &lst) | 2816 | void KateDocument::undoTypeList(QValueList<int> &lst) |
2818 | { | 2817 | { |
2819 | lst.clear(); | 2818 | lst.clear(); |
2820 | for (int i = currentUndo-1; i>=0 ;i--) | 2819 | for (int i = currentUndo-1; i>=0 ;i--) |
2821 | lst.append(undoList.at(i)->undoType); | 2820 | lst.append(undoList.at(i)->undoType); |
2822 | } | 2821 | } |
2823 | 2822 | ||
2824 | void KateDocument::redoTypeList(QValueList<int> &lst) | 2823 | void KateDocument::redoTypeList(QValueList<int> &lst) |
2825 | { | 2824 | { |
2826 | lst.clear(); | 2825 | lst.clear(); |
2827 | for (int i = currentUndo+1; i<(int)undoList.count(); i++) | 2826 | for (int i = currentUndo+1; i<(int)undoList.count(); i++) |
2828 | lst.append(undoList.at(i)->undoType); | 2827 | lst.append(undoList.at(i)->undoType); |
2829 | } | 2828 | } |
2830 | 2829 | ||
2831 | void KateDocument::undo(VConfig &c, int count) { | 2830 | void KateDocument::undo(VConfig &c, int count) { |
2832 | KateActionGroup *g = 0L; | 2831 | KateActionGroup *g = 0L; |
2833 | int num; | 2832 | int num; |
2834 | bool needUpdate = false; // don't update the cursor until completely done | 2833 | bool needUpdate = false; // don't update the cursor until completely done |
2835 | 2834 | ||
2836 | if (count <= 0) return; | 2835 | if (count <= 0) return; |
2837 | 2836 | ||
2838 | for (num = 0 ; num < count ; num++) { | 2837 | for (num = 0 ; num < count ; num++) { |
2839 | if (currentUndo <= 0) break; | 2838 | if (currentUndo <= 0) break; |
2840 | currentUndo--; | 2839 | currentUndo--; |
2841 | g = undoList.at(currentUndo); | 2840 | g = undoList.at(currentUndo); |
2842 | doActionGroup(g, c.flags, true); // do not setModified() or newUndo() | 2841 | doActionGroup(g, c.flags, true); // do not setModified() or newUndo() |
2843 | needUpdate = true; | 2842 | needUpdate = true; |
2844 | 2843 | ||
2845 | // if (num == 0) recordReset(); | 2844 | // if (num == 0) recordReset(); |
2846 | } | 2845 | } |
2847 | 2846 | ||
2848 | if (needUpdate) { | 2847 | if (needUpdate) { |
2849 | // since we told doActionGroup() not to do this stuff, we need to do it now | 2848 | // since we told doActionGroup() not to do this stuff, we need to do it now |
2850 | c.view->updateCursor(g->start); | 2849 | c.view->updateCursor(g->start); |
2851 | setModified(true); | 2850 | setModified(true); |
2852 | newUndo(); | 2851 | newUndo(); |
2853 | } | 2852 | } |
2854 | } | 2853 | } |
2855 | 2854 | ||
2856 | void KateDocument::redo(VConfig &c, int count) { | 2855 | void KateDocument::redo(VConfig &c, int count) { |
2857 | KateActionGroup *g = 0L; | 2856 | KateActionGroup *g = 0L; |
2858 | int num; | 2857 | int num; |
2859 | bool needUpdate = false; // don't update the cursor until completely done | 2858 | bool needUpdate = false; // don't update the cursor until completely done |
2860 | 2859 | ||
2861 | if (count <= 0) return; | 2860 | if (count <= 0) return; |
2862 | 2861 | ||
2863 | for (num = 0 ; num < count ; num++) { | 2862 | for (num = 0 ; num < count ; num++) { |
2864 | if (currentUndo+1 > (int)undoList.count()) break; | 2863 | if (currentUndo+1 > (int)undoList.count()) break; |
2865 | g = undoList.at(currentUndo); | 2864 | g = undoList.at(currentUndo); |
2866 | currentUndo++; | 2865 | currentUndo++; |
2867 | doActionGroup(g, c.flags, true); // do not setModified() or newUndo() | 2866 | doActionGroup(g, c.flags, true); // do not setModified() or newUndo() |
2868 | needUpdate = true; | 2867 | needUpdate = true; |
2869 | 2868 | ||
2870 | // if (num == 0) recordReset(); | 2869 | // if (num == 0) recordReset(); |
2871 | } | 2870 | } |
2872 | 2871 | ||
2873 | if (needUpdate) { | 2872 | if (needUpdate) { |
2874 | // since we told doActionGroup() not to do this stuff, we need to do it now | 2873 | // since we told doActionGroup() not to do this stuff, we need to do it now |
2875 | c.view->updateCursor(g->end); | 2874 | c.view->updateCursor(g->end); |
2876 | setModified(true); | 2875 | setModified(true); |
2877 | newUndo(); | 2876 | newUndo(); |
2878 | } | 2877 | } |
2879 | } | 2878 | } |
2880 | 2879 | ||
2881 | void KateDocument::clearRedo() { | 2880 | void KateDocument::clearRedo() { |
2882 | // disable redos | 2881 | // disable redos |
2883 | // this was added as an assist to the spell checker | 2882 | // this was added as an assist to the spell checker |
2884 | bool deleted = false; | 2883 | bool deleted = false; |
2885 | 2884 | ||
2886 | while ((int) undoList.count() > currentUndo) { | 2885 | while ((int) undoList.count() > currentUndo) { |
2887 | deleted = true; | 2886 | deleted = true; |
2888 | undoList.removeLast(); | 2887 | undoList.removeLast(); |
2889 | } | 2888 | } |
2890 | 2889 | ||
2891 | if (deleted) newUndo(); | 2890 | if (deleted) newUndo(); |
2892 | } | 2891 | } |
2893 | 2892 | ||
2894 | void KateDocument::setUndoSteps(int steps) { | 2893 | void KateDocument::setUndoSteps(int steps) { |
2895 | if (steps < 5) steps = 5; | 2894 | if (steps < 5) steps = 5; |
2896 | undoSteps = steps; | 2895 | undoSteps = steps; |
2897 | } | 2896 | } |
2898 | 2897 | ||
2899 | void KateDocument::setPseudoModal(QWidget *w) { | 2898 | void KateDocument::setPseudoModal(QWidget *w) { |
2900 | // QWidget *old = pseudoModal; | 2899 | // QWidget *old = pseudoModal; |
2901 | 2900 | ||
2902 | // (glenebob) | 2901 | // (glenebob) |
2903 | // this is a temporary hack to make the spell checker work a little | 2902 | // this is a temporary hack to make the spell checker work a little |
2904 | // better - as kspell progresses, this sort of thing should become | 2903 | // better - as kspell progresses, this sort of thing should become |
2905 | // obsolete or worked around more cleanly | 2904 | // obsolete or worked around more cleanly |
2906 | // this is relied upon *only* by the spell-check code | 2905 | // this is relied upon *only* by the spell-check code |
2907 | if (pseudoModal && pseudoModal != (QWidget*)1L) | 2906 | if (pseudoModal && pseudoModal != (QWidget*)1L) |
2908 | delete pseudoModal; | 2907 | delete pseudoModal; |
2909 | 2908 | ||
2910 | // pseudoModal = 0L; | 2909 | // pseudoModal = 0L; |
2911 | // if (old || w) recordReset(); | 2910 | // if (old || w) recordReset(); |
2912 | 2911 | ||
2913 | pseudoModal = w; | 2912 | pseudoModal = w; |
2914 | } | 2913 | } |
2915 | 2914 | ||
2916 | 2915 | ||
2917 | void KateDocument::newBracketMark(PointStruc &cursor, BracketMark &bm) | 2916 | void KateDocument::newBracketMark(PointStruc &cursor, BracketMark &bm) |
2918 | { | 2917 | { |
2919 | TextLine::Ptr textLine; | 2918 | TextLine::Ptr textLine; |
2920 | int x, line, count, attr; | 2919 | int x, line, count, attr; |
2921 | QChar bracket, opposite, ch; | 2920 | QChar bracket, opposite, ch; |
2922 | Attribute *a; | 2921 | Attribute *a; |
2923 | 2922 | ||
2924 | bm.eXPos = -1; //mark bracked mark as invalid | 2923 | bm.eXPos = -1; //mark bracked mark as invalid |
2925 | x = cursor.x -1; // -1 to look at left side of cursor | 2924 | x = cursor.x -1; // -1 to look at left side of cursor |
2926 | if (x < 0) return; | 2925 | if (x < 0) return; |
2927 | line = cursor.y; //current line | 2926 | line = cursor.y; //current line |
2928 | count = 0; //bracket counter for nested brackets | 2927 | count = 0; //bracket counter for nested brackets |
2929 | 2928 | ||
2930 | textLine = getTextLine(line); | 2929 | textLine = getTextLine(line); |
2931 | if (!textLine) return; | 2930 | if (!textLine) return; |
2932 | 2931 | ||
2933 | bracket = textLine->getChar(x); | 2932 | bracket = textLine->getChar(x); |
2934 | attr = textLine->getAttr(x); | 2933 | attr = textLine->getAttr(x); |
2935 | 2934 | ||
2936 | if (bracket == '(' || bracket == '[' || bracket == '{') | 2935 | if (bracket == '(' || bracket == '[' || bracket == '{') |
2937 | { | 2936 | { |
2938 | //get opposite bracket | 2937 | //get opposite bracket |
2939 | opposite = ')'; | 2938 | opposite = ')'; |
2940 | if (bracket == '[') opposite = ']'; | 2939 | if (bracket == '[') opposite = ']'; |
2941 | if (bracket == '{') opposite = '}'; | 2940 | if (bracket == '{') opposite = '}'; |
2942 | //get attribute of bracket (opposite bracket must have the same attribute) | 2941 | //get attribute of bracket (opposite bracket must have the same attribute) |
2943 | x++; | 2942 | x++; |
2944 | while (line - cursor.y < 40) { | 2943 | while (line - cursor.y < 40) { |
2945 | //go to next line on end of line | 2944 | //go to next line on end of line |
2946 | while (x >= (int) textLine->length()) { | 2945 | while (x >= (int) textLine->length()) { |
2947 | line++; | 2946 | line++; |
2948 | if (line > lastLine()) return; | 2947 | if (line > lastLine()) return; |
2949 | textLine = getTextLine(line); | 2948 | textLine = getTextLine(line); |
2950 | x = 0; | 2949 | x = 0; |
2951 | } | 2950 | } |
2952 | if (textLine->getAttr(x) == attr) { | 2951 | if (textLine->getAttr(x) == attr) { |
2953 | //try to find opposite bracked | 2952 | //try to find opposite bracked |
2954 | ch = textLine->getChar(x); | 2953 | ch = textLine->getChar(x); |
2955 | if (ch == bracket) count++; //same bracket : increase counter | 2954 | if (ch == bracket) count++; //same bracket : increase counter |
2956 | if (ch == opposite) { | 2955 | if (ch == opposite) { |
2957 | count--; | 2956 | count--; |
2958 | if (count < 0) goto found; | 2957 | if (count < 0) goto found; |
2959 | } | 2958 | } |
2960 | } | 2959 | } |
2961 | x++; | 2960 | x++; |
2962 | } | 2961 | } |
2963 | } | 2962 | } |
2964 | else if (bracket == ')' || bracket == ']' || bracket == '}') | 2963 | else if (bracket == ')' || bracket == ']' || bracket == '}') |
2965 | { | 2964 | { |
2966 | opposite = '('; | 2965 | opposite = '('; |
2967 | if (bracket == ']') opposite = '['; | 2966 | if (bracket == ']') opposite = '['; |
2968 | if (bracket == '}') opposite = '{'; | 2967 | if (bracket == '}') opposite = '{'; |
2969 | x--; | 2968 | x--; |
2970 | while (cursor.y - line < 20) { | 2969 | while (cursor.y - line < 20) { |
2971 | 2970 | ||
2972 | while (x < 0) { | 2971 | while (x < 0) { |
2973 | line--; | 2972 | line--; |
2974 | if (line < 0) return; | 2973 | if (line < 0) return; |
2975 | textLine = getTextLine(line); | 2974 | textLine = getTextLine(line); |
2976 | x = textLine->length() -1; | 2975 | x = textLine->length() -1; |
2977 | } | 2976 | } |
2978 | if (textLine->getAttr(x) == attr) { | 2977 | if (textLine->getAttr(x) == attr) { |
2979 | ch = textLine->getChar(x); | 2978 | ch = textLine->getChar(x); |
2980 | if (ch == bracket) count++; | 2979 | if (ch == bracket) count++; |
2981 | if (ch == opposite) { | 2980 | if (ch == opposite) { |
2982 | count--; | 2981 | count--; |
2983 | if (count < 0) goto found; | 2982 | if (count < 0) goto found; |
2984 | } | 2983 | } |
2985 | } | 2984 | } |
2986 | x--; | 2985 | x--; |
2987 | } | 2986 | } |
2988 | } | 2987 | } |
2989 | return; | 2988 | return; |
2990 | 2989 | ||
2991 | found: | 2990 | found: |
2992 | //cursor position of opposite bracket | 2991 | //cursor position of opposite bracket |
2993 | bm.cursor.x = x; | 2992 | bm.cursor.x = x; |
2994 | bm.cursor.y = line; | 2993 | bm.cursor.y = line; |
2995 | //x position (start and end) of related bracket | 2994 | //x position (start and end) of related bracket |
2996 | bm.sXPos = textWidth(textLine, x); | 2995 | bm.sXPos = textWidth(textLine, x); |
2997 | a = &m_attribs[attr]; | 2996 | a = &m_attribs[attr]; |
2998 | 2997 | ||
2999 | if (a->bold && a->italic) | 2998 | if (a->bold && a->italic) |
3000 | bm.eXPos = bm.sXPos + myFontMetricsBI.width(bracket); | 2999 | bm.eXPos = bm.sXPos + myFontMetricsBI.width(bracket); |
3001 | else if (a->bold) | 3000 | else if (a->bold) |
3002 | bm.eXPos = bm.sXPos + myFontMetricsBold.width(bracket); | 3001 | bm.eXPos = bm.sXPos + myFontMetricsBold.width(bracket); |
3003 | else if (a->italic) | 3002 | else if (a->italic) |
3004 | bm.eXPos = bm.sXPos + myFontMetricsItalic.width(bracket); | 3003 | bm.eXPos = bm.sXPos + myFontMetricsItalic.width(bracket); |
3005 | else | 3004 | else |
3006 | bm.eXPos = bm.sXPos + myFontMetrics.width(bracket); | 3005 | bm.eXPos = bm.sXPos + myFontMetrics.width(bracket); |
3007 | } | 3006 | } |
3008 | 3007 | ||
3009 | void KateDocument::clipboardChanged() { //slot | 3008 | void KateDocument::clipboardChanged() { //slot |
3010 | //#if defined(_WS_X11_) | 3009 | //#if defined(_WS_X11_) |
3011 | if (m_singleSelection) { | 3010 | if (m_singleSelection) { |
3012 | disconnect(QApplication::clipboard(), SIGNAL(dataChanged()), | 3011 | disconnect(QApplication::clipboard(), SIGNAL(dataChanged()), |
3013 | this, SLOT(clipboardChanged())); | 3012 | this, SLOT(clipboardChanged())); |
3014 | deselectAll(); | 3013 | deselectAll(); |
3015 | updateViews(); | 3014 | updateViews(); |
3016 | } | 3015 | } |
3017 | //#endif | 3016 | //#endif |
3018 | } | 3017 | } |
3019 | 3018 | ||
3020 | #if 0 | 3019 | #if 0 |
3021 | void KateDocument::guiActivateEvent( KParts::GUIActivateEvent *ev ) | 3020 | void KateDocument::guiActivateEvent( KParts::GUIActivateEvent *ev ) |
3022 | { | 3021 | { |
3023 | KParts::ReadWritePart::guiActivateEvent( ev ); | 3022 | KParts::ReadWritePart::guiActivateEvent( ev ); |
3024 | if ( ev->activated() ) | 3023 | if ( ev->activated() ) |
3025 | emit selectionChanged(); | 3024 | emit selectionChanged(); |
3026 | } | 3025 | } |
3027 | #endif | 3026 | #endif |
3028 | 3027 | ||
3029 | void KateDocument::setDocName (QString docName) | 3028 | void KateDocument::setDocName (QString docName) |
3030 | { | 3029 | { |
3031 | myDocName = docName; | 3030 | myDocName = docName; |
3032 | emit nameChanged (this); | 3031 | emit nameChanged (this); |
3033 | } | 3032 | } |
3034 | 3033 | ||
3035 | void KateDocument::setDocFile (QString docFile) | 3034 | void KateDocument::setDocFile (QString docFile) |
3036 | { | 3035 | { |
3037 | m_file = docFile; | 3036 | m_file = docFile; |
3038 | emit fileNameChanged (); | 3037 | emit fileNameChanged (); |
3039 | } | 3038 | } |
3040 | 3039 | ||
3041 | void KateDocument::setMTime() | 3040 | void KateDocument::setMTime() |
3042 | { | 3041 | { |
3043 | if (fileInfo && !fileInfo->fileName().isEmpty()) { | 3042 | if (fileInfo && !fileInfo->fileName().isEmpty()) { |
3044 | fileInfo->refresh(); | 3043 | fileInfo->refresh(); |
3045 | mTime = fileInfo->lastModified(); | 3044 | mTime = fileInfo->lastModified(); |
3046 | } | 3045 | } |
3047 | } | 3046 | } |
3048 | 3047 | ||
3049 | void KateDocument::isModOnHD(bool forceReload) | 3048 | void KateDocument::isModOnHD(bool forceReload) |
3050 | { | 3049 | { |
3051 | if (fileInfo && !fileInfo->fileName().isEmpty()) { | 3050 | if (fileInfo && !fileInfo->fileName().isEmpty()) { |
3052 | fileInfo->refresh(); | 3051 | fileInfo->refresh(); |
3053 | if (fileInfo->lastModified() > mTime) { | 3052 | if (fileInfo->lastModified() > mTime) { |
3054 | if ( forceReload || | 3053 | if ( forceReload || |
3055 | (KMessageBox::warningContinueCancel(0, | 3054 | (KMessageBox::warningContinueCancel(0, |
3056 | (i18n("The file %1 has changed on disk.\nDo you want to reload it?\n\nIf you cancel you will lose these changes next time you save this file")).arg(m_url), | 3055 | (i18n("The file %1 has changed on disk.\nDo you want to reload it?\n\nIf you cancel you will lose these changes next time you save this file")).arg(m_url), |
3057 | i18n("File has changed on Disk"), | 3056 | i18n("File has changed on Disk"), |
3058 | i18n("Yes") ) == KMessageBox::Continue) | 3057 | i18n("Yes") ) == KMessageBox::Continue) |
3059 | ) | 3058 | ) |
3060 | reloadFile(); | 3059 | reloadFile(); |
3061 | else | 3060 | else |
3062 | setMTime(); | 3061 | setMTime(); |
3063 | } | 3062 | } |
3064 | } | 3063 | } |
3065 | } | 3064 | } |
3066 | 3065 | ||
3067 | void KateDocument::reloadFile() | 3066 | void KateDocument::reloadFile() |
3068 | { | 3067 | { |
3069 | #warning fixme | 3068 | #warning fixme |
3070 | #if 0 | 3069 | #if 0 |
3071 | if (fileInfo && !fileInfo->fileName().isEmpty()) { | 3070 | if (fileInfo && !fileInfo->fileName().isEmpty()) { |
3072 | KateDocument::openFile(); | 3071 | KateDocument::openFile(); |
3073 | setMTime(); | 3072 | setMTime(); |
3074 | } | 3073 | } |
3075 | #endif | 3074 | #endif |
3076 | } | 3075 | } |
3077 | 3076 | ||
3078 | void KateDocument::slotModChanged() | 3077 | void KateDocument::slotModChanged() |
3079 | { | 3078 | { |
3080 | emit modStateChanged (this); | 3079 | emit modStateChanged (this); |
3081 | } | 3080 | } |
3082 | 3081 | ||
3083 | QList<Kate::Mark> KateDocument::marks () | 3082 | QList<Kate::Mark> KateDocument::marks () |
3084 | { | 3083 | { |
3085 | QList<Kate::Mark> list; | 3084 | QList<Kate::Mark> list; |
3086 | TextLine::Ptr line; | 3085 | TextLine::Ptr line; |
3087 | 3086 | ||
3088 | for (int i=0; i < numLines(); i++) | 3087 | for (int i=0; i < numLines(); i++) |
3089 | { | 3088 | { |
3090 | line = getTextLine(i); | 3089 | line = getTextLine(i); |
3091 | if (line->mark() != 0) | 3090 | if (line->mark() != 0) |
3092 | { | 3091 | { |
3093 | Kate::Mark *mark=new Kate::Mark; | 3092 | Kate::Mark *mark=new Kate::Mark; |
3094 | mark->line = i; | 3093 | mark->line = i; |
3095 | mark->type = line->mark(); | 3094 | mark->type = line->mark(); |
3096 | list.append (mark); | 3095 | list.append (mark); |
3097 | } | 3096 | } |
3098 | } | 3097 | } |
3099 | 3098 | ||
3100 | return list; | 3099 | return list; |
3101 | } | 3100 | } |
3102 | 3101 | ||
3103 | void KateDocument::flush () | 3102 | void KateDocument::flush () |
3104 | { | 3103 | { |
3105 | if (isReadOnly()) | 3104 | if (isReadOnly()) |
3106 | return; | 3105 | return; |
3107 | 3106 | ||
3108 | m_url = QString::null; | 3107 | m_url = QString::null; |
3109 | fileInfo->setFile (QString()); | 3108 | fileInfo->setFile (QString()); |
3110 | setMTime(); | 3109 | setMTime(); |
3111 | 3110 | ||
3112 | clear(); | 3111 | clear(); |
3113 | updateViews(); | 3112 | updateViews(); |
3114 | 3113 | ||
3115 | emit fileNameChanged (); | 3114 | emit fileNameChanged (); |
3116 | } | 3115 | } |
3117 | 3116 | ||
3118 | void KateDocument::open (const QString &name) | 3117 | void KateDocument::open (const QString &name) |
3119 | { | 3118 | { |
3120 | openURL (name); | 3119 | openURL (name); |
3121 | } | 3120 | } |
3122 | 3121 | ||
3123 | void KateDocument::wrapText (uint col) | 3122 | void KateDocument::wrapText (uint col) |
3124 | { | 3123 | { |
3125 | int line = 0; | 3124 | int line = 0; |
3126 | int z = 0; | 3125 | int z = 0; |
3127 | 3126 | ||
3128 | while(true) | 3127 | while(true) |
3129 | { | 3128 | { |
3130 | TextLine::Ptr l = getTextLine(line); | 3129 | TextLine::Ptr l = getTextLine(line); |
3131 | 3130 | ||
3132 | if (l->length() > col) | 3131 | if (l->length() > col) |
3133 | { | 3132 | { |
3134 | TextLine::Ptr tl = new TextLine(); | 3133 | TextLine::Ptr tl = new TextLine(); |
3135 | buffer->insertLine(line+1,tl); | 3134 | buffer->insertLine(line+1,tl); |
3136 | const QChar *text = l->getText(); | 3135 | const QChar *text = l->getText(); |
3137 | 3136 | ||
3138 | for (z=col; z>0; z--) | 3137 | for (z=col; z>0; z--) |
3139 | { | 3138 | { |
3140 | if (z < 1) break; | 3139 | if (z < 1) break; |
3141 | if (text[z].isSpace()) break; | 3140 | if (text[z].isSpace()) break; |
3142 | } | 3141 | } |
3143 | 3142 | ||
3144 | if (z < 1) z=col; | 3143 | if (z < 1) z=col; |
3145 | 3144 | ||
3146 | l->wrap (tl, z); | 3145 | l->wrap (tl, z); |
3147 | } | 3146 | } |
3148 | 3147 | ||
3149 | line++; | 3148 | line++; |
3150 | if (line >= numLines()) break; | 3149 | if (line >= numLines()) break; |
3151 | }; | 3150 | }; |
3152 | 3151 | ||
3153 | newDocGeometry=true; | 3152 | newDocGeometry=true; |
3154 | updateLines(); | 3153 | updateLines(); |
3155 | updateViews(); | 3154 | updateViews(); |
3156 | } | 3155 | } |
3157 | 3156 | ||
3158 | void KateDocument::setWordWrap (bool on) | 3157 | void KateDocument::setWordWrap (bool on) |
3159 | { | 3158 | { |
3160 | if (on != myWordWrap && on) | 3159 | if (on != myWordWrap && on) |
3161 | wrapText (myWordWrapAt); | 3160 | wrapText (myWordWrapAt); |
3162 | 3161 | ||
3163 | myWordWrap = on; | 3162 | myWordWrap = on; |
3164 | } | 3163 | } |
3165 | 3164 | ||
3166 | void KateDocument::setWordWrapAt (uint col) | 3165 | void KateDocument::setWordWrapAt (uint col) |
3167 | { | 3166 | { |
3168 | if (myWordWrapAt != col && myWordWrap) | 3167 | if (myWordWrapAt != col && myWordWrap) |
3169 | wrapText (myWordWrapAt); | 3168 | wrapText (myWordWrapAt); |
3170 | 3169 | ||
3171 | myWordWrapAt = col; | 3170 | myWordWrapAt = col; |
3172 | } | 3171 | } |
3173 | 3172 | ||
3174 | void KateDocument::applyWordWrap () | 3173 | void KateDocument::applyWordWrap () |
3175 | { | 3174 | { |
3176 | wrapText (myWordWrapAt); | 3175 | wrapText (myWordWrapAt); |
3177 | } | 3176 | } |
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.h b/noncore/apps/tinykate/libkate/document/katedocument.h index 356541f..9d8ec6a 100644 --- a/noncore/apps/tinykate/libkate/document/katedocument.h +++ b/noncore/apps/tinykate/libkate/document/katedocument.h | |||
@@ -1,570 +1,570 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | katedocument.h - description | 2 | katedocument.h - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Jan 15 2001 | 4 | begin : Mon Jan 15 2001 |
5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann | 5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann |
6 | (C) 2002 by Joseph Wenninger | 6 | (C) 2002 by Joseph Wenninger |
7 | email : crossfire@babylon2k.de | 7 | email : crossfire@babylon2k.de |
8 | jowenn@kde.org | 8 | jowenn@kde.org |
9 | 9 | ||
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * * | 13 | * * |
14 | * This program is free software; you can redistribute it and/or modify * | 14 | * This program is free software; you can redistribute it and/or modify * |
15 | * it under the terms of the GNU General Public License as published by * | 15 | * it under the terms of the GNU General Public License as published by * |
16 | * the Free Software Foundation; either version 2 of the License, or * | 16 | * the Free Software Foundation; either version 2 of the License, or * |
17 | * (at your option) any later version. * | 17 | * (at your option) any later version. * |
18 | * * | 18 | * * |
19 | ***************************************************************************/ | 19 | ***************************************************************************/ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Copyright (C) 1998, 1999 Jochen Wilhelmy | 22 | Copyright (C) 1998, 1999 Jochen Wilhelmy |
23 | digisnap@cs.tu-berlin.de | 23 | digisnap@cs.tu-berlin.de |
24 | 24 | ||
25 | This library is free software; you can redistribute it and/or | 25 | This library is free software; you can redistribute it and/or |
26 | modify it under the terms of the GNU Library General Public | 26 | modify it under the terms of the GNU Library General Public |
27 | License as published by the Free Software Foundation; either | 27 | License as published by the Free Software Foundation; either |
28 | version 2 of the License, or (at your option) any later version. | 28 | version 2 of the License, or (at your option) any later version. |
29 | 29 | ||
30 | This library is distributed in the hope that it will be useful, | 30 | This library is distributed in the hope that it will be useful, |
31 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 31 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
33 | Library General Public License for more details. | 33 | Library General Public License for more details. |
34 | 34 | ||
35 | You should have received a copy of the GNU Library General Public License | 35 | You should have received a copy of the GNU Library General Public License |
36 | along with this library; see the file COPYING.LIB. If not, write to | 36 | along with this library; see the file COPYING.LIB. If not, write to |
37 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 37 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
38 | Boston, MA 02111-1307, USA. | 38 | Boston, MA 02111-1307, USA. |
39 | */ | 39 | */ |
40 | 40 | ||
41 | #ifndef kate_document_h | 41 | #ifndef kate_document_h |
42 | #define kate_document_h | 42 | #define kate_document_h |
43 | 43 | ||
44 | 44 | ||
45 | #include <qobject.h> | 45 | #include <qobject.h> |
46 | #include <qlist.h> | 46 | #include <qlist.h> |
47 | #include <qcolor.h> | 47 | #include <qcolor.h> |
48 | #include <qfont.h> | 48 | #include <qfont.h> |
49 | #include <qfontmetrics.h> | 49 | #include <qfontmetrics.h> |
50 | #include <qdatetime.h> | 50 | #include <qdatetime.h> |
51 | #include <qfileinfo.h> | 51 | #include <qfileinfo.h> |
52 | 52 | ||
53 | #include "../view/kateview.h" | 53 | #include "../view/kateview.h" |
54 | #include "katehighlight.h" | 54 | #include "katehighlight.h" |
55 | #include "katebuffer.h" | 55 | #include "katebuffer.h" |
56 | #include "katetextline.h" | 56 | #include "katetextline.h" |
57 | 57 | ||
58 | 58 | ||
59 | #include <qptrdict.h> | 59 | #include <qptrdict.h> |
60 | 60 | ||
61 | class KateCmd; | 61 | class KateCmd; |
62 | 62 | ||
63 | class CachedFontMetrics : public QFontMetrics { | 63 | class CachedFontMetrics : public QFontMetrics { |
64 | private: | 64 | private: |
65 | short *warray[256]; | 65 | short *warray[256]; |
66 | public: | 66 | public: |
67 | CachedFontMetrics(const QFont& f) : QFontMetrics(f) { | 67 | CachedFontMetrics(const QFont& f) : QFontMetrics(f) { |
68 | for (int i=0; i<256; i++) warray[i]=0; | 68 | for (int i=0; i<256; i++) warray[i]=0; |
69 | } | 69 | } |
70 | ~CachedFontMetrics() { | 70 | ~CachedFontMetrics() { |
71 | for (int i=0; i<256; i++) | 71 | for (int i=0; i<256; i++) |
72 | if (warray[i]) delete[] warray[i]; | 72 | if (warray[i]) delete[] warray[i]; |
73 | } | 73 | } |
74 | int width(QChar c) { | 74 | int width(QChar c) { |
75 | uchar cell=c.cell(); | 75 | uchar cell=c.cell(); |
76 | uchar row=c.row(); | 76 | uchar row=c.row(); |
77 | short *wa=warray[row]; | 77 | short *wa=warray[row]; |
78 | if (!wa) { | 78 | if (!wa) { |
79 | // qDebug("create row: %d",row); | 79 | // qDebug("create row: %d",row); |
80 | wa=warray[row]=new short[256]; | 80 | wa=warray[row]=new short[256]; |
81 | for (int i=0; i<256; i++) wa[i]=-1; | 81 | for (int i=0; i<256; i++) wa[i]=-1; |
82 | } | 82 | } |
83 | if (wa[cell]<0) wa[cell]=(short) QFontMetrics::width(c); | 83 | if (wa[cell]<0) wa[cell]=(short) QFontMetrics::width(c); |
84 | return (int)wa[cell]; | 84 | return (int)wa[cell]; |
85 | } | 85 | } |
86 | int width(QString s) { return QFontMetrics::width(s); } | 86 | int width(QString s) { return QFontMetrics::width(s); } |
87 | }; | 87 | }; |
88 | 88 | ||
89 | class Attribute { | 89 | class Attribute { |
90 | public: | 90 | public: |
91 | Attribute() { ; }; | 91 | Attribute() { ; }; |
92 | 92 | ||
93 | QColor col; | 93 | QColor col; |
94 | QColor selCol; | 94 | QColor selCol; |
95 | bool bold; | 95 | bool bold; |
96 | bool italic; | 96 | bool italic; |
97 | }; | 97 | }; |
98 | 98 | ||
99 | class KateAction { | 99 | class KateAction { |
100 | public: | 100 | public: |
101 | enum Action {replace, wordWrap, wordUnWrap, newLine, delLine, | 101 | enum Action {replace, wordWrap, wordUnWrap, newLine, delLine, |
102 | insLine, killLine};//, doubleLine, removeLine}; | 102 | insLine, killLine};//, doubleLine, removeLine}; |
103 | 103 | ||
104 | KateAction(Action, PointStruc &cursor, int len = 0, | 104 | KateAction(Action, PointStruc &cursor, int len = 0, |
105 | const QString &text = QString::null); | 105 | const QString &text = QString::null); |
106 | 106 | ||
107 | Action action; | 107 | Action action; |
108 | PointStruc cursor; | 108 | PointStruc cursor; |
109 | int len; | 109 | int len; |
110 | QString text; | 110 | QString text; |
111 | KateAction *next; | 111 | KateAction *next; |
112 | }; | 112 | }; |
113 | 113 | ||
114 | class KateActionGroup { | 114 | class KateActionGroup { |
115 | public: | 115 | public: |
116 | // the undo group types | 116 | // the undo group types |
117 | enum { ugNone, // | 117 | enum { ugNone, // |
118 | ugPaste, // paste | 118 | ugPaste, // paste |
119 | ugDelBlock, // delete/replace selected text | 119 | ugDelBlock, // delete/replace selected text |
120 | ugIndent, // indent | 120 | ugIndent, // indent |
121 | ugUnindent, // unindent | 121 | ugUnindent, // unindent |
122 | ugComment, // comment | 122 | ugComment, // comment |
123 | ugUncomment, // uncomment | 123 | ugUncomment, // uncomment |
124 | ugReplace, // text search/replace | 124 | ugReplace, // text search/replace |
125 | ugSpell, // spell check | 125 | ugSpell, // spell check |
126 | ugInsChar, // char type/deleting | 126 | ugInsChar, // char type/deleting |
127 | ugDelChar, // '' '' | 127 | ugDelChar, // '' '' |
128 | ugInsLine, // line insert/delete | 128 | ugInsLine, // line insert/delete |
129 | ugDelLine // '' '' | 129 | ugDelLine // '' '' |
130 | }; | 130 | }; |
131 | 131 | ||
132 | KateActionGroup(PointStruc &aStart, int type = ugNone); | 132 | KateActionGroup(PointStruc &aStart, int type = ugNone); |
133 | ~KateActionGroup(); | 133 | ~KateActionGroup(); |
134 | void insertAction(KateAction *); | 134 | void insertAction(KateAction *); |
135 | 135 | ||
136 | static const char * typeName(int type); | 136 | static const char * typeName(int type); |
137 | 137 | ||
138 | PointStruc start; | 138 | PointStruc start; |
139 | PointStruc end; | 139 | PointStruc end; |
140 | KateAction *action; | 140 | KateAction *action; |
141 | int undoType; | 141 | int undoType; |
142 | }; | 142 | }; |
143 | 143 | ||
144 | /** | 144 | /** |
145 | The text document. It contains the textlines, controls the | 145 | The text document. It contains the textlines, controls the |
146 | document changing operations and does undo/redo. WARNING: do not change | 146 | document changing operations and does undo/redo. WARNING: do not change |
147 | the text contents directly in methods where this is not explicitly | 147 | the text contents directly in methods where this is not explicitly |
148 | permitted. All changes have to be made with some basic operations, | 148 | permitted. All changes have to be made with some basic operations, |
149 | which are recorded by the undo/redo system. | 149 | which are recorded by the undo/redo system. |
150 | @see TextLine | 150 | @see TextLine |
151 | @author Jochen Wilhelmy | 151 | @author Jochen Wilhelmy |
152 | */ | 152 | */ |
153 | class KateDocument: public Kate::Document | 153 | class KateDocument: public Kate::Document |
154 | { | 154 | { |
155 | Q_OBJECT | 155 | Q_OBJECT |
156 | friend class KateViewInternal; | 156 | friend class KateViewInternal; |
157 | friend class KateView; | 157 | friend class KateView; |
158 | friend class KateIconBorder; | 158 | friend class KateIconBorder; |
159 | 159 | ||
160 | public: | 160 | public: |
161 | KateDocument(bool bSingleViewMode=false, bool bBrowserView=false, QWidget *parentWidget = 0, const char *widgetName = 0, QObject * = 0, const char * = 0); | 161 | KateDocument(bool bSingleViewMode=false, bool bBrowserView=false, QWidget *parentWidget = 0, const char *widgetName = 0, QObject * = 0, const char * = 0); |
162 | ~KateDocument(); | 162 | ~KateDocument(); |
163 | 163 | ||
164 | protected: | 164 | protected: |
165 | QFont myFont, myFontBold, myFontItalic, myFontBI; | 165 | QFont myFont, myFontBold, myFontItalic, myFontBI; |
166 | CachedFontMetrics myFontMetrics, myFontMetricsBold, myFontMetricsItalic, myFontMetricsBI; | 166 | CachedFontMetrics myFontMetrics, myFontMetricsBold, myFontMetricsItalic, myFontMetricsBI; |
167 | 167 | ||
168 | public: | 168 | public: |
169 | void setFont (QFont font); | 169 | void setFont (QFont font); |
170 | QFont getFont () { return myFont; }; | 170 | QFont getFont () { return myFont; }; |
171 | CachedFontMetrics getFontMetrics () { return myFontMetrics; }; | 171 | CachedFontMetrics getFontMetrics () { return myFontMetrics; }; |
172 | 172 | ||
173 | virtual bool saveFile(); | 173 | virtual bool saveFile(); |
174 | 174 | ||
175 | virtual KTextEditor::View *createView( QWidget *parent, const char *name ); | 175 | virtual KTextEditor::View *createView( QWidget *parent, const char *name ); |
176 | virtual QString textLine( int line ) const; | 176 | virtual QString textLine( int line ) const; |
177 | 177 | ||
178 | virtual void insertLine( const QString &s, int line = -1 ); | 178 | virtual void insertLine( const QString &s, int line = -1 ); |
179 | 179 | ||
180 | void insert_Line(const QString& s,int line=-1, bool update=true); | 180 | void insert_Line(const QString& s,int line=-1, bool update=true); |
181 | void remove_Line(int line,bool update=true); | 181 | void remove_Line(int line,bool update=true); |
182 | void replaceLine(const QString& s,int line=-1); | 182 | void replaceLine(const QString& s,int line=-1); |
183 | virtual void insertAt( const QString &s, int line, int col, bool mark = FALSE ); | 183 | virtual void insertAt( const QString &s, int line, int col, bool mark = FALSE ); |
184 | virtual void removeLine( int line ); | 184 | virtual void removeLine( int line ); |
185 | virtual int length() const; | 185 | virtual int length() const; |
186 | 186 | ||
187 | virtual void setSelection( int row_from, int col_from, int row_to, int col_t ); | 187 | virtual void setSelection( int row_from, int col_from, int row_to, int col_t ); |
188 | virtual bool hasSelection() const; | 188 | virtual bool hasSelection() const; |
189 | virtual QString selection() const; | 189 | virtual QString selection() const; |
190 | 190 | ||
191 | // only to make part work, don't change it ! | 191 | // only to make part work, don't change it ! |
192 | bool m_bSingleViewMode; | 192 | bool m_bSingleViewMode; |
193 | 193 | ||
194 | // public interface | 194 | // public interface |
195 | /** | 195 | /** |
196 | * gets the number of lines | 196 | * gets the number of lines |
197 | */ | 197 | */ |
198 | virtual int numLines() const; | 198 | virtual int numLines() const; |
199 | 199 | ||
200 | /** | 200 | /** |
201 | * gets the last line number (numLines() -1) | 201 | * gets the last line number (numLines() -1) |
202 | */ | 202 | */ |
203 | int lastLine() const {return numLines()-1;} | 203 | int lastLine() const {return numLines()-1;} |
204 | 204 | ||
205 | /** | 205 | /** |
206 | gets the given line | 206 | gets the given line |
207 | @return the TextLine object at the given line | 207 | @return the TextLine object at the given line |
208 | @see TextLine | 208 | @see TextLine |
209 | */ | 209 | */ |
210 | TextLine::Ptr getTextLine(int line) const; | 210 | TextLine::Ptr getTextLine(int line) const; |
211 | 211 | ||
212 | /** | 212 | /** |
213 | get the length in pixels of the given line | 213 | get the length in pixels of the given line |
214 | */ | 214 | */ |
215 | int textLength(int line); | 215 | int textLength(int line); |
216 | 216 | ||
217 | void setTabWidth(int); | 217 | void setTabWidth(int); |
218 | int tabWidth() {return tabChars;} | 218 | int tabWidth() {return tabChars;} |
219 | void setReadOnly(bool); | 219 | void setReadOnly(bool); |
220 | bool isReadOnly() const; | 220 | bool isReadOnly() const; |
221 | void setNewDoc( bool ); | 221 | void setNewDoc( bool ); |
222 | bool isNewDoc() const; | 222 | bool isNewDoc() const; |
223 | virtual void setReadWrite( bool ){}; | 223 | virtual void setReadWrite( bool ){}; |
224 | virtual bool isReadWrite() const {return true;} | 224 | virtual bool isReadWrite() const {return true;} |
225 | virtual void setModified(bool); | 225 | virtual void setModified(bool); |
226 | virtual bool isModified() const; | 226 | virtual bool isModified() const; |
227 | void setSingleSelection(bool ss) {m_singleSelection = ss;} | 227 | void setSingleSelection(bool ss) {m_singleSelection = ss;} |
228 | bool singleSelection() {return m_singleSelection;} | 228 | bool singleSelection() {return m_singleSelection;} |
229 | 229 | ||
230 | void readConfig(); | 230 | void readConfig(); |
231 | void writeConfig(); | 231 | void writeConfig(); |
232 | void readSessionConfig(KConfig *); | 232 | void readSessionConfig(KateConfig *); |
233 | void writeSessionConfig(KConfig *); | 233 | void writeSessionConfig(KateConfig *); |
234 | 234 | ||
235 | bool hasBrowserExtension() const { return m_bBrowserView; } | 235 | bool hasBrowserExtension() const { return m_bBrowserView; } |
236 | 236 | ||
237 | protected: | 237 | protected: |
238 | bool m_bBrowserView; | 238 | bool m_bBrowserView; |
239 | 239 | ||
240 | signals: | 240 | signals: |
241 | void selectionChanged(); | 241 | void selectionChanged(); |
242 | void highlightChanged(); | 242 | void highlightChanged(); |
243 | void modifiedChanged (); | 243 | void modifiedChanged (); |
244 | void preHighlightChanged(long); | 244 | void preHighlightChanged(long); |
245 | 245 | ||
246 | // search stuff | 246 | // search stuff |
247 | protected: | 247 | protected: |
248 | static QStringList searchForList; | 248 | static QStringList searchForList; |
249 | static QStringList replaceWithList; | 249 | static QStringList replaceWithList; |
250 | static uint uniqueID; | 250 | static uint uniqueID; |
251 | 251 | ||
252 | // highlight stuff | 252 | // highlight stuff |
253 | public: | 253 | public: |
254 | Highlight *highlight() {return m_highlight;} | 254 | Highlight *highlight() {return m_highlight;} |
255 | int highlightNum() {return hlManager->findHl(m_highlight);} | 255 | int highlightNum() {return hlManager->findHl(m_highlight);} |
256 | int numAttribs() {return m_numAttribs;} | 256 | int numAttribs() {return m_numAttribs;} |
257 | Attribute *attribs() {return m_attribs;} | 257 | Attribute *attribs() {return m_attribs;} |
258 | void setDontChangeHlOnSave(); | 258 | void setDontChangeHlOnSave(); |
259 | 259 | ||
260 | protected: | 260 | protected: |
261 | void setHighlight(int n); | 261 | void setHighlight(int n); |
262 | void makeAttribs(); | 262 | void makeAttribs(); |
263 | void updateFontData(); | 263 | void updateFontData(); |
264 | 264 | ||
265 | protected slots: | 265 | protected slots: |
266 | void hlChanged(); | 266 | void hlChanged(); |
267 | 267 | ||
268 | // view interaction | 268 | // view interaction |
269 | public: | 269 | public: |
270 | virtual void addView(KTextEditor::View *); | 270 | virtual void addView(KTextEditor::View *); |
271 | virtual void removeView(KTextEditor::View *); | 271 | virtual void removeView(KTextEditor::View *); |
272 | bool ownedView(KateView *); | 272 | bool ownedView(KateView *); |
273 | bool isLastView(int numViews); | 273 | bool isLastView(int numViews); |
274 | 274 | ||
275 | int getTextLineCount() {return numLines();} | 275 | int getTextLineCount() {return numLines();} |
276 | 276 | ||
277 | int textWidth(const TextLine::Ptr &, int cursorX); | 277 | int textWidth(const TextLine::Ptr &, int cursorX); |
278 | int textWidth(PointStruc &cursor); | 278 | int textWidth(PointStruc &cursor); |
279 | int textWidth(bool wrapCursor, PointStruc &cursor, int xPos); | 279 | int textWidth(bool wrapCursor, PointStruc &cursor, int xPos); |
280 | int textPos(const TextLine::Ptr &, int xPos); | 280 | int textPos(const TextLine::Ptr &, int xPos); |
281 | // int textPos(TextLine::Ptr &, int xPos, int &newXPos); | 281 | // int textPos(TextLine::Ptr &, int xPos, int &newXPos); |
282 | int textWidth(); | 282 | int textWidth(); |
283 | int textHeight(); | 283 | int textHeight(); |
284 | 284 | ||
285 | void insert(VConfig &, const QString &); | 285 | void insert(VConfig &, const QString &); |
286 | void insertFile(VConfig &, QIODevice &); | 286 | void insertFile(VConfig &, QIODevice &); |
287 | 287 | ||
288 | int currentColumn(PointStruc &cursor); | 288 | int currentColumn(PointStruc &cursor); |
289 | bool insertChars(VConfig &, const QString &chars); | 289 | bool insertChars(VConfig &, const QString &chars); |
290 | void newLine(VConfig &); | 290 | void newLine(VConfig &); |
291 | void killLine(VConfig &); | 291 | void killLine(VConfig &); |
292 | void backspace(VConfig &); | 292 | void backspace(VConfig &); |
293 | void del(VConfig &); | 293 | void del(VConfig &); |
294 | void clear(); | 294 | void clear(); |
295 | void cut(VConfig &); | 295 | void cut(VConfig &); |
296 | void copy(int flags); | 296 | void copy(int flags); |
297 | void paste(VConfig &); | 297 | void paste(VConfig &); |
298 | 298 | ||
299 | void toggleRect(int, int, int, int); | 299 | void toggleRect(int, int, int, int); |
300 | void selectTo(VConfig &c, PointStruc &cursor, int cXPos); | 300 | void selectTo(VConfig &c, PointStruc &cursor, int cXPos); |
301 | void selectAll(); | 301 | void selectAll(); |
302 | void deselectAll(); | 302 | void deselectAll(); |
303 | void invertSelection(); | 303 | void invertSelection(); |
304 | void selectWord(PointStruc &cursor, int flags); | 304 | void selectWord(PointStruc &cursor, int flags); |
305 | void selectLength(PointStruc &cursor, int length, int flags); | 305 | void selectLength(PointStruc &cursor, int length, int flags); |
306 | 306 | ||
307 | void indent(VConfig &c) {doIndent(c, 1);} | 307 | void indent(VConfig &c) {doIndent(c, 1);} |
308 | void unIndent(VConfig &c) {doIndent(c, -1);} | 308 | void unIndent(VConfig &c) {doIndent(c, -1);} |
309 | void cleanIndent(VConfig &c) {doIndent(c, 0);} | 309 | void cleanIndent(VConfig &c) {doIndent(c, 0);} |
310 | // called by indent/unIndent/cleanIndent | 310 | // called by indent/unIndent/cleanIndent |
311 | // just does some setup and then calls optimizeLeadingSpace() | 311 | // just does some setup and then calls optimizeLeadingSpace() |
312 | void doIndent(VConfig &, int change); | 312 | void doIndent(VConfig &, int change); |
313 | // optimize leading whitespace on a single line - see kwdoc.cpp for full description | 313 | // optimize leading whitespace on a single line - see kwdoc.cpp for full description |
314 | void optimizeLeadingSpace(int line, int flags, int change); | 314 | void optimizeLeadingSpace(int line, int flags, int change); |
315 | 315 | ||
316 | void comment(VConfig &c) {doComment(c, 1);} | 316 | void comment(VConfig &c) {doComment(c, 1);} |
317 | void unComment(VConfig &c) {doComment(c, -1);} | 317 | void unComment(VConfig &c) {doComment(c, -1);} |
318 | void doComment(VConfig &, int change); | 318 | void doComment(VConfig &, int change); |
319 | 319 | ||
320 | virtual QString text() const; | 320 | virtual QString text() const; |
321 | QString getWord(PointStruc &cursor); | 321 | QString getWord(PointStruc &cursor); |
322 | 322 | ||
323 | public slots: | 323 | public slots: |
324 | virtual void setText(const QString &); | 324 | virtual void setText(const QString &); |
325 | 325 | ||
326 | public: | 326 | public: |
327 | long needPreHighlight(long till); | 327 | long needPreHighlight(long till); |
328 | bool hasMarkedText() {return (selectEnd >= selectStart);} | 328 | bool hasMarkedText() {return (selectEnd >= selectStart);} |
329 | QString markedText(int flags); | 329 | QString markedText(int flags); |
330 | void delMarkedText(VConfig &/*, bool undo = true*/); | 330 | void delMarkedText(VConfig &/*, bool undo = true*/); |
331 | 331 | ||
332 | void tagLineRange(int line, int x1, int x2); | 332 | void tagLineRange(int line, int x1, int x2); |
333 | void tagLines(int start, int end); | 333 | void tagLines(int start, int end); |
334 | void tagAll(); | 334 | void tagAll(); |
335 | void updateLines(int startLine = 0, int endLine = 0xffffff, int flags = 0, int cursorY = -1); | 335 | void updateLines(int startLine = 0, int endLine = 0xffffff, int flags = 0, int cursorY = -1); |
336 | void updateMaxLength(TextLine::Ptr &); | 336 | void updateMaxLength(TextLine::Ptr &); |
337 | void updateViews(KateView *exclude = 0L); | 337 | void updateViews(KateView *exclude = 0L); |
338 | 338 | ||
339 | QColor &cursorCol(int x, int y); | 339 | QColor &cursorCol(int x, int y); |
340 | void paintTextLine(QPainter &, int line, int xStart, int xEnd, bool showTabs); | 340 | void paintTextLine(QPainter &, int line, int xStart, int xEnd, bool showTabs); |
341 | void paintTextLine(QPainter &, int line, int y, int xStart, int xEnd, bool showTabs); | 341 | void paintTextLine(QPainter &, int line, int y, int xStart, int xEnd, bool showTabs); |
342 | 342 | ||
343 | bool doSearch(SConfig &s, const QString &searchFor); | 343 | bool doSearch(SConfig &s, const QString &searchFor); |
344 | 344 | ||
345 | // internal | 345 | // internal |
346 | void tagLine(int line); | 346 | void tagLine(int line); |
347 | void insLine(int line); | 347 | void insLine(int line); |
348 | void delLine(int line); | 348 | void delLine(int line); |
349 | void optimizeSelection(); | 349 | void optimizeSelection(); |
350 | 350 | ||
351 | void doAction(KateAction *); | 351 | void doAction(KateAction *); |
352 | void doReplace(KateAction *); | 352 | void doReplace(KateAction *); |
353 | void doWordWrap(KateAction *); | 353 | void doWordWrap(KateAction *); |
354 | void doWordUnWrap(KateAction *); | 354 | void doWordUnWrap(KateAction *); |
355 | void doNewLine(KateAction *); | 355 | void doNewLine(KateAction *); |
356 | void doDelLine(KateAction *); | 356 | void doDelLine(KateAction *); |
357 | void doInsLine(KateAction *); | 357 | void doInsLine(KateAction *); |
358 | void doKillLine(KateAction *); | 358 | void doKillLine(KateAction *); |
359 | void newUndo(); | 359 | void newUndo(); |
360 | 360 | ||
361 | void recordStart(VConfig &, int newUndoType); | 361 | void recordStart(VConfig &, int newUndoType); |
362 | void recordStart(KateView *, PointStruc &, int flags, int newUndoType, bool keepModal = false, bool mergeUndo = false); | 362 | void recordStart(KateView *, PointStruc &, int flags, int newUndoType, bool keepModal = false, bool mergeUndo = false); |
363 | void recordAction(KateAction::Action, PointStruc &); | 363 | void recordAction(KateAction::Action, PointStruc &); |
364 | void recordInsert(VConfig &, const QString &text); | 364 | void recordInsert(VConfig &, const QString &text); |
365 | void recordReplace(VConfig &, int len, const QString &text); | 365 | void recordReplace(VConfig &, int len, const QString &text); |
366 | void recordInsert(PointStruc &, const QString &text); | 366 | void recordInsert(PointStruc &, const QString &text); |
367 | void recordDelete(PointStruc &, int len); | 367 | void recordDelete(PointStruc &, int len); |
368 | void recordReplace(PointStruc &, int len, const QString &text); | 368 | void recordReplace(PointStruc &, int len, const QString &text); |
369 | void recordEnd(VConfig &); | 369 | void recordEnd(VConfig &); |
370 | void recordEnd(KateView *, PointStruc &, int flags); | 370 | void recordEnd(KateView *, PointStruc &, int flags); |
371 | void doActionGroup(KateActionGroup *, int flags, bool undo = false); | 371 | void doActionGroup(KateActionGroup *, int flags, bool undo = false); |
372 | 372 | ||
373 | int nextUndoType(); | 373 | int nextUndoType(); |
374 | int nextRedoType(); | 374 | int nextRedoType(); |
375 | void undoTypeList(QValueList<int> &lst); | 375 | void undoTypeList(QValueList<int> &lst); |
376 | void redoTypeList(QValueList<int> &lst); | 376 | void redoTypeList(QValueList<int> &lst); |
377 | void undo(VConfig &, int count = 1); | 377 | void undo(VConfig &, int count = 1); |
378 | void redo(VConfig &, int count = 1); | 378 | void redo(VConfig &, int count = 1); |
379 | void clearRedo(); | 379 | void clearRedo(); |
380 | void setUndoSteps(int steps); | 380 | void setUndoSteps(int steps); |
381 | 381 | ||
382 | void setPseudoModal(QWidget *); | 382 | void setPseudoModal(QWidget *); |
383 | 383 | ||
384 | void newBracketMark(PointStruc &, BracketMark &); | 384 | void newBracketMark(PointStruc &, BracketMark &); |
385 | 385 | ||
386 | 386 | ||
387 | protected slots: | 387 | protected slots: |
388 | void clipboardChanged(); | 388 | void clipboardChanged(); |
389 | void slotBufferChanged(); | 389 | void slotBufferChanged(); |
390 | void slotBufferHighlight(long,long); | 390 | void slotBufferHighlight(long,long); |
391 | void doPreHighlight(); | 391 | void doPreHighlight(); |
392 | 392 | ||
393 | private slots: | 393 | private slots: |
394 | void slotViewDestroyed(); | 394 | void slotViewDestroyed(); |
395 | 395 | ||
396 | // member variables | 396 | // member variables |
397 | protected: | 397 | protected: |
398 | long PreHighlightedTill; | 398 | long PreHighlightedTill; |
399 | long RequestPreHighlightTill; | 399 | long RequestPreHighlightTill; |
400 | KWBuffer *buffer; | 400 | KWBuffer *buffer; |
401 | QColor colors[2]; | 401 | QColor colors[2]; |
402 | HlManager *hlManager; | 402 | HlManager *hlManager; |
403 | Highlight *m_highlight; | 403 | Highlight *m_highlight; |
404 | int m_numAttribs; | 404 | int m_numAttribs; |
405 | static const int maxAttribs; | 405 | static const int maxAttribs; |
406 | Attribute *m_attribs; | 406 | Attribute *m_attribs; |
407 | 407 | ||
408 | int eolMode; | 408 | int eolMode; |
409 | 409 | ||
410 | int tabChars; | 410 | int tabChars; |
411 | int m_tabWidth; | 411 | int m_tabWidth; |
412 | int fontHeight; | 412 | int fontHeight; |
413 | int fontAscent; | 413 | int fontAscent; |
414 | 414 | ||
415 | QList<KateView> views; | 415 | QList<KateView> views; |
416 | bool newDocGeometry; | 416 | bool newDocGeometry; |
417 | 417 | ||
418 | TextLine::Ptr longestLine; | 418 | TextLine::Ptr longestLine; |
419 | float maxLength; | 419 | float maxLength; |
420 | 420 | ||
421 | PointStruc select; | 421 | PointStruc select; |
422 | PointStruc anchor; | 422 | PointStruc anchor; |
423 | int aXPos; | 423 | int aXPos; |
424 | int selectStart; | 424 | int selectStart; |
425 | int selectEnd; | 425 | int selectEnd; |
426 | bool oldMarkState; | 426 | bool oldMarkState; |
427 | bool m_singleSelection; // false: windows-like, true: X11-like | 427 | bool m_singleSelection; // false: windows-like, true: X11-like |
428 | 428 | ||
429 | bool readOnly; | 429 | bool readOnly; |
430 | bool newDoc; // True if the file is a new document (used to determine whether | 430 | bool newDoc; // True if the file is a new document (used to determine whether |
431 | // to check for overwriting files on save) | 431 | // to check for overwriting files on save) |
432 | bool modified; | 432 | bool modified; |
433 | 433 | ||
434 | bool myWordWrap; | 434 | bool myWordWrap; |
435 | uint myWordWrapAt; | 435 | uint myWordWrapAt; |
436 | 436 | ||
437 | QList<KateActionGroup> undoList; | 437 | QList<KateActionGroup> undoList; |
438 | int currentUndo; | 438 | int currentUndo; |
439 | int undoState; | 439 | int undoState; |
440 | int undoSteps; | 440 | int undoSteps; |
441 | int tagStart; | 441 | int tagStart; |
442 | int tagEnd; | 442 | int tagEnd; |
443 | int undoCount; //counts merged undo steps | 443 | int undoCount; //counts merged undo steps |
444 | 444 | ||
445 | QWidget *pseudoModal; //the replace prompt is pseudo modal | 445 | QWidget *pseudoModal; //the replace prompt is pseudo modal |
446 | 446 | ||
447 | public: | 447 | public: |
448 | /** Tjecks if the file on disk is newer than document contents. | 448 | /** Tjecks if the file on disk is newer than document contents. |
449 | If forceReload is true, the document is reloaded without asking the user, | 449 | If forceReload is true, the document is reloaded without asking the user, |
450 | otherwise [default] the user is asked what to do. */ | 450 | otherwise [default] the user is asked what to do. */ |
451 | void isModOnHD(bool forceReload=false); | 451 | void isModOnHD(bool forceReload=false); |
452 | 452 | ||
453 | uint docID () {return myDocID;}; | 453 | uint docID () {return myDocID;}; |
454 | QString docName () {return myDocName;}; | 454 | QString docName () {return myDocName;}; |
455 | 455 | ||
456 | void setDocName (QString docName); | 456 | void setDocName (QString docName); |
457 | void setDocFile (QString docFile); | 457 | void setDocFile (QString docFile); |
458 | 458 | ||
459 | public slots: | 459 | public slots: |
460 | /** Reloads the current document from disk if possible */ | 460 | /** Reloads the current document from disk if possible */ |
461 | void reloadFile(); | 461 | void reloadFile(); |
462 | 462 | ||
463 | private slots: | 463 | private slots: |
464 | void slotModChanged (); | 464 | void slotModChanged (); |
465 | 465 | ||
466 | private: | 466 | private: |
467 | /** updates mTime to reflect file on fs. | 467 | /** updates mTime to reflect file on fs. |
468 | called from constructor and from saveFile. */ | 468 | called from constructor and from saveFile. */ |
469 | void setMTime(); | 469 | void setMTime(); |
470 | uint myDocID; | 470 | uint myDocID; |
471 | QFileInfo* fileInfo; | 471 | QFileInfo* fileInfo; |
472 | QDateTime mTime; | 472 | QDateTime mTime; |
473 | QString myDocName; | 473 | QString myDocName; |
474 | 474 | ||
475 | QString m_url; | 475 | QString m_url; |
476 | QString m_file; | 476 | QString m_file; |
477 | void openURL(const QString &filename); | 477 | void openURL(const QString &filename); |
478 | private: | 478 | private: |
479 | KateCmd *myCmd; | 479 | KateCmd *myCmd; |
480 | 480 | ||
481 | public: | 481 | public: |
482 | KateCmd *cmd () { return myCmd; }; | 482 | KateCmd *cmd () { return myCmd; }; |
483 | 483 | ||
484 | private: | 484 | private: |
485 | QString myEncoding; | 485 | QString myEncoding; |
486 | 486 | ||
487 | public: | 487 | public: |
488 | void setEncoding (QString e) { myEncoding = e; }; | 488 | void setEncoding (QString e) { myEncoding = e; }; |
489 | QString encoding() { return myEncoding; }; | 489 | QString encoding() { return myEncoding; }; |
490 | 490 | ||
491 | void setWordWrap (bool on); | 491 | void setWordWrap (bool on); |
492 | bool wordWrap () { return myWordWrap; }; | 492 | bool wordWrap () { return myWordWrap; }; |
493 | 493 | ||
494 | void setWordWrapAt (uint col); | 494 | void setWordWrapAt (uint col); |
495 | uint wordWrapAt () { return myWordWrapAt; }; | 495 | uint wordWrapAt () { return myWordWrapAt; }; |
496 | 496 | ||
497 | signals: | 497 | signals: |
498 | void modStateChanged (KateDocument *doc); | 498 | void modStateChanged (KateDocument *doc); |
499 | void nameChanged (KateDocument *doc); | 499 | void nameChanged (KateDocument *doc); |
500 | 500 | ||
501 | public: | 501 | public: |
502 | QList<Kate::Mark> marks (); | 502 | QList<Kate::Mark> marks (); |
503 | 503 | ||
504 | public slots: | 504 | public slots: |
505 | // clear buffer/filename - update the views | 505 | // clear buffer/filename - update the views |
506 | void flush (); | 506 | void flush (); |
507 | 507 | ||
508 | signals: | 508 | signals: |
509 | /** | 509 | /** |
510 | The file has been saved (perhaps the name has changed). The main window | 510 | The file has been saved (perhaps the name has changed). The main window |
511 | can use this to change its caption | 511 | can use this to change its caption |
512 | */ | 512 | */ |
513 | void fileNameChanged (); | 513 | void fileNameChanged (); |
514 | 514 | ||
515 | public: | 515 | public: |
516 | //end of line settings | 516 | //end of line settings |
517 | enum Eol_settings {eolUnix=0,eolDos=1,eolMacintosh=2}; | 517 | enum Eol_settings {eolUnix=0,eolDos=1,eolMacintosh=2}; |
518 | 518 | ||
519 | // for the DCOP interface | 519 | // for the DCOP interface |
520 | public: | 520 | public: |
521 | void open (const QString &name=0); | 521 | void open (const QString &name=0); |
522 | 522 | ||
523 | public: | 523 | public: |
524 | // wrap the text of the document at the column col | 524 | // wrap the text of the document at the column col |
525 | void wrapText (uint col); | 525 | void wrapText (uint col); |
526 | 526 | ||
527 | public slots: | 527 | public slots: |
528 | void applyWordWrap (); | 528 | void applyWordWrap (); |
529 | 529 | ||
530 | private: | 530 | private: |
531 | 531 | ||
532 | class KateDocPrivate | 532 | class KateDocPrivate |
533 | { | 533 | { |
534 | public: | 534 | public: |
535 | bool hlSetByUser; | 535 | bool hlSetByUser; |
536 | }; | 536 | }; |
537 | 537 | ||
538 | 538 | ||
539 | // BCI: Add a real d-pointer in the next BIC release | 539 | // BCI: Add a real d-pointer in the next BIC release |
540 | static QPtrDict<KateDocPrivate>* d_ptr; | 540 | static QPtrDict<KateDocPrivate>* d_ptr; |
541 | static void cleanup_d_ptr() | 541 | static void cleanup_d_ptr() |
542 | { | 542 | { |
543 | delete d_ptr; | 543 | delete d_ptr; |
544 | } | 544 | } |
545 | 545 | ||
546 | KateDocPrivate* d( const KateDocument* foo ) | 546 | KateDocPrivate* d( const KateDocument* foo ) |
547 | { | 547 | { |
548 | if ( !d_ptr ) { | 548 | if ( !d_ptr ) { |
549 | d_ptr = new QPtrDict<KateDocPrivate>; | 549 | d_ptr = new QPtrDict<KateDocPrivate>; |
550 | //qAddPostRoutine( cleanup_d_ptr ); | 550 | //qAddPostRoutine( cleanup_d_ptr ); |
551 | } | 551 | } |
552 | KateDocPrivate* ret = d_ptr->find( (void*) foo ); | 552 | KateDocPrivate* ret = d_ptr->find( (void*) foo ); |
553 | if ( ! ret ) { | 553 | if ( ! ret ) { |
554 | ret = new KateDocPrivate; | 554 | ret = new KateDocPrivate; |
555 | d_ptr->replace( (void*) foo, ret ); | 555 | d_ptr->replace( (void*) foo, ret ); |
556 | } | 556 | } |
557 | return ret; | 557 | return ret; |
558 | } | 558 | } |
559 | 559 | ||
560 | void delete_d( const KateDocument* foo ) | 560 | void delete_d( const KateDocument* foo ) |
561 | { | 561 | { |
562 | if ( d_ptr ) | 562 | if ( d_ptr ) |
563 | d_ptr->remove( (void*) foo ); | 563 | d_ptr->remove( (void*) foo ); |
564 | } | 564 | } |
565 | 565 | ||
566 | }; | 566 | }; |
567 | 567 | ||
568 | #endif | 568 | #endif |
569 | 569 | ||
570 | 570 | ||
diff --git a/noncore/apps/tinykate/libkate/document/katehighlight.cpp b/noncore/apps/tinykate/libkate/document/katehighlight.cpp index 797968b..0d2c283 100644 --- a/noncore/apps/tinykate/libkate/document/katehighlight.cpp +++ b/noncore/apps/tinykate/libkate/document/katehighlight.cpp | |||
@@ -1,1459 +1,1459 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (C) 1998, 1999 Jochen Wilhelmy | 2 | Copyright (C) 1998, 1999 Jochen Wilhelmy |
3 | digisnap@cs.tu-berlin.de | 3 | digisnap@cs.tu-berlin.de |
4 | (C) 2002, 2001 The Kate Team <kwrite-devel@kde.org> | 4 | (C) 2002, 2001 The Kate Team <kwrite-devel@kde.org> |
5 | (C) 2002 Joseph Wenninger <jowenn@kde.org> | 5 | (C) 2002 Joseph Wenninger <jowenn@kde.org> |
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <string.h> | 22 | #include <string.h> |
23 | 23 | ||
24 | #include <qtextstream.h> | 24 | #include <qtextstream.h> |
25 | #include <qpe/config.h> | 25 | #include <qpe/config.h> |
26 | #include <kglobal.h> | 26 | #include <kglobal.h> |
27 | //#include <kinstance.h> | 27 | //#include <kinstance.h> |
28 | //#include <kmimemagic.h> | 28 | //#include <kmimemagic.h> |
29 | #include <klocale.h> | 29 | #include <klocale.h> |
30 | //#include <kregexp.h> | 30 | //#include <kregexp.h> |
31 | #include <kglobalsettings.h> | 31 | #include <kglobalsettings.h> |
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | #include <kstddirs.h> | 33 | #include <kstddirs.h> |
34 | 34 | ||
35 | #include "katehighlight.h" | 35 | #include "katehighlight.h" |
36 | 36 | ||
37 | 37 | ||
38 | #include "katetextline.h" | 38 | #include "katetextline.h" |
39 | #include "katedocument.h" | 39 | #include "katedocument.h" |
40 | #include "katesyntaxdocument.h" | 40 | #include "katesyntaxdocument.h" |
41 | 41 | ||
42 | 42 | ||
43 | HlManager *HlManager::s_pSelf = 0; | 43 | HlManager *HlManager::s_pSelf = 0; |
44 | 44 | ||
45 | enum Item_styles { dsNormal,dsKeyword,dsDataType,dsDecVal,dsBaseN,dsFloat,dsChar,dsString,dsComment,dsOthers}; | 45 | enum Item_styles { dsNormal,dsKeyword,dsDataType,dsDecVal,dsBaseN,dsFloat,dsChar,dsString,dsComment,dsOthers}; |
46 | 46 | ||
47 | static bool trueBool = true; | 47 | static bool trueBool = true; |
48 | static QString stdDeliminator = QString ("!%&()*+,-./:;<=>?[]^{|}~ \t\\"); | 48 | static QString stdDeliminator = QString ("!%&()*+,-./:;<=>?[]^{|}~ \t\\"); |
49 | 49 | ||
50 | int getDefStyleNum(QString name) | 50 | int getDefStyleNum(QString name) |
51 | { | 51 | { |
52 | if (name=="dsNormal") return dsNormal; | 52 | if (name=="dsNormal") return dsNormal; |
53 | if (name=="dsKeyword") return dsKeyword; | 53 | if (name=="dsKeyword") return dsKeyword; |
54 | if (name=="dsDataType") return dsDataType; | 54 | if (name=="dsDataType") return dsDataType; |
55 | if (name=="dsDecVal") return dsDecVal; | 55 | if (name=="dsDecVal") return dsDecVal; |
56 | if (name=="dsBaseN") return dsBaseN; | 56 | if (name=="dsBaseN") return dsBaseN; |
57 | if (name=="dsFloat") return dsFloat; | 57 | if (name=="dsFloat") return dsFloat; |
58 | if (name=="dsChar") return dsChar; | 58 | if (name=="dsChar") return dsChar; |
59 | if (name=="dsString") return dsString; | 59 | if (name=="dsString") return dsString; |
60 | if (name=="dsComment") return dsComment; | 60 | if (name=="dsComment") return dsComment; |
61 | if (name=="dsOthers") return dsOthers; | 61 | if (name=="dsOthers") return dsOthers; |
62 | 62 | ||
63 | return dsNormal; | 63 | return dsNormal; |
64 | } | 64 | } |
65 | 65 | ||
66 | bool ustrchr(const QChar *s, uint len, QChar c) | 66 | bool ustrchr(const QChar *s, uint len, QChar c) |
67 | { | 67 | { |
68 | for (int z=0; z < len; z++) | 68 | for (int z=0; z < len; z++) |
69 | { | 69 | { |
70 | if (*s == c) return true; | 70 | if (*s == c) return true; |
71 | s++; | 71 | s++; |
72 | } | 72 | } |
73 | 73 | ||
74 | return false; | 74 | return false; |
75 | } | 75 | } |
76 | 76 | ||
77 | HlItem::HlItem(int attribute, int context) | 77 | HlItem::HlItem(int attribute, int context) |
78 | : attr(attribute), ctx(context) {subItems=0; | 78 | : attr(attribute), ctx(context) {subItems=0; |
79 | } | 79 | } |
80 | 80 | ||
81 | HlItem::~HlItem() | 81 | HlItem::~HlItem() |
82 | { | 82 | { |
83 | //kdDebug(13010)<<"In hlItem::~HlItem()"<<endl; | 83 | //kdDebug(13010)<<"In hlItem::~HlItem()"<<endl; |
84 | if (subItems!=0) {subItems->setAutoDelete(true); subItems->clear(); delete subItems;} | 84 | if (subItems!=0) {subItems->setAutoDelete(true); subItems->clear(); delete subItems;} |
85 | } | 85 | } |
86 | 86 | ||
87 | bool HlItem::startEnable(QChar c) | 87 | bool HlItem::startEnable(QChar c) |
88 | { | 88 | { |
89 | return true; | 89 | return true; |
90 | } | 90 | } |
91 | 91 | ||
92 | HlCharDetect::HlCharDetect(int attribute, int context, QChar c) | 92 | HlCharDetect::HlCharDetect(int attribute, int context, QChar c) |
93 | : HlItem(attribute,context), sChar(c) { | 93 | : HlItem(attribute,context), sChar(c) { |
94 | } | 94 | } |
95 | 95 | ||
96 | const QChar *HlCharDetect::checkHgl(const QChar *str, int len, bool) { | 96 | const QChar *HlCharDetect::checkHgl(const QChar *str, int len, bool) { |
97 | if (*str == sChar) return str + 1; | 97 | if (*str == sChar) return str + 1; |
98 | return 0L; | 98 | return 0L; |
99 | } | 99 | } |
100 | 100 | ||
101 | Hl2CharDetect::Hl2CharDetect(int attribute, int context, QChar ch1, QChar ch2) | 101 | Hl2CharDetect::Hl2CharDetect(int attribute, int context, QChar ch1, QChar ch2) |
102 | : HlItem(attribute,context) { | 102 | : HlItem(attribute,context) { |
103 | sChar1 = ch1; | 103 | sChar1 = ch1; |
104 | sChar2 = ch2; | 104 | sChar2 = ch2; |
105 | } | 105 | } |
106 | 106 | ||
107 | const QChar *Hl2CharDetect::checkHgl(const QChar *str, int len, bool) { | 107 | const QChar *Hl2CharDetect::checkHgl(const QChar *str, int len, bool) { |
108 | if (str[0] == sChar1 && str[1] == sChar2) return str + 2; | 108 | if (str[0] == sChar1 && str[1] == sChar2) return str + 2; |
109 | return 0L; | 109 | return 0L; |
110 | } | 110 | } |
111 | 111 | ||
112 | HlStringDetect::HlStringDetect(int attribute, int context, const QString &s, bool inSensitive) | 112 | HlStringDetect::HlStringDetect(int attribute, int context, const QString &s, bool inSensitive) |
113 | : HlItem(attribute, context), str(inSensitive ? s.upper():s), _inSensitive(inSensitive) { | 113 | : HlItem(attribute, context), str(inSensitive ? s.upper():s), _inSensitive(inSensitive) { |
114 | } | 114 | } |
115 | 115 | ||
116 | HlStringDetect::~HlStringDetect() { | 116 | HlStringDetect::~HlStringDetect() { |
117 | } | 117 | } |
118 | 118 | ||
119 | const QChar *HlStringDetect::checkHgl(const QChar *s, int len, bool) { | 119 | const QChar *HlStringDetect::checkHgl(const QChar *s, int len, bool) { |
120 | if (!_inSensitive) {if (memcmp(s, str.unicode(), str.length()*sizeof(QChar)) == 0) return s + str.length();} | 120 | if (!_inSensitive) {if (memcmp(s, str.unicode(), str.length()*sizeof(QChar)) == 0) return s + str.length();} |
121 | else | 121 | else |
122 | { | 122 | { |
123 | QString tmp=QString(s,str.length()).upper(); | 123 | QString tmp=QString(s,str.length()).upper(); |
124 | if (tmp==str) return s+str.length(); | 124 | if (tmp==str) return s+str.length(); |
125 | } | 125 | } |
126 | return 0L; | 126 | return 0L; |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | HlRangeDetect::HlRangeDetect(int attribute, int context, QChar ch1, QChar ch2) | 130 | HlRangeDetect::HlRangeDetect(int attribute, int context, QChar ch1, QChar ch2) |
131 | : HlItem(attribute,context) { | 131 | : HlItem(attribute,context) { |
132 | sChar1 = ch1; | 132 | sChar1 = ch1; |
133 | sChar2 = ch2; | 133 | sChar2 = ch2; |
134 | } | 134 | } |
135 | 135 | ||
136 | const QChar *HlRangeDetect::checkHgl(const QChar *s, int len, bool) { | 136 | const QChar *HlRangeDetect::checkHgl(const QChar *s, int len, bool) { |
137 | if (*s == sChar1) | 137 | if (*s == sChar1) |
138 | { | 138 | { |
139 | do | 139 | do |
140 | { | 140 | { |
141 | s++; | 141 | s++; |
142 | len--; | 142 | len--; |
143 | if (len == 0) return 0L; | 143 | if (len == 0) return 0L; |
144 | } | 144 | } |
145 | while (*s != sChar2); | 145 | while (*s != sChar2); |
146 | 146 | ||
147 | return s + 1; | 147 | return s + 1; |
148 | } | 148 | } |
149 | return 0L; | 149 | return 0L; |
150 | } | 150 | } |
151 | 151 | ||
152 | HlKeyword::HlKeyword (int attribute, int context,bool casesensitive, const QChar *deliminator, uint deliLen) | 152 | HlKeyword::HlKeyword (int attribute, int context,bool casesensitive, const QChar *deliminator, uint deliLen) |
153 | : HlItem(attribute,context), dict (113, casesensitive) | 153 | : HlItem(attribute,context), dict (113, casesensitive) |
154 | { | 154 | { |
155 | deliminatorChars = deliminator; | 155 | deliminatorChars = deliminator; |
156 | deliminatorLen = deliLen; | 156 | deliminatorLen = deliLen; |
157 | _caseSensitive=casesensitive; | 157 | _caseSensitive=casesensitive; |
158 | } | 158 | } |
159 | 159 | ||
160 | HlKeyword::~HlKeyword() { | 160 | HlKeyword::~HlKeyword() { |
161 | } | 161 | } |
162 | 162 | ||
163 | bool HlKeyword::startEnable(QChar c) | 163 | bool HlKeyword::startEnable(QChar c) |
164 | { | 164 | { |
165 | return ustrchr(deliminatorChars, deliminatorLen, c); | 165 | return ustrchr(deliminatorChars, deliminatorLen, c); |
166 | } | 166 | } |
167 | 167 | ||
168 | // If we use a dictionary for lookup we don't really need | 168 | // If we use a dictionary for lookup we don't really need |
169 | // an item as such we are using the key to lookup | 169 | // an item as such we are using the key to lookup |
170 | void HlKeyword::addWord(const QString &word) | 170 | void HlKeyword::addWord(const QString &word) |
171 | { | 171 | { |
172 | words.append(word); | 172 | words.append(word); |
173 | dict.insert(word,&trueBool); | 173 | dict.insert(word,&trueBool); |
174 | } | 174 | } |
175 | 175 | ||
176 | void HlKeyword::addList(const QStringList& list) | 176 | void HlKeyword::addList(const QStringList& list) |
177 | { | 177 | { |
178 | 178 | ||
179 | words+=list; | 179 | words+=list; |
180 | for(uint i=0;i<list.count();i++) dict.insert(list[i], &trueBool); | 180 | for(uint i=0;i<list.count();i++) dict.insert(list[i], &trueBool); |
181 | } | 181 | } |
182 | 182 | ||
183 | const QChar *HlKeyword::checkHgl(const QChar *s, int len, bool b) | 183 | const QChar *HlKeyword::checkHgl(const QChar *s, int len, bool b) |
184 | { | 184 | { |
185 | if (len == 0) return 0L; | 185 | if (len == 0) return 0L; |
186 | 186 | ||
187 | const QChar *s2 = s; | 187 | const QChar *s2 = s; |
188 | 188 | ||
189 | while ( (len > 0) && (!ustrchr(deliminatorChars, deliminatorLen, *s2)) ) | 189 | while ( (len > 0) && (!ustrchr(deliminatorChars, deliminatorLen, *s2)) ) |
190 | { | 190 | { |
191 | s2++; | 191 | s2++; |
192 | len--; | 192 | len--; |
193 | } | 193 | } |
194 | 194 | ||
195 | if (s2 == s) return 0L; | 195 | if (s2 == s) return 0L; |
196 | 196 | ||
197 | QString lookup = QString(s,s2-s); | 197 | QString lookup = QString(s,s2-s); |
198 | 198 | ||
199 | if ( dict.find(lookup) ) return s2; | 199 | if ( dict.find(lookup) ) return s2; |
200 | return 0L; | 200 | return 0L; |
201 | } | 201 | } |
202 | 202 | ||
203 | HlInt::HlInt(int attribute, int context) | 203 | HlInt::HlInt(int attribute, int context) |
204 | : HlItem(attribute,context) { | 204 | : HlItem(attribute,context) { |
205 | } | 205 | } |
206 | 206 | ||
207 | const QChar *HlInt::checkHgl(const QChar *str, int len, bool) { | 207 | const QChar *HlInt::checkHgl(const QChar *str, int len, bool) { |
208 | const QChar *s,*s1; | 208 | const QChar *s,*s1; |
209 | 209 | ||
210 | s = str; | 210 | s = str; |
211 | while (s->isDigit()) s++; | 211 | while (s->isDigit()) s++; |
212 | if (s > str) | 212 | if (s > str) |
213 | { | 213 | { |
214 | if (subItems) | 214 | if (subItems) |
215 | { | 215 | { |
216 | for (HlItem *it=subItems->first();it;it=subItems->next()) | 216 | for (HlItem *it=subItems->first();it;it=subItems->next()) |
217 | { | 217 | { |
218 | s1=it->checkHgl(s, len, false); | 218 | s1=it->checkHgl(s, len, false); |
219 | if (s1) return s1; | 219 | if (s1) return s1; |
220 | } | 220 | } |
221 | } | 221 | } |
222 | return s; | 222 | return s; |
223 | } | 223 | } |
224 | return 0L; | 224 | return 0L; |
225 | } | 225 | } |
226 | 226 | ||
227 | HlFloat::HlFloat(int attribute, int context) | 227 | HlFloat::HlFloat(int attribute, int context) |
228 | : HlItem(attribute,context) { | 228 | : HlItem(attribute,context) { |
229 | } | 229 | } |
230 | 230 | ||
231 | const QChar *HlFloat::checkHgl(const QChar *s, int len, bool) { | 231 | const QChar *HlFloat::checkHgl(const QChar *s, int len, bool) { |
232 | bool b, p; | 232 | bool b, p; |
233 | const QChar *s1; | 233 | const QChar *s1; |
234 | 234 | ||
235 | b = false; | 235 | b = false; |
236 | while (s->isDigit()){ | 236 | while (s->isDigit()){ |
237 | s++; | 237 | s++; |
238 | b = true; | 238 | b = true; |
239 | } | 239 | } |
240 | if (p = (*s == '.')) { | 240 | if (p = (*s == '.')) { |
241 | s++; | 241 | s++; |
242 | while (s->isDigit()) { | 242 | while (s->isDigit()) { |
243 | s++; | 243 | s++; |
244 | b = true; | 244 | b = true; |
245 | } | 245 | } |
246 | } | 246 | } |
247 | if (!b) return 0L; | 247 | if (!b) return 0L; |
248 | if ((*s&0xdf) == 'E') s++; | 248 | if ((*s&0xdf) == 'E') s++; |
249 | else | 249 | else |
250 | if (!p) return 0L; | 250 | if (!p) return 0L; |
251 | else | 251 | else |
252 | { | 252 | { |
253 | if (subItems) | 253 | if (subItems) |
254 | { | 254 | { |
255 | for (HlItem *it=subItems->first();it;it=subItems->next()) | 255 | for (HlItem *it=subItems->first();it;it=subItems->next()) |
256 | { | 256 | { |
257 | s1=it->checkHgl(s, len, false); | 257 | s1=it->checkHgl(s, len, false); |
258 | if (s1) return s1; | 258 | if (s1) return s1; |
259 | } | 259 | } |
260 | } | 260 | } |
261 | return s; | 261 | return s; |
262 | } | 262 | } |
263 | if ((*s == '-')||(*s =='+')) s++; | 263 | if ((*s == '-')||(*s =='+')) s++; |
264 | b = false; | 264 | b = false; |
265 | while (s->isDigit()) { | 265 | while (s->isDigit()) { |
266 | s++; | 266 | s++; |
267 | b = true; | 267 | b = true; |
268 | } | 268 | } |
269 | if (b) | 269 | if (b) |
270 | { | 270 | { |
271 | if (subItems) | 271 | if (subItems) |
272 | { | 272 | { |
273 | for (HlItem *it=subItems->first();it;it=subItems->next()) | 273 | for (HlItem *it=subItems->first();it;it=subItems->next()) |
274 | { | 274 | { |
275 | s1=it->checkHgl(s, len, false); | 275 | s1=it->checkHgl(s, len, false); |
276 | if (s1) return s1; | 276 | if (s1) return s1; |
277 | } | 277 | } |
278 | } | 278 | } |
279 | return s; | 279 | return s; |
280 | } | 280 | } |
281 | else return 0L; | 281 | else return 0L; |
282 | } | 282 | } |
283 | 283 | ||
284 | 284 | ||
285 | HlCInt::HlCInt(int attribute, int context) | 285 | HlCInt::HlCInt(int attribute, int context) |
286 | : HlInt(attribute,context) { | 286 | : HlInt(attribute,context) { |
287 | } | 287 | } |
288 | 288 | ||
289 | const QChar *HlCInt::checkHgl(const QChar *s, int len, bool lineStart) { | 289 | const QChar *HlCInt::checkHgl(const QChar *s, int len, bool lineStart) { |
290 | 290 | ||
291 | // if (*s == '0') s++; else s = HlInt::checkHgl(s); | 291 | // if (*s == '0') s++; else s = HlInt::checkHgl(s); |
292 | s = HlInt::checkHgl(s, len, lineStart); | 292 | s = HlInt::checkHgl(s, len, lineStart); |
293 | if (s != 0L) { | 293 | if (s != 0L) { |
294 | int l = 0; | 294 | int l = 0; |
295 | int u = 0; | 295 | int u = 0; |
296 | const QChar *str; | 296 | const QChar *str; |
297 | 297 | ||
298 | do { | 298 | do { |
299 | str = s; | 299 | str = s; |
300 | if ((*s&0xdf) == 'L' ) { | 300 | if ((*s&0xdf) == 'L' ) { |
301 | l++; | 301 | l++; |
302 | if (l > 2) return 0L; | 302 | if (l > 2) return 0L; |
303 | s++; | 303 | s++; |
304 | } | 304 | } |
305 | if ((*s&0xdf) == 'U' ){ | 305 | if ((*s&0xdf) == 'U' ){ |
306 | u++; | 306 | u++; |
307 | if (u > 1) return 0L; | 307 | if (u > 1) return 0L; |
308 | s++; | 308 | s++; |
309 | } | 309 | } |
310 | } while (s != str); | 310 | } while (s != str); |
311 | } | 311 | } |
312 | return s; | 312 | return s; |
313 | } | 313 | } |
314 | 314 | ||
315 | HlCOct::HlCOct(int attribute, int context) | 315 | HlCOct::HlCOct(int attribute, int context) |
316 | : HlItem(attribute,context) { | 316 | : HlItem(attribute,context) { |
317 | } | 317 | } |
318 | 318 | ||
319 | const QChar *HlCOct::checkHgl(const QChar *str, int len, bool) { | 319 | const QChar *HlCOct::checkHgl(const QChar *str, int len, bool) { |
320 | const QChar *s; | 320 | const QChar *s; |
321 | 321 | ||
322 | if (*str == '0') { | 322 | if (*str == '0') { |
323 | str++; | 323 | str++; |
324 | s = str; | 324 | s = str; |
325 | while (*s >= '0' && *s <= '7') s++; | 325 | while (*s >= '0' && *s <= '7') s++; |
326 | if (s > str) { | 326 | if (s > str) { |
327 | if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++; | 327 | if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++; |
328 | return s; | 328 | return s; |
329 | } | 329 | } |
330 | } | 330 | } |
331 | return 0L; | 331 | return 0L; |
332 | } | 332 | } |
333 | 333 | ||
334 | HlCHex::HlCHex(int attribute, int context) | 334 | HlCHex::HlCHex(int attribute, int context) |
335 | : HlItem(attribute,context) { | 335 | : HlItem(attribute,context) { |
336 | } | 336 | } |
337 | 337 | ||
338 | const QChar *HlCHex::checkHgl(const QChar *str, int len, bool) { | 338 | const QChar *HlCHex::checkHgl(const QChar *str, int len, bool) { |
339 | const QChar *s=str; | 339 | const QChar *s=str; |
340 | #if 0 | 340 | #if 0 |
341 | int i; | 341 | int i; |
342 | for (i=0;(*s)!='\0';s++,i++); | 342 | for (i=0;(*s)!='\0';s++,i++); |
343 | QString line(str,i); | 343 | QString line(str,i); |
344 | QRegExp3 rx("0[xX][a-fA-F\\d]+[UuLl]?"); // this matches but is also matching parenthesis | 344 | QRegExp3 rx("0[xX][a-fA-F\\d]+[UuLl]?"); // this matches but is also matching parenthesis |
345 | int pos=rx.search(line,0); | 345 | int pos=rx.search(line,0); |
346 | if(pos > -1) return str+rx.matchedLength(); | 346 | if(pos > -1) return str+rx.matchedLength(); |
347 | else | 347 | else |
348 | return 0L; | 348 | return 0L; |
349 | 349 | ||
350 | #else | 350 | #else |
351 | if (str[0] == '0' && ((str[1]&0xdf) == 'X' )) { | 351 | if (str[0] == '0' && ((str[1]&0xdf) == 'X' )) { |
352 | str += 2; | 352 | str += 2; |
353 | s = str; | 353 | s = str; |
354 | while (s->isDigit() || ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') /*|| (*s >= 'a' && *s <= 'f')*/) s++; | 354 | while (s->isDigit() || ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') /*|| (*s >= 'a' && *s <= 'f')*/) s++; |
355 | if (s > str) { | 355 | if (s > str) { |
356 | if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++; | 356 | if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++; |
357 | return s; | 357 | return s; |
358 | } | 358 | } |
359 | } | 359 | } |
360 | return 0L; | 360 | return 0L; |
361 | #endif | 361 | #endif |
362 | } | 362 | } |
363 | 363 | ||
364 | HlCFloat::HlCFloat(int attribute, int context) | 364 | HlCFloat::HlCFloat(int attribute, int context) |
365 | : HlFloat(attribute,context) { | 365 | : HlFloat(attribute,context) { |
366 | } | 366 | } |
367 | 367 | ||
368 | const QChar *HlCFloat::checkHgl(const QChar *s, int len, bool lineStart) { | 368 | const QChar *HlCFloat::checkHgl(const QChar *s, int len, bool lineStart) { |
369 | 369 | ||
370 | s = HlFloat::checkHgl(s, len, lineStart); | 370 | s = HlFloat::checkHgl(s, len, lineStart); |
371 | if (s && ((*s&0xdf) == 'F' )) s++; | 371 | if (s && ((*s&0xdf) == 'F' )) s++; |
372 | return s; | 372 | return s; |
373 | } | 373 | } |
374 | 374 | ||
375 | HlAnyChar::HlAnyChar(int attribute, int context, const QChar* charList, uint len) | 375 | HlAnyChar::HlAnyChar(int attribute, int context, const QChar* charList, uint len) |
376 | : HlItem(attribute, context) { | 376 | : HlItem(attribute, context) { |
377 | _charList=charList; | 377 | _charList=charList; |
378 | _charListLen=len; | 378 | _charListLen=len; |
379 | } | 379 | } |
380 | 380 | ||
381 | const QChar *HlAnyChar::checkHgl(const QChar *s, int len, bool) | 381 | const QChar *HlAnyChar::checkHgl(const QChar *s, int len, bool) |
382 | { | 382 | { |
383 | if (ustrchr(_charList, _charListLen, *s)) return s +1; | 383 | if (ustrchr(_charList, _charListLen, *s)) return s +1; |
384 | return 0L; | 384 | return 0L; |
385 | } | 385 | } |
386 | 386 | ||
387 | HlRegExpr::HlRegExpr(int attribute, int context,QString regexp) | 387 | HlRegExpr::HlRegExpr(int attribute, int context,QString regexp) |
388 | : HlItem(attribute, context) { | 388 | : HlItem(attribute, context) { |
389 | 389 | ||
390 | handlesLinestart=regexp.startsWith("^"); | 390 | handlesLinestart=regexp.startsWith("^"); |
391 | if(!handlesLinestart) regexp.prepend("^"); | 391 | if(!handlesLinestart) regexp.prepend("^"); |
392 | Expr=new QRegExp3(regexp); | 392 | Expr=new QRegExp3(regexp); |
393 | } | 393 | } |
394 | 394 | ||
395 | const QChar *HlRegExpr::checkHgl(const QChar *s, int len, bool lineStart) | 395 | const QChar *HlRegExpr::checkHgl(const QChar *s, int len, bool lineStart) |
396 | { | 396 | { |
397 | if ((!lineStart) && handlesLinestart) return 0; | 397 | if ((!lineStart) && handlesLinestart) return 0; |
398 | 398 | ||
399 | QString line(s,len); | 399 | QString line(s,len); |
400 | int pos = Expr->search( line, 0 ); | 400 | int pos = Expr->search( line, 0 ); |
401 | if (pos==-1) return 0L; | 401 | if (pos==-1) return 0L; |
402 | else | 402 | else |
403 | return (s+Expr->matchedLength()); | 403 | return (s+Expr->matchedLength()); |
404 | }; | 404 | }; |
405 | 405 | ||
406 | 406 | ||
407 | HlLineContinue::HlLineContinue(int attribute, int context) | 407 | HlLineContinue::HlLineContinue(int attribute, int context) |
408 | : HlItem(attribute,context) { | 408 | : HlItem(attribute,context) { |
409 | } | 409 | } |
410 | 410 | ||
411 | const QChar *HlLineContinue::checkHgl(const QChar *s, int len, bool) { | 411 | const QChar *HlLineContinue::checkHgl(const QChar *s, int len, bool) { |
412 | 412 | ||
413 | if ((s[0].latin1() == '\\') && (len == 1)) | 413 | if ((s[0].latin1() == '\\') && (len == 1)) |
414 | { | 414 | { |
415 | return s + 1; | 415 | return s + 1; |
416 | } | 416 | } |
417 | return 0L; | 417 | return 0L; |
418 | } | 418 | } |
419 | 419 | ||
420 | 420 | ||
421 | HlCStringChar::HlCStringChar(int attribute, int context) | 421 | HlCStringChar::HlCStringChar(int attribute, int context) |
422 | : HlItem(attribute,context) { | 422 | : HlItem(attribute,context) { |
423 | } | 423 | } |
424 | 424 | ||
425 | //checks for hex and oct (for example \x1b or \033) | 425 | //checks for hex and oct (for example \x1b or \033) |
426 | const QChar *checkCharHexOct(const QChar *str) { | 426 | const QChar *checkCharHexOct(const QChar *str) { |
427 | const QChar *s; | 427 | const QChar *s; |
428 | s=str; | 428 | s=str; |
429 | int n; | 429 | int n; |
430 | if (*s == 'x') { | 430 | if (*s == 'x') { |
431 | n = 0; | 431 | n = 0; |
432 | do { | 432 | do { |
433 | s++; | 433 | s++; |
434 | n *= 16; | 434 | n *= 16; |
435 | if (s->isDigit()) n += *s - '0'; | 435 | if (s->isDigit()) n += *s - '0'; |
436 | else if ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') n += (*s&0xdf) - 'A' + 10; | 436 | else if ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') n += (*s&0xdf) - 'A' + 10; |
437 | // else if (*s >= 'a' && *s <= 'f') n += *s - 'a' + 10; | 437 | // else if (*s >= 'a' && *s <= 'f') n += *s - 'a' + 10; |
438 | else break; | 438 | else break; |
439 | if (n >= 256) return 0L; | 439 | if (n >= 256) return 0L; |
440 | } while (true); | 440 | } while (true); |
441 | if (s - str == 1) return 0L; | 441 | if (s - str == 1) return 0L; |
442 | } else { | 442 | } else { |
443 | if (!(*s >= '0' && *s <= '7')) return 0L; | 443 | if (!(*s >= '0' && *s <= '7')) return 0L; |
444 | n = *s - '0'; | 444 | n = *s - '0'; |
445 | do { | 445 | do { |
446 | s++; | 446 | s++; |
447 | n *= 8; | 447 | n *= 8; |
448 | if (*s >= '0' && *s <= '7') n += *s - '0'; else break; | 448 | if (*s >= '0' && *s <= '7') n += *s - '0'; else break; |
449 | if (n >= 256) return s; | 449 | if (n >= 256) return s; |
450 | } while (s - str < 3); | 450 | } while (s - str < 3); |
451 | } | 451 | } |
452 | return s; | 452 | return s; |
453 | } | 453 | } |
454 | // checks for C escaped chars \n and escaped hex/octal chars | 454 | // checks for C escaped chars \n and escaped hex/octal chars |
455 | const QChar *checkEscapedChar(const QChar *s, int len) { | 455 | const QChar *checkEscapedChar(const QChar *s, int len) { |
456 | int i; | 456 | int i; |
457 | if (s[0] == '\\' && (len > 1) ) { | 457 | if (s[0] == '\\' && (len > 1) ) { |
458 | s++; | 458 | s++; |
459 | switch(*s){ | 459 | switch(*s){ |
460 | case 'a': // checks for control chars | 460 | case 'a': // checks for control chars |
461 | case 'b': // we want to fall through | 461 | case 'b': // we want to fall through |
462 | case 'e': | 462 | case 'e': |
463 | case 'f': | 463 | case 'f': |
464 | 464 | ||
465 | case 'n': | 465 | case 'n': |
466 | case 'r': | 466 | case 'r': |
467 | case 't': | 467 | case 't': |
468 | case 'v': | 468 | case 'v': |
469 | case '\'': | 469 | case '\'': |
470 | case '\"': | 470 | case '\"': |
471 | case '?' : // added ? ANSI C classifies this as an escaped char | 471 | case '?' : // added ? ANSI C classifies this as an escaped char |
472 | case '\\': s++; | 472 | case '\\': s++; |
473 | break; | 473 | break; |
474 | case 'x': // if it's like \xff | 474 | case 'x': // if it's like \xff |
475 | s++; // eat the x | 475 | s++; // eat the x |
476 | // these for loops can probably be | 476 | // these for loops can probably be |
477 | // replaced with something else but | 477 | // replaced with something else but |
478 | // for right now they work | 478 | // for right now they work |
479 | // check for hexdigits | 479 | // check for hexdigits |
480 | for(i=0;i<2 &&(*s >= '0' && *s <= '9' || (*s&0xdf) >= 'A' && (*s&0xdf) <= 'F');i++,s++); | 480 | for(i=0;i<2 &&(*s >= '0' && *s <= '9' || (*s&0xdf) >= 'A' && (*s&0xdf) <= 'F');i++,s++); |
481 | if(i==0) return 0L; // takes care of case '\x' | 481 | if(i==0) return 0L; // takes care of case '\x' |
482 | break; | 482 | break; |
483 | 483 | ||
484 | case '0': case '1': case '2': case '3' : | 484 | case '0': case '1': case '2': case '3' : |
485 | case '4': case '5': case '6': case '7' : | 485 | case '4': case '5': case '6': case '7' : |
486 | for(i=0;i < 3 &&(*s >='0'&& *s<='7');i++,s++); | 486 | for(i=0;i < 3 &&(*s >='0'&& *s<='7');i++,s++); |
487 | break; | 487 | break; |
488 | default: return 0L; | 488 | default: return 0L; |
489 | } | 489 | } |
490 | return s; | 490 | return s; |
491 | } | 491 | } |
492 | return 0L; | 492 | return 0L; |
493 | } | 493 | } |
494 | 494 | ||
495 | const QChar *HlCStringChar::checkHgl(const QChar *str, int len, bool) { | 495 | const QChar *HlCStringChar::checkHgl(const QChar *str, int len, bool) { |
496 | return checkEscapedChar(str, len); | 496 | return checkEscapedChar(str, len); |
497 | } | 497 | } |
498 | 498 | ||
499 | 499 | ||
500 | HlCChar::HlCChar(int attribute, int context) | 500 | HlCChar::HlCChar(int attribute, int context) |
501 | : HlItem(attribute,context) { | 501 | : HlItem(attribute,context) { |
502 | } | 502 | } |
503 | 503 | ||
504 | const QChar *HlCChar::checkHgl(const QChar *str, int len, bool) { | 504 | const QChar *HlCChar::checkHgl(const QChar *str, int len, bool) { |
505 | const QChar *s; | 505 | const QChar *s; |
506 | 506 | ||
507 | if ((len > 1) && (str[0] == '\'') && (str[1] != '\'')) | 507 | if ((len > 1) && (str[0] == '\'') && (str[1] != '\'')) |
508 | { | 508 | { |
509 | s = checkEscapedChar(&str[1], len); //try to match escaped char | 509 | s = checkEscapedChar(&str[1], len); //try to match escaped char |
510 | if (!s) s = &str[2]; //match single non-escaped char | 510 | if (!s) s = &str[2]; //match single non-escaped char |
511 | if (*s == '\'') return s + 1; | 511 | if (*s == '\'') return s + 1; |
512 | } | 512 | } |
513 | return 0L; | 513 | return 0L; |
514 | } | 514 | } |
515 | 515 | ||
516 | 516 | ||
517 | //-------- | 517 | //-------- |
518 | ItemStyle::ItemStyle() : selCol(Qt::white), bold(false), italic(false) { | 518 | ItemStyle::ItemStyle() : selCol(Qt::white), bold(false), italic(false) { |
519 | } | 519 | } |
520 | 520 | ||
521 | ItemStyle::ItemStyle(const QColor &col, const QColor &selCol, | 521 | ItemStyle::ItemStyle(const QColor &col, const QColor &selCol, |
522 | bool bold, bool italic) | 522 | bool bold, bool italic) |
523 | : col(col), selCol(selCol), bold(bold), italic(italic) { | 523 | : col(col), selCol(selCol), bold(bold), italic(italic) { |
524 | } | 524 | } |
525 | 525 | ||
526 | ItemData::ItemData(const QString name, int defStyleNum) | 526 | ItemData::ItemData(const QString name, int defStyleNum) |
527 | : name(name), defStyleNum(defStyleNum), defStyle(true) { | 527 | : name(name), defStyleNum(defStyleNum), defStyle(true) { |
528 | } | 528 | } |
529 | 529 | ||
530 | ItemData::ItemData(const QString name, int defStyleNum, | 530 | ItemData::ItemData(const QString name, int defStyleNum, |
531 | const QColor &col, const QColor &selCol, bool bold, bool italic) | 531 | const QColor &col, const QColor &selCol, bool bold, bool italic) |
532 | : ItemStyle(col,selCol,bold,italic), name(name), defStyleNum(defStyleNum), | 532 | : ItemStyle(col,selCol,bold,italic), name(name), defStyleNum(defStyleNum), |
533 | defStyle(false) { | 533 | defStyle(false) { |
534 | } | 534 | } |
535 | 535 | ||
536 | HlData::HlData(const QString &wildcards, const QString &mimetypes, const QString &identifier) | 536 | HlData::HlData(const QString &wildcards, const QString &mimetypes, const QString &identifier) |
537 | : wildcards(wildcards), mimetypes(mimetypes), identifier(identifier) { | 537 | : wildcards(wildcards), mimetypes(mimetypes), identifier(identifier) { |
538 | 538 | ||
539 | //JW itemDataList.setAutoDelete(true); | 539 | //JW itemDataList.setAutoDelete(true); |
540 | } | 540 | } |
541 | 541 | ||
542 | HlContext::HlContext(int attribute, int lineEndContext, int _lineBeginContext) | 542 | HlContext::HlContext(int attribute, int lineEndContext, int _lineBeginContext) |
543 | : attr(attribute), ctx(lineEndContext),lineBeginContext(_lineBeginContext) { | 543 | : attr(attribute), ctx(lineEndContext),lineBeginContext(_lineBeginContext) { |
544 | items.setAutoDelete(true); | 544 | items.setAutoDelete(true); |
545 | } | 545 | } |
546 | 546 | ||
547 | Hl2CharDetect::Hl2CharDetect(int attribute, int context, const QChar *s) | 547 | Hl2CharDetect::Hl2CharDetect(int attribute, int context, const QChar *s) |
548 | : HlItem(attribute,context) { | 548 | : HlItem(attribute,context) { |
549 | sChar1 = s[0]; | 549 | sChar1 = s[0]; |
550 | sChar2 = s[1]; | 550 | sChar2 = s[1]; |
551 | } | 551 | } |
552 | 552 | ||
553 | Highlight::Highlight(syntaxModeListItem *def) : refCount(0) | 553 | Highlight::Highlight(syntaxModeListItem *def) : refCount(0) |
554 | { | 554 | { |
555 | noHl = false; | 555 | noHl = false; |
556 | 556 | ||
557 | if (def == 0) | 557 | if (def == 0) |
558 | { | 558 | { |
559 | noHl = true; | 559 | noHl = true; |
560 | iName = I18N_NOOP("Normal"); | 560 | iName = I18N_NOOP("Normal"); |
561 | iSection = ""; | 561 | iSection = ""; |
562 | } | 562 | } |
563 | else | 563 | else |
564 | { | 564 | { |
565 | iName = def->name; | 565 | iName = def->name; |
566 | iSection = def->section; | 566 | iSection = def->section; |
567 | iWildcards = def->extension; | 567 | iWildcards = def->extension; |
568 | iMimetypes = def->mimetype; | 568 | iMimetypes = def->mimetype; |
569 | identifier = def->identifier; | 569 | identifier = def->identifier; |
570 | } | 570 | } |
571 | deliminator = stdDeliminator; | 571 | deliminator = stdDeliminator; |
572 | deliminatorChars = deliminator.unicode(); | 572 | deliminatorChars = deliminator.unicode(); |
573 | deliminatorLen = deliminator.length(); | 573 | deliminatorLen = deliminator.length(); |
574 | } | 574 | } |
575 | 575 | ||
576 | Highlight::~Highlight() | 576 | Highlight::~Highlight() |
577 | { | 577 | { |
578 | } | 578 | } |
579 | 579 | ||
580 | int Highlight::doHighlight(int ctxNum, TextLine *textLine) | 580 | int Highlight::doHighlight(int ctxNum, TextLine *textLine) |
581 | { | 581 | { |
582 | if (noHl) | 582 | if (noHl) |
583 | { | 583 | { |
584 | textLine->setAttribs(0,0,textLine->length()); | 584 | textLine->setAttribs(0,0,textLine->length()); |
585 | textLine->setAttr(0); | 585 | textLine->setAttr(0); |
586 | return 0; | 586 | return 0; |
587 | } | 587 | } |
588 | 588 | ||
589 | HlContext *context; | 589 | HlContext *context; |
590 | const QChar *s2; | 590 | const QChar *s2; |
591 | HlItem *item; | 591 | HlItem *item; |
592 | 592 | ||
593 | context = contextList[ctxNum]; | 593 | context = contextList[ctxNum]; |
594 | if (context->lineBeginContext!=-1) | 594 | if (context->lineBeginContext!=-1) |
595 | { | 595 | { |
596 | ctxNum=context->lineBeginContext; | 596 | ctxNum=context->lineBeginContext; |
597 | context=contextList[ctxNum]; | 597 | context=contextList[ctxNum]; |
598 | } | 598 | } |
599 | 599 | ||
600 | QChar lastChar = ' '; | 600 | QChar lastChar = ' '; |
601 | 601 | ||
602 | // first char | 602 | // first char |
603 | const QChar *str = textLine->getText(); | 603 | const QChar *str = textLine->getText(); |
604 | 604 | ||
605 | // non space char - index of that char | 605 | // non space char - index of that char |
606 | const QChar *s1 = textLine->firstNonSpace(); | 606 | const QChar *s1 = textLine->firstNonSpace(); |
607 | uint z = textLine->firstChar(); | 607 | uint z = textLine->firstChar(); |
608 | 608 | ||
609 | // length of textline | 609 | // length of textline |
610 | uint len = textLine->length(); | 610 | uint len = textLine->length(); |
611 | 611 | ||
612 | bool found = false; | 612 | bool found = false; |
613 | while (z < len) | 613 | while (z < len) |
614 | { | 614 | { |
615 | found = false; | 615 | found = false; |
616 | 616 | ||
617 | for (item = context->items.first(); item != 0L; item = context->items.next()) | 617 | for (item = context->items.first(); item != 0L; item = context->items.next()) |
618 | { | 618 | { |
619 | if (item->startEnable(lastChar)) | 619 | if (item->startEnable(lastChar)) |
620 | { | 620 | { |
621 | s2 = item->checkHgl(s1, len-z, z==0); | 621 | s2 = item->checkHgl(s1, len-z, z==0); |
622 | if (s2 > s1) | 622 | if (s2 > s1) |
623 | { | 623 | { |
624 | qDebug("An item has been detected"); | 624 | qDebug("An item has been detected"); |
625 | textLine->setAttribs(item->attr,s1 - str,s2 - str); | 625 | textLine->setAttribs(item->attr,s1 - str,s2 - str); |
626 | ctxNum = item->ctx; | 626 | ctxNum = item->ctx; |
627 | context = contextList[ctxNum]; | 627 | context = contextList[ctxNum]; |
628 | z = z + s2 - s1 - 1; | 628 | z = z + s2 - s1 - 1; |
629 | s1 = s2 - 1; | 629 | s1 = s2 - 1; |
630 | found = true; | 630 | found = true; |
631 | break; | 631 | break; |
632 | } | 632 | } |
633 | } | 633 | } |
634 | } | 634 | } |
635 | 635 | ||
636 | // nothing found: set attribute of one char | 636 | // nothing found: set attribute of one char |
637 | if (!found) | 637 | if (!found) |
638 | textLine->setAttribs(context->attr,s1 - str,s1 - str + 1); | 638 | textLine->setAttribs(context->attr,s1 - str,s1 - str + 1); |
639 | 639 | ||
640 | lastChar = *s1; | 640 | lastChar = *s1; |
641 | s1++; | 641 | s1++; |
642 | z++; | 642 | z++; |
643 | } | 643 | } |
644 | 644 | ||
645 | //set "end of line"-properties | 645 | //set "end of line"-properties |
646 | textLine->setAttr(context->attr); | 646 | textLine->setAttr(context->attr); |
647 | 647 | ||
648 | //return new context | 648 | //return new context |
649 | return context->ctx; | 649 | return context->ctx; |
650 | } | 650 | } |
651 | 651 | ||
652 | KConfig *Highlight::getKConfig() { | 652 | KateConfig *Highlight::getKateConfig() { |
653 | KConfig *config; | 653 | KateConfig *config; |
654 | config=KGlobal::config(); | 654 | config=KGlobal::config(); |
655 | config->setGroup(iName + QString(" Highlight")); | 655 | config->setGroup(iName + QString(" Highlight")); |
656 | return config; | 656 | return config; |
657 | } | 657 | } |
658 | 658 | ||
659 | QString Highlight::getWildcards() { | 659 | QString Highlight::getWildcards() { |
660 | KConfig *config; | 660 | KateConfig *config; |
661 | 661 | ||
662 | config = getKConfig(); | 662 | config = getKateConfig(); |
663 | 663 | ||
664 | //if wildcards not yet in config, then use iWildCards as default | 664 | //if wildcards not yet in config, then use iWildCards as default |
665 | return config->readEntry("Wildcards", iWildcards); | 665 | return config->readEntry("Wildcards", iWildcards); |
666 | } | 666 | } |
667 | 667 | ||
668 | 668 | ||
669 | QString Highlight::getMimetypes() { | 669 | QString Highlight::getMimetypes() { |
670 | KConfig *config; | 670 | KateConfig *config; |
671 | 671 | ||
672 | config = getKConfig(); | 672 | config = getKateConfig(); |
673 | 673 | ||
674 | return config->readEntry("Mimetypes", iMimetypes); | 674 | return config->readEntry("Mimetypes", iMimetypes); |
675 | } | 675 | } |
676 | 676 | ||
677 | 677 | ||
678 | HlData *Highlight::getData() { | 678 | HlData *Highlight::getData() { |
679 | KConfig *config; | 679 | KateConfig *config; |
680 | HlData *hlData; | 680 | HlData *hlData; |
681 | 681 | ||
682 | config = getKConfig(); | 682 | config = getKateConfig(); |
683 | 683 | ||
684 | // iWildcards = config->readEntry("Wildcards"); | 684 | // iWildcards = config->readEntry("Wildcards"); |
685 | // iMimetypes = config->readEntry("Mimetypes"); | 685 | // iMimetypes = config->readEntry("Mimetypes"); |
686 | // hlData = new HlData(iWildcards,iMimetypes); | 686 | // hlData = new HlData(iWildcards,iMimetypes); |
687 | hlData = new HlData( | 687 | hlData = new HlData( |
688 | config->readEntry("Wildcards", iWildcards), | 688 | config->readEntry("Wildcards", iWildcards), |
689 | config->readEntry("Mimetypes", iMimetypes), | 689 | config->readEntry("Mimetypes", iMimetypes), |
690 | config->readEntry("Identifier", identifier)); | 690 | config->readEntry("Identifier", identifier)); |
691 | getItemDataList(hlData->itemDataList, config); | 691 | getItemDataList(hlData->itemDataList, config); |
692 | return hlData; | 692 | return hlData; |
693 | } | 693 | } |
694 | 694 | ||
695 | void Highlight::setData(HlData *hlData) { | 695 | void Highlight::setData(HlData *hlData) { |
696 | KConfig *config; | 696 | KateConfig *config; |
697 | 697 | ||
698 | config = getKConfig(); | 698 | config = getKateConfig(); |
699 | 699 | ||
700 | // iWildcards = hlData->wildcards; | 700 | // iWildcards = hlData->wildcards; |
701 | // iMimetypes = hlData->mimetypes; | 701 | // iMimetypes = hlData->mimetypes; |
702 | 702 | ||
703 | config->writeEntry("Wildcards",hlData->wildcards); | 703 | config->writeEntry("Wildcards",hlData->wildcards); |
704 | config->writeEntry("Mimetypes",hlData->mimetypes); | 704 | config->writeEntry("Mimetypes",hlData->mimetypes); |
705 | 705 | ||
706 | setItemDataList(hlData->itemDataList,config); | 706 | setItemDataList(hlData->itemDataList,config); |
707 | } | 707 | } |
708 | 708 | ||
709 | void Highlight::getItemDataList(ItemDataList &list) { | 709 | void Highlight::getItemDataList(ItemDataList &list) { |
710 | KConfig *config; | 710 | KateConfig *config; |
711 | 711 | ||
712 | config = getKConfig(); | 712 | config = getKateConfig(); |
713 | getItemDataList(list, config); | 713 | getItemDataList(list, config); |
714 | } | 714 | } |
715 | 715 | ||
716 | void Highlight::getItemDataList(ItemDataList &list, KConfig *config) { | 716 | void Highlight::getItemDataList(ItemDataList &list, KateConfig *config) { |
717 | ItemData *p; | 717 | ItemData *p; |
718 | QString s; | 718 | QString s; |
719 | QRgb col, selCol; | 719 | QRgb col, selCol; |
720 | 720 | ||
721 | list.clear(); | 721 | list.clear(); |
722 | //JW list.setAutoDelete(true); | 722 | //JW list.setAutoDelete(true); |
723 | createItemData(list); | 723 | createItemData(list); |
724 | 724 | ||
725 | for (p = list.first(); p != 0L; p = list.next()) { | 725 | for (p = list.first(); p != 0L; p = list.next()) { |
726 | s = config->readEntry(p->name); | 726 | s = config->readEntry(p->name); |
727 | if (!s.isEmpty()) { | 727 | if (!s.isEmpty()) { |
728 | sscanf(s.latin1(),"%d,%X,%X,%d,%d", &p->defStyle,&col,&selCol,&p->bold,&p->italic); | 728 | sscanf(s.latin1(),"%d,%X,%X,%d,%d", &p->defStyle,&col,&selCol,&p->bold,&p->italic); |
729 | p->col.setRgb(col); | 729 | p->col.setRgb(col); |
730 | p->selCol.setRgb(selCol); | 730 | p->selCol.setRgb(selCol); |
731 | } | 731 | } |
732 | } | 732 | } |
733 | } | 733 | } |
734 | 734 | ||
735 | /******************************************************************************************* | 735 | /******************************************************************************************* |
736 | Highlight - setItemDataList | 736 | Highlight - setItemDataList |
737 | saves the ItemData / attribute / style definitions to the apps configfile. | 737 | saves the ItemData / attribute / style definitions to the apps configfile. |
738 | Especially needed for user overridden values. | 738 | Especially needed for user overridden values. |
739 | 739 | ||
740 | * input: ItemDataList &list :reference to the list, whose | 740 | * input: ItemDataList &list :reference to the list, whose |
741 | * items should be saved | 741 | * items should be saved |
742 | * KConfig *config :Pointer KDE configuration | 742 | * KateConfig *config :Pointer KDE configuration |
743 | * class, which should be used | 743 | * class, which should be used |
744 | * as storage | 744 | * as storage |
745 | ************* | 745 | ************* |
746 | * output: none | 746 | * output: none |
747 | ************* | 747 | ************* |
748 | * return value: none | 748 | * return value: none |
749 | *******************************************************************************************/ | 749 | *******************************************************************************************/ |
750 | 750 | ||
751 | void Highlight::setItemDataList(ItemDataList &list, KConfig *config) { | 751 | void Highlight::setItemDataList(ItemDataList &list, KateConfig *config) { |
752 | ItemData *p; | 752 | ItemData *p; |
753 | QString s; | 753 | QString s; |
754 | 754 | ||
755 | for (p = list.first(); p != 0L; p = list.next()) { | 755 | for (p = list.first(); p != 0L; p = list.next()) { |
756 | s.sprintf("%d,%X,%X,%d,%d", | 756 | s.sprintf("%d,%X,%X,%d,%d", |
757 | p->defStyle,p->col.rgb(),p->selCol.rgb(),p->bold,p->italic); | 757 | p->defStyle,p->col.rgb(),p->selCol.rgb(),p->bold,p->italic); |
758 | config->writeEntry(p->name,s); | 758 | config->writeEntry(p->name,s); |
759 | } | 759 | } |
760 | } | 760 | } |
761 | 761 | ||
762 | 762 | ||
763 | /******************************************************************************************* | 763 | /******************************************************************************************* |
764 | Highlight - use | 764 | Highlight - use |
765 | Increase the usage count and trigger initialization if needed | 765 | Increase the usage count and trigger initialization if needed |
766 | 766 | ||
767 | * input: none | 767 | * input: none |
768 | ************* | 768 | ************* |
769 | * output: none | 769 | * output: none |
770 | ************* | 770 | ************* |
771 | * return value: none | 771 | * return value: none |
772 | *******************************************************************************************/ | 772 | *******************************************************************************************/ |
773 | 773 | ||
774 | void Highlight::use() | 774 | void Highlight::use() |
775 | { | 775 | { |
776 | if (refCount == 0) init(); | 776 | if (refCount == 0) init(); |
777 | refCount++; | 777 | refCount++; |
778 | } | 778 | } |
779 | 779 | ||
780 | 780 | ||
781 | /******************************************************************************************* | 781 | /******************************************************************************************* |
782 | Highlight - release | 782 | Highlight - release |
783 | Decrease the usage count and trigger a cleanup if needed | 783 | Decrease the usage count and trigger a cleanup if needed |
784 | 784 | ||
785 | * input: none | 785 | * input: none |
786 | ************* | 786 | ************* |
787 | * output: none | 787 | * output: none |
788 | ************* | 788 | ************* |
789 | * return value: none | 789 | * return value: none |
790 | *******************************************************************************************/ | 790 | *******************************************************************************************/ |
791 | 791 | ||
792 | void Highlight::release() | 792 | void Highlight::release() |
793 | { | 793 | { |
794 | refCount--; | 794 | refCount--; |
795 | if (refCount == 0) done(); | 795 | if (refCount == 0) done(); |
796 | } | 796 | } |
797 | 797 | ||
798 | /******************************************************************************************* | 798 | /******************************************************************************************* |
799 | Highlight - init | 799 | Highlight - init |
800 | If it's the first time a particular highlighting is used create the needed contextlist | 800 | If it's the first time a particular highlighting is used create the needed contextlist |
801 | 801 | ||
802 | * input: none | 802 | * input: none |
803 | ************* | 803 | ************* |
804 | * output: none | 804 | * output: none |
805 | ************* | 805 | ************* |
806 | * return value: none | 806 | * return value: none |
807 | *******************************************************************************************/ | 807 | *******************************************************************************************/ |
808 | 808 | ||
809 | void Highlight::init() | 809 | void Highlight::init() |
810 | { | 810 | { |
811 | if (noHl) | 811 | if (noHl) |
812 | return; | 812 | return; |
813 | 813 | ||
814 | for (int z = 0; z < nContexts; z++) contextList[z] = 0L; | 814 | for (int z = 0; z < nContexts; z++) contextList[z] = 0L; |
815 | makeContextList(); | 815 | makeContextList(); |
816 | } | 816 | } |
817 | 817 | ||
818 | 818 | ||
819 | /******************************************************************************************* | 819 | /******************************************************************************************* |
820 | Highlight - done | 820 | Highlight - done |
821 | If the there is no document using the highlighting style free the complete context | 821 | If the there is no document using the highlighting style free the complete context |
822 | structure. | 822 | structure. |
823 | 823 | ||
824 | * input: none | 824 | * input: none |
825 | ************* | 825 | ************* |
826 | * output: none | 826 | * output: none |
827 | ************* | 827 | ************* |
828 | * return value: none | 828 | * return value: none |
829 | *******************************************************************************************/ | 829 | *******************************************************************************************/ |
830 | 830 | ||
831 | void Highlight::done() | 831 | void Highlight::done() |
832 | { | 832 | { |
833 | if (noHl) | 833 | if (noHl) |
834 | return; | 834 | return; |
835 | 835 | ||
836 | for (int z = 0; z < nContexts; z++) delete contextList[z]; | 836 | for (int z = 0; z < nContexts; z++) delete contextList[z]; |
837 | } | 837 | } |
838 | 838 | ||
839 | 839 | ||
840 | /******************************************************************************************* | 840 | /******************************************************************************************* |
841 | Highlight - createItemData | 841 | Highlight - createItemData |
842 | This function reads the itemData entries from the config file, which specifies the | 842 | This function reads the itemData entries from the config file, which specifies the |
843 | default attribute styles for matched items/contexts. | 843 | default attribute styles for matched items/contexts. |
844 | 844 | ||
845 | * input: none | 845 | * input: none |
846 | ************* | 846 | ************* |
847 | * output: ItemDataList &list :A reference to the internal | 847 | * output: ItemDataList &list :A reference to the internal |
848 | list containing the parsed | 848 | list containing the parsed |
849 | default config | 849 | default config |
850 | ************* | 850 | ************* |
851 | * return value: none | 851 | * return value: none |
852 | *******************************************************************************************/ | 852 | *******************************************************************************************/ |
853 | 853 | ||
854 | void Highlight::createItemData(ItemDataList &list) | 854 | void Highlight::createItemData(ItemDataList &list) |
855 | { | 855 | { |
856 | qDebug("Highlight::createItemData"); | 856 | qDebug("Highlight::createItemData"); |
857 | 857 | ||
858 | // If no highlighting is selected we need only one default. | 858 | // If no highlighting is selected we need only one default. |
859 | if (noHl) | 859 | if (noHl) |
860 | { | 860 | { |
861 | list.append(new ItemData(I18N_NOOP("Normal Text"), dsNormal)); | 861 | list.append(new ItemData(I18N_NOOP("Normal Text"), dsNormal)); |
862 | return; | 862 | return; |
863 | } | 863 | } |
864 | 864 | ||
865 | QString color; | 865 | QString color; |
866 | QString selColor; | 866 | QString selColor; |
867 | QString bold; | 867 | QString bold; |
868 | QString italic; | 868 | QString italic; |
869 | 869 | ||
870 | // If the internal list isn't already available read the config file | 870 | // If the internal list isn't already available read the config file |
871 | if (internalIDList.count()==0) | 871 | if (internalIDList.count()==0) |
872 | { | 872 | { |
873 | //if all references to the list are destried the contents will also be deleted | 873 | //if all references to the list are destried the contents will also be deleted |
874 | internalIDList.setAutoDelete(true); | 874 | internalIDList.setAutoDelete(true); |
875 | syntaxContextData *data; | 875 | syntaxContextData *data; |
876 | 876 | ||
877 | qDebug("Trying to read itemData section"); | 877 | qDebug("Trying to read itemData section"); |
878 | 878 | ||
879 | //Tell the syntax document class which file we want to parse and which data group | 879 | //Tell the syntax document class which file we want to parse and which data group |
880 | HlManager::self()->syntax->setIdentifier(identifier); | 880 | HlManager::self()->syntax->setIdentifier(identifier); |
881 | data=HlManager::self()->syntax->getGroupInfo("highlighting","itemData"); | 881 | data=HlManager::self()->syntax->getGroupInfo("highlighting","itemData"); |
882 | //begin with the real parsing | 882 | //begin with the real parsing |
883 | while (HlManager::self()->syntax->nextGroup(data)) | 883 | while (HlManager::self()->syntax->nextGroup(data)) |
884 | { | 884 | { |
885 | qDebug("Setting up one itemData element"); | 885 | qDebug("Setting up one itemData element"); |
886 | // read all attributes | 886 | // read all attributes |
887 | color=HlManager::self()->syntax->groupData(data,QString("color")); | 887 | color=HlManager::self()->syntax->groupData(data,QString("color")); |
888 | selColor=HlManager::self()->syntax->groupData(data,QString("selColor")); | 888 | selColor=HlManager::self()->syntax->groupData(data,QString("selColor")); |
889 | bold=HlManager::self()->syntax->groupData(data,QString("bold")); | 889 | bold=HlManager::self()->syntax->groupData(data,QString("bold")); |
890 | italic=HlManager::self()->syntax->groupData(data,QString("italic")); | 890 | italic=HlManager::self()->syntax->groupData(data,QString("italic")); |
891 | //check if the user overrides something | 891 | //check if the user overrides something |
892 | if ( (!color.isEmpty()) && (!selColor.isEmpty()) && (!bold.isEmpty()) && (!italic.isEmpty())) | 892 | if ( (!color.isEmpty()) && (!selColor.isEmpty()) && (!bold.isEmpty()) && (!italic.isEmpty())) |
893 | { | 893 | { |
894 | //create a user defined style | 894 | //create a user defined style |
895 | internalIDList.append(new ItemData( | 895 | internalIDList.append(new ItemData( |
896 | HlManager::self()->syntax->groupData(data,QString("name")).simplifyWhiteSpace(), | 896 | HlManager::self()->syntax->groupData(data,QString("name")).simplifyWhiteSpace(), |
897 | getDefStyleNum(HlManager::self()->syntax->groupData(data,QString("defStyleNum"))), | 897 | getDefStyleNum(HlManager::self()->syntax->groupData(data,QString("defStyleNum"))), |
898 | QColor(color),QColor(selColor),(bold=="true") || (bold=="1"), (italic=="true") || (italic=="1") | 898 | QColor(color),QColor(selColor),(bold=="true") || (bold=="1"), (italic=="true") || (italic=="1") |
899 | )); | 899 | )); |
900 | } | 900 | } |
901 | else | 901 | else |
902 | { | 902 | { |
903 | //assign a default style | 903 | //assign a default style |
904 | internalIDList.append(new ItemData( | 904 | internalIDList.append(new ItemData( |
905 | HlManager::self()->syntax->groupData(data,QString("name")).simplifyWhiteSpace(), | 905 | HlManager::self()->syntax->groupData(data,QString("name")).simplifyWhiteSpace(), |
906 | getDefStyleNum(HlManager::self()->syntax->groupData(data,QString("defStyleNum"))))); | 906 | getDefStyleNum(HlManager::self()->syntax->groupData(data,QString("defStyleNum"))))); |
907 | 907 | ||
908 | } | 908 | } |
909 | } | 909 | } |
910 | //clean up | 910 | //clean up |
911 | if (data) HlManager::self()->syntax->freeGroupInfo(data); | 911 | if (data) HlManager::self()->syntax->freeGroupInfo(data); |
912 | } | 912 | } |
913 | 913 | ||
914 | //set the ouput reference | 914 | //set the ouput reference |
915 | list=internalIDList; | 915 | list=internalIDList; |
916 | } | 916 | } |
917 | 917 | ||
918 | 918 | ||
919 | /******************************************************************************************* | 919 | /******************************************************************************************* |
920 | Highlight - lookupAttrName | 920 | Highlight - lookupAttrName |
921 | This function is a helper for makeContextList and createHlItem. It looks the given | 921 | This function is a helper for makeContextList and createHlItem. It looks the given |
922 | attribute name in the itemData list up and returns it's index | 922 | attribute name in the itemData list up and returns it's index |
923 | 923 | ||
924 | * input: QString &name :the attribute name to lookup | 924 | * input: QString &name :the attribute name to lookup |
925 | * ItemDataList &iDl :the list containing all | 925 | * ItemDataList &iDl :the list containing all |
926 | * available attributes | 926 | * available attributes |
927 | ************* | 927 | ************* |
928 | * output: none | 928 | * output: none |
929 | ************* | 929 | ************* |
930 | * return value: int :The index of the attribute | 930 | * return value: int :The index of the attribute |
931 | * or 0 | 931 | * or 0 |
932 | *******************************************************************************************/ | 932 | *******************************************************************************************/ |
933 | 933 | ||
934 | int Highlight::lookupAttrName(const QString& name, ItemDataList &iDl) | 934 | int Highlight::lookupAttrName(const QString& name, ItemDataList &iDl) |
935 | { | 935 | { |
936 | for (int i=0;i<iDl.count();i++) | 936 | for (int i=0;i<iDl.count();i++) |
937 | { | 937 | { |
938 | if (iDl.at(i)->name==name) return i; | 938 | if (iDl.at(i)->name==name) return i; |
939 | } | 939 | } |
940 | kdDebug(13010)<<"Couldn't resolve itemDataName"<<endl; | 940 | kdDebug(13010)<<"Couldn't resolve itemDataName"<<endl; |
941 | return 0; | 941 | return 0; |
942 | } | 942 | } |
943 | 943 | ||
944 | 944 | ||
945 | /******************************************************************************************* | 945 | /******************************************************************************************* |
946 | Highlight - createHlItem | 946 | Highlight - createHlItem |
947 | This function is a helper for makeContextList. It parses the xml file for | 947 | This function is a helper for makeContextList. It parses the xml file for |
948 | information, how single or multi line comments are marked | 948 | information, how single or multi line comments are marked |
949 | 949 | ||
950 | * input: syntaxContextData *data : Data about the item read from | 950 | * input: syntaxContextData *data : Data about the item read from |
951 | * the xml file | 951 | * the xml file |
952 | * ItemDataList &iDl : List of all available itemData | 952 | * ItemDataList &iDl : List of all available itemData |
953 | * entries. Needed for attribute | 953 | * entries. Needed for attribute |
954 | * name->index translation | 954 | * name->index translation |
955 | ************* | 955 | ************* |
956 | * output: none | 956 | * output: none |
957 | ************* | 957 | ************* |
958 | * return value: HlItem * : Pointer to the newly created item | 958 | * return value: HlItem * : Pointer to the newly created item |
959 | * object | 959 | * object |
960 | *******************************************************************************************/ | 960 | *******************************************************************************************/ |
961 | 961 | ||
962 | HlItem *Highlight::createHlItem(syntaxContextData *data, ItemDataList &iDl) | 962 | HlItem *Highlight::createHlItem(syntaxContextData *data, ItemDataList &iDl) |
963 | { | 963 | { |
964 | // No highlighting -> exit | 964 | // No highlighting -> exit |
965 | if (noHl) | 965 | if (noHl) |
966 | return 0; | 966 | return 0; |
967 | 967 | ||
968 | // get the (tagname) itemd type | 968 | // get the (tagname) itemd type |
969 | QString dataname=HlManager::self()->syntax->groupItemData(data,QString("")); | 969 | QString dataname=HlManager::self()->syntax->groupItemData(data,QString("")); |
970 | 970 | ||
971 | // BEGIN - Translation of the attribute parameter | 971 | // BEGIN - Translation of the attribute parameter |
972 | QString tmpAttr=HlManager::self()->syntax->groupItemData(data,QString("attribute")).simplifyWhiteSpace(); | 972 | QString tmpAttr=HlManager::self()->syntax->groupItemData(data,QString("attribute")).simplifyWhiteSpace(); |
973 | int attr; | 973 | int attr; |
974 | if (QString("%1").arg(tmpAttr.toInt())==tmpAttr) | 974 | if (QString("%1").arg(tmpAttr.toInt())==tmpAttr) |
975 | attr=tmpAttr.toInt(); | 975 | attr=tmpAttr.toInt(); |
976 | else | 976 | else |
977 | attr=lookupAttrName(tmpAttr,iDl); | 977 | attr=lookupAttrName(tmpAttr,iDl); |
978 | // END - Translation of the attribute parameter | 978 | // END - Translation of the attribute parameter |
979 | 979 | ||
980 | // Info about context switch | 980 | // Info about context switch |
981 | int context=((HlManager::self()->syntax->groupItemData(data,QString("context"))).toInt()); | 981 | int context=((HlManager::self()->syntax->groupItemData(data,QString("context"))).toInt()); |
982 | 982 | ||
983 | // Get the char parameter (eg DetectChar) | 983 | // Get the char parameter (eg DetectChar) |
984 | char chr; | 984 | char chr; |
985 | if (! HlManager::self()->syntax->groupItemData(data,QString("char")).isEmpty()) | 985 | if (! HlManager::self()->syntax->groupItemData(data,QString("char")).isEmpty()) |
986 | chr= (HlManager::self()->syntax->groupItemData(data,QString("char")).latin1())[0]; | 986 | chr= (HlManager::self()->syntax->groupItemData(data,QString("char")).latin1())[0]; |
987 | else | 987 | else |
988 | chr=0; | 988 | chr=0; |
989 | 989 | ||
990 | // Get the String parameter (eg. StringDetect) | 990 | // Get the String parameter (eg. StringDetect) |
991 | QString stringdata=HlManager::self()->syntax->groupItemData(data,QString("String")); | 991 | QString stringdata=HlManager::self()->syntax->groupItemData(data,QString("String")); |
992 | 992 | ||
993 | // Get a second char parameter (char1) (eg Detect2Chars) | 993 | // Get a second char parameter (char1) (eg Detect2Chars) |
994 | char chr1; | 994 | char chr1; |
995 | if (! HlManager::self()->syntax->groupItemData(data,QString("char1")).isEmpty()) | 995 | if (! HlManager::self()->syntax->groupItemData(data,QString("char1")).isEmpty()) |
996 | chr1= (HlManager::self()->syntax->groupItemData(data,QString("char1")).latin1())[0]; | 996 | chr1= (HlManager::self()->syntax->groupItemData(data,QString("char1")).latin1())[0]; |
997 | else | 997 | else |
998 | chr1=0; | 998 | chr1=0; |
999 | 999 | ||
1000 | // Will be removed eventuall. Atm used for StringDetect | 1000 | // Will be removed eventuall. Atm used for StringDetect |
1001 | bool insensitive=(HlManager::self()->syntax->groupItemData(data,QString("insensitive"))==QString("TRUE")); | 1001 | bool insensitive=(HlManager::self()->syntax->groupItemData(data,QString("insensitive"))==QString("TRUE")); |
1002 | 1002 | ||
1003 | 1003 | ||
1004 | //Create the item corresponding to it's type and set it's parameters | 1004 | //Create the item corresponding to it's type and set it's parameters |
1005 | if (dataname=="keyword") | 1005 | if (dataname=="keyword") |
1006 | { | 1006 | { |
1007 | HlKeyword *keyword=new HlKeyword(attr,context,casesensitive, | 1007 | HlKeyword *keyword=new HlKeyword(attr,context,casesensitive, |
1008 | deliminatorChars, deliminatorLen); | 1008 | deliminatorChars, deliminatorLen); |
1009 | 1009 | ||
1010 | //Get the entries for the keyword lookup list | 1010 | //Get the entries for the keyword lookup list |
1011 | keyword->addList(HlManager::self()->syntax->finddata("highlighting",stringdata)); | 1011 | keyword->addList(HlManager::self()->syntax->finddata("highlighting",stringdata)); |
1012 | return keyword; | 1012 | return keyword; |
1013 | } else | 1013 | } else |
1014 | if (dataname=="Float") return (new HlFloat(attr,context)); else | 1014 | if (dataname=="Float") return (new HlFloat(attr,context)); else |
1015 | if (dataname=="Int") return(new HlInt(attr,context)); else | 1015 | if (dataname=="Int") return(new HlInt(attr,context)); else |
1016 | if (dataname=="DetectChar") return(new HlCharDetect(attr,context,chr)); else | 1016 | if (dataname=="DetectChar") return(new HlCharDetect(attr,context,chr)); else |
1017 | if (dataname=="Detect2Chars") return(new Hl2CharDetect(attr,context,chr,chr1)); else | 1017 | if (dataname=="Detect2Chars") return(new Hl2CharDetect(attr,context,chr,chr1)); else |
1018 | if (dataname=="RangeDetect") return(new HlRangeDetect(attr,context, chr, chr1)); else | 1018 | if (dataname=="RangeDetect") return(new HlRangeDetect(attr,context, chr, chr1)); else |
1019 | if (dataname=="LineContinue") return(new HlLineContinue(attr,context)); else | 1019 | if (dataname=="LineContinue") return(new HlLineContinue(attr,context)); else |
1020 | if (dataname=="StringDetect") return(new HlStringDetect(attr,context,stringdata,insensitive)); else | 1020 | if (dataname=="StringDetect") return(new HlStringDetect(attr,context,stringdata,insensitive)); else |
1021 | if (dataname=="AnyChar") return(new HlAnyChar(attr,context,stringdata.unicode(), stringdata.length())); else | 1021 | if (dataname=="AnyChar") return(new HlAnyChar(attr,context,stringdata.unicode(), stringdata.length())); else |
1022 | if (dataname=="RegExpr") return(new HlRegExpr(attr,context,stringdata)); else | 1022 | if (dataname=="RegExpr") return(new HlRegExpr(attr,context,stringdata)); else |
1023 | if(dataname=="HlCChar") return ( new HlCChar(attr,context));else | 1023 | if(dataname=="HlCChar") return ( new HlCChar(attr,context));else |
1024 | if(dataname=="HlCHex") return (new HlCHex(attr,context));else | 1024 | if(dataname=="HlCHex") return (new HlCHex(attr,context));else |
1025 | if(dataname=="HlCOct") return (new HlCOct(attr,context)); else | 1025 | if(dataname=="HlCOct") return (new HlCOct(attr,context)); else |
1026 | if(dataname=="HlCStringChar") return (new HlCStringChar(attr,context)); else | 1026 | if(dataname=="HlCStringChar") return (new HlCStringChar(attr,context)); else |
1027 | 1027 | ||
1028 | { | 1028 | { |
1029 | // oops, unknown type. Perhaps a spelling error in the xml file | 1029 | // oops, unknown type. Perhaps a spelling error in the xml file |
1030 | return 0; | 1030 | return 0; |
1031 | } | 1031 | } |
1032 | 1032 | ||
1033 | 1033 | ||
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | 1036 | ||
1037 | /******************************************************************************************* | 1037 | /******************************************************************************************* |
1038 | Highlight - isInWord | 1038 | Highlight - isInWord |
1039 | 1039 | ||
1040 | * input: Qchar c Character to investigate | 1040 | * input: Qchar c Character to investigate |
1041 | ************* | 1041 | ************* |
1042 | * output: none | 1042 | * output: none |
1043 | ************* | 1043 | ************* |
1044 | * return value: returns true, if c is no deliminator | 1044 | * return value: returns true, if c is no deliminator |
1045 | *******************************************************************************************/ | 1045 | *******************************************************************************************/ |
1046 | 1046 | ||
1047 | bool Highlight::isInWord(QChar c) | 1047 | bool Highlight::isInWord(QChar c) |
1048 | { | 1048 | { |
1049 | return !ustrchr(deliminatorChars, deliminatorLen, c); | 1049 | return !ustrchr(deliminatorChars, deliminatorLen, c); |
1050 | } | 1050 | } |
1051 | 1051 | ||
1052 | 1052 | ||
1053 | 1053 | ||
1054 | /******************************************************************************************* | 1054 | /******************************************************************************************* |
1055 | Highlight - readCommentConfig | 1055 | Highlight - readCommentConfig |
1056 | This function is a helper for makeContextList. It parses the xml file for | 1056 | This function is a helper for makeContextList. It parses the xml file for |
1057 | information, how single or multi line comments are marked | 1057 | information, how single or multi line comments are marked |
1058 | 1058 | ||
1059 | * input: none | 1059 | * input: none |
1060 | ************* | 1060 | ************* |
1061 | * output: none | 1061 | * output: none |
1062 | ************* | 1062 | ************* |
1063 | * return value: none | 1063 | * return value: none |
1064 | *******************************************************************************************/ | 1064 | *******************************************************************************************/ |
1065 | 1065 | ||
1066 | void Highlight::readCommentConfig() | 1066 | void Highlight::readCommentConfig() |
1067 | { | 1067 | { |
1068 | 1068 | ||
1069 | cslStart = ""; | 1069 | cslStart = ""; |
1070 | HlManager::self()->syntax->setIdentifier(identifier); | 1070 | HlManager::self()->syntax->setIdentifier(identifier); |
1071 | 1071 | ||
1072 | syntaxContextData *data=HlManager::self()->syntax->getGroupInfo("general","comment"); | 1072 | syntaxContextData *data=HlManager::self()->syntax->getGroupInfo("general","comment"); |
1073 | if (data) | 1073 | if (data) |
1074 | { | 1074 | { |
1075 | // kdDebug(13010)<<"COMMENT DATA FOUND"<<endl; | 1075 | // kdDebug(13010)<<"COMMENT DATA FOUND"<<endl; |
1076 | while (HlManager::self()->syntax->nextGroup(data)) | 1076 | while (HlManager::self()->syntax->nextGroup(data)) |
1077 | { | 1077 | { |
1078 | 1078 | ||
1079 | if (HlManager::self()->syntax->groupData(data,"name")=="singleLine") | 1079 | if (HlManager::self()->syntax->groupData(data,"name")=="singleLine") |
1080 | cslStart=HlManager::self()->syntax->groupData(data,"start"); | 1080 | cslStart=HlManager::self()->syntax->groupData(data,"start"); |
1081 | if (HlManager::self()->syntax->groupData(data,"name")=="multiLine") | 1081 | if (HlManager::self()->syntax->groupData(data,"name")=="multiLine") |
1082 | { | 1082 | { |
1083 | cmlStart=HlManager::self()->syntax->groupData(data,"start"); | 1083 | cmlStart=HlManager::self()->syntax->groupData(data,"start"); |
1084 | cmlEnd=HlManager::self()->syntax->groupData(data,"end"); | 1084 | cmlEnd=HlManager::self()->syntax->groupData(data,"end"); |
1085 | } | 1085 | } |
1086 | } | 1086 | } |
1087 | HlManager::self()->syntax->freeGroupInfo(data); | 1087 | HlManager::self()->syntax->freeGroupInfo(data); |
1088 | } | 1088 | } |
1089 | 1089 | ||
1090 | } | 1090 | } |
1091 | 1091 | ||
1092 | /******************************************************************************************* | 1092 | /******************************************************************************************* |
1093 | Highlight - readGlobalKeyWordConfig | 1093 | Highlight - readGlobalKeyWordConfig |
1094 | This function is a helper for makeContextList. It parses the xml file for | 1094 | This function is a helper for makeContextList. It parses the xml file for |
1095 | information, if keywords should be treated case(in)sensitive and creates the keyword | 1095 | information, if keywords should be treated case(in)sensitive and creates the keyword |
1096 | delimiter list. Which is the default list, without any given weak deliminiators | 1096 | delimiter list. Which is the default list, without any given weak deliminiators |
1097 | 1097 | ||
1098 | * input: none | 1098 | * input: none |
1099 | ************* | 1099 | ************* |
1100 | * output: none | 1100 | * output: none |
1101 | ************* | 1101 | ************* |
1102 | * return value: none | 1102 | * return value: none |
1103 | *******************************************************************************************/ | 1103 | *******************************************************************************************/ |
1104 | 1104 | ||
1105 | 1105 | ||
1106 | void Highlight::readGlobalKeywordConfig() | 1106 | void Highlight::readGlobalKeywordConfig() |
1107 | { | 1107 | { |
1108 | // Tell the syntax document class which file we want to parse | 1108 | // Tell the syntax document class which file we want to parse |
1109 | HlManager::self()->syntax->setIdentifier(identifier); | 1109 | HlManager::self()->syntax->setIdentifier(identifier); |
1110 | 1110 | ||
1111 | // Get the keywords config entry | 1111 | // Get the keywords config entry |
1112 | syntaxContextData * data=HlManager::self()->syntax->getConfig("general","keywords"); | 1112 | syntaxContextData * data=HlManager::self()->syntax->getConfig("general","keywords"); |
1113 | if (data) | 1113 | if (data) |
1114 | { | 1114 | { |
1115 | kdDebug(13010)<<"Found global keyword config"<<endl; | 1115 | kdDebug(13010)<<"Found global keyword config"<<endl; |
1116 | 1116 | ||
1117 | if (HlManager::self()->syntax->groupItemData(data,QString("casesensitive"))!="0") | 1117 | if (HlManager::self()->syntax->groupItemData(data,QString("casesensitive"))!="0") |
1118 | casesensitive=true; else {casesensitive=false; kdDebug(13010)<<"Turning on case insensitiveness"<<endl;} | 1118 | casesensitive=true; else {casesensitive=false; kdDebug(13010)<<"Turning on case insensitiveness"<<endl;} |
1119 | //get the weak deliminators | 1119 | //get the weak deliminators |
1120 | weakDeliminator=(!HlManager::self()->syntax->groupItemData(data,QString("weakDeliminator"))); | 1120 | weakDeliminator=(!HlManager::self()->syntax->groupItemData(data,QString("weakDeliminator"))); |
1121 | 1121 | ||
1122 | // remove any weakDelimitars (if any) from the default list and store this list. | 1122 | // remove any weakDelimitars (if any) from the default list and store this list. |
1123 | int f; | 1123 | int f; |
1124 | for (int s=0; s < weakDeliminator.length(); s++) | 1124 | for (int s=0; s < weakDeliminator.length(); s++) |
1125 | { | 1125 | { |
1126 | f = 0; | 1126 | f = 0; |
1127 | f = deliminator.find (weakDeliminator[s]); | 1127 | f = deliminator.find (weakDeliminator[s]); |
1128 | 1128 | ||
1129 | if (f > -1) | 1129 | if (f > -1) |
1130 | deliminator.remove (f, 1); | 1130 | deliminator.remove (f, 1); |
1131 | } | 1131 | } |
1132 | 1132 | ||
1133 | deliminatorChars = deliminator.unicode(); | 1133 | deliminatorChars = deliminator.unicode(); |
1134 | deliminatorLen = deliminator.length(); | 1134 | deliminatorLen = deliminator.length(); |
1135 | 1135 | ||
1136 | HlManager::self()->syntax->freeGroupInfo(data); | 1136 | HlManager::self()->syntax->freeGroupInfo(data); |
1137 | } | 1137 | } |
1138 | else | 1138 | else |
1139 | { | 1139 | { |
1140 | //Default values | 1140 | //Default values |
1141 | casesensitive=true; | 1141 | casesensitive=true; |
1142 | weakDeliminator=QString(""); | 1142 | weakDeliminator=QString(""); |
1143 | } | 1143 | } |
1144 | 1144 | ||
1145 | } | 1145 | } |
1146 | 1146 | ||
1147 | /******************************************************************************************* | 1147 | /******************************************************************************************* |
1148 | Highlight - makeContextList | 1148 | Highlight - makeContextList |
1149 | That's the most important initialization function for each highlighting. It's called | 1149 | That's the most important initialization function for each highlighting. It's called |
1150 | each time a document gets a highlighting style assigned. parses the xml file and | 1150 | each time a document gets a highlighting style assigned. parses the xml file and |
1151 | creates a corresponding internal structure | 1151 | creates a corresponding internal structure |
1152 | 1152 | ||
1153 | * input: none | 1153 | * input: none |
1154 | ************* | 1154 | ************* |
1155 | * output: none | 1155 | * output: none |
1156 | ************* | 1156 | ************* |
1157 | * return value: none | 1157 | * return value: none |
1158 | *******************************************************************************************/ | 1158 | *******************************************************************************************/ |
1159 | 1159 | ||
1160 | 1160 | ||
1161 | void Highlight::makeContextList() | 1161 | void Highlight::makeContextList() |
1162 | { | 1162 | { |
1163 | if (noHl) | 1163 | if (noHl) |
1164 | return; | 1164 | return; |
1165 | 1165 | ||
1166 | HlKeyword *keyword=0, *dataType=0; | 1166 | HlKeyword *keyword=0, *dataType=0; |
1167 | syntaxContextData *data, *datasub; | 1167 | syntaxContextData *data, *datasub; |
1168 | HlItem *c; | 1168 | HlItem *c; |
1169 | 1169 | ||
1170 | readCommentConfig(); | 1170 | readCommentConfig(); |
1171 | readGlobalKeywordConfig(); | 1171 | readGlobalKeywordConfig(); |
1172 | 1172 | ||
1173 | // Let the syntax document class know, which file we'd like to parse | 1173 | // Let the syntax document class know, which file we'd like to parse |
1174 | HlManager::self()->syntax->setIdentifier(identifier); | 1174 | HlManager::self()->syntax->setIdentifier(identifier); |
1175 | 1175 | ||
1176 | // This list is needed for the translation of the attribute parameter, if the itemData name is given instead of the index | 1176 | // This list is needed for the translation of the attribute parameter, if the itemData name is given instead of the index |
1177 | ItemDataList iDl; | 1177 | ItemDataList iDl; |
1178 | createItemData(iDl); | 1178 | createItemData(iDl); |
1179 | 1179 | ||
1180 | //start the real work | 1180 | //start the real work |
1181 | data=HlManager::self()->syntax->getGroupInfo("highlighting","context"); | 1181 | data=HlManager::self()->syntax->getGroupInfo("highlighting","context"); |
1182 | int i=0; | 1182 | int i=0; |
1183 | if (data) | 1183 | if (data) |
1184 | { | 1184 | { |
1185 | while (HlManager::self()->syntax->nextGroup(data)) | 1185 | while (HlManager::self()->syntax->nextGroup(data)) |
1186 | { | 1186 | { |
1187 | 1187 | ||
1188 | // BEGIN - Translation of the attribute parameter | 1188 | // BEGIN - Translation of the attribute parameter |
1189 | QString tmpAttr=HlManager::self()->syntax->groupData(data,QString("attribute")).simplifyWhiteSpace(); | 1189 | QString tmpAttr=HlManager::self()->syntax->groupData(data,QString("attribute")).simplifyWhiteSpace(); |
1190 | int attr; | 1190 | int attr; |
1191 | if (QString("%1").arg(tmpAttr.toInt())==tmpAttr) | 1191 | if (QString("%1").arg(tmpAttr.toInt())==tmpAttr) |
1192 | attr=tmpAttr.toInt(); | 1192 | attr=tmpAttr.toInt(); |
1193 | else | 1193 | else |
1194 | attr=lookupAttrName(tmpAttr,iDl); | 1194 | attr=lookupAttrName(tmpAttr,iDl); |
1195 | // END - Translation of the attribute parameter | 1195 | // END - Translation of the attribute parameter |
1196 | 1196 | ||
1197 | contextList[i]=new HlContext( | 1197 | contextList[i]=new HlContext( |
1198 | attr, | 1198 | attr, |
1199 | (HlManager::self()->syntax->groupData(data,QString("lineEndContext"))).toInt(), | 1199 | (HlManager::self()->syntax->groupData(data,QString("lineEndContext"))).toInt(), |
1200 | (HlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).isEmpty()?-1: | 1200 | (HlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).isEmpty()?-1: |
1201 | (HlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).toInt()); | 1201 | (HlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).toInt()); |
1202 | 1202 | ||
1203 | 1203 | ||
1204 | //Let's create all items for the context | 1204 | //Let's create all items for the context |
1205 | while (HlManager::self()->syntax->nextItem(data)) | 1205 | while (HlManager::self()->syntax->nextItem(data)) |
1206 | { | 1206 | { |
1207 | // kdDebug(13010)<< "In make Contextlist: Item:"<<endl; | 1207 | // kdDebug(13010)<< "In make Contextlist: Item:"<<endl; |
1208 | c=createHlItem(data,iDl); | 1208 | c=createHlItem(data,iDl); |
1209 | if (c) | 1209 | if (c) |
1210 | { | 1210 | { |
1211 | contextList[i]->items.append(c); | 1211 | contextList[i]->items.append(c); |
1212 | 1212 | ||
1213 | // Not supported completely atm and only one level. Subitems.(all have to be matched to at once) | 1213 | // Not supported completely atm and only one level. Subitems.(all have to be matched to at once) |
1214 | datasub=HlManager::self()->syntax->getSubItems(data); | 1214 | datasub=HlManager::self()->syntax->getSubItems(data); |
1215 | bool tmpbool; | 1215 | bool tmpbool; |
1216 | if (tmpbool=HlManager::self()->syntax->nextItem(datasub)) | 1216 | if (tmpbool=HlManager::self()->syntax->nextItem(datasub)) |
1217 | { | 1217 | { |
1218 | c->subItems=new QList<HlItem>; | 1218 | c->subItems=new QList<HlItem>; |
1219 | for (;tmpbool;tmpbool=HlManager::self()->syntax->nextItem(datasub)) | 1219 | for (;tmpbool;tmpbool=HlManager::self()->syntax->nextItem(datasub)) |
1220 | c->subItems->append(createHlItem(datasub,iDl)); | 1220 | c->subItems->append(createHlItem(datasub,iDl)); |
1221 | } | 1221 | } |
1222 | HlManager::self()->syntax->freeGroupInfo(datasub); | 1222 | HlManager::self()->syntax->freeGroupInfo(datasub); |
1223 | // end of sublevel | 1223 | // end of sublevel |
1224 | } | 1224 | } |
1225 | // kdDebug(13010)<<"Last line in loop"<<endl; | 1225 | // kdDebug(13010)<<"Last line in loop"<<endl; |
1226 | } | 1226 | } |
1227 | i++; | 1227 | i++; |
1228 | } | 1228 | } |
1229 | } | 1229 | } |
1230 | 1230 | ||
1231 | HlManager::self()->syntax->freeGroupInfo(data); | 1231 | HlManager::self()->syntax->freeGroupInfo(data); |
1232 | 1232 | ||
1233 | 1233 | ||
1234 | } | 1234 | } |
1235 | 1235 | ||
1236 | HlManager::HlManager() : QObject(0L) | 1236 | HlManager::HlManager() : QObject(0L) |
1237 | { | 1237 | { |
1238 | syntax = new SyntaxDocument(); | 1238 | syntax = new SyntaxDocument(); |
1239 | SyntaxModeList modeList = syntax->modeList(); | 1239 | SyntaxModeList modeList = syntax->modeList(); |
1240 | 1240 | ||
1241 | hlList.setAutoDelete(true); | 1241 | hlList.setAutoDelete(true); |
1242 | hlList.append(new Highlight(0)); | 1242 | hlList.append(new Highlight(0)); |
1243 | 1243 | ||
1244 | uint i=0; | 1244 | uint i=0; |
1245 | while (i < modeList.count()) | 1245 | while (i < modeList.count()) |
1246 | { | 1246 | { |
1247 | hlList.append(new Highlight(modeList.at(i))); | 1247 | hlList.append(new Highlight(modeList.at(i))); |
1248 | i++; | 1248 | i++; |
1249 | } | 1249 | } |
1250 | } | 1250 | } |
1251 | 1251 | ||
1252 | HlManager::~HlManager() { | 1252 | HlManager::~HlManager() { |
1253 | if(syntax) delete syntax; | 1253 | if(syntax) delete syntax; |
1254 | } | 1254 | } |
1255 | 1255 | ||
1256 | HlManager *HlManager::self() | 1256 | HlManager *HlManager::self() |
1257 | { | 1257 | { |
1258 | if ( !s_pSelf ) | 1258 | if ( !s_pSelf ) |
1259 | s_pSelf = new HlManager; | 1259 | s_pSelf = new HlManager; |
1260 | return s_pSelf; | 1260 | return s_pSelf; |
1261 | } | 1261 | } |
1262 | 1262 | ||
1263 | Highlight *HlManager::getHl(int n) { | 1263 | Highlight *HlManager::getHl(int n) { |
1264 | if (n < 0 || n >= (int) hlList.count()) n = 0; | 1264 | if (n < 0 || n >= (int) hlList.count()) n = 0; |
1265 | return hlList.at(n); | 1265 | return hlList.at(n); |
1266 | } | 1266 | } |
1267 | 1267 | ||
1268 | int HlManager::defaultHl() { | 1268 | int HlManager::defaultHl() { |
1269 | KConfig *config; | 1269 | KateConfig *config; |
1270 | config = KGlobal::config(); | 1270 | config = KGlobal::config(); |
1271 | config->setGroup("General Options"); | 1271 | config->setGroup("General Options"); |
1272 | 1272 | ||
1273 | #warning fixme return nameFind(config->readEntry("Highlight")); | 1273 | #warning fixme return nameFind(config->readEntry("Highlight")); |
1274 | 1274 | ||
1275 | } | 1275 | } |
1276 | 1276 | ||
1277 | 1277 | ||
1278 | int HlManager::nameFind(const QString &name) { | 1278 | int HlManager::nameFind(const QString &name) { |
1279 | int z; | 1279 | int z; |
1280 | 1280 | ||
1281 | for (z = hlList.count() - 1; z > 0; z--) { | 1281 | for (z = hlList.count() - 1; z > 0; z--) { |
1282 | if (hlList.at(z)->iName == name) break; | 1282 | if (hlList.at(z)->iName == name) break; |
1283 | } | 1283 | } |
1284 | return z; | 1284 | return z; |
1285 | } | 1285 | } |
1286 | 1286 | ||
1287 | int HlManager::wildcardFind(const QString &fileName) { | 1287 | int HlManager::wildcardFind(const QString &fileName) { |
1288 | Highlight *highlight; | 1288 | Highlight *highlight; |
1289 | int p1, p2; | 1289 | int p1, p2; |
1290 | QString w; | 1290 | QString w; |
1291 | for (highlight = hlList.first(); highlight != 0L; highlight = hlList.next()) { | 1291 | for (highlight = hlList.first(); highlight != 0L; highlight = hlList.next()) { |
1292 | p1 = 0; | 1292 | p1 = 0; |
1293 | w = highlight->getWildcards(); | 1293 | w = highlight->getWildcards(); |
1294 | while (p1 < (int) w.length()) { | 1294 | while (p1 < (int) w.length()) { |
1295 | p2 = w.find(';',p1); | 1295 | p2 = w.find(';',p1); |
1296 | if (p2 == -1) p2 = w.length(); | 1296 | if (p2 == -1) p2 = w.length(); |
1297 | if (p1 < p2) { | 1297 | if (p1 < p2) { |
1298 | QRegExp regExp(w.mid(p1,p2 - p1),true,true); | 1298 | QRegExp regExp(w.mid(p1,p2 - p1),true,true); |
1299 | if (regExp.match(fileName) == 0) return hlList.at(); | 1299 | if (regExp.match(fileName) == 0) return hlList.at(); |
1300 | } | 1300 | } |
1301 | p1 = p2 + 1; | 1301 | p1 = p2 + 1; |
1302 | } | 1302 | } |
1303 | } | 1303 | } |
1304 | return -1; | 1304 | return -1; |
1305 | } | 1305 | } |
1306 | 1306 | ||
1307 | 1307 | ||
1308 | int HlManager::makeAttribs(Highlight *highlight, Attribute *a, int maxAttribs) { | 1308 | int HlManager::makeAttribs(Highlight *highlight, Attribute *a, int maxAttribs) { |
1309 | ItemStyleList defaultStyleList; | 1309 | ItemStyleList defaultStyleList; |
1310 | ItemStyle *defaultStyle; | 1310 | ItemStyle *defaultStyle; |
1311 | ItemDataList itemDataList; | 1311 | ItemDataList itemDataList; |
1312 | ItemData *itemData; | 1312 | ItemData *itemData; |
1313 | int nAttribs, z; | 1313 | int nAttribs, z; |
1314 | 1314 | ||
1315 | qDebug("HlManager::makeAttribs"); | 1315 | qDebug("HlManager::makeAttribs"); |
1316 | 1316 | ||
1317 | defaultStyleList.setAutoDelete(true); | 1317 | defaultStyleList.setAutoDelete(true); |
1318 | getDefaults(defaultStyleList); | 1318 | getDefaults(defaultStyleList); |
1319 | 1319 | ||
1320 | // itemDataList.setAutoDelete(true); | 1320 | // itemDataList.setAutoDelete(true); |
1321 | highlight->getItemDataList(itemDataList); | 1321 | highlight->getItemDataList(itemDataList); |
1322 | nAttribs = itemDataList.count(); | 1322 | nAttribs = itemDataList.count(); |
1323 | for (z = 0; z < nAttribs; z++) { | 1323 | for (z = 0; z < nAttribs; z++) { |
1324 | qDebug("HlManager::makeAttribs: createing one attribute definition"); | 1324 | qDebug("HlManager::makeAttribs: createing one attribute definition"); |
1325 | itemData = itemDataList.at(z); | 1325 | itemData = itemDataList.at(z); |
1326 | if (itemData->defStyle) { | 1326 | if (itemData->defStyle) { |
1327 | // default style | 1327 | // default style |
1328 | defaultStyle = defaultStyleList.at(itemData->defStyleNum); | 1328 | defaultStyle = defaultStyleList.at(itemData->defStyleNum); |
1329 | a[z].col = defaultStyle->col; | 1329 | a[z].col = defaultStyle->col; |
1330 | a[z].selCol = defaultStyle->selCol; | 1330 | a[z].selCol = defaultStyle->selCol; |
1331 | a[z].bold = defaultStyle->bold; | 1331 | a[z].bold = defaultStyle->bold; |
1332 | a[z].italic = defaultStyle->italic; | 1332 | a[z].italic = defaultStyle->italic; |
1333 | } else { | 1333 | } else { |
1334 | // custom style | 1334 | // custom style |
1335 | a[z].col = itemData->col; | 1335 | a[z].col = itemData->col; |
1336 | a[z].selCol = itemData->selCol; | 1336 | a[z].selCol = itemData->selCol; |
1337 | a[z].bold = itemData->bold; | 1337 | a[z].bold = itemData->bold; |
1338 | a[z].italic = itemData->italic; | 1338 | a[z].italic = itemData->italic; |
1339 | } | 1339 | } |
1340 | } | 1340 | } |
1341 | 1341 | ||
1342 | for (; z < maxAttribs; z++) { | 1342 | for (; z < maxAttribs; z++) { |
1343 | a[z].col = black; | 1343 | a[z].col = black; |
1344 | a[z].selCol = black; | 1344 | a[z].selCol = black; |
1345 | a[z].bold = defaultStyle->bold; | 1345 | a[z].bold = defaultStyle->bold; |
1346 | a[z].italic = defaultStyle->italic; | 1346 | a[z].italic = defaultStyle->italic; |
1347 | } | 1347 | } |
1348 | return nAttribs; | 1348 | return nAttribs; |
1349 | } | 1349 | } |
1350 | 1350 | ||
1351 | int HlManager::defaultStyles() { | 1351 | int HlManager::defaultStyles() { |
1352 | return 10; | 1352 | return 10; |
1353 | } | 1353 | } |
1354 | 1354 | ||
1355 | QString HlManager::defaultStyleName(int n) | 1355 | QString HlManager::defaultStyleName(int n) |
1356 | { | 1356 | { |
1357 | static QStringList names; | 1357 | static QStringList names; |
1358 | 1358 | ||
1359 | if (names.isEmpty()) | 1359 | if (names.isEmpty()) |
1360 | { | 1360 | { |
1361 | names << i18n("Normal"); | 1361 | names << i18n("Normal"); |
1362 | names << i18n("Keyword"); | 1362 | names << i18n("Keyword"); |
1363 | names << i18n("Data Type"); | 1363 | names << i18n("Data Type"); |
1364 | names << i18n("Decimal/Value"); | 1364 | names << i18n("Decimal/Value"); |
1365 | names << i18n("Base-N Integer"); | 1365 | names << i18n("Base-N Integer"); |
1366 | names << i18n("Floating Point"); | 1366 | names << i18n("Floating Point"); |
1367 | names << i18n("Character"); | 1367 | names << i18n("Character"); |
1368 | names << i18n("String"); | 1368 | names << i18n("String"); |
1369 | names << i18n("Comment"); | 1369 | names << i18n("Comment"); |
1370 | names << i18n("Others"); | 1370 | names << i18n("Others"); |
1371 | } | 1371 | } |
1372 | 1372 | ||
1373 | return names[n]; | 1373 | return names[n]; |
1374 | } | 1374 | } |
1375 | 1375 | ||
1376 | void HlManager::getDefaults(ItemStyleList &list) { | 1376 | void HlManager::getDefaults(ItemStyleList &list) { |
1377 | KConfig *config; | 1377 | KateConfig *config; |
1378 | int z; | 1378 | int z; |
1379 | ItemStyle *i; | 1379 | ItemStyle *i; |
1380 | QString s; | 1380 | QString s; |
1381 | QRgb col, selCol; | 1381 | QRgb col, selCol; |
1382 | 1382 | ||
1383 | list.setAutoDelete(true); | 1383 | list.setAutoDelete(true); |
1384 | //ItemStyle(color, selected color, bold, italic) | 1384 | //ItemStyle(color, selected color, bold, italic) |
1385 | list.append(new ItemStyle(black,white,false,false)); //normal | 1385 | list.append(new ItemStyle(black,white,false,false)); //normal |
1386 | list.append(new ItemStyle(black,white,true,false)); //keyword | 1386 | list.append(new ItemStyle(black,white,true,false)); //keyword |
1387 | list.append(new ItemStyle(darkRed,white,false,false)); //datatype | 1387 | list.append(new ItemStyle(darkRed,white,false,false)); //datatype |
1388 | list.append(new ItemStyle(blue,cyan,false,false)); //decimal/value | 1388 | list.append(new ItemStyle(blue,cyan,false,false)); //decimal/value |
1389 | list.append(new ItemStyle(darkCyan,cyan,false,false)); //base n | 1389 | list.append(new ItemStyle(darkCyan,cyan,false,false)); //base n |
1390 | list.append(new ItemStyle(darkMagenta,cyan,false,false));//float | 1390 | list.append(new ItemStyle(darkMagenta,cyan,false,false));//float |
1391 | list.append(new ItemStyle(magenta,magenta,false,false)); //char | 1391 | list.append(new ItemStyle(magenta,magenta,false,false)); //char |
1392 | list.append(new ItemStyle(red,red,false,false)); //string | 1392 | list.append(new ItemStyle(red,red,false,false)); //string |
1393 | list.append(new ItemStyle(darkGray,gray,false,true)); //comment | 1393 | list.append(new ItemStyle(darkGray,gray,false,true)); //comment |
1394 | list.append(new ItemStyle(darkGreen,green,false,false)); //others | 1394 | list.append(new ItemStyle(darkGreen,green,false,false)); //others |
1395 | 1395 | ||
1396 | #warning fixme | 1396 | #warning fixme |
1397 | /* | 1397 | /* |
1398 | config = KateFactory::instance()->config(); | 1398 | config = KateFactory::instance()->config(); |
1399 | config->setGroup("Default Item Styles"); | 1399 | config->setGroup("Default Item Styles"); |
1400 | for (z = 0; z < defaultStyles(); z++) { | 1400 | for (z = 0; z < defaultStyles(); z++) { |
1401 | i = list.at(z); | 1401 | i = list.at(z); |
1402 | s = config->readEntry(defaultStyleName(z)); | 1402 | s = config->readEntry(defaultStyleName(z)); |
1403 | if (!s.isEmpty()) { | 1403 | if (!s.isEmpty()) { |
1404 | sscanf(s.latin1(),"%X,%X,%d,%d",&col,&selCol,&i->bold,&i->italic); | 1404 | sscanf(s.latin1(),"%X,%X,%d,%d",&col,&selCol,&i->bold,&i->italic); |
1405 | i->col.setRgb(col); | 1405 | i->col.setRgb(col); |
1406 | i->selCol.setRgb(selCol); | 1406 | i->selCol.setRgb(selCol); |
1407 | } | 1407 | } |
1408 | } | 1408 | } |
1409 | */ | 1409 | */ |
1410 | } | 1410 | } |
1411 | 1411 | ||
1412 | void HlManager::setDefaults(ItemStyleList &list) { | 1412 | void HlManager::setDefaults(ItemStyleList &list) { |
1413 | KConfig *config; | 1413 | KateConfig *config; |
1414 | int z; | 1414 | int z; |
1415 | ItemStyle *i; | 1415 | ItemStyle *i; |
1416 | char s[64]; | 1416 | char s[64]; |
1417 | #warning fixme | 1417 | #warning fixme |
1418 | /* | 1418 | /* |
1419 | config = KateFactory::instance()->config(); | 1419 | config = KateFactory::instance()->config(); |
1420 | config->setGroup("Default Item Styles"); | 1420 | config->setGroup("Default Item Styles"); |
1421 | for (z = 0; z < defaultStyles(); z++) { | 1421 | for (z = 0; z < defaultStyles(); z++) { |
1422 | i = list.at(z); | 1422 | i = list.at(z); |
1423 | sprintf(s,"%X,%X,%d,%d",i->col.rgb(),i->selCol.rgb(),i->bold, i->italic); | 1423 | sprintf(s,"%X,%X,%d,%d",i->col.rgb(),i->selCol.rgb(),i->bold, i->italic); |
1424 | config->writeEntry(defaultStyleName(z),s); | 1424 | config->writeEntry(defaultStyleName(z),s); |
1425 | } | 1425 | } |
1426 | */ | 1426 | */ |
1427 | emit changed(); | 1427 | emit changed(); |
1428 | } | 1428 | } |
1429 | 1429 | ||
1430 | 1430 | ||
1431 | int HlManager::highlights() { | 1431 | int HlManager::highlights() { |
1432 | return (int) hlList.count(); | 1432 | return (int) hlList.count(); |
1433 | } | 1433 | } |
1434 | 1434 | ||
1435 | QString HlManager::hlName(int n) { | 1435 | QString HlManager::hlName(int n) { |
1436 | return hlList.at(n)->iName; | 1436 | return hlList.at(n)->iName; |
1437 | } | 1437 | } |
1438 | 1438 | ||
1439 | QString HlManager::hlSection(int n) { | 1439 | QString HlManager::hlSection(int n) { |
1440 | return hlList.at(n)->iSection; | 1440 | return hlList.at(n)->iSection; |
1441 | } | 1441 | } |
1442 | 1442 | ||
1443 | void HlManager::getHlDataList(HlDataList &list) { | 1443 | void HlManager::getHlDataList(HlDataList &list) { |
1444 | int z; | 1444 | int z; |
1445 | 1445 | ||
1446 | for (z = 0; z < (int) hlList.count(); z++) { | 1446 | for (z = 0; z < (int) hlList.count(); z++) { |
1447 | list.append(hlList.at(z)->getData()); | 1447 | list.append(hlList.at(z)->getData()); |
1448 | } | 1448 | } |
1449 | } | 1449 | } |
1450 | 1450 | ||
1451 | void HlManager::setHlDataList(HlDataList &list) { | 1451 | void HlManager::setHlDataList(HlDataList &list) { |
1452 | int z; | 1452 | int z; |
1453 | 1453 | ||
1454 | for (z = 0; z < (int) hlList.count(); z++) { | 1454 | for (z = 0; z < (int) hlList.count(); z++) { |
1455 | hlList.at(z)->setData(list.at(z)); | 1455 | hlList.at(z)->setData(list.at(z)); |
1456 | } | 1456 | } |
1457 | //notify documents about changes in highlight configuration | 1457 | //notify documents about changes in highlight configuration |
1458 | emit changed(); | 1458 | emit changed(); |
1459 | } | 1459 | } |
diff --git a/noncore/apps/tinykate/libkate/document/katehighlight.h b/noncore/apps/tinykate/libkate/document/katehighlight.h index 1baddcc..fddf585 100644 --- a/noncore/apps/tinykate/libkate/document/katehighlight.h +++ b/noncore/apps/tinykate/libkate/document/katehighlight.h | |||
@@ -1,349 +1,349 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (C) 1998, 1999 Jochen Wilhelmy | 2 | Copyright (C) 1998, 1999 Jochen Wilhelmy |
3 | digisnap@cs.tu-berlin.de | 3 | digisnap@cs.tu-berlin.de |
4 | (C) 2002, 2001 The Kate Team <kwrite-devel@kde.org> | 4 | (C) 2002, 2001 The Kate Team <kwrite-devel@kde.org> |
5 | (C) 2002 Joseph Wenninger <jowenn@kde.org> | 5 | (C) 2002 Joseph Wenninger <jowenn@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #ifndef _HIGHLIGHT_H_ | 23 | #ifndef _HIGHLIGHT_H_ |
24 | #define _HIGHLIGHT_H_ | 24 | #define _HIGHLIGHT_H_ |
25 | 25 | ||
26 | #include <qlist.h> | 26 | #include <qlist.h> |
27 | #include <qdialog.h> | 27 | #include <qdialog.h> |
28 | 28 | ||
29 | #include <kcolorbtn.h> | 29 | #include <kcolorbtn.h> |
30 | #include <qstrvec.h> | 30 | #include <qstrvec.h> |
31 | #include <qdict.h> | 31 | #include <qdict.h> |
32 | #include <qregexp.h> | 32 | #include <qregexp.h> |
33 | #include "../qt3back/qregexp3.h" | 33 | #include "../qt3back/qregexp3.h" |
34 | #include <kdebug.h> | 34 | #include <kdebug.h> |
35 | 35 | ||
36 | class SyntaxDocument; | 36 | class SyntaxDocument; |
37 | struct syntaxModeListItem; | 37 | struct syntaxModeListItem; |
38 | struct syntaxContextData; | 38 | struct syntaxContextData; |
39 | 39 | ||
40 | class QCheckBox; | 40 | class QCheckBox; |
41 | class QComboBox; | 41 | class QComboBox; |
42 | class QLineEdit; | 42 | class QLineEdit; |
43 | 43 | ||
44 | class TextLine; | 44 | class TextLine; |
45 | class Attribute; | 45 | class Attribute; |
46 | 46 | ||
47 | class HlItem { | 47 | class HlItem { |
48 | public: | 48 | public: |
49 | HlItem(int attribute, int context); | 49 | HlItem(int attribute, int context); |
50 | virtual ~HlItem(); | 50 | virtual ~HlItem(); |
51 | virtual bool startEnable(QChar); | 51 | virtual bool startEnable(QChar); |
52 | virtual const QChar *checkHgl(const QChar *, int len, bool) = 0; | 52 | virtual const QChar *checkHgl(const QChar *, int len, bool) = 0; |
53 | QList<HlItem> *subItems; | 53 | QList<HlItem> *subItems; |
54 | int attr; | 54 | int attr; |
55 | int ctx; | 55 | int ctx; |
56 | }; | 56 | }; |
57 | 57 | ||
58 | class HlCharDetect : public HlItem { | 58 | class HlCharDetect : public HlItem { |
59 | public: | 59 | public: |
60 | HlCharDetect(int attribute, int context, QChar); | 60 | HlCharDetect(int attribute, int context, QChar); |
61 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 61 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
62 | protected: | 62 | protected: |
63 | QChar sChar; | 63 | QChar sChar; |
64 | }; | 64 | }; |
65 | 65 | ||
66 | class Hl2CharDetect : public HlItem { | 66 | class Hl2CharDetect : public HlItem { |
67 | public: | 67 | public: |
68 | Hl2CharDetect(int attribute, int context, QChar ch1, QChar ch2); | 68 | Hl2CharDetect(int attribute, int context, QChar ch1, QChar ch2); |
69 | Hl2CharDetect(int attribute, int context, const QChar *ch); | 69 | Hl2CharDetect(int attribute, int context, const QChar *ch); |
70 | 70 | ||
71 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 71 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
72 | protected: | 72 | protected: |
73 | QChar sChar1; | 73 | QChar sChar1; |
74 | QChar sChar2; | 74 | QChar sChar2; |
75 | }; | 75 | }; |
76 | 76 | ||
77 | class HlStringDetect : public HlItem { | 77 | class HlStringDetect : public HlItem { |
78 | public: | 78 | public: |
79 | HlStringDetect(int attribute, int context, const QString &, bool inSensitive=false); | 79 | HlStringDetect(int attribute, int context, const QString &, bool inSensitive=false); |
80 | virtual ~HlStringDetect(); | 80 | virtual ~HlStringDetect(); |
81 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 81 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
82 | protected: | 82 | protected: |
83 | const QString str; | 83 | const QString str; |
84 | bool _inSensitive; | 84 | bool _inSensitive; |
85 | }; | 85 | }; |
86 | 86 | ||
87 | class HlRangeDetect : public HlItem { | 87 | class HlRangeDetect : public HlItem { |
88 | public: | 88 | public: |
89 | HlRangeDetect(int attribute, int context, QChar ch1, QChar ch2); | 89 | HlRangeDetect(int attribute, int context, QChar ch1, QChar ch2); |
90 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 90 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
91 | protected: | 91 | protected: |
92 | QChar sChar1; | 92 | QChar sChar1; |
93 | QChar sChar2; | 93 | QChar sChar2; |
94 | }; | 94 | }; |
95 | 95 | ||
96 | class HlKeyword : public HlItem | 96 | class HlKeyword : public HlItem |
97 | { | 97 | { |
98 | public: | 98 | public: |
99 | HlKeyword(int attribute, int context,bool casesensitive, const QChar *deliminator, uint deliLen); | 99 | HlKeyword(int attribute, int context,bool casesensitive, const QChar *deliminator, uint deliLen); |
100 | virtual ~HlKeyword(); | 100 | virtual ~HlKeyword(); |
101 | 101 | ||
102 | virtual void addWord(const QString &); | 102 | virtual void addWord(const QString &); |
103 | virtual void addList(const QStringList &); | 103 | virtual void addList(const QStringList &); |
104 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 104 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
105 | QStringList getList() { return words;}; | 105 | QStringList getList() { return words;}; |
106 | virtual bool startEnable(QChar c); | 106 | virtual bool startEnable(QChar c); |
107 | 107 | ||
108 | protected: | 108 | protected: |
109 | QStringList words; | 109 | QStringList words; |
110 | QDict<bool> dict; | 110 | QDict<bool> dict; |
111 | bool _caseSensitive; | 111 | bool _caseSensitive; |
112 | const QChar *deliminatorChars; | 112 | const QChar *deliminatorChars; |
113 | uint deliminatorLen; | 113 | uint deliminatorLen; |
114 | }; | 114 | }; |
115 | 115 | ||
116 | class HlPHex : public HlItem { | 116 | class HlPHex : public HlItem { |
117 | public: | 117 | public: |
118 | HlPHex(int attribute,int context); | 118 | HlPHex(int attribute,int context); |
119 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 119 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
120 | }; | 120 | }; |
121 | class HlInt : public HlItem { | 121 | class HlInt : public HlItem { |
122 | public: | 122 | public: |
123 | HlInt(int attribute, int context); | 123 | HlInt(int attribute, int context); |
124 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 124 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
125 | }; | 125 | }; |
126 | 126 | ||
127 | class HlFloat : public HlItem { | 127 | class HlFloat : public HlItem { |
128 | public: | 128 | public: |
129 | HlFloat(int attribute, int context); | 129 | HlFloat(int attribute, int context); |
130 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 130 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
131 | }; | 131 | }; |
132 | 132 | ||
133 | class HlCInt : public HlInt { | 133 | class HlCInt : public HlInt { |
134 | public: | 134 | public: |
135 | HlCInt(int attribute, int context); | 135 | HlCInt(int attribute, int context); |
136 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 136 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
137 | }; | 137 | }; |
138 | 138 | ||
139 | class HlCOct : public HlItem { | 139 | class HlCOct : public HlItem { |
140 | public: | 140 | public: |
141 | HlCOct(int attribute, int context); | 141 | HlCOct(int attribute, int context); |
142 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 142 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
143 | }; | 143 | }; |
144 | 144 | ||
145 | class HlCHex : public HlItem { | 145 | class HlCHex : public HlItem { |
146 | public: | 146 | public: |
147 | HlCHex(int attribute, int context); | 147 | HlCHex(int attribute, int context); |
148 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 148 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
149 | }; | 149 | }; |
150 | 150 | ||
151 | class HlCFloat : public HlFloat { | 151 | class HlCFloat : public HlFloat { |
152 | public: | 152 | public: |
153 | HlCFloat(int attribute, int context); | 153 | HlCFloat(int attribute, int context); |
154 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 154 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
155 | }; | 155 | }; |
156 | 156 | ||
157 | class HlLineContinue : public HlItem { | 157 | class HlLineContinue : public HlItem { |
158 | public: | 158 | public: |
159 | HlLineContinue(int attribute, int context); | 159 | HlLineContinue(int attribute, int context); |
160 | virtual bool endEnable(QChar c) {return c == '\0';} | 160 | virtual bool endEnable(QChar c) {return c == '\0';} |
161 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 161 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
162 | }; | 162 | }; |
163 | 163 | ||
164 | class HlCStringChar : public HlItem { | 164 | class HlCStringChar : public HlItem { |
165 | public: | 165 | public: |
166 | HlCStringChar(int attribute, int context); | 166 | HlCStringChar(int attribute, int context); |
167 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 167 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
168 | }; | 168 | }; |
169 | 169 | ||
170 | class HlCChar : public HlItem { | 170 | class HlCChar : public HlItem { |
171 | public: | 171 | public: |
172 | HlCChar(int attribute, int context); | 172 | HlCChar(int attribute, int context); |
173 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 173 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
174 | }; | 174 | }; |
175 | 175 | ||
176 | class HlAnyChar : public HlItem { | 176 | class HlAnyChar : public HlItem { |
177 | public: | 177 | public: |
178 | HlAnyChar(int attribute, int context, const QChar* charList, uint len); | 178 | HlAnyChar(int attribute, int context, const QChar* charList, uint len); |
179 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 179 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
180 | const QChar* _charList; | 180 | const QChar* _charList; |
181 | uint _charListLen; | 181 | uint _charListLen; |
182 | }; | 182 | }; |
183 | 183 | ||
184 | class HlRegExpr : public HlItem { | 184 | class HlRegExpr : public HlItem { |
185 | public: | 185 | public: |
186 | HlRegExpr(int attribute, int context,QString expr); | 186 | HlRegExpr(int attribute, int context,QString expr); |
187 | ~HlRegExpr(){delete Expr;}; | 187 | ~HlRegExpr(){delete Expr;}; |
188 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 188 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
189 | QRegExp3 *Expr; | 189 | QRegExp3 *Expr; |
190 | bool handlesLinestart; | 190 | bool handlesLinestart; |
191 | }; | 191 | }; |
192 | 192 | ||
193 | //-------- | 193 | //-------- |
194 | 194 | ||
195 | 195 | ||
196 | //Item Style: color, selected color, bold, italic | 196 | //Item Style: color, selected color, bold, italic |
197 | class ItemStyle { | 197 | class ItemStyle { |
198 | public: | 198 | public: |
199 | ItemStyle(); | 199 | ItemStyle(); |
200 | // ItemStyle(const ItemStyle &); | 200 | // ItemStyle(const ItemStyle &); |
201 | ItemStyle(const QColor &, const QColor &, bool bold, bool italic); | 201 | ItemStyle(const QColor &, const QColor &, bool bold, bool italic); |
202 | ItemStyle(ItemStyle *its){col=its->col;selCol=its->selCol; bold=its->bold; italic=its->italic;} | 202 | ItemStyle(ItemStyle *its){col=its->col;selCol=its->selCol; bold=its->bold; italic=its->italic;} |
203 | // void setData(const ItemStyle &); | 203 | // void setData(const ItemStyle &); |
204 | QColor col; | 204 | QColor col; |
205 | QColor selCol; | 205 | QColor selCol; |
206 | int bold; //boolean value | 206 | int bold; //boolean value |
207 | int italic; //boolean value | 207 | int italic; //boolean value |
208 | }; | 208 | }; |
209 | 209 | ||
210 | typedef QList<ItemStyle> ItemStyleList; | 210 | typedef QList<ItemStyle> ItemStyleList; |
211 | 211 | ||
212 | //Item Properties: name, Item Style, Item Font | 212 | //Item Properties: name, Item Style, Item Font |
213 | class ItemData : public ItemStyle { | 213 | class ItemData : public ItemStyle { |
214 | public: | 214 | public: |
215 | ItemData(const QString name, int defStyleNum); | 215 | ItemData(const QString name, int defStyleNum); |
216 | ItemData(const QString name, int defStyleNum, | 216 | ItemData(const QString name, int defStyleNum, |
217 | const QColor&, const QColor&, bool bold, bool italic); | 217 | const QColor&, const QColor&, bool bold, bool italic); |
218 | ItemData(ItemData | 218 | ItemData(ItemData |
219 | *itd):ItemStyle((ItemStyle*)itd),name(itd->name),defStyleNum(itd->defStyleNum),defStyle(itd->defStyle){;} | 219 | *itd):ItemStyle((ItemStyle*)itd),name(itd->name),defStyleNum(itd->defStyleNum),defStyle(itd->defStyle){;} |
220 | const QString name; | 220 | const QString name; |
221 | int defStyleNum; | 221 | int defStyleNum; |
222 | int defStyle; //boolean value | 222 | int defStyle; //boolean value |
223 | }; | 223 | }; |
224 | 224 | ||
225 | typedef QList<ItemData> ItemDataList; | 225 | typedef QList<ItemData> ItemDataList; |
226 | 226 | ||
227 | class HlData { | 227 | class HlData { |
228 | public: | 228 | public: |
229 | HlData(const QString &wildcards, const QString &mimetypes,const QString &identifier); | 229 | HlData(const QString &wildcards, const QString &mimetypes,const QString &identifier); |
230 | ItemDataList itemDataList; | 230 | ItemDataList itemDataList; |
231 | QString wildcards; | 231 | QString wildcards; |
232 | QString mimetypes; | 232 | QString mimetypes; |
233 | QString identifier; | 233 | QString identifier; |
234 | }; | 234 | }; |
235 | 235 | ||
236 | typedef QList<HlData> HlDataList; | 236 | typedef QList<HlData> HlDataList; |
237 | 237 | ||
238 | class HlManager; | 238 | class HlManager; |
239 | class KConfig; | 239 | class KateConfig; |
240 | 240 | ||
241 | //context | 241 | //context |
242 | class HlContext { | 242 | class HlContext { |
243 | public: | 243 | public: |
244 | HlContext(int attribute, int lineEndContext,int _lineBeginContext); | 244 | HlContext(int attribute, int lineEndContext,int _lineBeginContext); |
245 | QList<HlItem> items; | 245 | QList<HlItem> items; |
246 | int attr; | 246 | int attr; |
247 | int ctx; | 247 | int ctx; |
248 | int lineBeginContext; | 248 | int lineBeginContext; |
249 | }; | 249 | }; |
250 | 250 | ||
251 | class Highlight | 251 | class Highlight |
252 | { | 252 | { |
253 | friend class HlManager; | 253 | friend class HlManager; |
254 | 254 | ||
255 | public: | 255 | public: |
256 | Highlight(syntaxModeListItem *def); | 256 | Highlight(syntaxModeListItem *def); |
257 | ~Highlight(); | 257 | ~Highlight(); |
258 | 258 | ||
259 | int doHighlight(int ctxNum, TextLine *); | 259 | int doHighlight(int ctxNum, TextLine *); |
260 | 260 | ||
261 | KConfig *getKConfig(); | 261 | KateConfig *getKateConfig(); |
262 | QString getWildcards(); | 262 | QString getWildcards(); |
263 | QString getMimetypes(); | 263 | QString getMimetypes(); |
264 | HlData *getData(); | 264 | HlData *getData(); |
265 | void setData(HlData *); | 265 | void setData(HlData *); |
266 | void getItemDataList(ItemDataList &); | 266 | void getItemDataList(ItemDataList &); |
267 | void getItemDataList(ItemDataList &, KConfig *); | 267 | void getItemDataList(ItemDataList &, KateConfig *); |
268 | void setItemDataList(ItemDataList &, KConfig *); | 268 | void setItemDataList(ItemDataList &, KateConfig *); |
269 | QString name() {return iName;} | 269 | QString name() {return iName;} |
270 | QString section() {return iSection;} | 270 | QString section() {return iSection;} |
271 | void use(); | 271 | void use(); |
272 | void release(); | 272 | void release(); |
273 | bool isInWord(QChar c); | 273 | bool isInWord(QChar c); |
274 | 274 | ||
275 | QString getCommentStart() {return cmlStart;}; | 275 | QString getCommentStart() {return cmlStart;}; |
276 | QString getCommentEnd() {return cmlEnd;}; | 276 | QString getCommentEnd() {return cmlEnd;}; |
277 | QString getCommentSingleLineStart() { return cslStart;}; | 277 | QString getCommentSingleLineStart() { return cslStart;}; |
278 | 278 | ||
279 | protected: | 279 | protected: |
280 | void init(); | 280 | void init(); |
281 | void done(); | 281 | void done(); |
282 | void makeContextList (); | 282 | void makeContextList (); |
283 | void createItemData (ItemDataList &list); | 283 | void createItemData (ItemDataList &list); |
284 | void readGlobalKeywordConfig(); | 284 | void readGlobalKeywordConfig(); |
285 | void readCommentConfig(); | 285 | void readCommentConfig(); |
286 | HlItem *createHlItem(struct syntaxContextData *data, ItemDataList &iDl); | 286 | HlItem *createHlItem(struct syntaxContextData *data, ItemDataList &iDl); |
287 | int lookupAttrName(const QString& name, ItemDataList &iDl); | 287 | int lookupAttrName(const QString& name, ItemDataList &iDl); |
288 | ItemDataList internalIDList; | 288 | ItemDataList internalIDList; |
289 | static const int nContexts = 32; | 289 | static const int nContexts = 32; |
290 | HlContext *contextList[nContexts]; | 290 | HlContext *contextList[nContexts]; |
291 | 291 | ||
292 | bool noHl; | 292 | bool noHl; |
293 | bool casesensitive; | 293 | bool casesensitive; |
294 | QString weakDeliminator; | 294 | QString weakDeliminator; |
295 | QString deliminator; | 295 | QString deliminator; |
296 | const QChar *deliminatorChars; | 296 | const QChar *deliminatorChars; |
297 | uint deliminatorLen; | 297 | uint deliminatorLen; |
298 | QString cmlStart; | 298 | QString cmlStart; |
299 | QString cmlEnd; | 299 | QString cmlEnd; |
300 | QString cslStart; | 300 | QString cslStart; |
301 | QString iName; | 301 | QString iName; |
302 | QString iSection; | 302 | QString iSection; |
303 | QString iWildcards; | 303 | QString iWildcards; |
304 | QString iMimetypes; | 304 | QString iMimetypes; |
305 | QString identifier; | 305 | QString identifier; |
306 | int refCount; | 306 | int refCount; |
307 | }; | 307 | }; |
308 | 308 | ||
309 | class HlManager : public QObject { | 309 | class HlManager : public QObject { |
310 | Q_OBJECT | 310 | Q_OBJECT |
311 | public: | 311 | public: |
312 | HlManager(); | 312 | HlManager(); |
313 | ~HlManager(); | 313 | ~HlManager(); |
314 | 314 | ||
315 | static HlManager *self(); | 315 | static HlManager *self(); |
316 | 316 | ||
317 | Highlight *getHl(int n); | 317 | Highlight *getHl(int n); |
318 | int defaultHl(); | 318 | int defaultHl(); |
319 | int nameFind(const QString &name); | 319 | int nameFind(const QString &name); |
320 | 320 | ||
321 | int wildcardFind(const QString &fileName); | 321 | int wildcardFind(const QString &fileName); |
322 | int findHl(Highlight *h) {return hlList.find(h);} | 322 | int findHl(Highlight *h) {return hlList.find(h);} |
323 | 323 | ||
324 | int makeAttribs(Highlight *, Attribute *, int maxAttribs); | 324 | int makeAttribs(Highlight *, Attribute *, int maxAttribs); |
325 | 325 | ||
326 | int defaultStyles(); | 326 | int defaultStyles(); |
327 | QString defaultStyleName(int n); | 327 | QString defaultStyleName(int n); |
328 | void getDefaults(ItemStyleList &); | 328 | void getDefaults(ItemStyleList &); |
329 | void setDefaults(ItemStyleList &); | 329 | void setDefaults(ItemStyleList &); |
330 | 330 | ||
331 | int highlights(); | 331 | int highlights(); |
332 | QString hlName(int n); | 332 | QString hlName(int n); |
333 | QString hlSection(int n); | 333 | QString hlSection(int n); |
334 | void getHlDataList(HlDataList &); | 334 | void getHlDataList(HlDataList &); |
335 | void setHlDataList(HlDataList &); | 335 | void setHlDataList(HlDataList &); |
336 | 336 | ||
337 | SyntaxDocument *syntax; | 337 | SyntaxDocument *syntax; |
338 | 338 | ||
339 | signals: | 339 | signals: |
340 | void changed(); | 340 | void changed(); |
341 | protected: | 341 | protected: |
342 | QList<Highlight> hlList; | 342 | QList<Highlight> hlList; |
343 | static HlManager *s_pSelf; | 343 | static HlManager *s_pSelf; |
344 | }; | 344 | }; |
345 | 345 | ||
346 | 346 | ||
347 | 347 | ||
348 | 348 | ||
349 | #endif //_HIGHLIGHT_H_ | 349 | #endif //_HIGHLIGHT_H_ |
diff --git a/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp b/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp index e45daa4..844f27d 100644 --- a/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp +++ b/noncore/apps/tinykate/libkate/document/katesyntaxdocument.cpp | |||
@@ -1,311 +1,305 @@ | |||
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 <kateconfig.h> | ||
19 | #include <qfile.h> | 20 | #include <qfile.h> |
20 | #include <kdebug.h> | 21 | #include <kdebug.h> |
21 | #include <kstddirs.h> | 22 | #include <kstddirs.h> |
22 | #include <klocale.h> | 23 | #include <klocale.h> |
23 | #include <kmessagebox.h> | 24 | #include <kmessagebox.h> |
24 | #include <qstringlist.h> | 25 | #include <qstringlist.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 | KateConfig *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 | |||
67 | if ((config->hasGroup(Group)) && (!force)) | 66 | if ((config->hasGroup(Group)) && (!force)) |
68 | { | 67 | { |
69 | config->setGroup(Group); | 68 | config->setGroup(Group); |
70 | syntaxModeListItem *mli=new syntaxModeListItem; | 69 | syntaxModeListItem *mli=new syntaxModeListItem; |
71 | mli->name = config->readEntry("name",""); | 70 | mli->name = config->readEntry("name",""); |
72 | mli->section = config->readEntry("section",""); | 71 | mli->section = config->readEntry("section",""); |
73 | mli->mimetype = config->readEntry("mimetype",""); | 72 | mli->mimetype = config->readEntry("mimetype",""); |
74 | mli->extension = config->readEntry("extension",""); | 73 | mli->extension = config->readEntry("extension",""); |
75 | mli->identifier = *it; | 74 | mli->identifier = *it; |
76 | myModeList.append(mli); | 75 | myModeList.append(mli); |
77 | } | 76 | } |
78 | else | 77 | else |
79 | { | 78 | { |
80 | qDebug("Found a description file:"+path+(*it)); | 79 | qDebug("Found a description file:"+path+(*it)); |
81 | setIdentifier(path+(*it)); | 80 | setIdentifier(path+(*it)); |
82 | Opie::XMLElement *e=m_root; | 81 | Opie::XMLElement *e=m_root; |
83 | if (e) | 82 | if (e) |
84 | { | 83 | { |
85 | e=e->firstChild(); | 84 | e=e->firstChild(); |
86 | qDebug(e->tagName()); | 85 | qDebug(e->tagName()); |
87 | if (e->tagName()=="language") | 86 | if (e->tagName()=="language") |
88 | { | 87 | { |
89 | syntaxModeListItem *mli=new syntaxModeListItem; | 88 | syntaxModeListItem *mli=new syntaxModeListItem; |
90 | mli->name = e->attribute("name"); | 89 | mli->name = e->attribute("name"); |
91 | mli->section = e->attribute("section"); | 90 | mli->section = e->attribute("section"); |
92 | mli->mimetype = e->attribute("mimetype"); | 91 | mli->mimetype = e->attribute("mimetype"); |
93 | mli->extension = e->attribute("extensions"); | 92 | mli->extension = e->attribute("extensions"); |
94 | qDebug(QString("valid description for: %1/%2").arg(mli->section).arg(mli->name)); | 93 | qDebug(QString("valid description for: %1/%2").arg(mli->section).arg(mli->name)); |
95 | if (mli->section.isEmpty()) | 94 | if (mli->section.isEmpty()) |
96 | mli->section=i18n("Other"); | 95 | mli->section=i18n("Other"); |
97 | 96 | ||
98 | mli->identifier = path+(*it); | 97 | mli->identifier = path+(*it); |
99 | #warning fixme | ||
100 | /* | ||
101 | config->setGroup(Group); | 98 | config->setGroup(Group); |
102 | config->writeEntry("name",mli->name); | 99 | config->writeEntry("name",mli->name); |
103 | config->writeEntry("section",mli->section); | 100 | config->writeEntry("section",mli->section); |
104 | config->writeEntry("mimetype",mli->mimetype); | 101 | config->writeEntry("mimetype",mli->mimetype); |
105 | config->writeEntry("extension",mli->extension); | 102 | config->writeEntry("extension",mli->extension); |
106 | */ | ||
107 | myModeList.append(mli); | 103 | myModeList.append(mli); |
108 | } | 104 | } |
109 | } | 105 | } |
110 | } | ||
111 | } | 106 | } |
112 | // } | 107 | } |
113 | |||
114 | // config->sync(); | 108 | // config->sync(); |
115 | } | 109 | } |
116 | 110 | ||
117 | SyntaxModeList SyntaxDocument::modeList() | 111 | SyntaxModeList SyntaxDocument::modeList() |
118 | { | 112 | { |
119 | return myModeList; | 113 | return myModeList; |
120 | } | 114 | } |
121 | 115 | ||
122 | bool SyntaxDocument::nextGroup( syntaxContextData* data) | 116 | bool SyntaxDocument::nextGroup( syntaxContextData* data) |
123 | { | 117 | { |
124 | if(!data) return false; | 118 | if(!data) return false; |
125 | 119 | ||
126 | if (!data->currentGroup) | 120 | if (!data->currentGroup) |
127 | data->currentGroup=data->parent->firstChild(); | 121 | data->currentGroup=data->parent->firstChild(); |
128 | else | 122 | else |
129 | data->currentGroup=data->currentGroup->nextChild(); | 123 | data->currentGroup=data->currentGroup->nextChild(); |
130 | 124 | ||
131 | data->item=0; | 125 | data->item=0; |
132 | 126 | ||
133 | if (!data->currentGroup) | 127 | if (!data->currentGroup) |
134 | return false; | 128 | return false; |
135 | else | 129 | else |
136 | return true; | 130 | return true; |
137 | } | 131 | } |
138 | 132 | ||
139 | bool SyntaxDocument::nextItem( syntaxContextData* data) | 133 | bool SyntaxDocument::nextItem( syntaxContextData* data) |
140 | { | 134 | { |
141 | if(!data) return false; | 135 | if(!data) return false; |
142 | 136 | ||
143 | if (!data->item) | 137 | if (!data->item) |
144 | data->item=data->currentGroup->firstChild(); | 138 | data->item=data->currentGroup->firstChild(); |
145 | else | 139 | else |
146 | data->item=data->item->nextChild(); | 140 | data->item=data->item->nextChild(); |
147 | 141 | ||
148 | if (!data->item) | 142 | if (!data->item) |
149 | return false; | 143 | return false; |
150 | else | 144 | else |
151 | return true; | 145 | return true; |
152 | } | 146 | } |
153 | 147 | ||
154 | QString SyntaxDocument::groupItemData( syntaxContextData* data,QString name) | 148 | QString SyntaxDocument::groupItemData( syntaxContextData* data,QString name) |
155 | { | 149 | { |
156 | if(!data) | 150 | if(!data) |
157 | return QString::null; | 151 | return QString::null; |
158 | 152 | ||
159 | if ( (data->item) && (name.isEmpty())) | 153 | if ( (data->item) && (name.isEmpty())) |
160 | return data->item->tagName(); | 154 | return data->item->tagName(); |
161 | 155 | ||
162 | if (data->item) | 156 | if (data->item) |
163 | return data->item->attribute(name); | 157 | return data->item->attribute(name); |
164 | else | 158 | else |
165 | return QString(); | 159 | return QString(); |
166 | } | 160 | } |
167 | 161 | ||
168 | QString SyntaxDocument::groupData( syntaxContextData* data,QString name) | 162 | QString SyntaxDocument::groupData( syntaxContextData* data,QString name) |
169 | { | 163 | { |
170 | if(!data) | 164 | if(!data) |
171 | return QString::null; | 165 | return QString::null; |
172 | 166 | ||
173 | if (data->currentGroup) | 167 | if (data->currentGroup) |
174 | return data->currentGroup->attribute(name); | 168 | return data->currentGroup->attribute(name); |
175 | else | 169 | else |
176 | return QString(); | 170 | return QString(); |
177 | } | 171 | } |
178 | 172 | ||
179 | void SyntaxDocument::freeGroupInfo( syntaxContextData* data) | 173 | void SyntaxDocument::freeGroupInfo( syntaxContextData* data) |
180 | { | 174 | { |
181 | if (data) | 175 | if (data) |
182 | delete data; | 176 | delete data; |
183 | } | 177 | } |
184 | 178 | ||
185 | syntaxContextData* SyntaxDocument::getSubItems(syntaxContextData* data) | 179 | syntaxContextData* SyntaxDocument::getSubItems(syntaxContextData* data) |
186 | { | 180 | { |
187 | syntaxContextData *retval=new syntaxContextData; | 181 | syntaxContextData *retval=new syntaxContextData; |
188 | retval->parent=0; | 182 | retval->parent=0; |
189 | retval->currentGroup=0; | 183 | retval->currentGroup=0; |
190 | retval->item=0; | 184 | retval->item=0; |
191 | if (data != 0) | 185 | if (data != 0) |
192 | { | 186 | { |
193 | retval->parent=data->currentGroup; | 187 | retval->parent=data->currentGroup; |
194 | retval->currentGroup=data->item; | 188 | retval->currentGroup=data->item; |
195 | retval->item=0; | 189 | retval->item=0; |
196 | } | 190 | } |
197 | 191 | ||
198 | return retval; | 192 | return retval; |
199 | } | 193 | } |
200 | 194 | ||
201 | syntaxContextData* SyntaxDocument::getConfig(const QString& mainGroupName, const QString &Config) | 195 | syntaxContextData* SyntaxDocument::getConfig(const QString& mainGroupName, const QString &Config) |
202 | { | 196 | { |
203 | Opie::XMLElement *e = m_root->firstChild()->firstChild(); | 197 | Opie::XMLElement *e = m_root->firstChild()->firstChild(); |
204 | 198 | ||
205 | while (e) | 199 | while (e) |
206 | { | 200 | { |
207 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl; | 201 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl; |
208 | 202 | ||
209 | if (e->tagName().compare(mainGroupName)==0 ) | 203 | if (e->tagName().compare(mainGroupName)==0 ) |
210 | { | 204 | { |
211 | Opie::XMLElement *e1=e->firstChild(); | 205 | Opie::XMLElement *e1=e->firstChild(); |
212 | 206 | ||
213 | while (e1) | 207 | while (e1) |
214 | { | 208 | { |
215 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl; | 209 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl; |
216 | 210 | ||
217 | if (e1->tagName()==Config) | 211 | if (e1->tagName()==Config) |
218 | { | 212 | { |
219 | syntaxContextData *data=new ( syntaxContextData); | 213 | syntaxContextData *data=new ( syntaxContextData); |
220 | data->currentGroup=0; | 214 | data->currentGroup=0; |
221 | data->parent=0; | 215 | data->parent=0; |
222 | data->item=e1; | 216 | data->item=e1; |
223 | return data; | 217 | return data; |
224 | } | 218 | } |
225 | 219 | ||
226 | e1=e1->nextChild(); | 220 | e1=e1->nextChild(); |
227 | } | 221 | } |
228 | 222 | ||
229 | kdDebug(13010) << "WARNING :returning null 3"<< endl; | 223 | kdDebug(13010) << "WARNING :returning null 3"<< endl; |
230 | return 0; | 224 | return 0; |
231 | } | 225 | } |
232 | 226 | ||
233 | e=e->nextChild(); | 227 | e=e->nextChild(); |
234 | } | 228 | } |
235 | 229 | ||
236 | kdDebug(13010) << "WARNING :returning null 4" << endl; | 230 | kdDebug(13010) << "WARNING :returning null 4" << endl; |
237 | return 0; | 231 | return 0; |
238 | } | 232 | } |
239 | 233 | ||
240 | 234 | ||
241 | 235 | ||
242 | syntaxContextData* SyntaxDocument::getGroupInfo(const QString& mainGroupName, const QString &group) | 236 | syntaxContextData* SyntaxDocument::getGroupInfo(const QString& mainGroupName, const QString &group) |
243 | { | 237 | { |
244 | 238 | ||
245 | Opie::XMLElement *e=m_root->firstChild()->firstChild(); | 239 | Opie::XMLElement *e=m_root->firstChild()->firstChild(); |
246 | 240 | ||
247 | while (e) | 241 | while (e) |
248 | { | 242 | { |
249 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl; | 243 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl; |
250 | 244 | ||
251 | if (e->tagName().compare(mainGroupName)==0 ) | 245 | if (e->tagName().compare(mainGroupName)==0 ) |
252 | { | 246 | { |
253 | Opie::XMLElement *e1=e->firstChild(); | 247 | Opie::XMLElement *e1=e->firstChild(); |
254 | 248 | ||
255 | while (e1) | 249 | while (e1) |
256 | { | 250 | { |
257 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl; | 251 | kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl; |
258 | if (e1->tagName()==group+"s") | 252 | if (e1->tagName()==group+"s") |
259 | { | 253 | { |
260 | syntaxContextData *data=new ( syntaxContextData); | 254 | syntaxContextData *data=new ( syntaxContextData); |
261 | data->parent=e1; | 255 | data->parent=e1; |
262 | data->currentGroup=0; | 256 | data->currentGroup=0; |
263 | data->item=0; | 257 | data->item=0; |
264 | return data; | 258 | return data; |
265 | } | 259 | } |
266 | 260 | ||
267 | e1=e1->nextChild(); | 261 | e1=e1->nextChild(); |
268 | } | 262 | } |
269 | 263 | ||
270 | kdDebug(13010) << "WARNING : getGroupInfo returning null :1 " << endl; | 264 | kdDebug(13010) << "WARNING : getGroupInfo returning null :1 " << endl; |
271 | return 0; | 265 | return 0; |
272 | } | 266 | } |
273 | 267 | ||
274 | e=e->nextChild(); | 268 | e=e->nextChild(); |
275 | } | 269 | } |
276 | 270 | ||
277 | kdDebug(13010) << "WARNING : getGroupInfo returning null :2" << endl; | 271 | kdDebug(13010) << "WARNING : getGroupInfo returning null :2" << endl; |
278 | return 0; | 272 | return 0; |
279 | } | 273 | } |
280 | 274 | ||
281 | 275 | ||
282 | QStringList& SyntaxDocument::finddata(const QString& mainGroup,const QString& type,bool clearList) | 276 | QStringList& SyntaxDocument::finddata(const QString& mainGroup,const QString& type,bool clearList) |
283 | { | 277 | { |
284 | Opie::XMLElement *e = m_root->firstChild(); | 278 | Opie::XMLElement *e = m_root->firstChild(); |
285 | if (clearList) | 279 | if (clearList) |
286 | m_data.clear(); | 280 | m_data.clear(); |
287 | 281 | ||
288 | for(e=e->firstChild(); e; e=e->nextChild()) | 282 | for(e=e->firstChild(); e; e=e->nextChild()) |
289 | { | 283 | { |
290 | if (e->tagName()==mainGroup) | 284 | if (e->tagName()==mainGroup) |
291 | { | 285 | { |
292 | for (Opie::XMLElement *e1=e->firstChild();e1;e1=e1->nextChild()) | 286 | for (Opie::XMLElement *e1=e->firstChild();e1;e1=e1->nextChild()) |
293 | { | 287 | { |
294 | if (e1->tagName()!="list") continue; | 288 | if (e1->tagName()!="list") continue; |
295 | 289 | ||
296 | if (e1->attribute("name")==type) | 290 | if (e1->attribute("name")==type) |
297 | { | 291 | { |
298 | for (Opie::XMLElement *e2=e1->firstChild();e2;e2=e2->nextChild()) | 292 | for (Opie::XMLElement *e2=e1->firstChild();e2;e2=e2->nextChild()) |
299 | { | 293 | { |
300 | qDebug("FOUND A LIST ENTRY("+e2->tagName()+"):"+e2->firstChild()->value()); | 294 | qDebug("FOUND A LIST ENTRY("+e2->tagName()+"):"+e2->firstChild()->value()); |
301 | m_data+=e2->firstChild()->value().stripWhiteSpace(); | 295 | m_data+=e2->firstChild()->value().stripWhiteSpace(); |
302 | } | 296 | } |
303 | break; | 297 | break; |
304 | } | 298 | } |
305 | } | 299 | } |
306 | break; | 300 | break; |
307 | } | 301 | } |
308 | } | 302 | } |
309 | 303 | ||
310 | return m_data; | 304 | return m_data; |
311 | } | 305 | } |
diff --git a/noncore/apps/tinykate/libkate/interfaces/document.h b/noncore/apps/tinykate/libkate/interfaces/document.h index cbfd1b3..af885f1 100644 --- a/noncore/apps/tinykate/libkate/interfaces/document.h +++ b/noncore/apps/tinykate/libkate/interfaces/document.h | |||
@@ -1,103 +1,103 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | document.h - description | 2 | document.h - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Jan 15 2001 | 4 | begin : Mon Jan 15 2001 |
5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann | 5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann |
6 | (C) 2002 by Joseph Wenninger | 6 | (C) 2002 by Joseph Wenninger |
7 | email : crossfire@babylon2k.de | 7 | email : crossfire@babylon2k.de |
8 | jowenn@kde.org | 8 | jowenn@kde.org |
9 | ***************************************************************************/ | 9 | ***************************************************************************/ |
10 | 10 | ||
11 | /*************************************************************************** | 11 | /*************************************************************************** |
12 | This library is free software; you can redistribute it and/or | 12 | This library is free software; you can redistribute it and/or |
13 | modify it under the terms of the GNU Library General Public | 13 | modify it under the terms of the GNU Library General Public |
14 | License as published by the Free Software Foundation; either | 14 | License as published by the Free Software Foundation; either |
15 | version 2 of the License, or (at your option) any later version. | 15 | version 2 of the License, or (at your option) any later version. |
16 | 16 | ||
17 | This library is distributed in the hope that it will be useful, | 17 | This library is distributed in the hope that it will be useful, |
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 | Library General Public License for more details. | 20 | Library General Public License for more details. |
21 | 21 | ||
22 | You should have received a copy of the GNU Library General Public License | 22 | You should have received a copy of the GNU Library General Public License |
23 | along with this library; see the file COPYING.LIB. If not, write to | 23 | along with this library; see the file COPYING.LIB. If not, write to |
24 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 24 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | ***************************************************************************/ | 26 | ***************************************************************************/ |
27 | 27 | ||
28 | #ifndef _KATE_DOCUMENT_INCLUDE_ | 28 | #ifndef _KATE_DOCUMENT_INCLUDE_ |
29 | #define _KATE_DOCUMENT_INCLUDE_ | 29 | #define _KATE_DOCUMENT_INCLUDE_ |
30 | 30 | ||
31 | #include <ktexteditor.h> | 31 | #include <ktexteditor.h> |
32 | 32 | ||
33 | class KConfig; | 33 | class KateConfig; |
34 | 34 | ||
35 | namespace Kate | 35 | namespace Kate |
36 | { | 36 | { |
37 | 37 | ||
38 | /** internal class for document bookmarks. */ | 38 | /** internal class for document bookmarks. */ |
39 | class Mark | 39 | class Mark |
40 | { | 40 | { |
41 | public: | 41 | public: |
42 | uint line; | 42 | uint line; |
43 | uint type; | 43 | uint type; |
44 | }; | 44 | }; |
45 | 45 | ||
46 | /** This interface provedes access to the Kate Document class. | 46 | /** This interface provedes access to the Kate Document class. |
47 | */ | 47 | */ |
48 | class Document : public KTextEditor::Document | 48 | class Document : public KTextEditor::Document |
49 | { | 49 | { |
50 | Q_OBJECT | 50 | Q_OBJECT |
51 | 51 | ||
52 | public: | 52 | public: |
53 | Document (); | 53 | Document (); |
54 | virtual ~Document (); | 54 | virtual ~Document (); |
55 | 55 | ||
56 | public: | 56 | public: |
57 | /** Read document config. | 57 | /** Read document config. |
58 | */ | 58 | */ |
59 | virtual void readConfig () { ; }; | 59 | virtual void readConfig () { ; }; |
60 | /** Save document config. | 60 | /** Save document config. |
61 | */ | 61 | */ |
62 | virtual void writeConfig () { ; }; | 62 | virtual void writeConfig () { ; }; |
63 | 63 | ||
64 | /** Read document session config. | 64 | /** Read document session config. |
65 | */ | 65 | */ |
66 | virtual void readSessionConfig (KConfig *) { ; }; | 66 | virtual void readSessionConfig (KateConfig *) { ; }; |
67 | /** Save document session config. | 67 | /** Save document session config. |
68 | */ | 68 | */ |
69 | virtual void writeSessionConfig (KConfig *) { ; }; | 69 | virtual void writeSessionConfig (KateConfig *) { ; }; |
70 | 70 | ||
71 | /** Returns the document ID. | 71 | /** Returns the document ID. |
72 | */ | 72 | */ |
73 | virtual uint docID () { return 0L; }; | 73 | virtual uint docID () { return 0L; }; |
74 | 74 | ||
75 | /** Defines possible mark types. A line can have marks of different types. | 75 | /** Defines possible mark types. A line can have marks of different types. |
76 | */ | 76 | */ |
77 | enum marks | 77 | enum marks |
78 | { | 78 | { |
79 | Bookmark = 1, | 79 | Bookmark = 1, |
80 | Breakpoint = 2, | 80 | Breakpoint = 2, |
81 | markType0 = 4, | 81 | markType0 = 4, |
82 | markType1 = 8, | 82 | markType1 = 8, |
83 | markType2 = 16, | 83 | markType2 = 16, |
84 | markType3 = 32, | 84 | markType3 = 32, |
85 | markType4 = 64, | 85 | markType4 = 64, |
86 | markType5 = 128, | 86 | markType5 = 128, |
87 | markType6 = 256, | 87 | markType6 = 256, |
88 | markType7 = 512, | 88 | markType7 = 512, |
89 | markType8 = 1024 | 89 | markType8 = 1024 |
90 | }; | 90 | }; |
91 | 91 | ||
92 | /** A list of all marks in a document. Use binary comparing to find marks of a specific type. | 92 | /** A list of all marks in a document. Use binary comparing to find marks of a specific type. |
93 | */ | 93 | */ |
94 | virtual QList<Mark> marks () { QList<Mark> l; return l; }; | 94 | virtual QList<Mark> marks () { QList<Mark> l; return l; }; |
95 | 95 | ||
96 | public slots: | 96 | public slots: |
97 | // clear buffer/filename - update the views | 97 | // clear buffer/filename - update the views |
98 | virtual void flush () { ; }; | 98 | virtual void flush () { ; }; |
99 | }; | 99 | }; |
100 | 100 | ||
101 | }; | 101 | }; |
102 | 102 | ||
103 | #endif | 103 | #endif |
diff --git a/noncore/apps/tinykate/libkate/interfaces/view.h b/noncore/apps/tinykate/libkate/interfaces/view.h index 5b24bb5..5846395 100644 --- a/noncore/apps/tinykate/libkate/interfaces/view.h +++ b/noncore/apps/tinykate/libkate/interfaces/view.h | |||
@@ -1,160 +1,160 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | view.h - description | 2 | view.h - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Jan 15 2001 | 4 | begin : Mon Jan 15 2001 |
5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann | 5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann |
6 | (C) 2002 by Joseph Wenninger | 6 | (C) 2002 by Joseph Wenninger |
7 | email : crossfire@babylon2k.de | 7 | email : crossfire@babylon2k.de |
8 | jowenn@kde.org | 8 | jowenn@kde.org |
9 | ***************************************************************************/ | 9 | ***************************************************************************/ |
10 | 10 | ||
11 | /*************************************************************************** | 11 | /*************************************************************************** |
12 | This library is free software; you can redistribute it and/or | 12 | This library is free software; you can redistribute it and/or |
13 | modify it under the terms of the GNU Library General Public | 13 | modify it under the terms of the GNU Library General Public |
14 | License as published by the Free Software Foundation; either | 14 | License as published by the Free Software Foundation; either |
15 | version 2 of the License, or (at your option) any later version. | 15 | version 2 of the License, or (at your option) any later version. |
16 | 16 | ||
17 | This library is distributed in the hope that it will be useful, | 17 | This library is distributed in the hope that it will be useful, |
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 | Library General Public License for more details. | 20 | Library General Public License for more details. |
21 | 21 | ||
22 | You should have received a copy of the GNU Library General Public License | 22 | You should have received a copy of the GNU Library General Public License |
23 | along with this library; see the file COPYING.LIB. If not, write to | 23 | along with this library; see the file COPYING.LIB. If not, write to |
24 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 24 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | ***************************************************************************/ | 26 | ***************************************************************************/ |
27 | 27 | ||
28 | #ifndef _KATE_VIEW_INCLUDE_ | 28 | #ifndef _KATE_VIEW_INCLUDE_ |
29 | #define _KATE_VIEW_INCLUDE_ | 29 | #define _KATE_VIEW_INCLUDE_ |
30 | 30 | ||
31 | #include <ktexteditor.h> | 31 | #include <ktexteditor.h> |
32 | 32 | ||
33 | class KConfig; | 33 | class KateConfig; |
34 | 34 | ||
35 | namespace Kate | 35 | namespace Kate |
36 | { | 36 | { |
37 | 37 | ||
38 | class Document; | 38 | class Document; |
39 | class Mark; | 39 | class Mark; |
40 | 40 | ||
41 | /** This interface provides access to the view. | 41 | /** This interface provides access to the view. |
42 | */ | 42 | */ |
43 | class View : public KTextEditor::View | 43 | class View : public KTextEditor::View |
44 | { | 44 | { |
45 | Q_OBJECT | 45 | Q_OBJECT |
46 | 46 | ||
47 | public: | 47 | public: |
48 | View ( KTextEditor::Document *doc, QWidget *parent, const char *name = 0 ); | 48 | View ( KTextEditor::Document *doc, QWidget *parent, const char *name = 0 ); |
49 | virtual ~View (); | 49 | virtual ~View (); |
50 | 50 | ||
51 | /** Returns a pointer to the document of the view. | 51 | /** Returns a pointer to the document of the view. |
52 | */ | 52 | */ |
53 | virtual Document *getDoc () { return 0L; }; | 53 | virtual Document *getDoc () { return 0L; }; |
54 | 54 | ||
55 | /** Returns the marked text in the view. | 55 | /** Returns the marked text in the view. |
56 | */ | 56 | */ |
57 | virtual QString markedText () { return 0L; }; | 57 | virtual QString markedText () { return 0L; }; |
58 | 58 | ||
59 | public slots: | 59 | public slots: |
60 | /** popup a config dialog for the editor part. | 60 | /** popup a config dialog for the editor part. |
61 | */ | 61 | */ |
62 | virtual void configDialog () { ; }; | 62 | virtual void configDialog () { ; }; |
63 | 63 | ||
64 | // Highlighting slots | 64 | // Highlighting slots |
65 | virtual void setHl (int) { ; }; | 65 | virtual void setHl (int) { ; }; |
66 | virtual int getHl () { return 0; }; | 66 | virtual int getHl () { return 0; }; |
67 | virtual int getHlCount () { return 0; }; | 67 | virtual int getHlCount () { return 0; }; |
68 | virtual QString getHlName (int) { return 0L; }; | 68 | virtual QString getHlName (int) { return 0L; }; |
69 | virtual QString getHlSection (int) { return 0L; }; | 69 | virtual QString getHlSection (int) { return 0L; }; |
70 | 70 | ||
71 | // undo/redo stuff | 71 | // undo/redo stuff |
72 | virtual void undo () { ; }; | 72 | virtual void undo () { ; }; |
73 | virtual void redo () { ; }; | 73 | virtual void redo () { ; }; |
74 | virtual void undoHistory() { ; }; | 74 | virtual void undoHistory() { ; }; |
75 | 75 | ||
76 | public: | 76 | public: |
77 | // read/save config of the view | 77 | // read/save config of the view |
78 | virtual void readConfig () { ; }; | 78 | virtual void readConfig () { ; }; |
79 | virtual void writeConfig () { ; }; | 79 | virtual void writeConfig () { ; }; |
80 | 80 | ||
81 | // read/save sessionconfig of the view | 81 | // read/save sessionconfig of the view |
82 | virtual void readSessionConfig (KConfig *) { ; }; | 82 | virtual void readSessionConfig (KateConfig *) { ; }; |
83 | virtual void writeSessionConfig (KConfig *) { ; }; | 83 | virtual void writeSessionConfig (KateConfig *) { ; }; |
84 | 84 | ||
85 | public slots: | 85 | public slots: |
86 | // some simply key commands | 86 | // some simply key commands |
87 | virtual void keyReturn () { ; }; | 87 | virtual void keyReturn () { ; }; |
88 | virtual void keyDelete () { ; }; | 88 | virtual void keyDelete () { ; }; |
89 | virtual void backspace () { ; }; | 89 | virtual void backspace () { ; }; |
90 | virtual void killLine () { ; }; | 90 | virtual void killLine () { ; }; |
91 | 91 | ||
92 | // move cursor in the view | 92 | // move cursor in the view |
93 | virtual void cursorLeft () { ; }; | 93 | virtual void cursorLeft () { ; }; |
94 | virtual void shiftCursorLeft () { ; }; | 94 | virtual void shiftCursorLeft () { ; }; |
95 | virtual void cursorRight () { ; }; | 95 | virtual void cursorRight () { ; }; |
96 | virtual void shiftCursorRight () { ; }; | 96 | virtual void shiftCursorRight () { ; }; |
97 | virtual void wordLeft () { ; }; | 97 | virtual void wordLeft () { ; }; |
98 | virtual void shiftWordLeft () { ; }; | 98 | virtual void shiftWordLeft () { ; }; |
99 | virtual void wordRight () { ; }; | 99 | virtual void wordRight () { ; }; |
100 | virtual void shiftWordRight () { ; }; | 100 | virtual void shiftWordRight () { ; }; |
101 | virtual void home () { ; }; | 101 | virtual void home () { ; }; |
102 | virtual void shiftHome () { ; }; | 102 | virtual void shiftHome () { ; }; |
103 | virtual void end () { ; }; | 103 | virtual void end () { ; }; |
104 | virtual void shiftEnd () { ; }; | 104 | virtual void shiftEnd () { ; }; |
105 | virtual void up () { ; }; | 105 | virtual void up () { ; }; |
106 | virtual void shiftUp () { ; }; | 106 | virtual void shiftUp () { ; }; |
107 | virtual void down () { ; }; | 107 | virtual void down () { ; }; |
108 | virtual void shiftDown () { ; }; | 108 | virtual void shiftDown () { ; }; |
109 | virtual void scrollUp () { ; }; | 109 | virtual void scrollUp () { ; }; |
110 | virtual void scrollDown () { ; }; | 110 | virtual void scrollDown () { ; }; |
111 | virtual void topOfView () { ; }; | 111 | virtual void topOfView () { ; }; |
112 | virtual void bottomOfView () { ; }; | 112 | virtual void bottomOfView () { ; }; |
113 | virtual void pageUp () { ; }; | 113 | virtual void pageUp () { ; }; |
114 | virtual void shiftPageUp () { ; }; | 114 | virtual void shiftPageUp () { ; }; |
115 | virtual void pageDown () { ; }; | 115 | virtual void pageDown () { ; }; |
116 | virtual void shiftPageDown () { ; }; | 116 | virtual void shiftPageDown () { ; }; |
117 | virtual void top () { ; }; | 117 | virtual void top () { ; }; |
118 | virtual void shiftTop () { ; }; | 118 | virtual void shiftTop () { ; }; |
119 | virtual void bottom () { ; }; | 119 | virtual void bottom () { ; }; |
120 | virtual void shiftBottom () { ; }; | 120 | virtual void shiftBottom () { ; }; |
121 | 121 | ||
122 | public slots: | 122 | public slots: |
123 | // edit command popup window | 123 | // edit command popup window |
124 | virtual void slotEditCommand () { ; }; | 124 | virtual void slotEditCommand () { ; }; |
125 | 125 | ||
126 | // icon border enable/disable | 126 | // icon border enable/disable |
127 | virtual void setIconBorder (bool) { ; }; | 127 | virtual void setIconBorder (bool) { ; }; |
128 | virtual void toggleIconBorder () { ; }; | 128 | virtual void toggleIconBorder () { ; }; |
129 | 129 | ||
130 | // goto mark | 130 | // goto mark |
131 | virtual void gotoMark (Mark *) { ; }; | 131 | virtual void gotoMark (Mark *) { ; }; |
132 | 132 | ||
133 | // toggle current line bookmark or clear all bookmarks | 133 | // toggle current line bookmark or clear all bookmarks |
134 | virtual void toggleBookmark () { ; }; | 134 | virtual void toggleBookmark () { ; }; |
135 | virtual void clearBookmarks () { ; }; | 135 | virtual void clearBookmarks () { ; }; |
136 | 136 | ||
137 | public: | 137 | public: |
138 | // is iconborder visible ? | 138 | // is iconborder visible ? |
139 | virtual bool iconBorder() { return false; }; | 139 | virtual bool iconBorder() { return false; }; |
140 | 140 | ||
141 | public slots: | 141 | public slots: |
142 | /** | 142 | /** |
143 | Flushes the document of the text widget. The user is given | 143 | Flushes the document of the text widget. The user is given |
144 | a chance to save the current document if the current document has | 144 | a chance to save the current document if the current document has |
145 | been modified. | 145 | been modified. |
146 | */ | 146 | */ |
147 | virtual void flush () { ; }; | 147 | virtual void flush () { ; }; |
148 | 148 | ||
149 | public: | 149 | public: |
150 | /** | 150 | /** |
151 | Returns true if the current document can be | 151 | Returns true if the current document can be |
152 | discarded. If the document is modified, the user is asked if he wants | 152 | discarded. If the document is modified, the user is asked if he wants |
153 | to save it. On "cancel" the function returns false. | 153 | to save it. On "cancel" the function returns false. |
154 | */ | 154 | */ |
155 | virtual bool canDiscard() { return false; }; | 155 | virtual bool canDiscard() { return false; }; |
156 | }; | 156 | }; |
157 | 157 | ||
158 | }; | 158 | }; |
159 | 159 | ||
160 | #endif | 160 | #endif |
diff --git a/noncore/apps/tinykate/libkate/kateconfig.cpp b/noncore/apps/tinykate/libkate/kateconfig.cpp new file mode 100644 index 0000000..06ac49f --- a/dev/null +++ b/noncore/apps/tinykate/libkate/kateconfig.cpp | |||
@@ -0,0 +1,634 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include <qdir.h> | ||
22 | #include <qfile.h> | ||
23 | #include <qfileinfo.h> | ||
24 | #include <qmessagebox.h> | ||
25 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | ||
26 | #include <qtextcodec.h> | ||
27 | #endif | ||
28 | #include <qtextstream.h> | ||
29 | |||
30 | #include <sys/stat.h> | ||
31 | #include <sys/types.h> | ||
32 | #include <fcntl.h> | ||
33 | #include <stdlib.h> | ||
34 | #include <unistd.h> | ||
35 | |||
36 | #define QTOPIA_INTERNAL_LANGLIST | ||
37 | #include "kateconfig.h" | ||
38 | #include <qpe/global.h> | ||
39 | |||
40 | |||
41 | /*! | ||
42 | \internal | ||
43 | */ | ||
44 | QString KateConfig::configFilename(const QString& name, Domain d) | ||
45 | { | ||
46 | switch (d) { | ||
47 | case File: | ||
48 | return name; | ||
49 | case User: { | ||
50 | QDir dir = (QString(getenv("HOME")) + "/Settings"); | ||
51 | if ( !dir.exists() ) | ||
52 | mkdir(dir.path().local8Bit(),0700); | ||
53 | return dir.path() + "/" + name + ".conf"; | ||
54 | } | ||
55 | } | ||
56 | return name; | ||
57 | } | ||
58 | |||
59 | /*! | ||
60 | \class KateConfig config.h | ||
61 | \brief The KateConfig class provides for saving application cofniguration state. | ||
62 | |||
63 | You should keep a KateConfig in existence only while you do not want others | ||
64 | to be able to change the state. There is no locking currently, but there | ||
65 | may be in the future. | ||
66 | */ | ||
67 | |||
68 | /*! | ||
69 | \enum KateConfig::KateConfigGroup | ||
70 | \internal | ||
71 | */ | ||
72 | |||
73 | /*! | ||
74 | \enum KateConfig::Domain | ||
75 | |||
76 | \value File | ||
77 | \value User | ||
78 | |||
79 | See KateConfig for details. | ||
80 | */ | ||
81 | |||
82 | /*! | ||
83 | Constructs a config that will load or create a configuration with the | ||
84 | given \a name in the given \a domain. | ||
85 | |||
86 | You must call setGroup() before doing much else with the KateConfig. | ||
87 | |||
88 | In the default Domain, \e User, | ||
89 | the configuration is user-specific. \a name should not contain "/" in | ||
90 | this case, and in general should be the name of the C++ class that is | ||
91 | primarily responsible for maintaining the configuration. | ||
92 | |||
93 | In the File Domain, \a name is an absolute filename. | ||
94 | */ | ||
95 | KateConfig::KateConfig( const QString &name, Domain domain ) | ||
96 | : filename( configFilename(name,domain) ) | ||
97 | { | ||
98 | qWarning("KateConfig constructor\n"); | ||
99 | git = groups.end(); | ||
100 | read(); | ||
101 | QStringList l = Global::languageList(); | ||
102 | lang = l[0]; | ||
103 | glang = l[1]; | ||
104 | } | ||
105 | |||
106 | |||
107 | // Sharp ROM compatibility | ||
108 | KateConfig::KateConfig ( const QString &name, bool what ) | ||
109 | : filename( configFilename(name,what ? User : File) ) | ||
110 | { | ||
111 | git = groups.end(); | ||
112 | read(); | ||
113 | QStringList l = Global::languageList(); | ||
114 | lang = l[0]; | ||
115 | glang = l[1]; | ||
116 | } | ||
117 | |||
118 | /*! | ||
119 | Writes any changes to disk and destroys the in-memory object. | ||
120 | */ | ||
121 | KateConfig::~KateConfig() | ||
122 | { | ||
123 | qWarning("KateConfig destructor\n"); | ||
124 | if ( changed ) | ||
125 | write(); | ||
126 | } | ||
127 | |||
128 | /*! | ||
129 | Returns whether the current group has an entry called \a key. | ||
130 | */ | ||
131 | bool KateConfig::hasKey( const QString &key ) const | ||
132 | { | ||
133 | if ( groups.end() == git ) | ||
134 | return FALSE; | ||
135 | KateConfigGroup::ConstIterator it = ( *git ).find( key ); | ||
136 | return it != ( *git ).end(); | ||
137 | } | ||
138 | |||
139 | /*! | ||
140 | Sets the current group for subsequent reading and writing of | ||
141 | entries to \a gname. Grouping allows the application to partition the namespace. | ||
142 | |||
143 | This function must be called prior to any reading or writing | ||
144 | of entries. | ||
145 | |||
146 | The \a gname must not be empty. | ||
147 | */ | ||
148 | void KateConfig::setGroup( const QString &gname ) | ||
149 | { | ||
150 | QMap< QString, KateConfigGroup>::Iterator it = groups.find( gname ); | ||
151 | if ( it == groups.end() ) { | ||
152 | git = groups.insert( gname, KateConfigGroup() ); | ||
153 | changed = TRUE; | ||
154 | return; | ||
155 | } | ||
156 | git = it; | ||
157 | } | ||
158 | |||
159 | /*! | ||
160 | Writes a (\a key, \a value) entry to the current group. | ||
161 | |||
162 | \sa readEntry() | ||
163 | */ | ||
164 | void KateConfig::writeEntry( const QString &key, const char* value ) | ||
165 | { | ||
166 | writeEntry(key,QString(value)); | ||
167 | } | ||
168 | |||
169 | /*! | ||
170 | Writes a (\a key, \a value) entry to the current group. | ||
171 | |||
172 | \sa readEntry() | ||
173 | */ | ||
174 | void KateConfig::writeEntry( const QString &key, const QString &value ) | ||
175 | { | ||
176 | if ( git == groups.end() ) { | ||
177 | qWarning( "no group set" ); | ||
178 | return; | ||
179 | } | ||
180 | if ( (*git)[key] != value ) { | ||
181 | ( *git ).insert( key, value ); | ||
182 | changed = TRUE; | ||
183 | } | ||
184 | } | ||
185 | |||
186 | /* | ||
187 | Note that the degree of protection offered by the encryption here is | ||
188 | only sufficient to avoid the most casual observation of the configuration | ||
189 | files. People with access to the files can write down the contents and | ||
190 | decrypt it using this source code. | ||
191 | |||
192 | Conceivably, and at some burden to the user, this encryption could | ||
193 | be improved. | ||
194 | */ | ||
195 | static QString encipher(const QString& plain) | ||
196 | { | ||
197 | // mainly, we make it long | ||
198 | QString cipher; | ||
199 | int mix=28730492; | ||
200 | for (int i=0; i<(int)plain.length(); i++) { | ||
201 | int u = plain[i].unicode(); | ||
202 | int c = u ^ mix; | ||
203 | QString x = QString::number(c,36); | ||
204 | cipher.append(QChar('a'+x.length())); | ||
205 | cipher.append(x); | ||
206 | mix *= u; | ||
207 | } | ||
208 | return cipher; | ||
209 | } | ||
210 | |||
211 | static QString decipher(const QString& cipher) | ||
212 | { | ||
213 | QString plain; | ||
214 | int mix=28730492; | ||
215 | for (int i=0; i<(int)cipher.length();) { | ||
216 | int l = cipher[i].unicode()-'a'; | ||
217 | QString x = cipher.mid(i+1,l); i+=l+1; | ||
218 | int u = x.toInt(0,36) ^ mix; | ||
219 | plain.append(QChar(u)); | ||
220 | mix *= u; | ||
221 | } | ||
222 | return plain; | ||
223 | } | ||
224 | |||
225 | /*! | ||
226 | Writes an encrypted (\a key, \a value) entry to the current group. | ||
227 | |||
228 | Note that the degree of protection offered by the encryption is | ||
229 | only sufficient to avoid the most casual observation of the configuration | ||
230 | files. | ||
231 | |||
232 | \sa readEntry() | ||
233 | */ | ||
234 | void KateConfig::writeEntryCrypt( const QString &key, const QString &value ) | ||
235 | { | ||
236 | if ( git == groups.end() ) { | ||
237 | qWarning( "no group set" ); | ||
238 | return; | ||
239 | } | ||
240 | QString evalue = encipher(value); | ||
241 | if ( (*git)[key] != evalue ) { | ||
242 | ( *git ).insert( key, evalue ); | ||
243 | changed = TRUE; | ||
244 | } | ||
245 | } | ||
246 | |||
247 | /*! | ||
248 | Writes a (\a key, \a num) entry to the current group. | ||
249 | |||
250 | \sa readNumEntry() | ||
251 | */ | ||
252 | void KateConfig::writeEntry( const QString &key, int num ) | ||
253 | { | ||
254 | QString s; | ||
255 | s.setNum( num ); | ||
256 | writeEntry( key, s ); | ||
257 | } | ||
258 | |||
259 | void KateConfig::writeEntry( const QString &key, unsigned int num ) | ||
260 | { | ||
261 | QString s; | ||
262 | s.setNum( num ); | ||
263 | writeEntry( key, s ); | ||
264 | } | ||
265 | |||
266 | #ifdef Q_HAS_BOOL_TYPE | ||
267 | /*! | ||
268 | Writes a (\a key, \a b) entry to the current group. This is equivalent | ||
269 | to writing a 0 or 1 as an integer entry. | ||
270 | |||
271 | \sa readBoolEntry() | ||
272 | */ | ||
273 | void KateConfig::writeEntry( const QString &key, bool b ) | ||
274 | { | ||
275 | QString s; | ||
276 | s.setNum( ( int )b ); | ||
277 | writeEntry( key, s ); | ||
278 | } | ||
279 | #endif | ||
280 | |||
281 | /*! | ||
282 | Writes a (\a key, \a lst) entry to the current group. The list | ||
283 | is separated by \a sep, so the strings must not contain that character. | ||
284 | |||
285 | \sa readListEntry() | ||
286 | */ | ||
287 | void KateConfig::writeEntry( const QString &key, const QStringList &lst, const QChar &sep ) | ||
288 | { | ||
289 | QString s; | ||
290 | QStringList::ConstIterator it = lst.begin(); | ||
291 | for ( ; it != lst.end(); ++it ) | ||
292 | s += *it + sep; | ||
293 | writeEntry( key, s ); | ||
294 | } | ||
295 | |||
296 | void KateConfig::writeEntry( const QString &key, const QColor &val ) | ||
297 | { | ||
298 | QStringList l; | ||
299 | l.append( QString().setNum(val.red()) ); | ||
300 | l.append( QString().setNum(val.green()) ); | ||
301 | l.append( QString().setNum(val.blue()) ); | ||
302 | |||
303 | writeEntry( key, l, QChar(',') ); | ||
304 | } | ||
305 | |||
306 | void KateConfig::writeEntry( const QString &key, const QFont &val ) | ||
307 | { | ||
308 | QStringList l; | ||
309 | l.append( val.family() ); | ||
310 | l.append( QString().setNum(val.pointSize()) ); | ||
311 | l.append( QString().setNum(val.weight()) ); | ||
312 | l.append( QString().setNum((int)val.italic()) ); | ||
313 | l.append( QString().setNum((int)val.charSet()) ); | ||
314 | |||
315 | writeEntry( key, l, QChar(',') ); | ||
316 | } | ||
317 | |||
318 | /*! | ||
319 | Removes the \a key entry from the current group. Does nothing if | ||
320 | there is no such entry. | ||
321 | */ | ||
322 | |||
323 | void KateConfig::removeEntry( const QString &key ) | ||
324 | { | ||
325 | if ( git == groups.end() ) { | ||
326 | qWarning( "no group set" ); | ||
327 | return; | ||
328 | } | ||
329 | ( *git ).remove( key ); | ||
330 | changed = TRUE; | ||
331 | } | ||
332 | |||
333 | /*! | ||
334 | \fn bool KateConfig::operator == ( const KateConfig & other ) const | ||
335 | |||
336 | Tests for equality with \a other. KateConfig objects are equal if they refer to the same filename. | ||
337 | */ | ||
338 | |||
339 | /*! | ||
340 | \fn bool KateConfig::operator != ( const KateConfig & other ) const | ||
341 | |||
342 | Tests for inequality with \a other. KateConfig objects are equal if they refer to the same filename. | ||
343 | */ | ||
344 | |||
345 | /*! | ||
346 | \fn QString KateConfig::readEntry( const QString &key, const QString &deflt ) const | ||
347 | |||
348 | Reads a string entry stored with \a key, defaulting to \a deflt if there is no entry. | ||
349 | */ | ||
350 | |||
351 | /*! | ||
352 | \internal | ||
353 | For compatibility, non-const version. | ||
354 | */ | ||
355 | QString KateConfig::readEntry( const QString &key, const QString &deflt ) | ||
356 | { | ||
357 | QString res = readEntryDirect( key+"["+lang+"]" ); | ||
358 | if ( !res.isNull() ) | ||
359 | return res; | ||
360 | if ( !glang.isEmpty() ) { | ||
361 | res = readEntryDirect( key+"["+glang+"]" ); | ||
362 | if ( !res.isNull() ) | ||
363 | return res; | ||
364 | } | ||
365 | return readEntryDirect( key, deflt ); | ||
366 | } | ||
367 | |||
368 | /*! | ||
369 | \fn QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) const | ||
370 | |||
371 | Reads an encrypted string entry stored with \a key, defaulting to \a deflt if there is no entry. | ||
372 | */ | ||
373 | |||
374 | /*! | ||
375 | \internal | ||
376 | For compatibility, non-const version. | ||
377 | */ | ||
378 | QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) | ||
379 | { | ||
380 | QString res = readEntryDirect( key+"["+lang+"]" ); | ||
381 | if ( res.isNull() && glang.isEmpty() ) | ||
382 | res = readEntryDirect( key+"["+glang+"]" ); | ||
383 | if ( res.isNull() ) | ||
384 | res = readEntryDirect( key, QString::null ); | ||
385 | if ( res.isNull() ) | ||
386 | return deflt; | ||
387 | return decipher(res); | ||
388 | } | ||
389 | |||
390 | /*! | ||
391 | \fn QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) const | ||
392 | \internal | ||
393 | */ | ||
394 | |||
395 | /*! | ||
396 | \internal | ||
397 | For compatibility, non-const version. | ||
398 | */ | ||
399 | QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) | ||
400 | { | ||
401 | if ( git == groups.end() ) { | ||
402 | //qWarning( "no group set" ); | ||
403 | return deflt; | ||
404 | } | ||
405 | KateConfigGroup::ConstIterator it = ( *git ).find( key ); | ||
406 | if ( it != ( *git ).end() ) | ||
407 | return *it; | ||
408 | else | ||
409 | return deflt; | ||
410 | } | ||
411 | |||
412 | /*! | ||
413 | \fn int KateConfig::readNumEntry( const QString &key, int deflt ) const | ||
414 | Reads a numeric entry stored with \a key, defaulting to \a deflt if there is no entry. | ||
415 | */ | ||
416 | |||
417 | /*! | ||
418 | \internal | ||
419 | For compatibility, non-const version. | ||
420 | */ | ||
421 | int KateConfig::readNumEntry( const QString &key, int deflt ) | ||
422 | { | ||
423 | QString s = readEntry( key ); | ||
424 | if ( s.isEmpty() ) | ||
425 | return deflt; | ||
426 | else | ||
427 | return s.toInt(); | ||
428 | } | ||
429 | |||
430 | /*! | ||
431 | \fn bool KateConfig::readBoolEntry( const QString &key, bool deflt ) const | ||
432 | Reads a bool entry stored with \a key, defaulting to \a deflt if there is no entry. | ||
433 | */ | ||
434 | |||
435 | /*! | ||
436 | \internal | ||
437 | For compatibility, non-const version. | ||
438 | */ | ||
439 | bool KateConfig::readBoolEntry( const QString &key, bool deflt ) | ||
440 | { | ||
441 | QString s = readEntry( key ); | ||
442 | if ( s.isEmpty() ) | ||
443 | return deflt; | ||
444 | else | ||
445 | return (bool)s.toInt(); | ||
446 | } | ||
447 | |||
448 | /*! | ||
449 | \fn QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) const | ||
450 | Reads a string list entry stored with \a key, and with \a sep as the separator. | ||
451 | */ | ||
452 | |||
453 | /*! | ||
454 | \internal | ||
455 | For compatibility, non-const version. | ||
456 | */ | ||
457 | QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) | ||
458 | { | ||
459 | QString s = readEntry( key ); | ||
460 | if ( s.isEmpty() ) | ||
461 | return QStringList(); | ||
462 | else | ||
463 | return QStringList::split( sep, s ); | ||
464 | } | ||
465 | |||
466 | QColor KateConfig::readColorEntry( const QString &key, const QColor &def ) const | ||
467 | { | ||
468 | QStringList list = readListEntry(key, QChar(',')); | ||
469 | if( list.count() != 3 ) | ||
470 | return def; | ||
471 | |||
472 | return QColor(list[0].toInt(), list[1].toInt(), list[2].toInt()); | ||
473 | } | ||
474 | |||
475 | QFont KateConfig::readFontEntry( const QString &key, const QFont &def ) const | ||
476 | { | ||
477 | QStringList list = readListEntry(key, QChar(',')); | ||
478 | if( list.count() != 5 ) | ||
479 | return def; | ||
480 | |||
481 | return QFont(list[0], list[1].toInt(), list[2].toInt(), (bool)list[3].toInt(), (QFont::CharSet)list[4].toInt()); | ||
482 | } | ||
483 | |||
484 | QValueList<int> KateConfig::readIntListEntry( const QString &key ) const | ||
485 | { | ||
486 | QString s = readEntry( key ); | ||
487 | QValueList<int> il; | ||
488 | if ( s.isEmpty() ) | ||
489 | return il; | ||
490 | |||
491 | QStringList l = QStringList::split( QChar(','), s ); | ||
492 | |||
493 | QStringList::Iterator l_it; | ||
494 | for( l_it = l.begin(); l_it != l.end(); ++l_it ) | ||
495 | il.append( (*l_it).toInt() ); | ||
496 | return il; | ||
497 | } | ||
498 | |||
499 | /*! | ||
500 | Removes all entries from the current group. | ||
501 | */ | ||
502 | void KateConfig::clearGroup() | ||
503 | { | ||
504 | if ( git == groups.end() ) { | ||
505 | qWarning( "no group set" ); | ||
506 | return; | ||
507 | } | ||
508 | if ( !(*git).isEmpty() ) { | ||
509 | ( *git ).clear(); | ||
510 | changed = TRUE; | ||
511 | } | ||
512 | } | ||
513 | |||
514 | /*! | ||
515 | \internal | ||
516 | */ | ||
517 | void KateConfig::write( const QString &fn ) | ||
518 | { | ||
519 | QString strNewFile; | ||
520 | if ( !fn.isEmpty() ) | ||
521 | filename = fn; | ||
522 | strNewFile = filename + ".new"; | ||
523 | |||
524 | QFile f( strNewFile ); | ||
525 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) { | ||
526 | qWarning( "could not open for writing `%s'", strNewFile.latin1() ); | ||
527 | git = groups.end(); | ||
528 | return; | ||
529 | } | ||
530 | |||
531 | QString str; | ||
532 | QCString cstr; | ||
533 | QMap< QString, KateConfigGroup >::Iterator g_it = groups.begin(); | ||
534 | |||
535 | for ( ; g_it != groups.end(); ++g_it ) { | ||
536 | str += "[" + g_it.key() + "]\n"; | ||
537 | KateConfigGroup::Iterator e_it = ( *g_it ).begin(); | ||
538 | for ( ; e_it != ( *g_it ).end(); ++e_it ) | ||
539 | str += e_it.key() + " = " + *e_it + "\n"; | ||
540 | } | ||
541 | cstr = str.utf8(); | ||
542 | |||
543 | int total_length; | ||
544 | total_length = f.writeBlock( cstr.data(), cstr.length() ); | ||
545 | if ( total_length != int(cstr.length()) ) { | ||
546 | QMessageBox::critical( 0, QObject::tr("Out of Space"), | ||
547 | QObject::tr("There was a problem creating\nKateConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") ); | ||
548 | f.close(); | ||
549 | QFile::remove( strNewFile ); | ||
550 | return; | ||
551 | } | ||
552 | |||
553 | f.close(); | ||
554 | // now rename the file... | ||
555 | if ( rename( strNewFile, filename ) < 0 ) { | ||
556 | qWarning( "problem renaming the file %s to %s", strNewFile.latin1(), | ||
557 | filename.latin1() ); | ||
558 | QFile::remove( strNewFile ); | ||
559 | } | ||
560 | } | ||
561 | |||
562 | /*! | ||
563 | Returns whether the KateConfig is in a valid state. | ||
564 | */ | ||
565 | bool KateConfig::isValid() const | ||
566 | { | ||
567 | return groups.end() != git; | ||
568 | } | ||
569 | |||
570 | /*! | ||
571 | \internal | ||
572 | */ | ||
573 | void KateConfig::read() | ||
574 | { | ||
575 | changed = FALSE; | ||
576 | |||
577 | if ( !QFileInfo( filename ).exists() ) { | ||
578 | git = groups.end(); | ||
579 | return; | ||
580 | } | ||
581 | |||
582 | QFile f( filename ); | ||
583 | if ( !f.open( IO_ReadOnly ) ) { | ||
584 | git = groups.end(); | ||
585 | return; | ||
586 | } | ||
587 | |||
588 | QTextStream s( &f ); | ||
589 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | ||
590 | // The below should work, but doesn't in Qt 2.3.0 | ||
591 | s.setCodec( QTextCodec::codecForMib( 106 ) ); | ||
592 | #else | ||
593 | s.setEncoding( QTextStream::UnicodeUTF8 ); | ||
594 | #endif | ||
595 | |||
596 | QStringList list = QStringList::split('\n', s.read() ); | ||
597 | f.close(); | ||
598 | |||
599 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | ||
600 | if ( !parse( *it ) ) { | ||
601 | git = groups.end(); | ||
602 | return; | ||
603 | } | ||
604 | } | ||
605 | } | ||
606 | |||
607 | /*! | ||
608 | \internal | ||
609 | */ | ||
610 | bool KateConfig::parse( const QString &l ) | ||
611 | { | ||
612 | QString line = l.stripWhiteSpace(); | ||
613 | |||
614 | if ( line [0] == QChar ( '#' )) | ||
615 | return true; // ignore comments | ||
616 | |||
617 | if ( line[ 0 ] == QChar( '[' ) ) { | ||
618 | QString gname = line; | ||
619 | gname = gname.remove( 0, 1 ); | ||
620 | if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) | ||
621 | gname = gname.remove( gname.length() - 1, 1 ); | ||
622 | git = groups.insert( gname, KateConfigGroup() ); | ||
623 | } else if ( !line.isEmpty() ) { | ||
624 | if ( git == groups.end() ) | ||
625 | return FALSE; | ||
626 | int eq = line.find( '=' ); | ||
627 | if ( eq == -1 ) | ||
628 | return FALSE; | ||
629 | QString key = line.left(eq).stripWhiteSpace(); | ||
630 | QString value = line.mid(eq+1).stripWhiteSpace(); | ||
631 | ( *git ).insert( key, value ); | ||
632 | } | ||
633 | return TRUE; | ||
634 | } | ||
diff --git a/noncore/apps/tinykate/libkate/kateconfig.h b/noncore/apps/tinykate/libkate/kateconfig.h new file mode 100644 index 0000000..80a4e67 --- a/dev/null +++ b/noncore/apps/tinykate/libkate/kateconfig.h | |||
@@ -0,0 +1,117 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #ifndef KATECONFIG_H | ||
22 | #define KATECONFIG_H | ||
23 | |||
24 | // ##### could use QSettings with Qt 3.0 | ||
25 | |||
26 | #include <qmap.h> | ||
27 | #include <qstringlist.h> | ||
28 | #include <qfont.h> | ||
29 | #include <qcolor.h> | ||
30 | |||
31 | class KateConfigPrivate; | ||
32 | class KateConfig | ||
33 | { | ||
34 | public: | ||
35 | typedef QMap< QString, QString > KateConfigGroup; | ||
36 | |||
37 | enum Domain { File, User }; | ||
38 | KateConfig( const QString &name, Domain domain=User ); | ||
39 | ~KateConfig(); | ||
40 | |||
41 | bool operator == ( const KateConfig & other ) const { return (filename == other.filename); } | ||
42 | bool operator != ( const KateConfig & other ) const { return (filename != other.filename); } | ||
43 | |||
44 | bool isValid() const; | ||
45 | bool hasKey( const QString &key ) const; | ||
46 | |||
47 | // inline for better SharpROM BC | ||
48 | inline bool hasGroup ( const QString &gname ) const { return ( groups. find ( gname ) != groups. end ( )); }; | ||
49 | inline QStringList groupList ( ) const { QStringList sl; for ( QMap< QString, KateConfigGroup >::ConstIterator it = groups. begin ( ); it != groups. end ( ); ++it ) { sl << it.key(); } return sl; }; | ||
50 | |||
51 | void setGroup( const QString &gname ); | ||
52 | void writeEntry( const QString &key, const char* value ); | ||
53 | void writeEntry( const QString &key, const QString &value ); | ||
54 | void writeEntryCrypt( const QString &key, const QString &value ); | ||
55 | void writeEntry( const QString &key, int num ); | ||
56 | void writeEntry( const QString &key, unsigned int num ); | ||
57 | #ifdef Q_HAS_BOOL_TYPE | ||
58 | void writeEntry( const QString &key, bool b ); | ||
59 | #endif | ||
60 | void writeEntry( const QString &key, const QStringList &lst, const QChar &sep ); | ||
61 | void writeEntry( const QString &key, const QColor & ); | ||
62 | void writeEntry( const QString &key, const QFont & ); | ||
63 | void removeEntry( const QString &key ); | ||
64 | |||
65 | QString readEntry( const QString &key, const QString &deflt = QString::null ) const; | ||
66 | QString readEntryCrypt( const QString &key, const QString &deflt = QString::null ) const; | ||
67 | QString readEntryDirect( const QString &key, const QString &deflt = QString::null ) const; | ||
68 | int readNumEntry( const QString &key, int deflt = -1 ) const; | ||
69 | bool readBoolEntry( const QString &key, bool deflt = FALSE ) const; | ||
70 | QStringList readListEntry( const QString &key, const QChar &sep ) const; | ||
71 | QColor readColorEntry( const QString &, const QColor & ) const; | ||
72 | QFont readFontEntry( const QString &, const QFont & ) const; | ||
73 | QValueList<int> readIntListEntry( const QString &key ) const; | ||
74 | |||
75 | // For compatibility, non-const versions. | ||
76 | QString readEntry( const QString &key, const QString &deflt ); | ||
77 | QString readEntryCrypt( const QString &key, const QString &deflt ); | ||
78 | QString readEntryDirect( const QString &key, const QString &deflt ); | ||
79 | int readNumEntry( const QString &key, int deflt ); | ||
80 | bool readBoolEntry( const QString &key, bool deflt ); | ||
81 | QStringList readListEntry( const QString &key, const QChar &sep ); | ||
82 | |||
83 | void clearGroup(); | ||
84 | |||
85 | void write( const QString &fn = QString::null ); | ||
86 | |||
87 | protected: | ||
88 | void read(); | ||
89 | bool parse( const QString &line ); | ||
90 | |||
91 | QMap< QString, KateConfigGroup > groups; | ||
92 | QMap< QString, KateConfigGroup >::Iterator git; | ||
93 | QString filename; | ||
94 | QString lang; | ||
95 | QString glang; | ||
96 | bool changed; | ||
97 | KateConfigPrivate *d; | ||
98 | static QString configFilename(const QString& name, Domain); | ||
99 | |||
100 | private: // Sharp ROM compatibility | ||
101 | KateConfig( const QString &name, bool what ); | ||
102 | }; | ||
103 | |||
104 | inline QString KateConfig::readEntry( const QString &key, const QString &deflt ) const | ||
105 | { return ((KateConfig*)this)->readEntry(key,deflt); } | ||
106 | inline QString KateConfig::readEntryCrypt( const QString &key, const QString &deflt ) const | ||
107 | { return ((KateConfig*)this)->readEntryCrypt(key,deflt); } | ||
108 | inline QString KateConfig::readEntryDirect( const QString &key, const QString &deflt ) const | ||
109 | { return ((KateConfig*)this)->readEntryDirect(key,deflt); } | ||
110 | inline int KateConfig::readNumEntry( const QString &key, int deflt ) const | ||
111 | { return ((KateConfig*)this)->readNumEntry(key,deflt); } | ||
112 | inline bool KateConfig::readBoolEntry( const QString &key, bool deflt ) const | ||
113 | { return ((KateConfig*)this)->readBoolEntry(key,deflt); } | ||
114 | inline QStringList KateConfig::readListEntry( const QString &key, const QChar &sep ) const | ||
115 | { return ((KateConfig*)this)->readListEntry(key,sep); } | ||
116 | |||
117 | #endif | ||
diff --git a/noncore/apps/tinykate/libkate/libkate.pro b/noncore/apps/tinykate/libkate/libkate.pro index b0354e6..0082106 100644 --- a/noncore/apps/tinykate/libkate/libkate.pro +++ b/noncore/apps/tinykate/libkate/libkate.pro | |||
@@ -1,90 +1,91 @@ | |||
1 | TEMPLATE= lib | 1 | TEMPLATE= lib |
2 | CONFIG = qt warn_on release | 2 | CONFIG = qt warn_on release |
3 | HEADERS = microkde/kapplication.h \ | 3 | HEADERS = microkde/kapplication.h \ |
4 | microkde/kconfig.h \ | 4 | kateconfig.h \ |
5 | microkde/kdebug.h \ | 5 | microkde/kdebug.h \ |
6 | microkde/kdialog.h \ | 6 | microkde/kdialog.h \ |
7 | microkde/kdialogbase.h \ | 7 | microkde/kdialogbase.h \ |
8 | microkde/kfiledialog.h \ | 8 | microkde/kfiledialog.h \ |
9 | microkde/kglobal.h \ | 9 | microkde/kglobal.h \ |
10 | microkde/kiconloader.h \ | 10 | microkde/kiconloader.h \ |
11 | microkde/klineedit.h \ | 11 | microkde/klineedit.h \ |
12 | microkde/klocale.h \ | 12 | microkde/klocale.h \ |
13 | microkde/kmessagebox.h \ | 13 | microkde/kmessagebox.h \ |
14 | microkde/kprinter.h \ | 14 | microkde/kprinter.h \ |
15 | microkde/krestrictedline.h \ | 15 | microkde/krestrictedline.h \ |
16 | microkde/kseparator.h \ | 16 | microkde/kseparator.h \ |
17 | microkde/ksimpleconfig.h \ | ||
18 | microkde/kstandarddirs.h \ | 17 | microkde/kstandarddirs.h \ |
19 | microkde/ktempfile.h \ | 18 | microkde/ktempfile.h \ |
20 | microkde/kunload.h \ | 19 | microkde/kunload.h \ |
21 | microkde/kurlrequester.h \ | 20 | microkde/kurlrequester.h \ |
22 | microkde/kfontdialog.h \ | 21 | microkde/kfontdialog.h \ |
23 | microkde/krun.h \ | 22 | microkde/krun.h \ |
24 | microkde/knumvalidator.h \ | 23 | microkde/knumvalidator.h \ |
25 | microkde/kstaticdeleter.h \ | 24 | microkde/kstaticdeleter.h \ |
26 | microkde/klistview.h \ | 25 | microkde/klistview.h \ |
27 | microkde/kglobalsettings.h \ | 26 | microkde/kglobalsettings.h \ |
28 | microkde/kcolorbtn.h \ | 27 | microkde/kcolorbtn.h \ |
29 | \ | 28 | \ |
30 | \ | 29 | \ |
31 | qt3back/qregexp3.h \ | 30 | qt3back/qregexp3.h \ |
32 | kde/ksharedptr.h \ | 31 | kde/ksharedptr.h \ |
33 | document/katebuffer.h document/katedialogs.h \ | 32 | document/katebuffer.h document/katedialogs.h \ |
34 | document/katetextline.h \ | 33 | document/katetextline.h \ |
35 | document/katecmd.h \ | 34 | document/katecmd.h \ |
36 | document/katehighlight.h \ | 35 | document/katehighlight.h \ |
37 | document/katecmds.h document/katedocument.h \ | 36 | document/katecmds.h document/katedocument.h \ |
38 | document/katesyntaxdocument.h \ | 37 | document/katesyntaxdocument.h \ |
39 | view/kateundohistory.h \ | 38 | view/kateundohistory.h \ |
40 | view/kateview.h \ | 39 | view/kateview.h \ |
41 | view/kateviewdialog.h \ | 40 | view/kateviewdialog.h \ |
42 | interfaces/view.h \ | 41 | interfaces/view.h \ |
43 | interfaces/document.h \ | 42 | interfaces/document.h \ |
44 | ktexteditor/ktexteditor.h | 43 | ktexteditor/ktexteditor.h |
45 | 44 | ||
46 | SOURCES = microkde/kapplication.cpp \ | 45 | SOURCES = microkde/kapplication.cpp \ |
47 | microkde/kdialogbase.cpp \ | 46 | microkde/kdialogbase.cpp \ |
48 | microkde/kconfig.cpp \ | 47 | kateconfig.cpp \ |
49 | microkde/klocale.cpp \ | 48 | microkde/klocale.cpp \ |
50 | microkde/kmessagebox.cpp \ | 49 | microkde/kmessagebox.cpp \ |
51 | microkde/kprocess.cpp \ | 50 | microkde/kprocess.cpp \ |
52 | microkde/kstandarddirs.cpp \ | 51 | microkde/kstandarddirs.cpp \ |
53 | microkde/ktempfile.cpp \ | 52 | microkde/ktempfile.cpp \ |
54 | microkde/kurlrequester.cpp \ | 53 | microkde/kurlrequester.cpp \ |
55 | microkde/kcolordialog.cpp \ | 54 | microkde/kcolordialog.cpp \ |
56 | microkde/kfontdialog.cpp \ | 55 | microkde/kfontdialog.cpp \ |
57 | microkde/krun.cpp \ | 56 | microkde/krun.cpp \ |
58 | microkde/knumvalidator.cpp \ | 57 | microkde/knumvalidator.cpp \ |
59 | microkde/kglobal.cpp \ | 58 | microkde/kglobal.cpp \ |
60 | microkde/kglobalsettings.cpp \ | 59 | microkde/kglobalsettings.cpp \ |
61 | microkde/kcolorbtn.cpp \ | 60 | microkde/kcolorbtn.cpp \ |
62 | \ | 61 | \ |
63 | \ | 62 | \ |
64 | qt3back/qregexp3.cpp \ | 63 | qt3back/qregexp3.cpp \ |
65 | ktexteditor/ktexteditor.cpp \ | 64 | ktexteditor/ktexteditor.cpp \ |
66 | document/katebuffer.cpp document/katedialogs.cpp \ | 65 | document/katebuffer.cpp document/katedialogs.cpp \ |
67 | document/katehighlight.cpp \ | 66 | document/katehighlight.cpp \ |
68 | document/katecmd.cpp \ | 67 | document/katecmd.cpp \ |
69 | document/katesyntaxdocument.cpp document/katecmds.cpp \ | 68 | document/katesyntaxdocument.cpp document/katecmds.cpp \ |
70 | document/katedocument.cpp document/katetextline.cpp \ | 69 | document/katedocument.cpp document/katetextline.cpp \ |
71 | view/kateundohistory.cpp \ | 70 | view/kateundohistory.cpp \ |
72 | view/kateview.cpp \ | 71 | view/kateview.cpp \ |
73 | view/kateviewdialog.cpp \ | 72 | view/kateviewdialog.cpp \ |
74 | interfaces/interfaces.cpp | 73 | interfaces/interfaces.cpp |
75 | 74 | ||
76 | INTERFACES= | 75 | INTERFACES= |
77 | INCLUDEPATH+= $(OPIEDIR)/include $(OPIEDIR)/noncore/apps/tinykate/libkate/microkde \ | 76 | INCLUDEPATH+= $(OPIEDIR)/include \ |
77 | $(OPIEDIR)/noncore/apps/tinykate/libkate \ | ||
78 | $(OPIEDIR)/noncore/apps/tinykate/libkate/microkde \ | ||
78 | $(OPIEDIR)/noncore/apps/tinykate/libkate/document \ | 79 | $(OPIEDIR)/noncore/apps/tinykate/libkate/document \ |
79 | $(OPIEDIR)/noncore/apps/tinykate/libkate/view \ | 80 | $(OPIEDIR)/noncore/apps/tinykate/libkate/view \ |
80 | $(OPIEDIR)/noncore/apps/tinykate/libkate/interfaces \ | 81 | $(OPIEDIR)/noncore/apps/tinykate/libkate/interfaces \ |
81 | $(OPIEDIR)/noncore/apps/tinykate/libkate/ktexteditor \ | 82 | $(OPIEDIR)/noncore/apps/tinykate/libkate/ktexteditor \ |
82 | $(OPIEDIR)/noncore/apps/tinykate/libkate/qt3back | 83 | $(OPIEDIR)/noncore/apps/tinykate/libkate/qt3back |
83 | DEPENDPATH+= $(OPIEDIR)/include | 84 | DEPENDPATH+= $(OPIEDIR)/include |
84 | LIBS += -lqpe -lopie | 85 | LIBS += -lqpe -lopie |
85 | TARGET = tinykate | 86 | TARGET = tinykate |
86 | 87 | ||
87 | INCLUDEPATH += $(OPIEDIR)/include | 88 | INCLUDEPATH += $(OPIEDIR)/include |
88 | DESTDIR = $(OPIEDIR)/lib$(PROJMAK) | 89 | DESTDIR = $(OPIEDIR)/lib$(PROJMAK) |
89 | 90 | ||
90 | include ( $(OPIEDIR)/include.pro ) | 91 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/noncore/apps/tinykate/libkate/microkde/kconfig.cpp b/noncore/apps/tinykate/libkate/microkde/kconfig.cpp deleted file mode 100644 index d88bda0..0000000 --- a/noncore/apps/tinykate/libkate/microkde/kconfig.cpp +++ b/dev/null | |||
@@ -1,181 +0,0 @@ | |||
1 | #include <qfile.h> | ||
2 | #include <qtextstream.h> | ||
3 | |||
4 | #include "kdebug.h" | ||
5 | |||
6 | #include "kconfig.h" | ||
7 | |||
8 | QString KConfig::mGroup = ""; | ||
9 | //QString KConfig::mGroup = "General"; | ||
10 | |||
11 | KConfig::KConfig( const QString &fileName ) | ||
12 | : mFileName( fileName ), mDirty( false ) | ||
13 | { | ||
14 | kdDebug() << "KConfig::KConfig(): '" << fileName << "'" << endl; | ||
15 | |||
16 | load(); | ||
17 | } | ||
18 | |||
19 | |||
20 | KConfig::~KConfig() | ||
21 | { | ||
22 | sync(); | ||
23 | } | ||
24 | |||
25 | void KConfig::setGroup( const QString &group ) | ||
26 | { | ||
27 | return; | ||
28 | |||
29 | // kdDebug() << "KConfig::setGroup(): '" << group << "'" << endl; | ||
30 | |||
31 | mGroup = group; | ||
32 | |||
33 | if ( mGroup.right( 1 ) != "/" ) mGroup += "/"; | ||
34 | } | ||
35 | |||
36 | |||
37 | QValueList<int> KConfig::readIntListEntry( const QString & ) | ||
38 | { | ||
39 | QValueList<int> l; | ||
40 | return l; | ||
41 | } | ||
42 | |||
43 | int KConfig::readNumEntry( const QString &, int def ) | ||
44 | { | ||
45 | return def; | ||
46 | } | ||
47 | |||
48 | QString KConfig::readEntry( const QString &key, const QString &def ) | ||
49 | { | ||
50 | QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); | ||
51 | |||
52 | if ( it == mStringMap.end() ) { | ||
53 | return def; | ||
54 | } | ||
55 | |||
56 | return *it; | ||
57 | } | ||
58 | |||
59 | QStringList KConfig::readListEntry( const QString & ) | ||
60 | { | ||
61 | return QStringList(); | ||
62 | } | ||
63 | |||
64 | bool KConfig::readBoolEntry( const QString &key, bool def ) | ||
65 | { | ||
66 | QMap<QString,bool>::ConstIterator it = mBoolMap.find( mGroup + key ); | ||
67 | |||
68 | if ( it == mBoolMap.end() ) { | ||
69 | return def; | ||
70 | } | ||
71 | |||
72 | return *it; | ||
73 | } | ||
74 | |||
75 | QColor KConfig::readColorEntry( const QString &, QColor *def ) | ||
76 | { | ||
77 | if ( def ) return *def; | ||
78 | return QColor(); | ||
79 | } | ||
80 | |||
81 | QFont KConfig::readFontEntry( const QString &, QFont *def ) | ||
82 | { | ||
83 | if ( def ) return *def; | ||
84 | return QFont(); | ||
85 | } | ||
86 | |||
87 | |||
88 | void KConfig::writeEntry( const QString &, QValueList<int> ) | ||
89 | { | ||
90 | } | ||
91 | |||
92 | void KConfig::writeEntry( const QString &, int ) | ||
93 | { | ||
94 | } | ||
95 | |||
96 | void KConfig::writeEntry( const QString &key, const QString &value ) | ||
97 | { | ||
98 | mStringMap.insert( mGroup + key, value ); | ||
99 | |||
100 | mDirty = true; | ||
101 | } | ||
102 | |||
103 | void KConfig::writeEntry( const QString &, const QStringList & ) | ||
104 | { | ||
105 | } | ||
106 | |||
107 | void KConfig::writeEntry( const QString &key, bool value) | ||
108 | { | ||
109 | mBoolMap.insert( mGroup + key, value ); | ||
110 | |||
111 | mDirty = true; | ||
112 | } | ||
113 | |||
114 | void KConfig::writeEntry( const QString &, const QColor & ) | ||
115 | { | ||
116 | } | ||
117 | |||
118 | void KConfig::writeEntry( const QString &, const QFont & ) | ||
119 | { | ||
120 | } | ||
121 | |||
122 | void KConfig::load() | ||
123 | { | ||
124 | mBoolMap.clear(); | ||
125 | mStringMap.clear(); | ||
126 | |||
127 | QFile f( mFileName ); | ||
128 | if ( !f.open( IO_ReadOnly ) ) { | ||
129 | kdDebug() << "KConfig::load(): Can't open file '" << mFileName << "'" | ||
130 | << endl; | ||
131 | return; | ||
132 | } | ||
133 | |||
134 | |||
135 | QTextStream t( &f ); | ||
136 | |||
137 | QString line = t.readLine(); | ||
138 | |||
139 | while ( !line.isNull() ) { | ||
140 | QStringList tokens = QStringList::split( ",", line ); | ||
141 | if ( tokens[0] == "bool" ) { | ||
142 | bool value = false; | ||
143 | if ( tokens[2] == "1" ) value = true; | ||
144 | |||
145 | mBoolMap.insert( tokens[1], value ); | ||
146 | } else if ( tokens[0] == "QString" ) { | ||
147 | QString value = tokens[2]; | ||
148 | mStringMap.insert( tokens[1], value ); | ||
149 | } | ||
150 | |||
151 | line = t.readLine(); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | void KConfig::sync() | ||
156 | { | ||
157 | if ( !mDirty ) return; | ||
158 | |||
159 | QFile f( mFileName ); | ||
160 | if ( !f.open( IO_WriteOnly ) ) { | ||
161 | kdDebug() << "KConfig::sync(): Can't open file '" << mFileName << "'" | ||
162 | << endl; | ||
163 | return; | ||
164 | } | ||
165 | |||
166 | QTextStream t( &f ); | ||
167 | |||
168 | QMap<QString,bool>::ConstIterator itBool; | ||
169 | for( itBool = mBoolMap.begin(); itBool != mBoolMap.end(); ++itBool ) { | ||
170 | t << "bool," << itBool.key() << "," << (*itBool ) << endl; | ||
171 | } | ||
172 | |||
173 | QMap<QString,QString>::ConstIterator itString; | ||
174 | for( itString = mStringMap.begin(); itString != mStringMap.end(); ++itString ) { | ||
175 | t << "QString," << itString.key() << "," << (*itString ) << endl; | ||
176 | } | ||
177 | |||
178 | f.close(); | ||
179 | |||
180 | mDirty = false; | ||
181 | } | ||
diff --git a/noncore/apps/tinykate/libkate/microkde/kconfig.h b/noncore/apps/tinykate/libkate/microkde/kconfig.h deleted file mode 100644 index 8bd768a..0000000 --- a/noncore/apps/tinykate/libkate/microkde/kconfig.h +++ b/dev/null | |||
@@ -1,51 +0,0 @@ | |||
1 | #ifndef MINIKDE_KCONFIG_H | ||
2 | #define MINIKDE_KCONFIG_H | ||
3 | |||
4 | #include <qstring.h> | ||
5 | #include <qstringlist.h> | ||
6 | #include <qvaluelist.h> | ||
7 | #include <qcolor.h> | ||
8 | #include <qfont.h> | ||
9 | #include <qmap.h> | ||
10 | |||
11 | class KConfig | ||
12 | { | ||
13 | public: | ||
14 | KConfig( const QString & ); | ||
15 | ~KConfig(); | ||
16 | |||
17 | void setGroup( const QString & ); | ||
18 | |||
19 | bool hasGroup( const QString &) {return false;} | ||
20 | |||
21 | QValueList<int> readIntListEntry( const QString & ); | ||
22 | int readNumEntry( const QString &, int def=0 ); | ||
23 | QString readEntry( const QString &, const QString &def=QString::null ); | ||
24 | QStringList readListEntry( const QString & ); | ||
25 | bool readBoolEntry( const QString &, bool def=false ); | ||
26 | QColor readColorEntry( const QString &, QColor * ); | ||
27 | QFont readFontEntry( const QString &, QFont * ); | ||
28 | |||
29 | void writeEntry( const QString &, QValueList<int> ); | ||
30 | void writeEntry( const QString &, int ); | ||
31 | void writeEntry( const QString &, const QString & ); | ||
32 | void writeEntry( const QString &, const QStringList & ); | ||
33 | void writeEntry( const QString &, bool ); | ||
34 | void writeEntry( const QString &, const QColor & ); | ||
35 | void writeEntry( const QString &, const QFont & ); | ||
36 | |||
37 | void load(); | ||
38 | void sync(); | ||
39 | |||
40 | private: | ||
41 | static QString mGroup; | ||
42 | |||
43 | QString mFileName; | ||
44 | |||
45 | QMap<QString,bool> mBoolMap; | ||
46 | QMap<QString,QString> mStringMap; | ||
47 | |||
48 | bool mDirty; | ||
49 | }; | ||
50 | |||
51 | #endif | ||
diff --git a/noncore/apps/tinykate/libkate/microkde/kglobal.cpp b/noncore/apps/tinykate/libkate/microkde/kglobal.cpp index 572768d..9b5c4d3 100644 --- a/noncore/apps/tinykate/libkate/microkde/kglobal.cpp +++ b/noncore/apps/tinykate/libkate/microkde/kglobal.cpp | |||
@@ -1,49 +1,49 @@ | |||
1 | #include "kglobal.h" | 1 | #include "kglobal.h" |
2 | 2 | ||
3 | KLocale *KGlobal::mLocale = 0; | 3 | KLocale *KGlobal::mLocale = 0; |
4 | KConfig *KGlobal::mConfig = 0; | 4 | KateConfig *KGlobal::mConfig = 0; |
5 | KIconLoader *KGlobal::mIconLoader = 0; | 5 | KIconLoader *KGlobal::mIconLoader = 0; |
6 | KStandardDirs *KGlobal::mDirs = 0; | 6 | KStandardDirs *KGlobal::mDirs = 0; |
7 | 7 | ||
8 | QString KGlobal::mAppName = "godot"; | 8 | QString KGlobal::mAppName = "godot"; |
9 | 9 | ||
10 | KLocale *KGlobal::locale() | 10 | KLocale *KGlobal::locale() |
11 | { | 11 | { |
12 | if ( !mLocale ) { | 12 | if ( !mLocale ) { |
13 | mLocale = new KLocale(); | 13 | mLocale = new KLocale(); |
14 | } | 14 | } |
15 | 15 | ||
16 | return mLocale; | 16 | return mLocale; |
17 | } | 17 | } |
18 | 18 | ||
19 | KConfig *KGlobal::config() | 19 | KateConfig *KGlobal::config() |
20 | { | 20 | { |
21 | if ( !mConfig ) { | 21 | if ( !mConfig ) { |
22 | mConfig = new KConfig( KStandardDirs::appDir() + mAppName + "rc" ); | 22 | mConfig = new KateConfig( mAppName ); |
23 | } | 23 | } |
24 | 24 | ||
25 | return mConfig; | 25 | return mConfig; |
26 | } | 26 | } |
27 | 27 | ||
28 | KIconLoader *KGlobal::iconLoader() | 28 | KIconLoader *KGlobal::iconLoader() |
29 | { | 29 | { |
30 | if ( !mIconLoader ) { | 30 | if ( !mIconLoader ) { |
31 | mIconLoader = new KIconLoader(); | 31 | mIconLoader = new KIconLoader(); |
32 | } | 32 | } |
33 | 33 | ||
34 | return mIconLoader; | 34 | return mIconLoader; |
35 | } | 35 | } |
36 | 36 | ||
37 | KStandardDirs *KGlobal::dirs() | 37 | KStandardDirs *KGlobal::dirs() |
38 | { | 38 | { |
39 | if ( !mDirs ) { | 39 | if ( !mDirs ) { |
40 | mDirs = new KStandardDirs(); | 40 | mDirs = new KStandardDirs(); |
41 | } | 41 | } |
42 | 42 | ||
43 | return mDirs; | 43 | return mDirs; |
44 | } | 44 | } |
45 | 45 | ||
46 | void KGlobal::setAppName( const QString &appName ) | 46 | void KGlobal::setAppName( const QString &appName ) |
47 | { | 47 | { |
48 | mAppName = appName; | 48 | mAppName = appName; |
49 | } | 49 | } |
diff --git a/noncore/apps/tinykate/libkate/microkde/kglobal.h b/noncore/apps/tinykate/libkate/microkde/kglobal.h index 8985bd4..e4e2c79 100644 --- a/noncore/apps/tinykate/libkate/microkde/kglobal.h +++ b/noncore/apps/tinykate/libkate/microkde/kglobal.h | |||
@@ -1,27 +1,27 @@ | |||
1 | #ifndef MINIKDE_KGLOBAL_H | 1 | #ifndef MINIKDE_KGLOBAL_H |
2 | #define MINIKDE_KGLOBAL_H | 2 | #define MINIKDE_KGLOBAL_H |
3 | 3 | ||
4 | #include "klocale.h" | 4 | #include "klocale.h" |
5 | #include "kiconloader.h" | 5 | #include "kiconloader.h" |
6 | #include "kstandarddirs.h" | 6 | #include "kstandarddirs.h" |
7 | #include "kconfig.h" | 7 | #include <kateconfig.h> |
8 | 8 | ||
9 | class KGlobal { | 9 | class KGlobal { |
10 | public: | 10 | public: |
11 | static KLocale *locale(); | 11 | static KLocale *locale(); |
12 | static KConfig *config(); | 12 | static KateConfig *config(); |
13 | static KIconLoader *iconLoader(); | 13 | static KIconLoader *iconLoader(); |
14 | static KStandardDirs *dirs(); | 14 | static KStandardDirs *dirs(); |
15 | 15 | ||
16 | static void setAppName( const QString & ); | 16 | static void setAppName( const QString & ); |
17 | 17 | ||
18 | private: | 18 | private: |
19 | static KLocale *mLocale; | 19 | static KLocale *mLocale; |
20 | static KConfig *mConfig; | 20 | static KateConfig *mConfig; |
21 | static KIconLoader *mIconLoader; | 21 | static KIconLoader *mIconLoader; |
22 | static KStandardDirs *mDirs; | 22 | static KStandardDirs *mDirs; |
23 | 23 | ||
24 | static QString mAppName; | 24 | static QString mAppName; |
25 | }; | 25 | }; |
26 | 26 | ||
27 | #endif | 27 | #endif |
diff --git a/noncore/apps/tinykate/libkate/view/kateview.cpp b/noncore/apps/tinykate/libkate/view/kateview.cpp index 63e941f..af3b30d 100644 --- a/noncore/apps/tinykate/libkate/view/kateview.cpp +++ b/noncore/apps/tinykate/libkate/view/kateview.cpp | |||
@@ -1,2923 +1,2923 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | kateview.cpp - description | 2 | kateview.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Jan 15 2001 | 4 | begin : Mon Jan 15 2001 |
5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann | 5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann |
6 | (C) 2002 by Joseph Wenninger | 6 | (C) 2002 by Joseph Wenninger |
7 | email : crossfire@babylon2k.de | 7 | email : crossfire@babylon2k.de |
8 | jowenn@kde.org | 8 | jowenn@kde.org |
9 | ***************************************************************************/ | 9 | ***************************************************************************/ |
10 | 10 | ||
11 | /*************************************************************************** | 11 | /*************************************************************************** |
12 | * * | 12 | * * |
13 | * This program is free software; you can redistribute it and/or modify * | 13 | * This program is free software; you can redistribute it and/or modify * |
14 | * it under the terms of the GNU General Public License as published by * | 14 | * it under the terms of the GNU General Public License as published by * |
15 | * the Free Software Foundation; either version 2 of the License, or * | 15 | * the Free Software Foundation; either version 2 of the License, or * |
16 | * (at your option) any later version. * | 16 | * (at your option) any later version. * |
17 | * * | 17 | * * |
18 | ***************************************************************************/ | 18 | ***************************************************************************/ |
19 | 19 | ||
20 | /* | 20 | /* |
21 | Copyright (C) 1998, 1999 Jochen Wilhelmy | 21 | Copyright (C) 1998, 1999 Jochen Wilhelmy |
22 | digisnap@cs.tu-berlin.de | 22 | digisnap@cs.tu-berlin.de |
23 | 23 | ||
24 | This library is free software; you can redistribute it and/or | 24 | This library is free software; you can redistribute it and/or |
25 | modify it under the terms of the GNU Library General Public | 25 | modify it under the terms of the GNU Library General Public |
26 | License as published by the Free Software Foundation; either | 26 | License as published by the Free Software Foundation; either |
27 | version 2 of the License, or (at your option) any later version. | 27 | version 2 of the License, or (at your option) any later version. |
28 | 28 | ||
29 | This library is distributed in the hope that it will be useful, | 29 | This library is distributed in the hope that it will be useful, |
30 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 30 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
31 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 31 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
32 | Library General Public License for more details. | 32 | Library General Public License for more details. |
33 | 33 | ||
34 | You should have received a copy of the GNU Library General Public License | 34 | You should have received a copy of the GNU Library General Public License |
35 | along with this library; see the file COPYING.LIB. If not, write to | 35 | along with this library; see the file COPYING.LIB. If not, write to |
36 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 36 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
37 | Boston, MA 02111-1307, USA. | 37 | Boston, MA 02111-1307, USA. |
38 | */ | 38 | */ |
39 | 39 | ||
40 | 40 | ||
41 | 41 | ||
42 | #include "kateview.h" | 42 | #include "kateview.h" |
43 | 43 | ||
44 | #include "../document/katedocument.h" | 44 | #include "../document/katedocument.h" |
45 | #include "../document/katecmd.h" | 45 | #include "../document/katecmd.h" |
46 | #include "../document/katehighlight.h" | 46 | #include "../document/katehighlight.h" |
47 | #include "kateviewdialog.h" | 47 | #include "kateviewdialog.h" |
48 | #include "../document/katedialogs.h" | 48 | #include "../document/katedialogs.h" |
49 | #include <kateconfig.h> | ||
49 | 50 | ||
50 | #include <qfocusdata.h> | 51 | #include <qfocusdata.h> |
51 | #include <kdebug.h> | 52 | #include <kdebug.h> |
52 | #include <kapplication.h> | 53 | #include <kapplication.h> |
53 | #include <qscrollbar.h> | 54 | #include <qscrollbar.h> |
54 | #include <qiodevice.h> | 55 | #include <qiodevice.h> |
55 | #include <qpopupmenu.h> | 56 | #include <qpopupmenu.h> |
56 | #include <kpopupmenu.h> | 57 | #include <kpopupmenu.h> |
57 | #include <qkeycode.h> | 58 | #include <qkeycode.h> |
58 | #include <qintdict.h> | 59 | #include <qintdict.h> |
59 | #include <kconfig.h> | ||
60 | #include <qfont.h> | 60 | #include <qfont.h> |
61 | #include <qpainter.h> | 61 | #include <qpainter.h> |
62 | #include <qpixmap.h> | 62 | #include <qpixmap.h> |
63 | #include <qfileinfo.h> | 63 | #include <qfileinfo.h> |
64 | #include <qfile.h> | 64 | #include <qfile.h> |
65 | #include <qevent.h> | 65 | #include <qevent.h> |
66 | #include <qdir.h> | 66 | #include <qdir.h> |
67 | #include <qvbox.h> | 67 | #include <qvbox.h> |
68 | #include <qprintdialog.h> | 68 | #include <qprintdialog.h> |
69 | #include <qpaintdevicemetrics.h> | 69 | #include <qpaintdevicemetrics.h> |
70 | #include <qiodevice.h> | 70 | #include <qiodevice.h> |
71 | #include <qbuffer.h> | 71 | #include <qbuffer.h> |
72 | #include <qfocusdata.h> | 72 | #include <qfocusdata.h> |
73 | #include <klocale.h> | 73 | #include <klocale.h> |
74 | #include <kglobal.h> | 74 | #include <kglobal.h> |
75 | #include <kdebug.h> | 75 | #include <kdebug.h> |
76 | #include <kmessagebox.h> | 76 | #include <kmessagebox.h> |
77 | #include <qregexp.h> | 77 | #include <qregexp.h> |
78 | #include <kdialogbase.h> | 78 | #include <kdialogbase.h> |
79 | #include <klineeditdlg.h> | 79 | #include <klineeditdlg.h> |
80 | #include <qapplication.h> | 80 | #include <qapplication.h> |
81 | #include <kfiledialog.h> | 81 | #include <kfiledialog.h> |
82 | #include <kiconloader.h> | 82 | #include <kiconloader.h> |
83 | #include "../document/katetextline.h" | 83 | #include "../document/katetextline.h" |
84 | #include "kateviewdialog.h" | 84 | #include "kateviewdialog.h" |
85 | #include "kateundohistory.h" | 85 | #include "kateundohistory.h" |
86 | #include <qlayout.h> | 86 | #include <qlayout.h> |
87 | 87 | ||
88 | KateViewInternal::KateViewInternal(KateView *view, KateDocument *doc) : QWidget(view) | 88 | KateViewInternal::KateViewInternal(KateView *view, KateDocument *doc) : QWidget(view) |
89 | { | 89 | { |
90 | waitForPreHighlight=-1; | 90 | waitForPreHighlight=-1; |
91 | myView = view; | 91 | myView = view; |
92 | myDoc = doc; | 92 | myDoc = doc; |
93 | 93 | ||
94 | iconBorderWidth = 16; | 94 | iconBorderWidth = 16; |
95 | iconBorderHeight = 800; | 95 | iconBorderHeight = 800; |
96 | 96 | ||
97 | QWidget::setCursor(ibeamCursor); | 97 | QWidget::setCursor(ibeamCursor); |
98 | setBackgroundMode(NoBackground); | 98 | setBackgroundMode(NoBackground); |
99 | 99 | ||
100 | setFocusPolicy(StrongFocus); | 100 | setFocusPolicy(StrongFocus); |
101 | 101 | ||
102 | xScroll = new QScrollBar(QScrollBar::Horizontal,myView); | 102 | xScroll = new QScrollBar(QScrollBar::Horizontal,myView); |
103 | yScroll = new QScrollBar(QScrollBar::Vertical,myView); | 103 | yScroll = new QScrollBar(QScrollBar::Vertical,myView); |
104 | connect(xScroll,SIGNAL(valueChanged(int)),SLOT(changeXPos(int))); | 104 | connect(xScroll,SIGNAL(valueChanged(int)),SLOT(changeXPos(int))); |
105 | connect(yScroll,SIGNAL(valueChanged(int)),SLOT(changeYPos(int))); | 105 | connect(yScroll,SIGNAL(valueChanged(int)),SLOT(changeYPos(int))); |
106 | connect(yScroll,SIGNAL(valueChanged(int)),myView,SIGNAL(scrollValueChanged(int))); | 106 | connect(yScroll,SIGNAL(valueChanged(int)),myView,SIGNAL(scrollValueChanged(int))); |
107 | connect( doc, SIGNAL (preHighlightChanged(long)),this,SLOT(slotPreHighlightUpdate(long))); | 107 | connect( doc, SIGNAL (preHighlightChanged(long)),this,SLOT(slotPreHighlightUpdate(long))); |
108 | 108 | ||
109 | xPos = 0; | 109 | xPos = 0; |
110 | yPos = 0; | 110 | yPos = 0; |
111 | 111 | ||
112 | scrollTimer = 0; | 112 | scrollTimer = 0; |
113 | 113 | ||
114 | cursor.x = 0; | 114 | cursor.x = 0; |
115 | cursor.y = 0; | 115 | cursor.y = 0; |
116 | cursorOn = false; | 116 | cursorOn = false; |
117 | cursorTimer = 0; | 117 | cursorTimer = 0; |
118 | cXPos = 0; | 118 | cXPos = 0; |
119 | cOldXPos = 0; | 119 | cOldXPos = 0; |
120 | 120 | ||
121 | startLine = 0; | 121 | startLine = 0; |
122 | endLine = -1; | 122 | endLine = -1; |
123 | 123 | ||
124 | exposeCursor = false; | 124 | exposeCursor = false; |
125 | updateState = 0; | 125 | updateState = 0; |
126 | numLines = 0; | 126 | numLines = 0; |
127 | lineRanges = 0L; | 127 | lineRanges = 0L; |
128 | newXPos = -1; | 128 | newXPos = -1; |
129 | newYPos = -1; | 129 | newYPos = -1; |
130 | 130 | ||
131 | drawBuffer = new QPixmap (); | 131 | drawBuffer = new QPixmap (); |
132 | drawBuffer->setOptimization (QPixmap::BestOptim); | 132 | drawBuffer->setOptimization (QPixmap::BestOptim); |
133 | 133 | ||
134 | bm.sXPos = 0; | 134 | bm.sXPos = 0; |
135 | bm.eXPos = -1; | 135 | bm.eXPos = -1; |
136 | 136 | ||
137 | } | 137 | } |
138 | 138 | ||
139 | 139 | ||
140 | KateViewInternal::~KateViewInternal() | 140 | KateViewInternal::~KateViewInternal() |
141 | { | 141 | { |
142 | delete [] lineRanges; | 142 | delete [] lineRanges; |
143 | delete drawBuffer; | 143 | delete drawBuffer; |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | void KateViewInternal::slotPreHighlightUpdate(long line) | 147 | void KateViewInternal::slotPreHighlightUpdate(long line) |
148 | { | 148 | { |
149 | //kdDebug()<<QString("slotPreHighlightUpdate - Wait for: %1, line: %2").arg(waitForPreHighlight).arg(line)<<endl; | 149 | //kdDebug()<<QString("slotPreHighlightUpdate - Wait for: %1, line: %2").arg(waitForPreHighlight).arg(line)<<endl; |
150 | if (waitForPreHighlight!=-1) | 150 | if (waitForPreHighlight!=-1) |
151 | { | 151 | { |
152 | if (line>=waitForPreHighlight) | 152 | if (line>=waitForPreHighlight) |
153 | { | 153 | { |
154 | waitForPreHighlight=-1; | 154 | waitForPreHighlight=-1; |
155 | repaint(); | 155 | repaint(); |
156 | } | 156 | } |
157 | } | 157 | } |
158 | } | 158 | } |
159 | 159 | ||
160 | void KateViewInternal::doCursorCommand(VConfig &c, int cmdNum) { | 160 | void KateViewInternal::doCursorCommand(VConfig &c, int cmdNum) { |
161 | 161 | ||
162 | switch (cmdNum) { | 162 | switch (cmdNum) { |
163 | case KateView::cmLeft: | 163 | case KateView::cmLeft: |
164 | cursorLeft(c); | 164 | cursorLeft(c); |
165 | break; | 165 | break; |
166 | case KateView::cmRight: | 166 | case KateView::cmRight: |
167 | cursorRight(c); | 167 | cursorRight(c); |
168 | break; | 168 | break; |
169 | case KateView::cmWordLeft: | 169 | case KateView::cmWordLeft: |
170 | wordLeft(c); | 170 | wordLeft(c); |
171 | break; | 171 | break; |
172 | case KateView::cmWordRight: | 172 | case KateView::cmWordRight: |
173 | wordRight(c); | 173 | wordRight(c); |
174 | break; | 174 | break; |
175 | case KateView::cmHome: | 175 | case KateView::cmHome: |
176 | home(c); | 176 | home(c); |
177 | break; | 177 | break; |
178 | case KateView::cmEnd: | 178 | case KateView::cmEnd: |
179 | end(c); | 179 | end(c); |
180 | break; | 180 | break; |
181 | case KateView::cmUp: | 181 | case KateView::cmUp: |
182 | cursorUp(c); | 182 | cursorUp(c); |
183 | break; | 183 | break; |
184 | case KateView::cmDown: | 184 | case KateView::cmDown: |
185 | cursorDown(c); | 185 | cursorDown(c); |
186 | break; | 186 | break; |
187 | case KateView::cmScrollUp: | 187 | case KateView::cmScrollUp: |
188 | scrollUp(c); | 188 | scrollUp(c); |
189 | break; | 189 | break; |
190 | case KateView::cmScrollDown: | 190 | case KateView::cmScrollDown: |
191 | scrollDown(c); | 191 | scrollDown(c); |
192 | break; | 192 | break; |
193 | case KateView::cmTopOfView: | 193 | case KateView::cmTopOfView: |
194 | topOfView(c); | 194 | topOfView(c); |
195 | break; | 195 | break; |
196 | case KateView::cmBottomOfView: | 196 | case KateView::cmBottomOfView: |
197 | bottomOfView(c); | 197 | bottomOfView(c); |
198 | break; | 198 | break; |
199 | case KateView::cmPageUp: | 199 | case KateView::cmPageUp: |
200 | pageUp(c); | 200 | pageUp(c); |
201 | break; | 201 | break; |
202 | case KateView::cmPageDown: | 202 | case KateView::cmPageDown: |
203 | pageDown(c); | 203 | pageDown(c); |
204 | break; | 204 | break; |
205 | case KateView::cmTop: | 205 | case KateView::cmTop: |
206 | top_home(c); | 206 | top_home(c); |
207 | break; | 207 | break; |
208 | case KateView::cmBottom: | 208 | case KateView::cmBottom: |
209 | bottom_end(c); | 209 | bottom_end(c); |
210 | break; | 210 | break; |
211 | } | 211 | } |
212 | } | 212 | } |
213 | 213 | ||
214 | void KateViewInternal::doEditCommand(VConfig &c, int cmdNum) { | 214 | void KateViewInternal::doEditCommand(VConfig &c, int cmdNum) { |
215 | 215 | ||
216 | switch (cmdNum) { | 216 | switch (cmdNum) { |
217 | case KateView::cmCopy: | 217 | case KateView::cmCopy: |
218 | myDoc->copy(c.flags); | 218 | myDoc->copy(c.flags); |
219 | return; | 219 | return; |
220 | case KateView::cmSelectAll: | 220 | case KateView::cmSelectAll: |
221 | myDoc->selectAll(); | 221 | myDoc->selectAll(); |
222 | return; | 222 | return; |
223 | case KateView::cmDeselectAll: | 223 | case KateView::cmDeselectAll: |
224 | myDoc->deselectAll(); | 224 | myDoc->deselectAll(); |
225 | return; | 225 | return; |
226 | case KateView::cmInvertSelection: | 226 | case KateView::cmInvertSelection: |
227 | myDoc->invertSelection(); | 227 | myDoc->invertSelection(); |
228 | return; | 228 | return; |
229 | } | 229 | } |
230 | if (myView->isReadOnly()) return; | 230 | if (myView->isReadOnly()) return; |
231 | switch (cmdNum) { | 231 | switch (cmdNum) { |
232 | case KateView::cmReturn: | 232 | case KateView::cmReturn: |
233 | if (c.flags & KateView::cfDelOnInput) myDoc->delMarkedText(c); | 233 | if (c.flags & KateView::cfDelOnInput) myDoc->delMarkedText(c); |
234 | myDoc->newLine(c); | 234 | myDoc->newLine(c); |
235 | //emit returnPressed(); | 235 | //emit returnPressed(); |
236 | //e->ignore(); | 236 | //e->ignore(); |
237 | return; | 237 | return; |
238 | case KateView::cmDelete: | 238 | case KateView::cmDelete: |
239 | if ((c.flags & KateView::cfDelOnInput) && myDoc->hasMarkedText()) | 239 | if ((c.flags & KateView::cfDelOnInput) && myDoc->hasMarkedText()) |
240 | myDoc->delMarkedText(c); | 240 | myDoc->delMarkedText(c); |
241 | else myDoc->del(c); | 241 | else myDoc->del(c); |
242 | return; | 242 | return; |
243 | case KateView::cmBackspace: | 243 | case KateView::cmBackspace: |
244 | if ((c.flags & KateView::cfDelOnInput) && myDoc->hasMarkedText()) | 244 | if ((c.flags & KateView::cfDelOnInput) && myDoc->hasMarkedText()) |
245 | myDoc->delMarkedText(c); | 245 | myDoc->delMarkedText(c); |
246 | else myDoc->backspace(c); | 246 | else myDoc->backspace(c); |
247 | return; | 247 | return; |
248 | case KateView::cmKillLine: | 248 | case KateView::cmKillLine: |
249 | myDoc->killLine(c); | 249 | myDoc->killLine(c); |
250 | return; | 250 | return; |
251 | case KateView::cmCut: | 251 | case KateView::cmCut: |
252 | myDoc->cut(c); | 252 | myDoc->cut(c); |
253 | return; | 253 | return; |
254 | case KateView::cmPaste: | 254 | case KateView::cmPaste: |
255 | if (c.flags & KateView::cfDelOnInput) myDoc->delMarkedText(c); | 255 | if (c.flags & KateView::cfDelOnInput) myDoc->delMarkedText(c); |
256 | myDoc->paste(c); | 256 | myDoc->paste(c); |
257 | return; | 257 | return; |
258 | case KateView::cmUndo: | 258 | case KateView::cmUndo: |
259 | myDoc->undo(c); | 259 | myDoc->undo(c); |
260 | return; | 260 | return; |
261 | case KateView::cmRedo: | 261 | case KateView::cmRedo: |
262 | myDoc->redo(c); | 262 | myDoc->redo(c); |
263 | return; | 263 | return; |
264 | case KateView::cmIndent: | 264 | case KateView::cmIndent: |
265 | myDoc->indent(c); | 265 | myDoc->indent(c); |
266 | return; | 266 | return; |
267 | case KateView::cmUnindent: | 267 | case KateView::cmUnindent: |
268 | myDoc->unIndent(c); | 268 | myDoc->unIndent(c); |
269 | return; | 269 | return; |
270 | case KateView::cmCleanIndent: | 270 | case KateView::cmCleanIndent: |
271 | myDoc->cleanIndent(c); | 271 | myDoc->cleanIndent(c); |
272 | return; | 272 | return; |
273 | case KateView::cmComment: | 273 | case KateView::cmComment: |
274 | myDoc->comment(c); | 274 | myDoc->comment(c); |
275 | return; | 275 | return; |
276 | case KateView::cmUncomment: | 276 | case KateView::cmUncomment: |
277 | myDoc->unComment(c); | 277 | myDoc->unComment(c); |
278 | return; | 278 | return; |
279 | } | 279 | } |
280 | } | 280 | } |
281 | 281 | ||
282 | void KateViewInternal::cursorLeft(VConfig &c) { | 282 | void KateViewInternal::cursorLeft(VConfig &c) { |
283 | 283 | ||
284 | cursor.x--; | 284 | cursor.x--; |
285 | if (c.flags & KateView::cfWrapCursor && cursor.x < 0 && cursor.y > 0) { | 285 | if (c.flags & KateView::cfWrapCursor && cursor.x < 0 && cursor.y > 0) { |
286 | cursor.y--; | 286 | cursor.y--; |
287 | cursor.x = myDoc->textLength(cursor.y); | 287 | cursor.x = myDoc->textLength(cursor.y); |
288 | } | 288 | } |
289 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 289 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
290 | changeState(c); | 290 | changeState(c); |
291 | } | 291 | } |
292 | 292 | ||
293 | void KateViewInternal::cursorRight(VConfig &c) { | 293 | void KateViewInternal::cursorRight(VConfig &c) { |
294 | 294 | ||
295 | if (c.flags & KateView::cfWrapCursor) { | 295 | if (c.flags & KateView::cfWrapCursor) { |
296 | if (cursor.x >= myDoc->textLength(cursor.y)) { | 296 | if (cursor.x >= myDoc->textLength(cursor.y)) { |
297 | if (cursor.y == myDoc->lastLine()) return; | 297 | if (cursor.y == myDoc->lastLine()) return; |
298 | cursor.y++; | 298 | cursor.y++; |
299 | cursor.x = -1; | 299 | cursor.x = -1; |
300 | } | 300 | } |
301 | } | 301 | } |
302 | cursor.x++; | 302 | cursor.x++; |
303 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 303 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
304 | changeState(c); | 304 | changeState(c); |
305 | } | 305 | } |
306 | 306 | ||
307 | void KateViewInternal::wordLeft(VConfig &c) { | 307 | void KateViewInternal::wordLeft(VConfig &c) { |
308 | Highlight *highlight; | 308 | Highlight *highlight; |
309 | 309 | ||
310 | highlight = myDoc->highlight(); | 310 | highlight = myDoc->highlight(); |
311 | TextLine::Ptr textLine = myDoc->getTextLine(cursor.y); | 311 | TextLine::Ptr textLine = myDoc->getTextLine(cursor.y); |
312 | 312 | ||
313 | if (cursor.x > 0) { | 313 | if (cursor.x > 0) { |
314 | do { | 314 | do { |
315 | cursor.x--; | 315 | cursor.x--; |
316 | } while (cursor.x > 0 && !highlight->isInWord(textLine->getChar(cursor.x))); | 316 | } while (cursor.x > 0 && !highlight->isInWord(textLine->getChar(cursor.x))); |
317 | while (cursor.x > 0 && highlight->isInWord(textLine->getChar(cursor.x -1))) | 317 | while (cursor.x > 0 && highlight->isInWord(textLine->getChar(cursor.x -1))) |
318 | cursor.x--; | 318 | cursor.x--; |
319 | } else { | 319 | } else { |
320 | if (cursor.y > 0) { | 320 | if (cursor.y > 0) { |
321 | cursor.y--; | 321 | cursor.y--; |
322 | textLine = myDoc->getTextLine(cursor.y); | 322 | textLine = myDoc->getTextLine(cursor.y); |
323 | cursor.x = textLine->length(); | 323 | cursor.x = textLine->length(); |
324 | } | 324 | } |
325 | } | 325 | } |
326 | 326 | ||
327 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 327 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
328 | changeState(c); | 328 | changeState(c); |
329 | } | 329 | } |
330 | 330 | ||
331 | void KateViewInternal::wordRight(VConfig &c) { | 331 | void KateViewInternal::wordRight(VConfig &c) { |
332 | Highlight *highlight; | 332 | Highlight *highlight; |
333 | int len; | 333 | int len; |
334 | 334 | ||
335 | highlight = myDoc->highlight(); | 335 | highlight = myDoc->highlight(); |
336 | TextLine::Ptr textLine = myDoc->getTextLine(cursor.y); | 336 | TextLine::Ptr textLine = myDoc->getTextLine(cursor.y); |
337 | len = textLine->length(); | 337 | len = textLine->length(); |
338 | 338 | ||
339 | if (cursor.x < len) { | 339 | if (cursor.x < len) { |
340 | do { | 340 | do { |
341 | cursor.x++; | 341 | cursor.x++; |
342 | } while (cursor.x < len && highlight->isInWord(textLine->getChar(cursor.x))); | 342 | } while (cursor.x < len && highlight->isInWord(textLine->getChar(cursor.x))); |
343 | while (cursor.x < len && !highlight->isInWord(textLine->getChar(cursor.x))) | 343 | while (cursor.x < len && !highlight->isInWord(textLine->getChar(cursor.x))) |
344 | cursor.x++; | 344 | cursor.x++; |
345 | } else { | 345 | } else { |
346 | if (cursor.y < myDoc->lastLine()) { | 346 | if (cursor.y < myDoc->lastLine()) { |
347 | cursor.y++; | 347 | cursor.y++; |
348 | textLine = myDoc->getTextLine(cursor.y); | 348 | textLine = myDoc->getTextLine(cursor.y); |
349 | cursor.x = 0; | 349 | cursor.x = 0; |
350 | } | 350 | } |
351 | } | 351 | } |
352 | 352 | ||
353 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 353 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
354 | changeState(c); | 354 | changeState(c); |
355 | } | 355 | } |
356 | 356 | ||
357 | void KateViewInternal::home(VConfig &c) { | 357 | void KateViewInternal::home(VConfig &c) { |
358 | int lc; | 358 | int lc; |
359 | 359 | ||
360 | lc = (c.flags & KateView::cfSmartHome) ? myDoc->getTextLine(cursor.y)->firstChar() : 0; | 360 | lc = (c.flags & KateView::cfSmartHome) ? myDoc->getTextLine(cursor.y)->firstChar() : 0; |
361 | if (lc <= 0 || cursor.x == lc) { | 361 | if (lc <= 0 || cursor.x == lc) { |
362 | cursor.x = 0; | 362 | cursor.x = 0; |
363 | cOldXPos = cXPos = 0; | 363 | cOldXPos = cXPos = 0; |
364 | } else { | 364 | } else { |
365 | cursor.x = lc; | 365 | cursor.x = lc; |
366 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 366 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
367 | } | 367 | } |
368 | 368 | ||
369 | changeState(c); | 369 | changeState(c); |
370 | } | 370 | } |
371 | 371 | ||
372 | void KateViewInternal::end(VConfig &c) { | 372 | void KateViewInternal::end(VConfig &c) { |
373 | cursor.x = myDoc->textLength(cursor.y); | 373 | cursor.x = myDoc->textLength(cursor.y); |
374 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 374 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
375 | changeState(c); | 375 | changeState(c); |
376 | } | 376 | } |
377 | 377 | ||
378 | 378 | ||
379 | void KateViewInternal::cursorUp(VConfig &c) { | 379 | void KateViewInternal::cursorUp(VConfig &c) { |
380 | 380 | ||
381 | cursor.y--; | 381 | cursor.y--; |
382 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); | 382 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); |
383 | changeState(c); | 383 | changeState(c); |
384 | } | 384 | } |
385 | 385 | ||
386 | 386 | ||
387 | void KateViewInternal::cursorDown(VConfig &c) { | 387 | void KateViewInternal::cursorDown(VConfig &c) { |
388 | int x; | 388 | int x; |
389 | 389 | ||
390 | if (cursor.y == myDoc->lastLine()) { | 390 | if (cursor.y == myDoc->lastLine()) { |
391 | x = myDoc->textLength(cursor.y); | 391 | x = myDoc->textLength(cursor.y); |
392 | if (cursor.x >= x) return; | 392 | if (cursor.x >= x) return; |
393 | cursor.x = x; | 393 | cursor.x = x; |
394 | cXPos = myDoc->textWidth(cursor); | 394 | cXPos = myDoc->textWidth(cursor); |
395 | } else { | 395 | } else { |
396 | cursor.y++; | 396 | cursor.y++; |
397 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor, cursor, cOldXPos); | 397 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor, cursor, cOldXPos); |
398 | } | 398 | } |
399 | changeState(c); | 399 | changeState(c); |
400 | } | 400 | } |
401 | 401 | ||
402 | void KateViewInternal::scrollUp(VConfig &c) { | 402 | void KateViewInternal::scrollUp(VConfig &c) { |
403 | 403 | ||
404 | if (! yPos) return; | 404 | if (! yPos) return; |
405 | 405 | ||
406 | newYPos = yPos - myDoc->fontHeight; | 406 | newYPos = yPos - myDoc->fontHeight; |
407 | if (cursor.y == (yPos + height())/myDoc->fontHeight -1) { | 407 | if (cursor.y == (yPos + height())/myDoc->fontHeight -1) { |
408 | cursor.y--; | 408 | cursor.y--; |
409 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); | 409 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); |
410 | 410 | ||
411 | changeState(c); | 411 | changeState(c); |
412 | } | 412 | } |
413 | } | 413 | } |
414 | 414 | ||
415 | void KateViewInternal::scrollDown(VConfig &c) { | 415 | void KateViewInternal::scrollDown(VConfig &c) { |
416 | 416 | ||
417 | if (endLine >= myDoc->lastLine()) return; | 417 | if (endLine >= myDoc->lastLine()) return; |
418 | 418 | ||
419 | newYPos = yPos + myDoc->fontHeight; | 419 | newYPos = yPos + myDoc->fontHeight; |
420 | if (cursor.y == (yPos + myDoc->fontHeight -1)/myDoc->fontHeight) { | 420 | if (cursor.y == (yPos + myDoc->fontHeight -1)/myDoc->fontHeight) { |
421 | cursor.y++; | 421 | cursor.y++; |
422 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); | 422 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); |
423 | changeState(c); | 423 | changeState(c); |
424 | } | 424 | } |
425 | } | 425 | } |
426 | 426 | ||
427 | void KateViewInternal::topOfView(VConfig &c) { | 427 | void KateViewInternal::topOfView(VConfig &c) { |
428 | 428 | ||
429 | cursor.y = (yPos + myDoc->fontHeight -1)/myDoc->fontHeight; | 429 | cursor.y = (yPos + myDoc->fontHeight -1)/myDoc->fontHeight; |
430 | cursor.x = 0; | 430 | cursor.x = 0; |
431 | cOldXPos = cXPos = 0; | 431 | cOldXPos = cXPos = 0; |
432 | changeState(c); | 432 | changeState(c); |
433 | } | 433 | } |
434 | 434 | ||
435 | void KateViewInternal::bottomOfView(VConfig &c) { | 435 | void KateViewInternal::bottomOfView(VConfig &c) { |
436 | 436 | ||
437 | cursor.y = (yPos + height())/myDoc->fontHeight -1; | 437 | cursor.y = (yPos + height())/myDoc->fontHeight -1; |
438 | if (cursor.y < 0) cursor.y = 0; | 438 | if (cursor.y < 0) cursor.y = 0; |
439 | if (cursor.y > myDoc->lastLine()) cursor.y = myDoc->lastLine(); | 439 | if (cursor.y > myDoc->lastLine()) cursor.y = myDoc->lastLine(); |
440 | cursor.x = 0; | 440 | cursor.x = 0; |
441 | cOldXPos = cXPos = 0; | 441 | cOldXPos = cXPos = 0; |
442 | changeState(c); | 442 | changeState(c); |
443 | } | 443 | } |
444 | 444 | ||
445 | void KateViewInternal::pageUp(VConfig &c) { | 445 | void KateViewInternal::pageUp(VConfig &c) { |
446 | int lines = (endLine - startLine - 1); | 446 | int lines = (endLine - startLine - 1); |
447 | 447 | ||
448 | if (lines <= 0) lines = 1; | 448 | if (lines <= 0) lines = 1; |
449 | 449 | ||
450 | if (!(c.flags & KateView::cfPageUDMovesCursor) && yPos > 0) { | 450 | if (!(c.flags & KateView::cfPageUDMovesCursor) && yPos > 0) { |
451 | newYPos = yPos - lines * myDoc->fontHeight; | 451 | newYPos = yPos - lines * myDoc->fontHeight; |
452 | if (newYPos < 0) newYPos = 0; | 452 | if (newYPos < 0) newYPos = 0; |
453 | } | 453 | } |
454 | cursor.y -= lines; | 454 | cursor.y -= lines; |
455 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor, cursor, cOldXPos); | 455 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor, cursor, cOldXPos); |
456 | changeState(c); | 456 | changeState(c); |
457 | // cursorPageUp(c); | 457 | // cursorPageUp(c); |
458 | } | 458 | } |
459 | 459 | ||
460 | void KateViewInternal::pageDown(VConfig &c) { | 460 | void KateViewInternal::pageDown(VConfig &c) { |
461 | 461 | ||
462 | int lines = (endLine - startLine - 1); | 462 | int lines = (endLine - startLine - 1); |
463 | 463 | ||
464 | if (!(c.flags & KateView::cfPageUDMovesCursor) && endLine < myDoc->lastLine()) { | 464 | if (!(c.flags & KateView::cfPageUDMovesCursor) && endLine < myDoc->lastLine()) { |
465 | if (lines < myDoc->lastLine() - endLine) | 465 | if (lines < myDoc->lastLine() - endLine) |
466 | newYPos = yPos + lines * myDoc->fontHeight; | 466 | newYPos = yPos + lines * myDoc->fontHeight; |
467 | else | 467 | else |
468 | newYPos = yPos + (myDoc->lastLine() - endLine) * myDoc->fontHeight; | 468 | newYPos = yPos + (myDoc->lastLine() - endLine) * myDoc->fontHeight; |
469 | } | 469 | } |
470 | cursor.y += lines; | 470 | cursor.y += lines; |
471 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); | 471 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); |
472 | changeState(c); | 472 | changeState(c); |
473 | // cursorPageDown(c); | 473 | // cursorPageDown(c); |
474 | } | 474 | } |
475 | 475 | ||
476 | // go to the top, same X position | 476 | // go to the top, same X position |
477 | void KateViewInternal::top(VConfig &c) { | 477 | void KateViewInternal::top(VConfig &c) { |
478 | 478 | ||
479 | // cursor.x = 0; | 479 | // cursor.x = 0; |
480 | cursor.y = 0; | 480 | cursor.y = 0; |
481 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); | 481 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); |
482 | // cOldXPos = cXPos = 0; | 482 | // cOldXPos = cXPos = 0; |
483 | changeState(c); | 483 | changeState(c); |
484 | } | 484 | } |
485 | 485 | ||
486 | // go to the bottom, same X position | 486 | // go to the bottom, same X position |
487 | void KateViewInternal::bottom(VConfig &c) { | 487 | void KateViewInternal::bottom(VConfig &c) { |
488 | 488 | ||
489 | // cursor.x = 0; | 489 | // cursor.x = 0; |
490 | cursor.y = myDoc->lastLine(); | 490 | cursor.y = myDoc->lastLine(); |
491 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); | 491 | cXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor,cursor,cOldXPos); |
492 | // cOldXPos = cXPos = 0; | 492 | // cOldXPos = cXPos = 0; |
493 | changeState(c); | 493 | changeState(c); |
494 | } | 494 | } |
495 | 495 | ||
496 | // go to the top left corner | 496 | // go to the top left corner |
497 | void KateViewInternal::top_home(VConfig &c) | 497 | void KateViewInternal::top_home(VConfig &c) |
498 | { | 498 | { |
499 | cursor.y = 0; | 499 | cursor.y = 0; |
500 | cursor.x = 0; | 500 | cursor.x = 0; |
501 | cOldXPos = cXPos = 0; | 501 | cOldXPos = cXPos = 0; |
502 | changeState(c); | 502 | changeState(c); |
503 | } | 503 | } |
504 | 504 | ||
505 | // go to the bottom right corner | 505 | // go to the bottom right corner |
506 | void KateViewInternal::bottom_end(VConfig &c) { | 506 | void KateViewInternal::bottom_end(VConfig &c) { |
507 | 507 | ||
508 | cursor.y = myDoc->lastLine(); | 508 | cursor.y = myDoc->lastLine(); |
509 | cursor.x = myDoc->textLength(cursor.y); | 509 | cursor.x = myDoc->textLength(cursor.y); |
510 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 510 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
511 | changeState(c); | 511 | changeState(c); |
512 | } | 512 | } |
513 | 513 | ||
514 | 514 | ||
515 | void KateViewInternal::changeXPos(int p) { | 515 | void KateViewInternal::changeXPos(int p) { |
516 | int dx; | 516 | int dx; |
517 | 517 | ||
518 | dx = xPos - p; | 518 | dx = xPos - p; |
519 | xPos = p; | 519 | xPos = p; |
520 | if (QABS(dx) < width()) scroll(dx, 0); else update(); | 520 | if (QABS(dx) < width()) scroll(dx, 0); else update(); |
521 | } | 521 | } |
522 | 522 | ||
523 | void KateViewInternal::changeYPos(int p) { | 523 | void KateViewInternal::changeYPos(int p) { |
524 | int dy; | 524 | int dy; |
525 | 525 | ||
526 | dy = yPos - p; | 526 | dy = yPos - p; |
527 | yPos = p; | 527 | yPos = p; |
528 | clearDirtyCache(height()); | 528 | clearDirtyCache(height()); |
529 | 529 | ||
530 | if (QABS(dy) < height()) | 530 | if (QABS(dy) < height()) |
531 | { | 531 | { |
532 | scroll(0, dy); | 532 | scroll(0, dy); |
533 | leftBorder->scroll(0, dy); | 533 | leftBorder->scroll(0, dy); |
534 | } | 534 | } |
535 | else | 535 | else |
536 | update(); | 536 | update(); |
537 | } | 537 | } |
538 | 538 | ||
539 | 539 | ||
540 | void KateViewInternal::getVConfig(VConfig &c) { | 540 | void KateViewInternal::getVConfig(VConfig &c) { |
541 | 541 | ||
542 | c.view = myView; | 542 | c.view = myView; |
543 | c.cursor = cursor; | 543 | c.cursor = cursor; |
544 | c.cXPos = cXPos; | 544 | c.cXPos = cXPos; |
545 | c.flags = myView->configFlags; | 545 | c.flags = myView->configFlags; |
546 | } | 546 | } |
547 | 547 | ||
548 | void KateViewInternal::changeState(VConfig &c) { | 548 | void KateViewInternal::changeState(VConfig &c) { |
549 | /* | 549 | /* |
550 | * we need to be sure to kill the selection on an attempted cursor | 550 | * we need to be sure to kill the selection on an attempted cursor |
551 | * movement even if the cursor doesn't physically move, | 551 | * movement even if the cursor doesn't physically move, |
552 | * but we need to be careful not to do some other things in this case, | 552 | * but we need to be careful not to do some other things in this case, |
553 | * like we don't want to expose the cursor | 553 | * like we don't want to expose the cursor |
554 | */ | 554 | */ |
555 | 555 | ||
556 | // if (cursor.x == c.cursor.x && cursor.y == c.cursor.y) return; | 556 | // if (cursor.x == c.cursor.x && cursor.y == c.cursor.y) return; |
557 | bool nullMove = (cursor.x == c.cursor.x && cursor.y == c.cursor.y); | 557 | bool nullMove = (cursor.x == c.cursor.x && cursor.y == c.cursor.y); |
558 | 558 | ||
559 | // if (cursor.y != c.cursor.y || c.flags & KateView::cfMark) myDoc->recordReset(); | 559 | // if (cursor.y != c.cursor.y || c.flags & KateView::cfMark) myDoc->recordReset(); |
560 | 560 | ||
561 | if (! nullMove) { | 561 | if (! nullMove) { |
562 | 562 | ||
563 | exposeCursor = true; | 563 | exposeCursor = true; |
564 | 564 | ||
565 | // mark old position of cursor as dirty | 565 | // mark old position of cursor as dirty |
566 | if (cursorOn) { | 566 | if (cursorOn) { |
567 | tagLines(c.cursor.y, c.cursor.y, c.cXPos -2, c.cXPos +3); | 567 | tagLines(c.cursor.y, c.cursor.y, c.cXPos -2, c.cXPos +3); |
568 | cursorOn = false; | 568 | cursorOn = false; |
569 | } | 569 | } |
570 | 570 | ||
571 | // mark old bracket mark position as dirty | 571 | // mark old bracket mark position as dirty |
572 | if (bm.sXPos < bm.eXPos) { | 572 | if (bm.sXPos < bm.eXPos) { |
573 | tagLines(bm.cursor.y, bm.cursor.y, bm.sXPos, bm.eXPos); | 573 | tagLines(bm.cursor.y, bm.cursor.y, bm.sXPos, bm.eXPos); |
574 | } | 574 | } |
575 | // make new bracket mark | 575 | // make new bracket mark |
576 | myDoc->newBracketMark(cursor, bm); | 576 | myDoc->newBracketMark(cursor, bm); |
577 | 577 | ||
578 | // remove trailing spaces when leaving a line | 578 | // remove trailing spaces when leaving a line |
579 | if (c.flags & KateView::cfRemoveSpaces && cursor.y != c.cursor.y) { | 579 | if (c.flags & KateView::cfRemoveSpaces && cursor.y != c.cursor.y) { |
580 | TextLine::Ptr textLine = myDoc->getTextLine(c.cursor.y); | 580 | TextLine::Ptr textLine = myDoc->getTextLine(c.cursor.y); |
581 | int newLen = textLine->lastChar(); | 581 | int newLen = textLine->lastChar(); |
582 | if (newLen != textLine->length()) { | 582 | if (newLen != textLine->length()) { |
583 | textLine->truncate(newLen); | 583 | textLine->truncate(newLen); |
584 | // if some spaces are removed, tag the line as dirty | 584 | // if some spaces are removed, tag the line as dirty |
585 | myDoc->tagLines(c.cursor.y, c.cursor.y); | 585 | myDoc->tagLines(c.cursor.y, c.cursor.y); |
586 | } | 586 | } |
587 | } | 587 | } |
588 | } | 588 | } |
589 | 589 | ||
590 | if (c.flags & KateView::cfMark) { | 590 | if (c.flags & KateView::cfMark) { |
591 | if (! nullMove) | 591 | if (! nullMove) |
592 | myDoc->selectTo(c, cursor, cXPos); | 592 | myDoc->selectTo(c, cursor, cXPos); |
593 | } else { | 593 | } else { |
594 | if (!(c.flags & KateView::cfPersistent)) | 594 | if (!(c.flags & KateView::cfPersistent)) |
595 | myDoc->deselectAll(); | 595 | myDoc->deselectAll(); |
596 | } | 596 | } |
597 | } | 597 | } |
598 | 598 | ||
599 | void KateViewInternal::insLine(int line) { | 599 | void KateViewInternal::insLine(int line) { |
600 | 600 | ||
601 | if (line <= cursor.y) { | 601 | if (line <= cursor.y) { |
602 | cursor.y++; | 602 | cursor.y++; |
603 | } | 603 | } |
604 | if (line < startLine) { | 604 | if (line < startLine) { |
605 | startLine++; | 605 | startLine++; |
606 | endLine++; | 606 | endLine++; |
607 | yPos += myDoc->fontHeight; | 607 | yPos += myDoc->fontHeight; |
608 | } else if (line <= endLine) { | 608 | } else if (line <= endLine) { |
609 | tagAll(); | 609 | tagAll(); |
610 | } | 610 | } |
611 | } | 611 | } |
612 | 612 | ||
613 | void KateViewInternal::delLine(int line) { | 613 | void KateViewInternal::delLine(int line) { |
614 | 614 | ||
615 | if (line <= cursor.y && cursor.y > 0) { | 615 | if (line <= cursor.y && cursor.y > 0) { |
616 | cursor.y--; | 616 | cursor.y--; |
617 | } | 617 | } |
618 | if (line < startLine) { | 618 | if (line < startLine) { |
619 | startLine--; | 619 | startLine--; |
620 | endLine--; | 620 | endLine--; |
621 | yPos -= myDoc->fontHeight; | 621 | yPos -= myDoc->fontHeight; |
622 | } else if (line <= endLine) { | 622 | } else if (line <= endLine) { |
623 | tagAll(); | 623 | tagAll(); |
624 | } | 624 | } |
625 | } | 625 | } |
626 | 626 | ||
627 | void KateViewInternal::updateCursor() { | 627 | void KateViewInternal::updateCursor() { |
628 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 628 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
629 | } | 629 | } |
630 | 630 | ||
631 | 631 | ||
632 | void KateViewInternal::updateCursor(PointStruc &newCursor) { | 632 | void KateViewInternal::updateCursor(PointStruc &newCursor) { |
633 | updateCursor(newCursor, myView->config()); | 633 | updateCursor(newCursor, myView->config()); |
634 | } | 634 | } |
635 | 635 | ||
636 | void KateViewInternal::updateCursor(PointStruc &newCursor, int flags) { | 636 | void KateViewInternal::updateCursor(PointStruc &newCursor, int flags) { |
637 | 637 | ||
638 | if (!(flags & KateView::cfPersistent)) myDoc->deselectAll(); | 638 | if (!(flags & KateView::cfPersistent)) myDoc->deselectAll(); |
639 | 639 | ||
640 | exposeCursor = true; | 640 | exposeCursor = true; |
641 | if (cursorOn) { | 641 | if (cursorOn) { |
642 | tagLines(cursor.y, cursor.y, cXPos -2, cXPos +3); | 642 | tagLines(cursor.y, cursor.y, cXPos -2, cXPos +3); |
643 | cursorOn = false; | 643 | cursorOn = false; |
644 | } | 644 | } |
645 | 645 | ||
646 | if (bm.sXPos < bm.eXPos) { | 646 | if (bm.sXPos < bm.eXPos) { |
647 | tagLines(bm.cursor.y, bm.cursor.y, bm.sXPos, bm.eXPos); | 647 | tagLines(bm.cursor.y, bm.cursor.y, bm.sXPos, bm.eXPos); |
648 | } | 648 | } |
649 | myDoc->newBracketMark(newCursor, bm); | 649 | myDoc->newBracketMark(newCursor, bm); |
650 | 650 | ||
651 | cursor = newCursor; | 651 | cursor = newCursor; |
652 | cOldXPos = cXPos = myDoc->textWidth(cursor); | 652 | cOldXPos = cXPos = myDoc->textWidth(cursor); |
653 | } | 653 | } |
654 | 654 | ||
655 | // init the line dirty cache | 655 | // init the line dirty cache |
656 | void KateViewInternal::clearDirtyCache(int height) { | 656 | void KateViewInternal::clearDirtyCache(int height) { |
657 | int lines, z; | 657 | int lines, z; |
658 | 658 | ||
659 | // calc start and end line of visible part | 659 | // calc start and end line of visible part |
660 | startLine = yPos/myDoc->fontHeight; | 660 | startLine = yPos/myDoc->fontHeight; |
661 | endLine = (yPos + height -1)/myDoc->fontHeight; | 661 | endLine = (yPos + height -1)/myDoc->fontHeight; |
662 | 662 | ||
663 | updateState = 0; | 663 | updateState = 0; |
664 | 664 | ||
665 | lines = endLine - startLine +1; | 665 | lines = endLine - startLine +1; |
666 | if (lines > numLines) { // resize the dirty cache | 666 | if (lines > numLines) { // resize the dirty cache |
667 | numLines = lines*2; | 667 | numLines = lines*2; |
668 | delete [] lineRanges; | 668 | delete [] lineRanges; |
669 | lineRanges = new LineRange[numLines]; | 669 | lineRanges = new LineRange[numLines]; |
670 | } | 670 | } |
671 | 671 | ||
672 | for (z = 0; z < lines; z++) { // clear all lines | 672 | for (z = 0; z < lines; z++) { // clear all lines |
673 | lineRanges[z].start = 0xffffff; | 673 | lineRanges[z].start = 0xffffff; |
674 | lineRanges[z].end = -2; | 674 | lineRanges[z].end = -2; |
675 | } | 675 | } |
676 | newXPos = newYPos = -1; | 676 | newXPos = newYPos = -1; |
677 | } | 677 | } |
678 | 678 | ||
679 | void KateViewInternal::tagLines(int start, int end, int x1, int x2) { | 679 | void KateViewInternal::tagLines(int start, int end, int x1, int x2) { |
680 | LineRange *r; | 680 | LineRange *r; |
681 | int z; | 681 | int z; |
682 | 682 | ||
683 | start -= startLine; | 683 | start -= startLine; |
684 | if (start < 0) start = 0; | 684 | if (start < 0) start = 0; |
685 | end -= startLine; | 685 | end -= startLine; |
686 | if (end > endLine - startLine) end = endLine - startLine; | 686 | if (end > endLine - startLine) end = endLine - startLine; |
687 | 687 | ||
688 | if (x1 <= 0) x1 = -2; | 688 | if (x1 <= 0) x1 = -2; |
689 | if (x1 < xPos-2) x1 = xPos-2; | 689 | if (x1 < xPos-2) x1 = xPos-2; |
690 | if (x2 > width() + xPos-2) x2 = width() + xPos-2; | 690 | if (x2 > width() + xPos-2) x2 = width() + xPos-2; |
691 | if (x1 >= x2) return; | 691 | if (x1 >= x2) return; |
692 | 692 | ||
693 | r = &lineRanges[start]; | 693 | r = &lineRanges[start]; |
694 | for (z = start; z <= end; z++) { | 694 | for (z = start; z <= end; z++) { |
695 | if (x1 < r->start) r->start = x1; | 695 | if (x1 < r->start) r->start = x1; |
696 | if (x2 > r->end) r->end = x2; | 696 | if (x2 > r->end) r->end = x2; |
697 | r++; | 697 | r++; |
698 | updateState |= 1; | 698 | updateState |= 1; |
699 | } | 699 | } |
700 | } | 700 | } |
701 | 701 | ||
702 | void KateViewInternal::tagAll() { | 702 | void KateViewInternal::tagAll() { |
703 | updateState = 3; | 703 | updateState = 3; |
704 | } | 704 | } |
705 | 705 | ||
706 | void KateViewInternal::setPos(int x, int y) { | 706 | void KateViewInternal::setPos(int x, int y) { |
707 | newXPos = x; | 707 | newXPos = x; |
708 | newYPos = y; | 708 | newYPos = y; |
709 | } | 709 | } |
710 | 710 | ||
711 | void KateViewInternal::center() { | 711 | void KateViewInternal::center() { |
712 | newXPos = 0; | 712 | newXPos = 0; |
713 | newYPos = cursor.y*myDoc->fontHeight - height()/2; | 713 | newYPos = cursor.y*myDoc->fontHeight - height()/2; |
714 | if (newYPos < 0) newYPos = 0; | 714 | if (newYPos < 0) newYPos = 0; |
715 | } | 715 | } |
716 | 716 | ||
717 | void KateViewInternal::updateView(int flags) { | 717 | void KateViewInternal::updateView(int flags) { |
718 | int fontHeight; | 718 | int fontHeight; |
719 | int oldXPos, oldYPos; | 719 | int oldXPos, oldYPos; |
720 | int w, h; | 720 | int w, h; |
721 | int z; | 721 | int z; |
722 | bool b; | 722 | bool b; |
723 | int xMax, yMax; | 723 | int xMax, yMax; |
724 | int cYPos; | 724 | int cYPos; |
725 | int cXPosMin, cXPosMax, cYPosMin, cYPosMax; | 725 | int cXPosMin, cXPosMax, cYPosMin, cYPosMax; |
726 | int dx, dy; | 726 | int dx, dy; |
727 | int pageScroll; | 727 | int pageScroll; |
728 | int scrollbarWidth = style().scrollBarExtent().width(); | 728 | int scrollbarWidth = style().scrollBarExtent().width(); |
729 | 729 | ||
730 | //debug("upView %d %d %d %d %d", exposeCursor, updateState, flags, newXPos, newYPos); | 730 | //debug("upView %d %d %d %d %d", exposeCursor, updateState, flags, newXPos, newYPos); |
731 | if (exposeCursor || flags & KateView::ufDocGeometry) { | 731 | if (exposeCursor || flags & KateView::ufDocGeometry) { |
732 | emit myView->newCurPos(); | 732 | emit myView->newCurPos(); |
733 | } else { | 733 | } else { |
734 | if (updateState == 0 && newXPos < 0 && newYPos < 0) return; | 734 | if (updateState == 0 && newXPos < 0 && newYPos < 0) return; |
735 | } | 735 | } |
736 | 736 | ||
737 | if (cursorTimer) { | 737 | if (cursorTimer) { |
738 | killTimer(cursorTimer); | 738 | killTimer(cursorTimer); |
739 | cursorTimer = startTimer(KApplication::cursorFlashTime() / 2); | 739 | cursorTimer = startTimer(KApplication::cursorFlashTime() / 2); |
740 | cursorOn = true; | 740 | cursorOn = true; |
741 | } | 741 | } |
742 | 742 | ||
743 | oldXPos = xPos; | 743 | oldXPos = xPos; |
744 | oldYPos = yPos; | 744 | oldYPos = yPos; |
745 | /* if (flags & ufPos) { | 745 | /* if (flags & ufPos) { |
746 | xPos = newXPos; | 746 | xPos = newXPos; |
747 | yPos = newYPos; | 747 | yPos = newYPos; |
748 | exposeCursor = true; | 748 | exposeCursor = true; |
749 | }*/ | 749 | }*/ |
750 | if (newXPos >= 0) xPos = newXPos; | 750 | if (newXPos >= 0) xPos = newXPos; |
751 | if (newYPos >= 0) yPos = newYPos; | 751 | if (newYPos >= 0) yPos = newYPos; |
752 | 752 | ||
753 | fontHeight = myDoc->fontHeight; | 753 | fontHeight = myDoc->fontHeight; |
754 | cYPos = cursor.y*fontHeight; | 754 | cYPos = cursor.y*fontHeight; |
755 | 755 | ||
756 | z = 0; | 756 | z = 0; |
757 | do { | 757 | do { |
758 | w = myView->width() - 4; | 758 | w = myView->width() - 4; |
759 | h = myView->height() - 4; | 759 | h = myView->height() - 4; |
760 | 760 | ||
761 | xMax = myDoc->textWidth() - w; | 761 | xMax = myDoc->textWidth() - w; |
762 | b = (xPos > 0 || xMax > 0); | 762 | b = (xPos > 0 || xMax > 0); |
763 | if (b) h -= scrollbarWidth; | 763 | if (b) h -= scrollbarWidth; |
764 | yMax = myDoc->textHeight() - h; | 764 | yMax = myDoc->textHeight() - h; |
765 | if (yPos > 0 || yMax > 0) { | 765 | if (yPos > 0 || yMax > 0) { |
766 | w -= scrollbarWidth; | 766 | w -= scrollbarWidth; |
767 | xMax += scrollbarWidth; | 767 | xMax += scrollbarWidth; |
768 | if (!b && xMax > 0) { | 768 | if (!b && xMax > 0) { |
769 | h -= scrollbarWidth; | 769 | h -= scrollbarWidth; |
770 | yMax += scrollbarWidth; | 770 | yMax += scrollbarWidth; |
771 | } | 771 | } |
772 | } | 772 | } |
773 | 773 | ||
774 | if (!exposeCursor) break; | 774 | if (!exposeCursor) break; |
775 | // if (flags & KateView::ufNoScroll) break; | 775 | // if (flags & KateView::ufNoScroll) break; |
776 | /* | 776 | /* |
777 | if (flags & KateView::ufCenter) { | 777 | if (flags & KateView::ufCenter) { |
778 | cXPosMin = xPos + w/3; | 778 | cXPosMin = xPos + w/3; |
779 | cXPosMax = xPos + (w*2)/3; | 779 | cXPosMax = xPos + (w*2)/3; |
780 | cYPosMin = yPos + h/3; | 780 | cYPosMin = yPos + h/3; |
781 | cYPosMax = yPos + ((h - fontHeight)*2)/3; | 781 | cYPosMax = yPos + ((h - fontHeight)*2)/3; |
782 | } else {*/ | 782 | } else {*/ |
783 | cXPosMin = xPos + 4; | 783 | cXPosMin = xPos + 4; |
784 | cXPosMax = xPos + w - 8; | 784 | cXPosMax = xPos + w - 8; |
785 | cYPosMin = yPos; | 785 | cYPosMin = yPos; |
786 | cYPosMax = yPos + (h - fontHeight); | 786 | cYPosMax = yPos + (h - fontHeight); |
787 | // } | 787 | // } |
788 | 788 | ||
789 | if (cXPos < cXPosMin) { | 789 | if (cXPos < cXPosMin) { |
790 | xPos -= cXPosMin - cXPos; | 790 | xPos -= cXPosMin - cXPos; |
791 | } | 791 | } |
792 | if (xPos < 0) xPos = 0; | 792 | if (xPos < 0) xPos = 0; |
793 | if (cXPos > cXPosMax) { | 793 | if (cXPos > cXPosMax) { |
794 | xPos += cXPos - cXPosMax; | 794 | xPos += cXPos - cXPosMax; |
795 | } | 795 | } |
796 | if (cYPos < cYPosMin) { | 796 | if (cYPos < cYPosMin) { |
797 | yPos -= cYPosMin - cYPos; | 797 | yPos -= cYPosMin - cYPos; |
798 | } | 798 | } |
799 | if (yPos < 0) yPos = 0; | 799 | if (yPos < 0) yPos = 0; |
800 | if (cYPos > cYPosMax) { | 800 | if (cYPos > cYPosMax) { |
801 | yPos += cYPos - cYPosMax; | 801 | yPos += cYPos - cYPosMax; |
802 | } | 802 | } |
803 | 803 | ||
804 | z++; | 804 | z++; |
805 | } while (z < 2); | 805 | } while (z < 2); |
806 | 806 | ||
807 | if (xMax < xPos) xMax = xPos; | 807 | if (xMax < xPos) xMax = xPos; |
808 | if (yMax < yPos) yMax = yPos; | 808 | if (yMax < yPos) yMax = yPos; |
809 | 809 | ||
810 | if (xMax > 0) { | 810 | if (xMax > 0) { |
811 | pageScroll = w - (w % fontHeight) - fontHeight; | 811 | pageScroll = w - (w % fontHeight) - fontHeight; |
812 | if (pageScroll <= 0) | 812 | if (pageScroll <= 0) |
813 | pageScroll = fontHeight; | 813 | pageScroll = fontHeight; |
814 | 814 | ||
815 | xScroll->blockSignals(true); | 815 | xScroll->blockSignals(true); |
816 | xScroll->setGeometry(2,h + 2,w,scrollbarWidth); | 816 | xScroll->setGeometry(2,h + 2,w,scrollbarWidth); |
817 | xScroll->setRange(0,xMax); | 817 | xScroll->setRange(0,xMax); |
818 | xScroll->setValue(xPos); | 818 | xScroll->setValue(xPos); |
819 | xScroll->setSteps(fontHeight,pageScroll); | 819 | xScroll->setSteps(fontHeight,pageScroll); |
820 | xScroll->blockSignals(false); | 820 | xScroll->blockSignals(false); |
821 | xScroll->show(); | 821 | xScroll->show(); |
822 | } else xScroll->hide(); | 822 | } else xScroll->hide(); |
823 | 823 | ||
824 | if (yMax > 0) { | 824 | if (yMax > 0) { |
825 | pageScroll = h - (h % fontHeight) - fontHeight; | 825 | pageScroll = h - (h % fontHeight) - fontHeight; |
826 | if (pageScroll <= 0) | 826 | if (pageScroll <= 0) |
827 | pageScroll = fontHeight; | 827 | pageScroll = fontHeight; |
828 | 828 | ||
829 | yScroll->blockSignals(true); | 829 | yScroll->blockSignals(true); |
830 | yScroll->setGeometry(w + 2,2,scrollbarWidth,h); | 830 | yScroll->setGeometry(w + 2,2,scrollbarWidth,h); |
831 | yScroll->setRange(0,yMax); | 831 | yScroll->setRange(0,yMax); |
832 | yScroll->setValue(yPos); | 832 | yScroll->setValue(yPos); |
833 | yScroll->setSteps(fontHeight,pageScroll); | 833 | yScroll->setSteps(fontHeight,pageScroll); |
834 | yScroll->blockSignals(false); | 834 | yScroll->blockSignals(false); |
835 | yScroll->show(); | 835 | yScroll->show(); |
836 | } else yScroll->hide(); | 836 | } else yScroll->hide(); |
837 | 837 | ||
838 | if (w != width() || h != height()) { | 838 | if (w != width() || h != height()) { |
839 | clearDirtyCache(h); | 839 | clearDirtyCache(h); |
840 | resize(w,h); | 840 | resize(w,h); |
841 | } else { | 841 | } else { |
842 | dx = oldXPos - xPos; | 842 | dx = oldXPos - xPos; |
843 | dy = oldYPos - yPos; | 843 | dy = oldYPos - yPos; |
844 | 844 | ||
845 | b = updateState == 3; | 845 | b = updateState == 3; |
846 | if (flags & KateView::ufUpdateOnScroll) { | 846 | if (flags & KateView::ufUpdateOnScroll) { |
847 | b |= dx || dy; | 847 | b |= dx || dy; |
848 | } else { | 848 | } else { |
849 | b |= QABS(dx)*3 > w*2 || QABS(dy)*3 > h*2; | 849 | b |= QABS(dx)*3 > w*2 || QABS(dy)*3 > h*2; |
850 | } | 850 | } |
851 | 851 | ||
852 | if (b) { | 852 | if (b) { |
853 | clearDirtyCache(h); | 853 | clearDirtyCache(h); |
854 | update(); | 854 | update(); |
855 | } else { | 855 | } else { |
856 | if (dy) | 856 | if (dy) |
857 | leftBorder->scroll(0, dy); | 857 | leftBorder->scroll(0, dy); |
858 | if (updateState > 0) paintTextLines(oldXPos, oldYPos); | 858 | if (updateState > 0) paintTextLines(oldXPos, oldYPos); |
859 | clearDirtyCache(h); | 859 | clearDirtyCache(h); |
860 | 860 | ||
861 | if (dx || dy) { | 861 | if (dx || dy) { |
862 | scroll(dx,dy); | 862 | scroll(dx,dy); |
863 | // kapp->syncX(); | 863 | // kapp->syncX(); |
864 | // scroll2(dx - dx/2,dy - dy/2); | 864 | // scroll2(dx - dx/2,dy - dy/2); |
865 | // } else { | 865 | // } else { |
866 | } | 866 | } |
867 | if (cursorOn) paintCursor(); | 867 | if (cursorOn) paintCursor(); |
868 | if (bm.eXPos > bm.sXPos) paintBracketMark(); | 868 | if (bm.eXPos > bm.sXPos) paintBracketMark(); |
869 | } | 869 | } |
870 | } | 870 | } |
871 | exposeCursor = false; | 871 | exposeCursor = false; |
872 | // updateState = 0; | 872 | // updateState = 0; |
873 | } | 873 | } |
874 | 874 | ||
875 | 875 | ||
876 | void KateViewInternal::paintTextLines(int xPos, int yPos) { | 876 | void KateViewInternal::paintTextLines(int xPos, int yPos) { |
877 | // int xStart, xEnd; | 877 | // int xStart, xEnd; |
878 | int line;//, z; | 878 | int line;//, z; |
879 | int h; | 879 | int h; |
880 | LineRange *r; | 880 | LineRange *r; |
881 | 881 | ||
882 | if (!drawBuffer) return; | 882 | if (!drawBuffer) return; |
883 | if (drawBuffer->isNull()) return; | 883 | if (drawBuffer->isNull()) return; |
884 | 884 | ||
885 | QPainter paint; | 885 | QPainter paint; |
886 | paint.begin(drawBuffer); | 886 | paint.begin(drawBuffer); |
887 | 887 | ||
888 | h = myDoc->fontHeight; | 888 | h = myDoc->fontHeight; |
889 | r = lineRanges; | 889 | r = lineRanges; |
890 | for (line = startLine; line <= endLine; line++) { | 890 | for (line = startLine; line <= endLine; line++) { |
891 | if (r->start < r->end) { | 891 | if (r->start < r->end) { |
892 | //debug("painttextline %d %d %d", line, r->start, r->end); | 892 | //debug("painttextline %d %d %d", line, r->start, r->end); |
893 | myDoc->paintTextLine(paint, line, r->start, r->end, myView->configFlags & KateView::cfShowTabs); | 893 | myDoc->paintTextLine(paint, line, r->start, r->end, myView->configFlags & KateView::cfShowTabs); |
894 | bitBlt(this, r->start - (xPos-2), line*h - yPos, drawBuffer, 0, 0, | 894 | bitBlt(this, r->start - (xPos-2), line*h - yPos, drawBuffer, 0, 0, |
895 | r->end - r->start, h); | 895 | r->end - r->start, h); |
896 | leftBorder->paintLine(line); | 896 | leftBorder->paintLine(line); |
897 | } | 897 | } |
898 | r++; | 898 | r++; |
899 | } | 899 | } |
900 | 900 | ||
901 | paint.end(); | 901 | paint.end(); |
902 | } | 902 | } |
903 | 903 | ||
904 | void KateViewInternal::paintCursor() { | 904 | void KateViewInternal::paintCursor() { |
905 | int h, y, x; | 905 | int h, y, x; |
906 | static int cx = 0, cy = 0, ch = 0; | 906 | static int cx = 0, cy = 0, ch = 0; |
907 | 907 | ||
908 | h = myDoc->fontHeight; | 908 | h = myDoc->fontHeight; |
909 | y = h*cursor.y - yPos; | 909 | y = h*cursor.y - yPos; |
910 | x = cXPos - (xPos-2); | 910 | x = cXPos - (xPos-2); |
911 | 911 | ||
912 | if(myDoc->myFont != font()) setFont(myDoc->myFont); | 912 | if(myDoc->myFont != font()) setFont(myDoc->myFont); |
913 | if(cx != x || cy != y || ch != h){ | 913 | if(cx != x || cy != y || ch != h){ |
914 | cx = x; | 914 | cx = x; |
915 | cy = y; | 915 | cy = y; |
916 | ch = h; | 916 | ch = h; |
917 | setMicroFocusHint(cx, cy, 0, ch - 2); | 917 | setMicroFocusHint(cx, cy, 0, ch - 2); |
918 | } | 918 | } |
919 | 919 | ||
920 | QPainter paint; | 920 | QPainter paint; |
921 | if (cursorOn) { | 921 | if (cursorOn) { |
922 | paint.begin(this); | 922 | paint.begin(this); |
923 | paint.setClipping(false); | 923 | paint.setClipping(false); |
924 | paint.setPen(myDoc->cursorCol(cursor.x,cursor.y)); | 924 | paint.setPen(myDoc->cursorCol(cursor.x,cursor.y)); |
925 | 925 | ||
926 | h += y - 1; | 926 | h += y - 1; |
927 | paint.drawLine(x, y, x, h); | 927 | paint.drawLine(x, y, x, h); |
928 | 928 | ||
929 | paint.end(); | 929 | paint.end(); |
930 | } else { if (drawBuffer && !drawBuffer->isNull()) { | 930 | } else { if (drawBuffer && !drawBuffer->isNull()) { |
931 | paint.begin(drawBuffer); | 931 | paint.begin(drawBuffer); |
932 | myDoc->paintTextLine(paint, cursor.y, cXPos - 2, cXPos + 3, myView->configFlags & KateView::cfShowTabs); | 932 | myDoc->paintTextLine(paint, cursor.y, cXPos - 2, cXPos + 3, myView->configFlags & KateView::cfShowTabs); |
933 | bitBlt(this,x - 2,y, drawBuffer, 0, 0, 5, h); | 933 | bitBlt(this,x - 2,y, drawBuffer, 0, 0, 5, h); |
934 | paint.end(); } | 934 | paint.end(); } |
935 | } | 935 | } |
936 | 936 | ||
937 | } | 937 | } |
938 | 938 | ||
939 | void KateViewInternal::paintBracketMark() { | 939 | void KateViewInternal::paintBracketMark() { |
940 | int y; | 940 | int y; |
941 | 941 | ||
942 | y = myDoc->fontHeight*(bm.cursor.y +1) - yPos -1; | 942 | y = myDoc->fontHeight*(bm.cursor.y +1) - yPos -1; |
943 | 943 | ||
944 | QPainter paint; | 944 | QPainter paint; |
945 | paint.begin(this); | 945 | paint.begin(this); |
946 | paint.setPen(myDoc->cursorCol(bm.cursor.x, bm.cursor.y)); | 946 | paint.setPen(myDoc->cursorCol(bm.cursor.x, bm.cursor.y)); |
947 | 947 | ||
948 | paint.drawLine(bm.sXPos - (xPos-2), y, bm.eXPos - (xPos-2) -1, y); | 948 | paint.drawLine(bm.sXPos - (xPos-2), y, bm.eXPos - (xPos-2) -1, y); |
949 | paint.end(); | 949 | paint.end(); |
950 | } | 950 | } |
951 | 951 | ||
952 | void KateViewInternal::placeCursor(int x, int y, int flags) { | 952 | void KateViewInternal::placeCursor(int x, int y, int flags) { |
953 | VConfig c; | 953 | VConfig c; |
954 | 954 | ||
955 | getVConfig(c); | 955 | getVConfig(c); |
956 | c.flags |= flags; | 956 | c.flags |= flags; |
957 | cursor.y = (yPos + y)/myDoc->fontHeight; | 957 | cursor.y = (yPos + y)/myDoc->fontHeight; |
958 | cXPos = cOldXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor, cursor,xPos-2 + x); | 958 | cXPos = cOldXPos = myDoc->textWidth(c.flags & KateView::cfWrapCursor, cursor,xPos-2 + x); |
959 | changeState(c); | 959 | changeState(c); |
960 | } | 960 | } |
961 | 961 | ||
962 | // given physical coordinates, report whether the text there is selected | 962 | // given physical coordinates, report whether the text there is selected |
963 | bool KateViewInternal::isTargetSelected(int x, int y) { | 963 | bool KateViewInternal::isTargetSelected(int x, int y) { |
964 | 964 | ||
965 | y = (yPos + y) / myDoc->fontHeight; | 965 | y = (yPos + y) / myDoc->fontHeight; |
966 | 966 | ||
967 | TextLine::Ptr line = myDoc->getTextLine(y); | 967 | TextLine::Ptr line = myDoc->getTextLine(y); |
968 | if (!line) | 968 | if (!line) |
969 | return false; | 969 | return false; |
970 | 970 | ||
971 | x = myDoc->textPos(line, x); | 971 | x = myDoc->textPos(line, x); |
972 | 972 | ||
973 | return line->isSelected(x); | 973 | return line->isSelected(x); |
974 | } | 974 | } |
975 | 975 | ||
976 | void KateViewInternal::focusInEvent(QFocusEvent *) { | 976 | void KateViewInternal::focusInEvent(QFocusEvent *) { |
977 | // debug("got focus %d",cursorTimer); | 977 | // debug("got focus %d",cursorTimer); |
978 | 978 | ||
979 | if (!cursorTimer) { | 979 | if (!cursorTimer) { |
980 | cursorTimer = startTimer(KApplication::cursorFlashTime() / 2); | 980 | cursorTimer = startTimer(KApplication::cursorFlashTime() / 2); |
981 | cursorOn = true; | 981 | cursorOn = true; |
982 | paintCursor(); | 982 | paintCursor(); |
983 | } | 983 | } |
984 | } | 984 | } |
985 | 985 | ||
986 | void KateViewInternal::focusOutEvent(QFocusEvent *) { | 986 | void KateViewInternal::focusOutEvent(QFocusEvent *) { |
987 | // debug("lost focus %d", cursorTimer); | 987 | // debug("lost focus %d", cursorTimer); |
988 | 988 | ||
989 | if (cursorTimer) { | 989 | if (cursorTimer) { |
990 | killTimer(cursorTimer); | 990 | killTimer(cursorTimer); |
991 | cursorTimer = 0; | 991 | cursorTimer = 0; |
992 | } | 992 | } |
993 | 993 | ||
994 | if (cursorOn) { | 994 | if (cursorOn) { |
995 | cursorOn = false; | 995 | cursorOn = false; |
996 | paintCursor(); | 996 | paintCursor(); |
997 | } | 997 | } |
998 | } | 998 | } |
999 | 999 | ||
1000 | void KateViewInternal::keyPressEvent(QKeyEvent *e) { | 1000 | void KateViewInternal::keyPressEvent(QKeyEvent *e) { |
1001 | VConfig c; | 1001 | VConfig c; |
1002 | // int ascii; | 1002 | // int ascii; |
1003 | 1003 | ||
1004 | /* if (e->state() & AltButton) { | 1004 | /* if (e->state() & AltButton) { |
1005 | e->ignore(); | 1005 | e->ignore(); |
1006 | return; | 1006 | return; |
1007 | }*/ | 1007 | }*/ |
1008 | // debug("ascii %i, key %i, state %i",e->ascii(), e->key(), e->state()); | 1008 | // debug("ascii %i, key %i, state %i",e->ascii(), e->key(), e->state()); |
1009 | 1009 | ||
1010 | getVConfig(c); | 1010 | getVConfig(c); |
1011 | // ascii = e->ascii(); | 1011 | // ascii = e->ascii(); |
1012 | 1012 | ||
1013 | if (!myView->isReadOnly()) { | 1013 | if (!myView->isReadOnly()) { |
1014 | if (c.flags & KateView::cfTabIndents && myDoc->hasMarkedText()) { | 1014 | if (c.flags & KateView::cfTabIndents && myDoc->hasMarkedText()) { |
1015 | if (e->key() == Qt::Key_Tab) { | 1015 | if (e->key() == Qt::Key_Tab) { |
1016 | myDoc->indent(c); | 1016 | myDoc->indent(c); |
1017 | myDoc->updateViews(); | 1017 | myDoc->updateViews(); |
1018 | return; | 1018 | return; |
1019 | } | 1019 | } |
1020 | if (e->key() == Qt::Key_Backtab) { | 1020 | if (e->key() == Qt::Key_Backtab) { |
1021 | myDoc->unIndent(c); | 1021 | myDoc->unIndent(c); |
1022 | myDoc->updateViews(); | 1022 | myDoc->updateViews(); |
1023 | return; | 1023 | return; |
1024 | } | 1024 | } |
1025 | } | 1025 | } |
1026 | if ( !(e->state() & ControlButton ) && myDoc->insertChars(c, e->text())) { | 1026 | if ( !(e->state() & ControlButton ) && myDoc->insertChars(c, e->text())) { |
1027 | myDoc->updateViews(); | 1027 | myDoc->updateViews(); |
1028 | e->accept(); | 1028 | e->accept(); |
1029 | return; | 1029 | return; |
1030 | } | 1030 | } |
1031 | } | 1031 | } |
1032 | e->ignore(); | 1032 | e->ignore(); |
1033 | } | 1033 | } |
1034 | 1034 | ||
1035 | void KateViewInternal::mousePressEvent(QMouseEvent *e) { | 1035 | void KateViewInternal::mousePressEvent(QMouseEvent *e) { |
1036 | 1036 | ||
1037 | if (e->button() == LeftButton) { | 1037 | if (e->button() == LeftButton) { |
1038 | 1038 | ||
1039 | int flags; | 1039 | int flags; |
1040 | 1040 | ||
1041 | flags = 0; | 1041 | flags = 0; |
1042 | if (e->state() & ShiftButton) { | 1042 | if (e->state() & ShiftButton) { |
1043 | flags |= KateView::cfMark; | 1043 | flags |= KateView::cfMark; |
1044 | if (e->state() & ControlButton) flags |= KateView::cfMark | KateView::cfKeepSelection; | 1044 | if (e->state() & ControlButton) flags |= KateView::cfMark | KateView::cfKeepSelection; |
1045 | } | 1045 | } |
1046 | placeCursor(e->x(), e->y(), flags); | 1046 | placeCursor(e->x(), e->y(), flags); |
1047 | scrollX = 0; | 1047 | scrollX = 0; |
1048 | scrollY = 0; | 1048 | scrollY = 0; |
1049 | if (!scrollTimer) scrollTimer = startTimer(50); | 1049 | if (!scrollTimer) scrollTimer = startTimer(50); |
1050 | myDoc->updateViews(); | 1050 | myDoc->updateViews(); |
1051 | } | 1051 | } |
1052 | if (e->button() == MidButton) { | 1052 | if (e->button() == MidButton) { |
1053 | placeCursor(e->x(), e->y()); | 1053 | placeCursor(e->x(), e->y()); |
1054 | if (! myView->isReadOnly()) | 1054 | if (! myView->isReadOnly()) |
1055 | myView->paste(); | 1055 | myView->paste(); |
1056 | } | 1056 | } |
1057 | if (myView->rmbMenu && e->button() == RightButton) { | 1057 | if (myView->rmbMenu && e->button() == RightButton) { |
1058 | myView->rmbMenu->popup(mapToGlobal(e->pos())); | 1058 | myView->rmbMenu->popup(mapToGlobal(e->pos())); |
1059 | } | 1059 | } |
1060 | myView->mousePressEvent(e); // this doesn't do anything, does it? | 1060 | myView->mousePressEvent(e); // this doesn't do anything, does it? |
1061 | // it does :-), we need this for KDevelop, so please don't uncomment it again -Sandy | 1061 | // it does :-), we need this for KDevelop, so please don't uncomment it again -Sandy |
1062 | } | 1062 | } |
1063 | 1063 | ||
1064 | void KateViewInternal::mouseDoubleClickEvent(QMouseEvent *e) { | 1064 | void KateViewInternal::mouseDoubleClickEvent(QMouseEvent *e) { |
1065 | 1065 | ||
1066 | if (e->button() == LeftButton) { | 1066 | if (e->button() == LeftButton) { |
1067 | VConfig c; | 1067 | VConfig c; |
1068 | getVConfig(c); | 1068 | getVConfig(c); |
1069 | myDoc->selectWord(c.cursor, c.flags); | 1069 | myDoc->selectWord(c.cursor, c.flags); |
1070 | myDoc->updateViews(); | 1070 | myDoc->updateViews(); |
1071 | } | 1071 | } |
1072 | } | 1072 | } |
1073 | 1073 | ||
1074 | void KateViewInternal::mouseReleaseEvent(QMouseEvent *e) { | 1074 | void KateViewInternal::mouseReleaseEvent(QMouseEvent *e) { |
1075 | 1075 | ||
1076 | if (e->button() == LeftButton) { | 1076 | if (e->button() == LeftButton) { |
1077 | if (myView->config() & KateView::cfMouseAutoCopy) myView->copy(); | 1077 | if (myView->config() & KateView::cfMouseAutoCopy) myView->copy(); |
1078 | killTimer(scrollTimer); | 1078 | killTimer(scrollTimer); |
1079 | scrollTimer = 0; | 1079 | scrollTimer = 0; |
1080 | } | 1080 | } |
1081 | } | 1081 | } |
1082 | 1082 | ||
1083 | void KateViewInternal::mouseMoveEvent(QMouseEvent *e) { | 1083 | void KateViewInternal::mouseMoveEvent(QMouseEvent *e) { |
1084 | 1084 | ||
1085 | if (e->state() & LeftButton) { | 1085 | if (e->state() & LeftButton) { |
1086 | int flags; | 1086 | int flags; |
1087 | int d; | 1087 | int d; |
1088 | int x = e->x(), | 1088 | int x = e->x(), |
1089 | y = e->y(); | 1089 | y = e->y(); |
1090 | 1090 | ||
1091 | mouseX = e->x(); | 1091 | mouseX = e->x(); |
1092 | mouseY = e->y(); | 1092 | mouseY = e->y(); |
1093 | scrollX = 0; | 1093 | scrollX = 0; |
1094 | scrollY = 0; | 1094 | scrollY = 0; |
1095 | d = myDoc->fontHeight; | 1095 | d = myDoc->fontHeight; |
1096 | if (mouseX < 0) { | 1096 | if (mouseX < 0) { |
1097 | mouseX = 0; | 1097 | mouseX = 0; |
1098 | scrollX = -d; | 1098 | scrollX = -d; |
1099 | } | 1099 | } |
1100 | if (mouseX > width()) { | 1100 | if (mouseX > width()) { |
1101 | mouseX = width(); | 1101 | mouseX = width(); |
1102 | scrollX = d; | 1102 | scrollX = d; |
1103 | } | 1103 | } |
1104 | if (mouseY < 0) { | 1104 | if (mouseY < 0) { |
1105 | mouseY = 0; | 1105 | mouseY = 0; |
1106 | scrollY = -d; | 1106 | scrollY = -d; |
1107 | } | 1107 | } |
1108 | if (mouseY > height()) { | 1108 | if (mouseY > height()) { |
1109 | mouseY = height(); | 1109 | mouseY = height(); |
1110 | scrollY = d; | 1110 | scrollY = d; |
1111 | } | 1111 | } |
1112 | //debug("modifiers %d", ((KGuiCmdApp *) kapp)->getModifiers()); | 1112 | //debug("modifiers %d", ((KGuiCmdApp *) kapp)->getModifiers()); |
1113 | flags = KateView::cfMark; | 1113 | flags = KateView::cfMark; |
1114 | if (e->state() & ControlButton) flags |= KateView::cfKeepSelection; | 1114 | if (e->state() & ControlButton) flags |= KateView::cfKeepSelection; |
1115 | placeCursor(mouseX, mouseY, flags); | 1115 | placeCursor(mouseX, mouseY, flags); |
1116 | myDoc->updateViews(/*ufNoScroll*/); | 1116 | myDoc->updateViews(/*ufNoScroll*/); |
1117 | } | 1117 | } |
1118 | } | 1118 | } |
1119 | 1119 | ||
1120 | 1120 | ||
1121 | 1121 | ||
1122 | void KateViewInternal::wheelEvent( QWheelEvent *e ) | 1122 | void KateViewInternal::wheelEvent( QWheelEvent *e ) |
1123 | { | 1123 | { |
1124 | if( yScroll->isVisible() == true ) | 1124 | if( yScroll->isVisible() == true ) |
1125 | { | 1125 | { |
1126 | QApplication::sendEvent( yScroll, e ); | 1126 | QApplication::sendEvent( yScroll, e ); |
1127 | } | 1127 | } |
1128 | } | 1128 | } |
1129 | 1129 | ||
1130 | 1130 | ||
1131 | 1131 | ||
1132 | void KateViewInternal::paintEvent(QPaintEvent *e) { | 1132 | void KateViewInternal::paintEvent(QPaintEvent *e) { |
1133 | int xStart, xEnd; | 1133 | int xStart, xEnd; |
1134 | int h; | 1134 | int h; |
1135 | int line, y, yEnd; | 1135 | int line, y, yEnd; |
1136 | 1136 | ||
1137 | QRect updateR = e->rect(); | 1137 | QRect updateR = e->rect(); |
1138 | 1138 | ||
1139 | if (!drawBuffer) return; | 1139 | if (!drawBuffer) return; |
1140 | if (drawBuffer->isNull()) return; | 1140 | if (drawBuffer->isNull()) return; |
1141 | 1141 | ||
1142 | QPainter paint; | 1142 | QPainter paint; |
1143 | paint.begin(drawBuffer); | 1143 | paint.begin(drawBuffer); |
1144 | 1144 | ||
1145 | xStart = xPos-2 + updateR.x(); | 1145 | xStart = xPos-2 + updateR.x(); |
1146 | xEnd = xStart + updateR.width(); | 1146 | xEnd = xStart + updateR.width(); |
1147 | 1147 | ||
1148 | h = myDoc->fontHeight; | 1148 | h = myDoc->fontHeight; |
1149 | line = (yPos + updateR.y()) / h; | 1149 | line = (yPos + updateR.y()) / h; |
1150 | y = line*h - yPos; | 1150 | y = line*h - yPos; |
1151 | yEnd = updateR.y() + updateR.height(); | 1151 | yEnd = updateR.y() + updateR.height(); |
1152 | waitForPreHighlight=myDoc->needPreHighlight(waitForPreHighlight=line+((long)(yEnd-y)/h)+5); | 1152 | waitForPreHighlight=myDoc->needPreHighlight(waitForPreHighlight=line+((long)(yEnd-y)/h)+5); |
1153 | 1153 | ||
1154 | while (y < yEnd) | 1154 | while (y < yEnd) |
1155 | { | 1155 | { |
1156 | TextLine *textLine; | 1156 | TextLine *textLine; |
1157 | int ctxNum = 0; | 1157 | int ctxNum = 0; |
1158 | myDoc->paintTextLine(paint, line, xStart, xEnd, myView->configFlags & KateView::cfShowTabs); | 1158 | myDoc->paintTextLine(paint, line, xStart, xEnd, myView->configFlags & KateView::cfShowTabs); |
1159 | bitBlt(this, updateR.x(), y, drawBuffer, 0, 0, updateR.width(), h); | 1159 | bitBlt(this, updateR.x(), y, drawBuffer, 0, 0, updateR.width(), h); |
1160 | leftBorder->paintLine(line); | 1160 | leftBorder->paintLine(line); |
1161 | line++; | 1161 | line++; |
1162 | y += h; | 1162 | y += h; |
1163 | } | 1163 | } |
1164 | paint.end(); | 1164 | paint.end(); |
1165 | 1165 | ||
1166 | if (cursorOn) paintCursor(); | 1166 | if (cursorOn) paintCursor(); |
1167 | if (bm.eXPos > bm.sXPos) paintBracketMark(); | 1167 | if (bm.eXPos > bm.sXPos) paintBracketMark(); |
1168 | } | 1168 | } |
1169 | 1169 | ||
1170 | void KateViewInternal::resizeEvent(QResizeEvent *) | 1170 | void KateViewInternal::resizeEvent(QResizeEvent *) |
1171 | { | 1171 | { |
1172 | drawBuffer->resize (width(), myDoc->fontHeight); | 1172 | drawBuffer->resize (width(), myDoc->fontHeight); |
1173 | leftBorder->resize(iconBorderWidth, height()); | 1173 | leftBorder->resize(iconBorderWidth, height()); |
1174 | } | 1174 | } |
1175 | 1175 | ||
1176 | void KateViewInternal::timerEvent(QTimerEvent *e) { | 1176 | void KateViewInternal::timerEvent(QTimerEvent *e) { |
1177 | if (e->timerId() == cursorTimer) { | 1177 | if (e->timerId() == cursorTimer) { |
1178 | cursorOn = !cursorOn; | 1178 | cursorOn = !cursorOn; |
1179 | paintCursor(); | 1179 | paintCursor(); |
1180 | } | 1180 | } |
1181 | if (e->timerId() == scrollTimer && (scrollX | scrollY)) { | 1181 | if (e->timerId() == scrollTimer && (scrollX | scrollY)) { |
1182 | xScroll->setValue(xPos + scrollX); | 1182 | xScroll->setValue(xPos + scrollX); |
1183 | yScroll->setValue(yPos + scrollY); | 1183 | yScroll->setValue(yPos + scrollY); |
1184 | 1184 | ||
1185 | placeCursor(mouseX, mouseY, KateView::cfMark); | 1185 | placeCursor(mouseX, mouseY, KateView::cfMark); |
1186 | myDoc->updateViews(/*ufNoScroll*/); | 1186 | myDoc->updateViews(/*ufNoScroll*/); |
1187 | } | 1187 | } |
1188 | } | 1188 | } |
1189 | 1189 | ||
1190 | uint KateView::uniqueID = 0; | 1190 | uint KateView::uniqueID = 0; |
1191 | 1191 | ||
1192 | KateView::KateView(KateDocument *doc, QWidget *parent, const char * name) : Kate::View (doc, parent, name) | 1192 | KateView::KateView(KateDocument *doc, QWidget *parent, const char * name) : Kate::View (doc, parent, name) |
1193 | { | 1193 | { |
1194 | 1194 | ||
1195 | myViewID = uniqueID; | 1195 | myViewID = uniqueID; |
1196 | uniqueID++; | 1196 | uniqueID++; |
1197 | 1197 | ||
1198 | active = false; | 1198 | active = false; |
1199 | myIconBorder = false; | 1199 | myIconBorder = false; |
1200 | 1200 | ||
1201 | myDoc = doc; | 1201 | myDoc = doc; |
1202 | myViewInternal = new KateViewInternal (this,doc); | 1202 | myViewInternal = new KateViewInternal (this,doc); |
1203 | myViewInternal->move(2, 2); | 1203 | myViewInternal->move(2, 2); |
1204 | myViewInternal->leftBorder = new KateIconBorder(this, myViewInternal); | 1204 | myViewInternal->leftBorder = new KateIconBorder(this, myViewInternal); |
1205 | myViewInternal->leftBorder->setGeometry(2, 2, myViewInternal->iconBorderWidth, myViewInternal->iconBorderHeight); | 1205 | myViewInternal->leftBorder->setGeometry(2, 2, myViewInternal->iconBorderWidth, myViewInternal->iconBorderHeight); |
1206 | myViewInternal->leftBorder->hide(); | 1206 | myViewInternal->leftBorder->hide(); |
1207 | 1207 | ||
1208 | doc->addView( this ); | 1208 | doc->addView( this ); |
1209 | 1209 | ||
1210 | 1210 | ||
1211 | // some defaults | 1211 | // some defaults |
1212 | configFlags = KateView::cfAutoIndent | KateView::cfBackspaceIndents | 1212 | configFlags = KateView::cfAutoIndent | KateView::cfBackspaceIndents |
1213 | | KateView::cfTabIndents | KateView::cfKeepIndentProfile | 1213 | | KateView::cfTabIndents | KateView::cfKeepIndentProfile |
1214 | | KateView::cfRemoveSpaces | 1214 | | KateView::cfRemoveSpaces |
1215 | | KateView::cfDelOnInput | KateView::cfMouseAutoCopy | KateView::cfWrapCursor | 1215 | | KateView::cfDelOnInput | KateView::cfMouseAutoCopy | KateView::cfWrapCursor |
1216 | | KateView::cfGroupUndo | KateView::cfShowTabs | KateView::cfSmartHome; | 1216 | | KateView::cfGroupUndo | KateView::cfShowTabs | KateView::cfSmartHome; |
1217 | 1217 | ||
1218 | searchFlags = 0; | 1218 | searchFlags = 0; |
1219 | replacePrompt = 0L; | 1219 | replacePrompt = 0L; |
1220 | rmbMenu = 0L; | 1220 | rmbMenu = 0L; |
1221 | 1221 | ||
1222 | 1222 | ||
1223 | setFocusProxy( myViewInternal ); | 1223 | setFocusProxy( myViewInternal ); |
1224 | myViewInternal->setFocus(); | 1224 | myViewInternal->setFocus(); |
1225 | resize(parent->width() -4, parent->height() -4); | 1225 | resize(parent->width() -4, parent->height() -4); |
1226 | 1226 | ||
1227 | 1227 | ||
1228 | myViewInternal->installEventFilter( this ); | 1228 | myViewInternal->installEventFilter( this ); |
1229 | 1229 | ||
1230 | //setupActions(); | 1230 | //setupActions(); |
1231 | 1231 | ||
1232 | connect( this, SIGNAL( newStatus() ), this, SLOT( slotUpdate() ) ); | 1232 | connect( this, SIGNAL( newStatus() ), this, SLOT( slotUpdate() ) ); |
1233 | connect( this, SIGNAL( newUndo() ), this, SLOT( slotNewUndo() ) ); | 1233 | connect( this, SIGNAL( newUndo() ), this, SLOT( slotNewUndo() ) ); |
1234 | connect( doc, SIGNAL( fileNameChanged() ), this, SLOT( slotFileStatusChanged() ) ); | 1234 | connect( doc, SIGNAL( fileNameChanged() ), this, SLOT( slotFileStatusChanged() ) ); |
1235 | connect( doc, SIGNAL( highlightChanged() ), this, SLOT( slotHighlightChanged() ) ); | 1235 | connect( doc, SIGNAL( highlightChanged() ), this, SLOT( slotHighlightChanged() ) ); |
1236 | 1236 | ||
1237 | readConfig(); | 1237 | readConfig(); |
1238 | // setHighlight->setCurrentItem(getHl()); | 1238 | // setHighlight->setCurrentItem(getHl()); |
1239 | slotUpdate(); | 1239 | slotUpdate(); |
1240 | } | 1240 | } |
1241 | 1241 | ||
1242 | KateView::~KateView() | 1242 | KateView::~KateView() |
1243 | { | 1243 | { |
1244 | writeConfig(); | ||
1244 | 1245 | ||
1245 | if (myDoc && !myDoc->m_bSingleViewMode) | 1246 | if (myDoc && !myDoc->m_bSingleViewMode) |
1246 | myDoc->removeView( this ); | 1247 | myDoc->removeView( this ); |
1247 | 1248 | ||
1248 | delete myViewInternal; | 1249 | delete myViewInternal; |
1249 | |||
1250 | } | 1250 | } |
1251 | 1251 | ||
1252 | #if 0 | 1252 | #if 0 |
1253 | void KateView::setupActions() | 1253 | void KateView::setupActions() |
1254 | { | 1254 | { |
1255 | #if 0 | 1255 | #if 0 |
1256 | KStdAction::close( this, SLOT(flush()), actionCollection(), "file_close" ); | 1256 | KStdAction::close( this, SLOT(flush()), actionCollection(), "file_close" ); |
1257 | 1257 | ||
1258 | KStdAction::save(this, SLOT(save()), actionCollection()); | 1258 | KStdAction::save(this, SLOT(save()), actionCollection()); |
1259 | 1259 | ||
1260 | // setup edit menu | 1260 | // setup edit menu |
1261 | editUndo = KStdAction::undo(this, SLOT(undo()), actionCollection()); | 1261 | editUndo = KStdAction::undo(this, SLOT(undo()), actionCollection()); |
1262 | editRedo = KStdAction::redo(this, SLOT(redo()), actionCollection()); | 1262 | editRedo = KStdAction::redo(this, SLOT(redo()), actionCollection()); |
1263 | editUndoHist = new KAction(i18n("Undo/Redo &History..."), 0, this, SLOT(undoHistory()), | 1263 | editUndoHist = new KAction(i18n("Undo/Redo &History..."), 0, this, SLOT(undoHistory()), |
1264 | actionCollection(), "edit_undoHistory"); | 1264 | actionCollection(), "edit_undoHistory"); |
1265 | KStdAction::cut(this, SLOT(cut()), actionCollection()); | 1265 | KStdAction::cut(this, SLOT(cut()), actionCollection()); |
1266 | KStdAction::copy(this, SLOT(copy()), actionCollection()); | 1266 | KStdAction::copy(this, SLOT(copy()), actionCollection()); |
1267 | KStdAction::paste(this, SLOT(paste()), actionCollection()); | 1267 | KStdAction::paste(this, SLOT(paste()), actionCollection()); |
1268 | 1268 | ||
1269 | if ( myDoc->hasBrowserExtension() ) | 1269 | if ( myDoc->hasBrowserExtension() ) |
1270 | { | 1270 | { |
1271 | KStdAction::saveAs(this, SLOT(saveAs()), myDoc->actionCollection()); | 1271 | KStdAction::saveAs(this, SLOT(saveAs()), myDoc->actionCollection()); |
1272 | KStdAction::find(this, SLOT(find()), myDoc->actionCollection(), "find"); | 1272 | KStdAction::find(this, SLOT(find()), myDoc->actionCollection(), "find"); |
1273 | KStdAction::findNext(this, SLOT(findAgain()), myDoc->actionCollection(), "find_again"); | 1273 | KStdAction::findNext(this, SLOT(findAgain()), myDoc->actionCollection(), "find_again"); |
1274 | KStdAction::findPrev(this, SLOT(findPrev()), myDoc->actionCollection(), "find_prev"); | 1274 | KStdAction::findPrev(this, SLOT(findPrev()), myDoc->actionCollection(), "find_prev"); |
1275 | KStdAction::gotoLine(this, SLOT(gotoLine()), myDoc->actionCollection(), "goto_line" ); | 1275 | KStdAction::gotoLine(this, SLOT(gotoLine()), myDoc->actionCollection(), "goto_line" ); |
1276 | new KAction(i18n("&Configure Editor..."), 0, this, SLOT(configDialog()),myDoc->actionCollection(), "set_confdlg"); | 1276 | new KAction(i18n("&Configure Editor..."), 0, this, SLOT(configDialog()),myDoc->actionCollection(), "set_confdlg"); |
1277 | setHighlight = new KSelectAction(i18n("&Highlight Mode"), 0, myDoc->actionCollection(), "set_highlight"); | 1277 | setHighlight = new KSelectAction(i18n("&Highlight Mode"), 0, myDoc->actionCollection(), "set_highlight"); |
1278 | KStdAction::selectAll(this, SLOT(selectAll()), myDoc->actionCollection(), "select_all"); | 1278 | KStdAction::selectAll(this, SLOT(selectAll()), myDoc->actionCollection(), "select_all"); |
1279 | new KAction(i18n("&Deselect All"), 0, this, SLOT(deselectAll()), | 1279 | new KAction(i18n("&Deselect All"), 0, this, SLOT(deselectAll()), |
1280 | myDoc->actionCollection(), "unselect_all"); | 1280 | myDoc->actionCollection(), "unselect_all"); |
1281 | new KAction(i18n("Invert &Selection"), 0, this, SLOT(invertSelection()), | 1281 | new KAction(i18n("Invert &Selection"), 0, this, SLOT(invertSelection()), |
1282 | myDoc->actionCollection(), "invert_select"); | 1282 | myDoc->actionCollection(), "invert_select"); |
1283 | 1283 | ||
1284 | new KAction(i18n("Increase Font Sizes"), "viewmag+", 0, this, SLOT(slotIncFontSizes()), | 1284 | new KAction(i18n("Increase Font Sizes"), "viewmag+", 0, this, SLOT(slotIncFontSizes()), |
1285 | myDoc->actionCollection(), "incFontSizes"); | 1285 | myDoc->actionCollection(), "incFontSizes"); |
1286 | new KAction(i18n("Decrease Font Sizes"), "viewmag-", 0, this, SLOT(slotDecFontSizes()), | 1286 | new KAction(i18n("Decrease Font Sizes"), "viewmag-", 0, this, SLOT(slotDecFontSizes()), |
1287 | myDoc->actionCollection(), "decFontSizes"); | 1287 | myDoc->actionCollection(), "decFontSizes"); |
1288 | } | 1288 | } |
1289 | else | 1289 | else |
1290 | { | 1290 | { |
1291 | KStdAction::saveAs(this, SLOT(saveAs()), actionCollection()); | 1291 | KStdAction::saveAs(this, SLOT(saveAs()), actionCollection()); |
1292 | KStdAction::find(this, SLOT(find()), actionCollection()); | 1292 | KStdAction::find(this, SLOT(find()), actionCollection()); |
1293 | KStdAction::findNext(this, SLOT(findAgain()), actionCollection()); | 1293 | KStdAction::findNext(this, SLOT(findAgain()), actionCollection()); |
1294 | KStdAction::findPrev(this, SLOT(findPrev()), actionCollection(), "edit_find_prev"); | 1294 | KStdAction::findPrev(this, SLOT(findPrev()), actionCollection(), "edit_find_prev"); |
1295 | KStdAction::gotoLine(this, SLOT(gotoLine()), actionCollection()); | 1295 | KStdAction::gotoLine(this, SLOT(gotoLine()), actionCollection()); |
1296 | new KAction(i18n("&Configure Editor..."), 0, this, SLOT(configDialog()),actionCollection(), "set_confdlg"); | 1296 | new KAction(i18n("&Configure Editor..."), 0, this, SLOT(configDialog()),actionCollection(), "set_confdlg"); |
1297 | setHighlight = new KSelectAction(i18n("&Highlight Mode"), 0, actionCollection(), "set_highlight"); | 1297 | setHighlight = new KSelectAction(i18n("&Highlight Mode"), 0, actionCollection(), "set_highlight"); |
1298 | KStdAction::selectAll(this, SLOT(selectAll()), actionCollection()); | 1298 | KStdAction::selectAll(this, SLOT(selectAll()), actionCollection()); |
1299 | new KAction(i18n("&Deselect All"), 0, this, SLOT(deselectAll()), | 1299 | new KAction(i18n("&Deselect All"), 0, this, SLOT(deselectAll()), |
1300 | actionCollection(), "edit_deselectAll"); | 1300 | actionCollection(), "edit_deselectAll"); |
1301 | new KAction(i18n("Invert &Selection"), 0, this, SLOT(invertSelection()), | 1301 | new KAction(i18n("Invert &Selection"), 0, this, SLOT(invertSelection()), |
1302 | actionCollection(), "edit_invertSelection"); | 1302 | actionCollection(), "edit_invertSelection"); |
1303 | 1303 | ||
1304 | new KAction(i18n("Increase Font Sizes"), "viewmag+", 0, this, SLOT(slotIncFontSizes()), | 1304 | new KAction(i18n("Increase Font Sizes"), "viewmag+", 0, this, SLOT(slotIncFontSizes()), |
1305 | actionCollection(), "incFontSizes"); | 1305 | actionCollection(), "incFontSizes"); |
1306 | new KAction(i18n("Decrease Font Sizes"), "viewmag-", 0, this, SLOT(slotDecFontSizes()), | 1306 | new KAction(i18n("Decrease Font Sizes"), "viewmag-", 0, this, SLOT(slotDecFontSizes()), |
1307 | actionCollection(), "decFontSizes"); | 1307 | actionCollection(), "decFontSizes"); |
1308 | } | 1308 | } |
1309 | 1309 | ||
1310 | new KAction(i18n("Apply Word Wrap"), 0, myDoc, SLOT(applyWordWrap()), actionCollection(), "edit_apply_wordwrap"); | 1310 | new KAction(i18n("Apply Word Wrap"), 0, myDoc, SLOT(applyWordWrap()), actionCollection(), "edit_apply_wordwrap"); |
1311 | 1311 | ||
1312 | KStdAction::replace(this, SLOT(replace()), actionCollection()); | 1312 | KStdAction::replace(this, SLOT(replace()), actionCollection()); |
1313 | 1313 | ||
1314 | new KAction(i18n("Editing Co&mmand"), Qt::CTRL+Qt::Key_M, this, SLOT(slotEditCommand()), | 1314 | new KAction(i18n("Editing Co&mmand"), Qt::CTRL+Qt::Key_M, this, SLOT(slotEditCommand()), |
1315 | actionCollection(), "edit_cmd"); | 1315 | actionCollection(), "edit_cmd"); |
1316 | 1316 | ||
1317 | // setup bookmark menu | 1317 | // setup bookmark menu |
1318 | bookmarkToggle = new KAction(i18n("Toggle &Bookmark"), Qt::CTRL+Qt::Key_B, this, SLOT(toggleBookmark()), actionCollection(), "edit_bookmarkToggle"); | 1318 | bookmarkToggle = new KAction(i18n("Toggle &Bookmark"), Qt::CTRL+Qt::Key_B, this, SLOT(toggleBookmark()), actionCollection(), "edit_bookmarkToggle"); |
1319 | bookmarkClear = new KAction(i18n("Clear Bookmarks"), 0, this, SLOT(clearBookmarks()), actionCollection(), "edit_bookmarksClear"); | 1319 | bookmarkClear = new KAction(i18n("Clear Bookmarks"), 0, this, SLOT(clearBookmarks()), actionCollection(), "edit_bookmarksClear"); |
1320 | 1320 | ||
1321 | // connect settings menu aboutToshow | 1321 | // connect settings menu aboutToshow |
1322 | bookmarkMenu = new KActionMenu(i18n("&Bookmarks"), actionCollection(), "bookmarks"); | 1322 | bookmarkMenu = new KActionMenu(i18n("&Bookmarks"), actionCollection(), "bookmarks"); |
1323 | connect(bookmarkMenu->popupMenu(), SIGNAL(aboutToShow()), this, SLOT(bookmarkMenuAboutToShow())); | 1323 | connect(bookmarkMenu->popupMenu(), SIGNAL(aboutToShow()), this, SLOT(bookmarkMenuAboutToShow())); |
1324 | 1324 | ||
1325 | new KToggleAction(i18n("Show &IconBorder"), Key_F6, this, SLOT(toggleIconBorder()), actionCollection(), "view_border"); | 1325 | new KToggleAction(i18n("Show &IconBorder"), Key_F6, this, SLOT(toggleIconBorder()), actionCollection(), "view_border"); |
1326 | 1326 | ||
1327 | // setup Tools menu | 1327 | // setup Tools menu |
1328 | KStdAction::spelling(this, SLOT(spellcheck()), actionCollection()); | 1328 | KStdAction::spelling(this, SLOT(spellcheck()), actionCollection()); |
1329 | new KAction(i18n("&Indent"), "indent", Qt::CTRL+Qt::Key_I, this, SLOT(indent()), | 1329 | new KAction(i18n("&Indent"), "indent", Qt::CTRL+Qt::Key_I, this, SLOT(indent()), |
1330 | actionCollection(), "tools_indent"); | 1330 | actionCollection(), "tools_indent"); |
1331 | new KAction(i18n("&Unindent"), "unindent", Qt::CTRL+Qt::Key_U, this, SLOT(unIndent()), | 1331 | new KAction(i18n("&Unindent"), "unindent", Qt::CTRL+Qt::Key_U, this, SLOT(unIndent()), |
1332 | actionCollection(), "tools_unindent"); | 1332 | actionCollection(), "tools_unindent"); |
1333 | new KAction(i18n("&Clean Indentation"), 0, this, SLOT(cleanIndent()), | 1333 | new KAction(i18n("&Clean Indentation"), 0, this, SLOT(cleanIndent()), |
1334 | actionCollection(), "tools_cleanIndent"); | 1334 | actionCollection(), "tools_cleanIndent"); |
1335 | new KAction(i18n("C&omment"), CTRL+Qt::Key_NumberSign, this, SLOT(comment()), | 1335 | new KAction(i18n("C&omment"), CTRL+Qt::Key_NumberSign, this, SLOT(comment()), |
1336 | actionCollection(), "tools_comment"); | 1336 | actionCollection(), "tools_comment"); |
1337 | new KAction(i18n("Unco&mment"), CTRL+SHIFT+Qt::Key_NumberSign, this, SLOT(uncomment()), | 1337 | new KAction(i18n("Unco&mment"), CTRL+SHIFT+Qt::Key_NumberSign, this, SLOT(uncomment()), |
1338 | actionCollection(), "tools_uncomment"); | 1338 | actionCollection(), "tools_uncomment"); |
1339 | 1339 | ||
1340 | setVerticalSelection = new KToggleAction(i18n("&Vertical Selection"), Key_F4, this, SLOT(toggleVertical()), | 1340 | setVerticalSelection = new KToggleAction(i18n("&Vertical Selection"), Key_F4, this, SLOT(toggleVertical()), |
1341 | actionCollection(), "set_verticalSelect"); | 1341 | actionCollection(), "set_verticalSelect"); |
1342 | 1342 | ||
1343 | connect(setHighlight, SIGNAL(activated(int)), this, SLOT(setHl(int))); | 1343 | connect(setHighlight, SIGNAL(activated(int)), this, SLOT(setHl(int))); |
1344 | QStringList list; | 1344 | QStringList list; |
1345 | for (int z = 0; z < HlManager::self()->highlights(); z++) | 1345 | for (int z = 0; z < HlManager::self()->highlights(); z++) |
1346 | list.append(HlManager::self()->hlName(z)); | 1346 | list.append(HlManager::self()->hlName(z)); |
1347 | setHighlight->setItems(list); | 1347 | setHighlight->setItems(list); |
1348 | 1348 | ||
1349 | setEndOfLine = new KSelectAction(i18n("&End Of Line"), 0, actionCollection(), "set_eol"); | 1349 | setEndOfLine = new KSelectAction(i18n("&End Of Line"), 0, actionCollection(), "set_eol"); |
1350 | connect(setEndOfLine, SIGNAL(activated(int)), this, SLOT(setEol(int))); | 1350 | connect(setEndOfLine, SIGNAL(activated(int)), this, SLOT(setEol(int))); |
1351 | list.clear(); | 1351 | list.clear(); |
1352 | list.append("&Unix"); | 1352 | list.append("&Unix"); |
1353 | list.append("&Windows/Dos"); | 1353 | list.append("&Windows/Dos"); |
1354 | list.append("&Macintosh"); | 1354 | list.append("&Macintosh"); |
1355 | setEndOfLine->setItems(list); | 1355 | setEndOfLine->setItems(list); |
1356 | #endif | 1356 | #endif |
1357 | } | 1357 | } |
1358 | #endif | 1358 | #endif |
1359 | 1359 | ||
1360 | void KateView::slotUpdate() | 1360 | void KateView::slotUpdate() |
1361 | { | 1361 | { |
1362 | int cfg = config(); | 1362 | int cfg = config(); |
1363 | 1363 | ||
1364 | #warning fixme setVerticalSelection->setChecked(cfg & KateView::cfVerticalSelect); | 1364 | #warning fixme setVerticalSelection->setChecked(cfg & KateView::cfVerticalSelect); |
1365 | 1365 | ||
1366 | slotNewUndo(); | 1366 | slotNewUndo(); |
1367 | } | 1367 | } |
1368 | void KateView::slotFileStatusChanged() | 1368 | void KateView::slotFileStatusChanged() |
1369 | { | 1369 | { |
1370 | int eol = getEol(); | 1370 | int eol = getEol(); |
1371 | eol = eol>=1 ? eol : 0; | 1371 | eol = eol>=1 ? eol : 0; |
1372 | 1372 | ||
1373 | #warning fixme setEndOfLine->setCurrentItem(eol); | 1373 | #warning fixme setEndOfLine->setCurrentItem(eol); |
1374 | } | 1374 | } |
1375 | void KateView::slotNewUndo() | 1375 | void KateView::slotNewUndo() |
1376 | { | 1376 | { |
1377 | #if 0 | 1377 | #if 0 |
1378 | int state = undoState(); | 1378 | int state = undoState(); |
1379 | 1379 | ||
1380 | editUndoHist->setEnabled(state & 1 || state & 2); | 1380 | editUndoHist->setEnabled(state & 1 || state & 2); |
1381 | 1381 | ||
1382 | QString t = i18n("Und&o"); // it would be nicer to fetch the original string | 1382 | QString t = i18n("Und&o"); // it would be nicer to fetch the original string |
1383 | if (state & 1) { | 1383 | if (state & 1) { |
1384 | editUndo->setEnabled(true); | 1384 | editUndo->setEnabled(true); |
1385 | t += ' '; | 1385 | t += ' '; |
1386 | t += i18n(undoTypeName(nextUndoType())); | 1386 | t += i18n(undoTypeName(nextUndoType())); |
1387 | } else { | 1387 | } else { |
1388 | editUndo->setEnabled(false); | 1388 | editUndo->setEnabled(false); |
1389 | } | 1389 | } |
1390 | editUndo->setText(t); | 1390 | editUndo->setText(t); |
1391 | 1391 | ||
1392 | t = i18n("Re&do"); // it would be nicer to fetch the original string | 1392 | t = i18n("Re&do"); // it would be nicer to fetch the original string |
1393 | if (state & 2) { | 1393 | if (state & 2) { |
1394 | editRedo->setEnabled(true); | 1394 | editRedo->setEnabled(true); |
1395 | t += ' '; | 1395 | t += ' '; |
1396 | t += i18n(undoTypeName(nextRedoType())); | 1396 | t += i18n(undoTypeName(nextRedoType())); |
1397 | } else { | 1397 | } else { |
1398 | editRedo->setEnabled(false); | 1398 | editRedo->setEnabled(false); |
1399 | } | 1399 | } |
1400 | editRedo->setText(t); | 1400 | editRedo->setText(t); |
1401 | #endif | 1401 | #endif |
1402 | } | 1402 | } |
1403 | 1403 | ||
1404 | void KateView::slotHighlightChanged() | 1404 | void KateView::slotHighlightChanged() |
1405 | { | 1405 | { |
1406 | // setHighlight->setCurrentItem(getHl()); | 1406 | // setHighlight->setCurrentItem(getHl()); |
1407 | } | 1407 | } |
1408 | 1408 | ||
1409 | 1409 | ||
1410 | void KateView::keyPressEvent( QKeyEvent *ev ) | 1410 | void KateView::keyPressEvent( QKeyEvent *ev ) |
1411 | { | 1411 | { |
1412 | switch ( ev->key() ) | 1412 | switch ( ev->key() ) |
1413 | { | 1413 | { |
1414 | case Key_Left: | 1414 | case Key_Left: |
1415 | if ( ev->state() & ShiftButton ) | 1415 | if ( ev->state() & ShiftButton ) |
1416 | { | 1416 | { |
1417 | if ( ev->state() & ControlButton ) | 1417 | if ( ev->state() & ControlButton ) |
1418 | shiftWordLeft(); | 1418 | shiftWordLeft(); |
1419 | else | 1419 | else |
1420 | shiftCursorLeft(); | 1420 | shiftCursorLeft(); |
1421 | } | 1421 | } |
1422 | else if ( ev->state() & ControlButton ) | 1422 | else if ( ev->state() & ControlButton ) |
1423 | wordLeft(); | 1423 | wordLeft(); |
1424 | else | 1424 | else |
1425 | cursorLeft(); | 1425 | cursorLeft(); |
1426 | break; | 1426 | break; |
1427 | case Key_Right: | 1427 | case Key_Right: |
1428 | if ( ev->state() & ShiftButton ) | 1428 | if ( ev->state() & ShiftButton ) |
1429 | { | 1429 | { |
1430 | if ( ev->state() & ControlButton ) | 1430 | if ( ev->state() & ControlButton ) |
1431 | shiftWordRight(); | 1431 | shiftWordRight(); |
1432 | else | 1432 | else |
1433 | shiftCursorRight(); | 1433 | shiftCursorRight(); |
1434 | } | 1434 | } |
1435 | else if ( ev->state() & ControlButton ) | 1435 | else if ( ev->state() & ControlButton ) |
1436 | wordRight(); | 1436 | wordRight(); |
1437 | else | 1437 | else |
1438 | cursorRight(); | 1438 | cursorRight(); |
1439 | break; | 1439 | break; |
1440 | case Key_Home: | 1440 | case Key_Home: |
1441 | if ( ev->state() & ShiftButton ) | 1441 | if ( ev->state() & ShiftButton ) |
1442 | { | 1442 | { |
1443 | if ( ev->state() & ControlButton ) | 1443 | if ( ev->state() & ControlButton ) |
1444 | shiftTop(); | 1444 | shiftTop(); |
1445 | else | 1445 | else |
1446 | shiftHome(); | 1446 | shiftHome(); |
1447 | } | 1447 | } |
1448 | else if ( ev->state() & ControlButton ) | 1448 | else if ( ev->state() & ControlButton ) |
1449 | top(); | 1449 | top(); |
1450 | else | 1450 | else |
1451 | home(); | 1451 | home(); |
1452 | break; | 1452 | break; |
1453 | case Key_End: | 1453 | case Key_End: |
1454 | if ( ev->state() & ShiftButton ) | 1454 | if ( ev->state() & ShiftButton ) |
1455 | { | 1455 | { |
1456 | if ( ev->state() & ControlButton ) | 1456 | if ( ev->state() & ControlButton ) |
1457 | shiftBottom(); | 1457 | shiftBottom(); |
1458 | else | 1458 | else |
1459 | shiftEnd(); | 1459 | shiftEnd(); |
1460 | } | 1460 | } |
1461 | else if ( ev->state() & ControlButton ) | 1461 | else if ( ev->state() & ControlButton ) |
1462 | bottom(); | 1462 | bottom(); |
1463 | else | 1463 | else |
1464 | end(); | 1464 | end(); |
1465 | break; | 1465 | break; |
1466 | case Key_Up: | 1466 | case Key_Up: |
1467 | if ( ev->state() & ShiftButton ) | 1467 | if ( ev->state() & ShiftButton ) |
1468 | shiftUp(); | 1468 | shiftUp(); |
1469 | else if ( ev->state() & ControlButton ) | 1469 | else if ( ev->state() & ControlButton ) |
1470 | scrollUp(); | 1470 | scrollUp(); |
1471 | else | 1471 | else |
1472 | up(); | 1472 | up(); |
1473 | break; | 1473 | break; |
1474 | case Key_Down: | 1474 | case Key_Down: |
1475 | if ( ev->state() & ShiftButton ) | 1475 | if ( ev->state() & ShiftButton ) |
1476 | shiftDown(); | 1476 | shiftDown(); |
1477 | else if ( ev->state() & ControlButton ) | 1477 | else if ( ev->state() & ControlButton ) |
1478 | scrollDown(); | 1478 | scrollDown(); |
1479 | else | 1479 | else |
1480 | down(); | 1480 | down(); |
1481 | break; | 1481 | break; |
1482 | case Key_PageUp: | 1482 | case Key_PageUp: |
1483 | if ( ev->state() & ShiftButton ) | 1483 | if ( ev->state() & ShiftButton ) |
1484 | shiftPageUp(); | 1484 | shiftPageUp(); |
1485 | else if ( ev->state() & ControlButton ) | 1485 | else if ( ev->state() & ControlButton ) |
1486 | topOfView(); | 1486 | topOfView(); |
1487 | else | 1487 | else |
1488 | pageUp(); | 1488 | pageUp(); |
1489 | break; | 1489 | break; |
1490 | case Key_PageDown: | 1490 | case Key_PageDown: |
1491 | if ( ev->state() & ShiftButton ) | 1491 | if ( ev->state() & ShiftButton ) |
1492 | shiftPageDown(); | 1492 | shiftPageDown(); |
1493 | else if ( ev->state() & ControlButton ) | 1493 | else if ( ev->state() & ControlButton ) |
1494 | bottomOfView(); | 1494 | bottomOfView(); |
1495 | else | 1495 | else |
1496 | pageDown(); | 1496 | pageDown(); |
1497 | break; | 1497 | break; |
1498 | case Key_Return: | 1498 | case Key_Return: |
1499 | case Key_Enter: | 1499 | case Key_Enter: |
1500 | keyReturn(); | 1500 | keyReturn(); |
1501 | break; | 1501 | break; |
1502 | case Key_Delete: | 1502 | case Key_Delete: |
1503 | if ( ev->state() & ControlButton ) | 1503 | if ( ev->state() & ControlButton ) |
1504 | { | 1504 | { |
1505 | VConfig c; | 1505 | VConfig c; |
1506 | shiftWordRight(); | 1506 | shiftWordRight(); |
1507 | myViewInternal->getVConfig(c); | 1507 | myViewInternal->getVConfig(c); |
1508 | myDoc->delMarkedText(c); | 1508 | myDoc->delMarkedText(c); |
1509 | myViewInternal->update(); | 1509 | myViewInternal->update(); |
1510 | } | 1510 | } |
1511 | else keyDelete(); | 1511 | else keyDelete(); |
1512 | break; | 1512 | break; |
1513 | case Key_Backspace: | 1513 | case Key_Backspace: |
1514 | if ( ev->state() & ControlButton ) | 1514 | if ( ev->state() & ControlButton ) |
1515 | { | 1515 | { |
1516 | VConfig c; | 1516 | VConfig c; |
1517 | shiftWordLeft(); | 1517 | shiftWordLeft(); |
1518 | myViewInternal->getVConfig(c); | 1518 | myViewInternal->getVConfig(c); |
1519 | myDoc->delMarkedText(c); | 1519 | myDoc->delMarkedText(c); |
1520 | myViewInternal->update(); | 1520 | myViewInternal->update(); |
1521 | } | 1521 | } |
1522 | else backspace(); | 1522 | else backspace(); |
1523 | break; | 1523 | break; |
1524 | case Key_Insert: | 1524 | case Key_Insert: |
1525 | toggleInsert(); | 1525 | toggleInsert(); |
1526 | break; | 1526 | break; |
1527 | case Key_K: | 1527 | case Key_K: |
1528 | if ( ev->state() & ControlButton ) | 1528 | if ( ev->state() & ControlButton ) |
1529 | { | 1529 | { |
1530 | killLine(); | 1530 | killLine(); |
1531 | break; | 1531 | break; |
1532 | } | 1532 | } |
1533 | default: | 1533 | default: |
1534 | KTextEditor::View::keyPressEvent( ev ); | 1534 | KTextEditor::View::keyPressEvent( ev ); |
1535 | return; | 1535 | return; |
1536 | break; | 1536 | break; |
1537 | } | 1537 | } |
1538 | ev->accept(); | 1538 | ev->accept(); |
1539 | } | 1539 | } |
1540 | 1540 | ||
1541 | 1541 | ||
1542 | void KateView::setCursorPosition( int line, int col, bool /*mark*/ ) | 1542 | void KateView::setCursorPosition( int line, int col, bool /*mark*/ ) |
1543 | { | 1543 | { |
1544 | setCursorPositionInternal( line, col ); | 1544 | setCursorPositionInternal( line, col ); |
1545 | } | 1545 | } |
1546 | 1546 | ||
1547 | void KateView::getCursorPosition( int *line, int *col ) | 1547 | void KateView::getCursorPosition( int *line, int *col ) |
1548 | { | 1548 | { |
1549 | if ( line ) | 1549 | if ( line ) |
1550 | *line = currentLine(); | 1550 | *line = currentLine(); |
1551 | 1551 | ||
1552 | if ( col ) | 1552 | if ( col ) |
1553 | *col = currentColumn(); | 1553 | *col = currentColumn(); |
1554 | } | 1554 | } |
1555 | 1555 | ||
1556 | 1556 | ||
1557 | int KateView::currentLine() { | 1557 | int KateView::currentLine() { |
1558 | return myViewInternal->cursor.y; | 1558 | return myViewInternal->cursor.y; |
1559 | } | 1559 | } |
1560 | 1560 | ||
1561 | int KateView::currentColumn() { | 1561 | int KateView::currentColumn() { |
1562 | return myDoc->currentColumn(myViewInternal->cursor); | 1562 | return myDoc->currentColumn(myViewInternal->cursor); |
1563 | } | 1563 | } |
1564 | 1564 | ||
1565 | int KateView::currentCharNum() { | 1565 | int KateView::currentCharNum() { |
1566 | return myViewInternal->cursor.x; | 1566 | return myViewInternal->cursor.x; |
1567 | } | 1567 | } |
1568 | 1568 | ||
1569 | void KateView::setCursorPositionInternal(int line, int col) { | 1569 | void KateView::setCursorPositionInternal(int line, int col) { |
1570 | PointStruc cursor; | 1570 | PointStruc cursor; |
1571 | 1571 | ||
1572 | cursor.x = col; | 1572 | cursor.x = col; |
1573 | cursor.y = line; | 1573 | cursor.y = line; |
1574 | myViewInternal->updateCursor(cursor); | 1574 | myViewInternal->updateCursor(cursor); |
1575 | myViewInternal->center(); | 1575 | myViewInternal->center(); |
1576 | // myViewInternal->updateView(ufPos, 0, line*myDoc->fontHeight - height()/2); | 1576 | // myViewInternal->updateView(ufPos, 0, line*myDoc->fontHeight - height()/2); |
1577 | // myDoc->updateViews(myViewInternal); //uptade all other views except this one | 1577 | // myDoc->updateViews(myViewInternal); //uptade all other views except this one |
1578 | myDoc->updateViews(); | 1578 | myDoc->updateViews(); |
1579 | } | 1579 | } |
1580 | 1580 | ||
1581 | int KateView::config() { | 1581 | int KateView::config() { |
1582 | int flags; | 1582 | int flags; |
1583 | 1583 | ||
1584 | flags = configFlags; | 1584 | flags = configFlags; |
1585 | if (myDoc->singleSelection()) flags |= KateView::cfSingleSelection; | 1585 | if (myDoc->singleSelection()) flags |= KateView::cfSingleSelection; |
1586 | return flags; | 1586 | return flags; |
1587 | } | 1587 | } |
1588 | 1588 | ||
1589 | void KateView::setConfig(int flags) { | 1589 | void KateView::setConfig(int flags) { |
1590 | bool updateView; | 1590 | bool updateView; |
1591 | 1591 | ||
1592 | // cfSingleSelection is a doc-property | 1592 | // cfSingleSelection is a doc-property |
1593 | myDoc->setSingleSelection(flags & KateView::cfSingleSelection); | 1593 | myDoc->setSingleSelection(flags & KateView::cfSingleSelection); |
1594 | flags &= ~KateView::cfSingleSelection; | 1594 | flags &= ~KateView::cfSingleSelection; |
1595 | 1595 | ||
1596 | if (flags != configFlags) { | 1596 | if (flags != configFlags) { |
1597 | // update the view if visibility of tabs has changed | 1597 | // update the view if visibility of tabs has changed |
1598 | updateView = (flags ^ configFlags) & KateView::cfShowTabs; | 1598 | updateView = (flags ^ configFlags) & KateView::cfShowTabs; |
1599 | configFlags = flags; | 1599 | configFlags = flags; |
1600 | emit newStatus(); | 1600 | emit newStatus(); |
1601 | if (updateView) myViewInternal->update(); | 1601 | if (updateView) myViewInternal->update(); |
1602 | } | 1602 | } |
1603 | } | 1603 | } |
1604 | 1604 | ||
1605 | int KateView::tabWidth() { | 1605 | int KateView::tabWidth() { |
1606 | return myDoc->tabChars; | 1606 | return myDoc->tabChars; |
1607 | } | 1607 | } |
1608 | 1608 | ||
1609 | void KateView::setTabWidth(int w) { | 1609 | void KateView::setTabWidth(int w) { |
1610 | myDoc->setTabWidth(w); | 1610 | myDoc->setTabWidth(w); |
1611 | myDoc->updateViews(); | 1611 | myDoc->updateViews(); |
1612 | } | 1612 | } |
1613 | 1613 | ||
1614 | void KateView::setEncoding (QString e) { | 1614 | void KateView::setEncoding (QString e) { |
1615 | myDoc->setEncoding (e); | 1615 | myDoc->setEncoding (e); |
1616 | myDoc->updateViews(); | 1616 | myDoc->updateViews(); |
1617 | } | 1617 | } |
1618 | 1618 | ||
1619 | int KateView::undoSteps() { | 1619 | int KateView::undoSteps() { |
1620 | return myDoc->undoSteps; | 1620 | return myDoc->undoSteps; |
1621 | } | 1621 | } |
1622 | 1622 | ||
1623 | void KateView::setUndoSteps(int s) { | 1623 | void KateView::setUndoSteps(int s) { |
1624 | myDoc->setUndoSteps(s); | 1624 | myDoc->setUndoSteps(s); |
1625 | } | 1625 | } |
1626 | 1626 | ||
1627 | bool KateView::isReadOnly() { | 1627 | bool KateView::isReadOnly() { |
1628 | return myDoc->readOnly; | 1628 | return myDoc->readOnly; |
1629 | } | 1629 | } |
1630 | 1630 | ||
1631 | bool KateView::isModified() { | 1631 | bool KateView::isModified() { |
1632 | return myDoc->modified; | 1632 | return myDoc->modified; |
1633 | } | 1633 | } |
1634 | 1634 | ||
1635 | void KateView::setReadOnly(bool m) { | 1635 | void KateView::setReadOnly(bool m) { |
1636 | myDoc->setReadOnly(m); | 1636 | myDoc->setReadOnly(m); |
1637 | } | 1637 | } |
1638 | 1638 | ||
1639 | void KateView::setModified(bool m) { | 1639 | void KateView::setModified(bool m) { |
1640 | myDoc->setModified(m); | 1640 | myDoc->setModified(m); |
1641 | } | 1641 | } |
1642 | 1642 | ||
1643 | bool KateView::isLastView() { | 1643 | bool KateView::isLastView() { |
1644 | return myDoc->isLastView(1); | 1644 | return myDoc->isLastView(1); |
1645 | } | 1645 | } |
1646 | 1646 | ||
1647 | KateDocument *KateView::doc() { | 1647 | KateDocument *KateView::doc() { |
1648 | return myDoc; | 1648 | return myDoc; |
1649 | } | 1649 | } |
1650 | 1650 | ||
1651 | int KateView::undoState() { | 1651 | int KateView::undoState() { |
1652 | if (isReadOnly()) | 1652 | if (isReadOnly()) |
1653 | return 0; | 1653 | return 0; |
1654 | else | 1654 | else |
1655 | return myDoc->undoState; | 1655 | return myDoc->undoState; |
1656 | } | 1656 | } |
1657 | 1657 | ||
1658 | int KateView::nextUndoType() { | 1658 | int KateView::nextUndoType() { |
1659 | return myDoc->nextUndoType(); | 1659 | return myDoc->nextUndoType(); |
1660 | } | 1660 | } |
1661 | 1661 | ||
1662 | int KateView::nextRedoType() { | 1662 | int KateView::nextRedoType() { |
1663 | return myDoc->nextRedoType(); | 1663 | return myDoc->nextRedoType(); |
1664 | } | 1664 | } |
1665 | 1665 | ||
1666 | void KateView::undoTypeList(QValueList<int> &lst) | 1666 | void KateView::undoTypeList(QValueList<int> &lst) |
1667 | { | 1667 | { |
1668 | myDoc->undoTypeList(lst); | 1668 | myDoc->undoTypeList(lst); |
1669 | } | 1669 | } |
1670 | 1670 | ||
1671 | void KateView::redoTypeList(QValueList<int> &lst) | 1671 | void KateView::redoTypeList(QValueList<int> &lst) |
1672 | { | 1672 | { |
1673 | myDoc->redoTypeList(lst); | 1673 | myDoc->redoTypeList(lst); |
1674 | } | 1674 | } |
1675 | 1675 | ||
1676 | const char * KateView::undoTypeName(int type) { | 1676 | const char * KateView::undoTypeName(int type) { |
1677 | return KateActionGroup::typeName(type); | 1677 | return KateActionGroup::typeName(type); |
1678 | } | 1678 | } |
1679 | 1679 | ||
1680 | QColor* KateView::getColors() | 1680 | QColor* KateView::getColors() |
1681 | { | 1681 | { |
1682 | return myDoc->colors; | 1682 | return myDoc->colors; |
1683 | } | 1683 | } |
1684 | 1684 | ||
1685 | void KateView::applyColors() | 1685 | void KateView::applyColors() |
1686 | { | 1686 | { |
1687 | myDoc->tagAll(); | 1687 | myDoc->tagAll(); |
1688 | myDoc->updateViews(); | 1688 | myDoc->updateViews(); |
1689 | } | 1689 | } |
1690 | 1690 | ||
1691 | bool KateView::isOverwriteMode() const | 1691 | bool KateView::isOverwriteMode() const |
1692 | { | 1692 | { |
1693 | return ( configFlags & KateView::cfOvr ); | 1693 | return ( configFlags & KateView::cfOvr ); |
1694 | } | 1694 | } |
1695 | 1695 | ||
1696 | void KateView::setOverwriteMode( bool b ) | 1696 | void KateView::setOverwriteMode( bool b ) |
1697 | { | 1697 | { |
1698 | if ( isOverwriteMode() && !b ) | 1698 | if ( isOverwriteMode() && !b ) |
1699 | setConfig( configFlags ^ KateView::cfOvr ); | 1699 | setConfig( configFlags ^ KateView::cfOvr ); |
1700 | else | 1700 | else |
1701 | setConfig( configFlags | KateView::cfOvr ); | 1701 | setConfig( configFlags | KateView::cfOvr ); |
1702 | } | 1702 | } |
1703 | 1703 | ||
1704 | void KateView::toggleInsert() { | 1704 | void KateView::toggleInsert() { |
1705 | setConfig(configFlags ^ KateView::cfOvr); | 1705 | setConfig(configFlags ^ KateView::cfOvr); |
1706 | } | 1706 | } |
1707 | 1707 | ||
1708 | void KateView::toggleVertical() | 1708 | void KateView::toggleVertical() |
1709 | { | 1709 | { |
1710 | setConfig(configFlags ^ KateView::cfVerticalSelect); | 1710 | setConfig(configFlags ^ KateView::cfVerticalSelect); |
1711 | } | 1711 | } |
1712 | 1712 | ||
1713 | 1713 | ||
1714 | int KateView::numLines() { | 1714 | int KateView::numLines() { |
1715 | return myDoc->numLines(); | 1715 | return myDoc->numLines(); |
1716 | } | 1716 | } |
1717 | 1717 | ||
1718 | QString KateView::text() { | 1718 | QString KateView::text() { |
1719 | return myDoc->text(); | 1719 | return myDoc->text(); |
1720 | } | 1720 | } |
1721 | 1721 | ||
1722 | QString KateView::currentTextLine() { | 1722 | QString KateView::currentTextLine() { |
1723 | TextLine::Ptr textLine = myDoc->getTextLine(myViewInternal->cursor.y); | 1723 | TextLine::Ptr textLine = myDoc->getTextLine(myViewInternal->cursor.y); |
1724 | return QString(textLine->getText(), textLine->length()); | 1724 | return QString(textLine->getText(), textLine->length()); |
1725 | } | 1725 | } |
1726 | 1726 | ||
1727 | QString KateView::textLine(int num) { | 1727 | QString KateView::textLine(int num) { |
1728 | TextLine::Ptr textLine = myDoc->getTextLine(num); | 1728 | TextLine::Ptr textLine = myDoc->getTextLine(num); |
1729 | return QString(textLine->getText(), textLine->length()); | 1729 | return QString(textLine->getText(), textLine->length()); |
1730 | } | 1730 | } |
1731 | 1731 | ||
1732 | QString KateView::currentWord() { | 1732 | QString KateView::currentWord() { |
1733 | return myDoc->getWord(myViewInternal->cursor); | 1733 | return myDoc->getWord(myViewInternal->cursor); |
1734 | } | 1734 | } |
1735 | 1735 | ||
1736 | QString KateView::word(int x, int y) { | 1736 | QString KateView::word(int x, int y) { |
1737 | PointStruc cursor; | 1737 | PointStruc cursor; |
1738 | cursor.y = (myViewInternal->yPos + y)/myDoc->fontHeight; | 1738 | cursor.y = (myViewInternal->yPos + y)/myDoc->fontHeight; |
1739 | if (cursor.y < 0 || cursor.y > myDoc->lastLine()) return QString(); | 1739 | if (cursor.y < 0 || cursor.y > myDoc->lastLine()) return QString(); |
1740 | cursor.x = myDoc->textPos(myDoc->getTextLine(cursor.y), myViewInternal->xPos-2 + x); | 1740 | cursor.x = myDoc->textPos(myDoc->getTextLine(cursor.y), myViewInternal->xPos-2 + x); |
1741 | return myDoc->getWord(cursor); | 1741 | return myDoc->getWord(cursor); |
1742 | } | 1742 | } |
1743 | 1743 | ||
1744 | void KateView::setText(const QString &s) { | 1744 | void KateView::setText(const QString &s) { |
1745 | myDoc->setText(s); | 1745 | myDoc->setText(s); |
1746 | myDoc->updateViews(); | 1746 | myDoc->updateViews(); |
1747 | } | 1747 | } |
1748 | 1748 | ||
1749 | void KateView::insertText(const QString &s, bool /*mark*/) { | 1749 | void KateView::insertText(const QString &s, bool /*mark*/) { |
1750 | VConfig c; | 1750 | VConfig c; |
1751 | myViewInternal->getVConfig(c); | 1751 | myViewInternal->getVConfig(c); |
1752 | myDoc->insert(c, s); | 1752 | myDoc->insert(c, s); |
1753 | myDoc->updateViews(); | 1753 | myDoc->updateViews(); |
1754 | } | 1754 | } |
1755 | 1755 | ||
1756 | bool KateView::hasMarkedText() { | 1756 | bool KateView::hasMarkedText() { |
1757 | return myDoc->hasMarkedText(); | 1757 | return myDoc->hasMarkedText(); |
1758 | } | 1758 | } |
1759 | 1759 | ||
1760 | QString KateView::markedText() { | 1760 | QString KateView::markedText() { |
1761 | return myDoc->markedText(configFlags); | 1761 | return myDoc->markedText(configFlags); |
1762 | } | 1762 | } |
1763 | 1763 | ||
1764 | bool KateView::canDiscard() { | 1764 | bool KateView::canDiscard() { |
1765 | int query; | 1765 | int query; |
1766 | 1766 | ||
1767 | if (isModified()) { | 1767 | if (isModified()) { |
1768 | query = KMessageBox::warningYesNoCancel(this, | 1768 | query = KMessageBox::warningYesNoCancel(this, |
1769 | i18n("The current Document has been modified.\nWould you like to save it?")); | 1769 | i18n("The current Document has been modified.\nWould you like to save it?")); |
1770 | switch (query) { | 1770 | switch (query) { |
1771 | case KMessageBox::Yes: //yes | 1771 | case KMessageBox::Yes: //yes |
1772 | if (save() == CANCEL) return false; | 1772 | if (save() == CANCEL) return false; |
1773 | if (isModified()) { | 1773 | if (isModified()) { |
1774 | query = KMessageBox::warningContinueCancel(this, | 1774 | query = KMessageBox::warningContinueCancel(this, |
1775 | i18n("Could not save the document.\nDiscard it and continue?"), | 1775 | i18n("Could not save the document.\nDiscard it and continue?"), |
1776 | QString::null, i18n("&Discard")); | 1776 | QString::null, i18n("&Discard")); |
1777 | if (query == KMessageBox::Cancel) return false; | 1777 | if (query == KMessageBox::Cancel) return false; |
1778 | } | 1778 | } |
1779 | break; | 1779 | break; |
1780 | case KMessageBox::Cancel: //cancel | 1780 | case KMessageBox::Cancel: //cancel |
1781 | return false; | 1781 | return false; |
1782 | } | 1782 | } |
1783 | } | 1783 | } |
1784 | return true; | 1784 | return true; |
1785 | } | 1785 | } |
1786 | 1786 | ||
1787 | void KateView::flush() | 1787 | void KateView::flush() |
1788 | { | 1788 | { |
1789 | if (canDiscard()) myDoc->flush(); | 1789 | if (canDiscard()) myDoc->flush(); |
1790 | } | 1790 | } |
1791 | 1791 | ||
1792 | KateView::fileResult KateView::save() { | 1792 | KateView::fileResult KateView::save() { |
1793 | int query = KMessageBox::Yes; | 1793 | int query = KMessageBox::Yes; |
1794 | if (isModified()) { | 1794 | if (isModified()) { |
1795 | return saveAs(); | 1795 | return saveAs(); |
1796 | } | 1796 | } |
1797 | return OK; | 1797 | return OK; |
1798 | } | 1798 | } |
1799 | 1799 | ||
1800 | KateView::fileResult KateView::saveAs() { | 1800 | KateView::fileResult KateView::saveAs() { |
1801 | return OK; | 1801 | return OK; |
1802 | } | 1802 | } |
1803 | 1803 | ||
1804 | void KateView::doCursorCommand(int cmdNum) { | 1804 | void KateView::doCursorCommand(int cmdNum) { |
1805 | VConfig c; | 1805 | VConfig c; |
1806 | myViewInternal->getVConfig(c); | 1806 | myViewInternal->getVConfig(c); |
1807 | if (cmdNum & selectFlag) c.flags |= KateView::cfMark; | 1807 | if (cmdNum & selectFlag) c.flags |= KateView::cfMark; |
1808 | if (cmdNum & multiSelectFlag) c.flags |= KateView::cfMark | KateView::cfKeepSelection; | 1808 | if (cmdNum & multiSelectFlag) c.flags |= KateView::cfMark | KateView::cfKeepSelection; |
1809 | cmdNum &= ~(selectFlag | multiSelectFlag); | 1809 | cmdNum &= ~(selectFlag | multiSelectFlag); |
1810 | myViewInternal->doCursorCommand(c, cmdNum); | 1810 | myViewInternal->doCursorCommand(c, cmdNum); |
1811 | myDoc->updateViews(); | 1811 | myDoc->updateViews(); |
1812 | } | 1812 | } |
1813 | 1813 | ||
1814 | void KateView::doEditCommand(int cmdNum) { | 1814 | void KateView::doEditCommand(int cmdNum) { |
1815 | VConfig c; | 1815 | VConfig c; |
1816 | myViewInternal->getVConfig(c); | 1816 | myViewInternal->getVConfig(c); |
1817 | myViewInternal->doEditCommand(c, cmdNum); | 1817 | myViewInternal->doEditCommand(c, cmdNum); |
1818 | myDoc->updateViews(); | 1818 | myDoc->updateViews(); |
1819 | } | 1819 | } |
1820 | 1820 | ||
1821 | void KateView::undoMultiple(int count) { | 1821 | void KateView::undoMultiple(int count) { |
1822 | if (isReadOnly()) | 1822 | if (isReadOnly()) |
1823 | return; | 1823 | return; |
1824 | 1824 | ||
1825 | VConfig c; | 1825 | VConfig c; |
1826 | myViewInternal->getVConfig(c); | 1826 | myViewInternal->getVConfig(c); |
1827 | myDoc->undo(c, count); | 1827 | myDoc->undo(c, count); |
1828 | myDoc->updateViews(); | 1828 | myDoc->updateViews(); |
1829 | } | 1829 | } |
1830 | 1830 | ||
1831 | void KateView::redoMultiple(int count) { | 1831 | void KateView::redoMultiple(int count) { |
1832 | if (isReadOnly()) | 1832 | if (isReadOnly()) |
1833 | return; | 1833 | return; |
1834 | 1834 | ||
1835 | VConfig c; | 1835 | VConfig c; |
1836 | myViewInternal->getVConfig(c); | 1836 | myViewInternal->getVConfig(c); |
1837 | myDoc->redo(c, count); | 1837 | myDoc->redo(c, count); |
1838 | myDoc->updateViews(); | 1838 | myDoc->updateViews(); |
1839 | } | 1839 | } |
1840 | 1840 | ||
1841 | void KateView::undoHistory() | 1841 | void KateView::undoHistory() |
1842 | { | 1842 | { |
1843 | UndoHistory *undoH; | 1843 | UndoHistory *undoH; |
1844 | 1844 | ||
1845 | undoH = new UndoHistory(this, this, "UndoHistory", true); | 1845 | undoH = new UndoHistory(this, this, "UndoHistory", true); |
1846 | 1846 | ||
1847 | undoH->setCaption(i18n("Undo/Redo History")); | 1847 | undoH->setCaption(i18n("Undo/Redo History")); |
1848 | 1848 | ||
1849 | connect(this,SIGNAL(newUndo()),undoH,SLOT(newUndo())); | 1849 | connect(this,SIGNAL(newUndo()),undoH,SLOT(newUndo())); |
1850 | connect(undoH,SIGNAL(undo(int)),this,SLOT(undoMultiple(int))); | 1850 | connect(undoH,SIGNAL(undo(int)),this,SLOT(undoMultiple(int))); |
1851 | connect(undoH,SIGNAL(redo(int)),this,SLOT(redoMultiple(int))); | 1851 | connect(undoH,SIGNAL(redo(int)),this,SLOT(redoMultiple(int))); |
1852 | 1852 | ||
1853 | undoH->exec(); | 1853 | undoH->exec(); |
1854 | 1854 | ||
1855 | delete undoH; | 1855 | delete undoH; |
1856 | } | 1856 | } |
1857 | 1857 | ||
1858 | static void kwview_addToStrList(QStringList &list, const QString &str) { | 1858 | static void kwview_addToStrList(QStringList &list, const QString &str) { |
1859 | if (list.count() > 0) { | 1859 | if (list.count() > 0) { |
1860 | if (list.first() == str) return; | 1860 | if (list.first() == str) return; |
1861 | QStringList::Iterator it; | 1861 | QStringList::Iterator it; |
1862 | it = list.find(str); | 1862 | it = list.find(str); |
1863 | if (*it != 0L) list.remove(it); | 1863 | if (*it != 0L) list.remove(it); |
1864 | if (list.count() >= 16) list.remove(list.fromLast()); | 1864 | if (list.count() >= 16) list.remove(list.fromLast()); |
1865 | } | 1865 | } |
1866 | list.prepend(str); | 1866 | list.prepend(str); |
1867 | } | 1867 | } |
1868 | 1868 | ||
1869 | void KateView::find() { | 1869 | void KateView::find() { |
1870 | SearchDialog *searchDialog; | 1870 | SearchDialog *searchDialog; |
1871 | 1871 | ||
1872 | if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected; | 1872 | if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected; |
1873 | 1873 | ||
1874 | searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList, | 1874 | searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList, |
1875 | searchFlags & ~KateView::sfReplace); | 1875 | searchFlags & ~KateView::sfReplace); |
1876 | 1876 | ||
1877 | // If the user has marked some text we use that otherwise | 1877 | // If the user has marked some text we use that otherwise |
1878 | // use the word under the cursor. | 1878 | // use the word under the cursor. |
1879 | QString str; | 1879 | QString str; |
1880 | if (myDoc->hasMarkedText()) | 1880 | if (myDoc->hasMarkedText()) |
1881 | str = markedText(); | 1881 | str = markedText(); |
1882 | 1882 | ||
1883 | if (str.isEmpty()) | 1883 | if (str.isEmpty()) |
1884 | str = currentWord(); | 1884 | str = currentWord(); |
1885 | 1885 | ||
1886 | if (!str.isEmpty()) | 1886 | if (!str.isEmpty()) |
1887 | { | 1887 | { |
1888 | str.replace(QRegExp("^\n"), ""); | 1888 | str.replace(QRegExp("^\n"), ""); |
1889 | int pos=str.find("\n"); | 1889 | int pos=str.find("\n"); |
1890 | if (pos>-1) | 1890 | if (pos>-1) |
1891 | str=str.left(pos); | 1891 | str=str.left(pos); |
1892 | searchDialog->setSearchText( str ); | 1892 | searchDialog->setSearchText( str ); |
1893 | } | 1893 | } |
1894 | 1894 | ||
1895 | myViewInternal->focusOutEvent(0L);// QT bug ? | 1895 | myViewInternal->focusOutEvent(0L);// QT bug ? |
1896 | if (searchDialog->exec() == QDialog::Accepted) { | 1896 | if (searchDialog->exec() == QDialog::Accepted) { |
1897 | kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor()); | 1897 | kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor()); |
1898 | searchFlags = searchDialog->getFlags() | (searchFlags & KateView::sfPrompt); | 1898 | searchFlags = searchDialog->getFlags() | (searchFlags & KateView::sfPrompt); |
1899 | initSearch(s, searchFlags); | 1899 | initSearch(s, searchFlags); |
1900 | findAgain(s); | 1900 | findAgain(s); |
1901 | } | 1901 | } |
1902 | delete searchDialog; | 1902 | delete searchDialog; |
1903 | } | 1903 | } |
1904 | 1904 | ||
1905 | void KateView::replace() { | 1905 | void KateView::replace() { |
1906 | SearchDialog *searchDialog; | 1906 | SearchDialog *searchDialog; |
1907 | 1907 | ||
1908 | if (isReadOnly()) return; | 1908 | if (isReadOnly()) return; |
1909 | 1909 | ||
1910 | if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected; | 1910 | if (!myDoc->hasMarkedText()) searchFlags &= ~KateView::sfSelected; |
1911 | searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList, | 1911 | searchDialog = new SearchDialog(this, myDoc->searchForList, myDoc->replaceWithList, |
1912 | searchFlags | KateView::sfReplace); | 1912 | searchFlags | KateView::sfReplace); |
1913 | 1913 | ||
1914 | // If the user has marked some text we use that otherwise | 1914 | // If the user has marked some text we use that otherwise |
1915 | // use the word under the cursor. | 1915 | // use the word under the cursor. |
1916 | QString str; | 1916 | QString str; |
1917 | if (myDoc->hasMarkedText()) | 1917 | if (myDoc->hasMarkedText()) |
1918 | str = markedText(); | 1918 | str = markedText(); |
1919 | 1919 | ||
1920 | if (str.isEmpty()) | 1920 | if (str.isEmpty()) |
1921 | str = currentWord(); | 1921 | str = currentWord(); |
1922 | 1922 | ||
1923 | if (!str.isEmpty()) | 1923 | if (!str.isEmpty()) |
1924 | { | 1924 | { |
1925 | str.replace(QRegExp("^\n"), ""); | 1925 | str.replace(QRegExp("^\n"), ""); |
1926 | int pos=str.find("\n"); | 1926 | int pos=str.find("\n"); |
1927 | if (pos>-1) | 1927 | if (pos>-1) |
1928 | str=str.left(pos); | 1928 | str=str.left(pos); |
1929 | searchDialog->setSearchText( str ); | 1929 | searchDialog->setSearchText( str ); |
1930 | } | 1930 | } |
1931 | 1931 | ||
1932 | myViewInternal->focusOutEvent(0L);// QT bug ? | 1932 | myViewInternal->focusOutEvent(0L);// QT bug ? |
1933 | if (searchDialog->exec() == QDialog::Accepted) { | 1933 | if (searchDialog->exec() == QDialog::Accepted) { |
1934 | // myDoc->recordReset(); | 1934 | // myDoc->recordReset(); |
1935 | kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor()); | 1935 | kwview_addToStrList(myDoc->searchForList, searchDialog->getSearchFor()); |
1936 | kwview_addToStrList(myDoc->replaceWithList, searchDialog->getReplaceWith()); | 1936 | kwview_addToStrList(myDoc->replaceWithList, searchDialog->getReplaceWith()); |
1937 | searchFlags = searchDialog->getFlags(); | 1937 | searchFlags = searchDialog->getFlags(); |
1938 | initSearch(s, searchFlags); | 1938 | initSearch(s, searchFlags); |
1939 | replaceAgain(); | 1939 | replaceAgain(); |
1940 | } | 1940 | } |
1941 | delete searchDialog; | 1941 | delete searchDialog; |
1942 | } | 1942 | } |
1943 | 1943 | ||
1944 | void KateView::gotoLine() { | 1944 | void KateView::gotoLine() { |
1945 | GotoLineDialog *dlg; | 1945 | GotoLineDialog *dlg; |
1946 | PointStruc cursor; | 1946 | PointStruc cursor; |
1947 | 1947 | ||
1948 | dlg = new GotoLineDialog(this, myViewInternal->cursor.y + 1, myDoc->numLines()); | 1948 | dlg = new GotoLineDialog(this, myViewInternal->cursor.y + 1, myDoc->numLines()); |
1949 | // dlg = new GotoLineDialog(myViewInternal->cursor.y + 1, this); | 1949 | // dlg = new GotoLineDialog(myViewInternal->cursor.y + 1, this); |
1950 | 1950 | ||
1951 | if (dlg->exec() == QDialog::Accepted) { | 1951 | if (dlg->exec() == QDialog::Accepted) { |
1952 | // myDoc->recordReset(); | 1952 | // myDoc->recordReset(); |
1953 | cursor.x = 0; | 1953 | cursor.x = 0; |
1954 | cursor.y = dlg->getLine() - 1; | 1954 | cursor.y = dlg->getLine() - 1; |
1955 | myDoc->needPreHighlight(cursor.y); | 1955 | myDoc->needPreHighlight(cursor.y); |
1956 | myViewInternal->updateCursor(cursor); | 1956 | myViewInternal->updateCursor(cursor); |
1957 | myViewInternal->center(); | 1957 | myViewInternal->center(); |
1958 | myViewInternal->updateView(KateView::ufUpdateOnScroll); | 1958 | myViewInternal->updateView(KateView::ufUpdateOnScroll); |
1959 | myDoc->updateViews(this); //uptade all other views except this one | 1959 | myDoc->updateViews(this); //uptade all other views except this one |
1960 | } | 1960 | } |
1961 | delete dlg; | 1961 | delete dlg; |
1962 | } | 1962 | } |
1963 | 1963 | ||
1964 | 1964 | ||
1965 | void KateView::initSearch(SConfig &s, int flags) { | 1965 | void KateView::initSearch(SConfig &s, int flags) { |
1966 | 1966 | ||
1967 | s.flags = flags; | 1967 | s.flags = flags; |
1968 | s.setPattern(myDoc->searchForList.first()); | 1968 | s.setPattern(myDoc->searchForList.first()); |
1969 | 1969 | ||
1970 | if (!(s.flags & KateView::sfFromBeginning)) { | 1970 | if (!(s.flags & KateView::sfFromBeginning)) { |
1971 | // If we are continuing a backward search, make sure we do not get stuck | 1971 | // If we are continuing a backward search, make sure we do not get stuck |
1972 | // at an existing match. | 1972 | // at an existing match. |
1973 | s.cursor = myViewInternal->cursor; | 1973 | s.cursor = myViewInternal->cursor; |
1974 | TextLine::Ptr textLine = myDoc->getTextLine(s.cursor.y); | 1974 | TextLine::Ptr textLine = myDoc->getTextLine(s.cursor.y); |
1975 | QString const txt(textLine->getText(),textLine->length()); | 1975 | QString const txt(textLine->getText(),textLine->length()); |
1976 | const QString searchFor= myDoc->searchForList.first(); | 1976 | const QString searchFor= myDoc->searchForList.first(); |
1977 | int pos = s.cursor.x-searchFor.length()-1; | 1977 | int pos = s.cursor.x-searchFor.length()-1; |
1978 | if ( pos < 0 ) pos = 0; | 1978 | if ( pos < 0 ) pos = 0; |
1979 | pos= txt.find(searchFor, pos, s.flags & KateView::sfCaseSensitive); | 1979 | pos= txt.find(searchFor, pos, s.flags & KateView::sfCaseSensitive); |
1980 | if ( s.flags & KateView::sfBackward ) | 1980 | if ( s.flags & KateView::sfBackward ) |
1981 | { | 1981 | { |
1982 | if ( pos <= s.cursor.x ) s.cursor.x= pos-1; | 1982 | if ( pos <= s.cursor.x ) s.cursor.x= pos-1; |
1983 | } | 1983 | } |
1984 | else | 1984 | else |
1985 | if ( pos == s.cursor.x ) s.cursor.x++; | 1985 | if ( pos == s.cursor.x ) s.cursor.x++; |
1986 | } else { | 1986 | } else { |
1987 | if (!(s.flags & KateView::sfBackward)) { | 1987 | if (!(s.flags & KateView::sfBackward)) { |
1988 | s.cursor.x = 0; | 1988 | s.cursor.x = 0; |
1989 | s.cursor.y = 0; | 1989 | s.cursor.y = 0; |
1990 | } else { | 1990 | } else { |
1991 | s.cursor.x = -1; | 1991 | s.cursor.x = -1; |
1992 | s.cursor.y = myDoc->lastLine(); | 1992 | s.cursor.y = myDoc->lastLine(); |
1993 | } | 1993 | } |
1994 | s.flags |= KateView::sfFinished; | 1994 | s.flags |= KateView::sfFinished; |
1995 | } | 1995 | } |
1996 | if (!(s.flags & KateView::sfBackward)) { | 1996 | if (!(s.flags & KateView::sfBackward)) { |
1997 | if (!(s.cursor.x || s.cursor.y)) | 1997 | if (!(s.cursor.x || s.cursor.y)) |
1998 | s.flags |= KateView::sfFinished; | 1998 | s.flags |= KateView::sfFinished; |
1999 | } | 1999 | } |
2000 | s.startCursor = s.cursor; | 2000 | s.startCursor = s.cursor; |
2001 | } | 2001 | } |
2002 | 2002 | ||
2003 | void KateView::continueSearch(SConfig &s) { | 2003 | void KateView::continueSearch(SConfig &s) { |
2004 | 2004 | ||
2005 | if (!(s.flags & KateView::sfBackward)) { | 2005 | if (!(s.flags & KateView::sfBackward)) { |
2006 | s.cursor.x = 0; | 2006 | s.cursor.x = 0; |
2007 | s.cursor.y = 0; | 2007 | s.cursor.y = 0; |
2008 | } else { | 2008 | } else { |
2009 | s.cursor.x = -1; | 2009 | s.cursor.x = -1; |
2010 | s.cursor.y = myDoc->lastLine(); | 2010 | s.cursor.y = myDoc->lastLine(); |
2011 | } | 2011 | } |
2012 | s.flags |= KateView::sfFinished; | 2012 | s.flags |= KateView::sfFinished; |
2013 | s.flags &= ~KateView::sfAgain; | 2013 | s.flags &= ~KateView::sfAgain; |
2014 | } | 2014 | } |
2015 | 2015 | ||
2016 | void KateView::findAgain(SConfig &s) { | 2016 | void KateView::findAgain(SConfig &s) { |
2017 | int query; | 2017 | int query; |
2018 | PointStruc cursor; | 2018 | PointStruc cursor; |
2019 | QString str; | 2019 | QString str; |
2020 | 2020 | ||
2021 | QString searchFor = myDoc->searchForList.first(); | 2021 | QString searchFor = myDoc->searchForList.first(); |
2022 | 2022 | ||
2023 | if( searchFor.isEmpty() ) { | 2023 | if( searchFor.isEmpty() ) { |
2024 | find(); | 2024 | find(); |
2025 | return; | 2025 | return; |
2026 | } | 2026 | } |
2027 | 2027 | ||
2028 | do { | 2028 | do { |
2029 | query = KMessageBox::Cancel; | 2029 | query = KMessageBox::Cancel; |
2030 | if (myDoc->doSearch(s,searchFor)) { | 2030 | if (myDoc->doSearch(s,searchFor)) { |
2031 | cursor = s.cursor; | 2031 | cursor = s.cursor; |
2032 | if (!(s.flags & KateView::sfBackward)) | 2032 | if (!(s.flags & KateView::sfBackward)) |
2033 | s.cursor.x += s.matchedLength; | 2033 | s.cursor.x += s.matchedLength; |
2034 | myViewInternal->updateCursor(s.cursor); //does deselectAll() | 2034 | myViewInternal->updateCursor(s.cursor); //does deselectAll() |
2035 | exposeFound(cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,false); | 2035 | exposeFound(cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,false); |
2036 | } else { | 2036 | } else { |
2037 | if (!(s.flags & KateView::sfFinished)) { | 2037 | if (!(s.flags & KateView::sfFinished)) { |
2038 | // ask for continue | 2038 | // ask for continue |
2039 | if (!(s.flags & KateView::sfBackward)) { | 2039 | if (!(s.flags & KateView::sfBackward)) { |
2040 | // forward search | 2040 | // forward search |
2041 | str = i18n("End of document reached.\n" | 2041 | str = i18n("End of document reached.\n" |
2042 | "Continue from the beginning?"); | 2042 | "Continue from the beginning?"); |
2043 | query = KMessageBox::warningContinueCancel(this, | 2043 | query = KMessageBox::warningContinueCancel(this, |
2044 | str, i18n("Find"), i18n("Continue")); | 2044 | str, i18n("Find"), i18n("Continue")); |
2045 | } else { | 2045 | } else { |
2046 | // backward search | 2046 | // backward search |
2047 | str = i18n("Beginning of document reached.\n" | 2047 | str = i18n("Beginning of document reached.\n" |
2048 | "Continue from the end?"); | 2048 | "Continue from the end?"); |
2049 | query = KMessageBox::warningContinueCancel(this, | 2049 | query = KMessageBox::warningContinueCancel(this, |
2050 | str, i18n("Find"), i18n("Continue")); | 2050 | str, i18n("Find"), i18n("Continue")); |
2051 | } | 2051 | } |
2052 | continueSearch(s); | 2052 | continueSearch(s); |
2053 | } else { | 2053 | } else { |
2054 | // wrapped | 2054 | // wrapped |
2055 | KMessageBox::sorry(this, | 2055 | KMessageBox::sorry(this, |
2056 | i18n("Search string '%1' not found!").arg(searchFor), | 2056 | i18n("Search string '%1' not found!").arg(searchFor), |
2057 | i18n("Find")); | 2057 | i18n("Find")); |
2058 | } | 2058 | } |
2059 | } | 2059 | } |
2060 | } while (query == KMessageBox::Continue); | 2060 | } while (query == KMessageBox::Continue); |
2061 | } | 2061 | } |
2062 | 2062 | ||
2063 | void KateView::replaceAgain() { | 2063 | void KateView::replaceAgain() { |
2064 | if (isReadOnly()) | 2064 | if (isReadOnly()) |
2065 | return; | 2065 | return; |
2066 | 2066 | ||
2067 | replaces = 0; | 2067 | replaces = 0; |
2068 | if (s.flags & KateView::sfPrompt) { | 2068 | if (s.flags & KateView::sfPrompt) { |
2069 | doReplaceAction(-1); | 2069 | doReplaceAction(-1); |
2070 | } else { | 2070 | } else { |
2071 | doReplaceAction(KateView::srAll); | 2071 | doReplaceAction(KateView::srAll); |
2072 | } | 2072 | } |
2073 | } | 2073 | } |
2074 | 2074 | ||
2075 | void KateView::doReplaceAction(int result, bool found) { | 2075 | void KateView::doReplaceAction(int result, bool found) { |
2076 | int rlen; | 2076 | int rlen; |
2077 | PointStruc cursor; | 2077 | PointStruc cursor; |
2078 | bool started; | 2078 | bool started; |
2079 | 2079 | ||
2080 | QString searchFor = myDoc->searchForList.first(); | 2080 | QString searchFor = myDoc->searchForList.first(); |
2081 | QString replaceWith = myDoc->replaceWithList.first(); | 2081 | QString replaceWith = myDoc->replaceWithList.first(); |
2082 | rlen = replaceWith.length(); | 2082 | rlen = replaceWith.length(); |
2083 | 2083 | ||
2084 | switch (result) { | 2084 | switch (result) { |
2085 | case KateView::srYes: //yes | 2085 | case KateView::srYes: //yes |
2086 | myDoc->recordStart(this, s.cursor, configFlags, | 2086 | myDoc->recordStart(this, s.cursor, configFlags, |
2087 | KateActionGroup::ugReplace, true); | 2087 | KateActionGroup::ugReplace, true); |
2088 | myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith); | 2088 | myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith); |
2089 | replaces++; | 2089 | replaces++; |
2090 | if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x) | 2090 | if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x) |
2091 | s.startCursor.x += rlen - s.matchedLength; | 2091 | s.startCursor.x += rlen - s.matchedLength; |
2092 | if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen; | 2092 | if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen; |
2093 | myDoc->recordEnd(this, s.cursor, configFlags | KateView::cfPersistent); | 2093 | myDoc->recordEnd(this, s.cursor, configFlags | KateView::cfPersistent); |
2094 | break; | 2094 | break; |
2095 | case KateView::srNo: //no | 2095 | case KateView::srNo: //no |
2096 | if (!(s.flags & KateView::sfBackward)) s.cursor.x += s.matchedLength; | 2096 | if (!(s.flags & KateView::sfBackward)) s.cursor.x += s.matchedLength; |
2097 | break; | 2097 | break; |
2098 | case KateView::srAll: //replace all | 2098 | case KateView::srAll: //replace all |
2099 | deleteReplacePrompt(); | 2099 | deleteReplacePrompt(); |
2100 | do { | 2100 | do { |
2101 | started = false; | 2101 | started = false; |
2102 | while (found || myDoc->doSearch(s,searchFor)) { | 2102 | while (found || myDoc->doSearch(s,searchFor)) { |
2103 | if (!started) { | 2103 | if (!started) { |
2104 | found = false; | 2104 | found = false; |
2105 | myDoc->recordStart(this, s.cursor, configFlags, | 2105 | myDoc->recordStart(this, s.cursor, configFlags, |
2106 | KateActionGroup::ugReplace); | 2106 | KateActionGroup::ugReplace); |
2107 | started = true; | 2107 | started = true; |
2108 | } | 2108 | } |
2109 | myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith); | 2109 | myDoc->recordReplace(s.cursor, s.matchedLength, replaceWith); |
2110 | replaces++; | 2110 | replaces++; |
2111 | if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x) | 2111 | if (s.cursor.y == s.startCursor.y && s.cursor.x < s.startCursor.x) |
2112 | s.startCursor.x += rlen - s.matchedLength; | 2112 | s.startCursor.x += rlen - s.matchedLength; |
2113 | if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen; | 2113 | if (!(s.flags & KateView::sfBackward)) s.cursor.x += rlen; |
2114 | } | 2114 | } |
2115 | if (started) myDoc->recordEnd(this, s.cursor, | 2115 | if (started) myDoc->recordEnd(this, s.cursor, |
2116 | configFlags | KateView::cfPersistent); | 2116 | configFlags | KateView::cfPersistent); |
2117 | } while (!askReplaceEnd()); | 2117 | } while (!askReplaceEnd()); |
2118 | return; | 2118 | return; |
2119 | case KateView::srCancel: //cancel | 2119 | case KateView::srCancel: //cancel |
2120 | deleteReplacePrompt(); | 2120 | deleteReplacePrompt(); |
2121 | return; | 2121 | return; |
2122 | default: | 2122 | default: |
2123 | replacePrompt = 0L; | 2123 | replacePrompt = 0L; |
2124 | } | 2124 | } |
2125 | 2125 | ||
2126 | do { | 2126 | do { |
2127 | if (myDoc->doSearch(s,searchFor)) { | 2127 | if (myDoc->doSearch(s,searchFor)) { |
2128 | //text found: highlight it, show replace prompt if needed and exit | 2128 | //text found: highlight it, show replace prompt if needed and exit |
2129 | cursor = s.cursor; | 2129 | cursor = s.cursor; |
2130 | if (!(s.flags & KateView::sfBackward)) cursor.x += s.matchedLength; | 2130 | if (!(s.flags & KateView::sfBackward)) cursor.x += s.matchedLength; |
2131 | myViewInternal->updateCursor(cursor); //does deselectAll() | 2131 | myViewInternal->updateCursor(cursor); //does deselectAll() |
2132 | exposeFound(s.cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,true); | 2132 | exposeFound(s.cursor,s.matchedLength,(s.flags & KateView::sfAgain) ? 0 : KateView::ufUpdateOnScroll,true); |
2133 | if (replacePrompt == 0L) { | 2133 | if (replacePrompt == 0L) { |
2134 | replacePrompt = new ReplacePrompt(this); | 2134 | replacePrompt = new ReplacePrompt(this); |
2135 | myDoc->setPseudoModal(replacePrompt);//disable(); | 2135 | myDoc->setPseudoModal(replacePrompt);//disable(); |
2136 | connect(replacePrompt,SIGNAL(clicked()),this,SLOT(replaceSlot())); | 2136 | connect(replacePrompt,SIGNAL(clicked()),this,SLOT(replaceSlot())); |
2137 | replacePrompt->show(); //this is not modal | 2137 | replacePrompt->show(); //this is not modal |
2138 | } | 2138 | } |
2139 | return; //exit if text found | 2139 | return; //exit if text found |
2140 | } | 2140 | } |
2141 | //nothing found: repeat until user cancels "repeat from beginning" dialog | 2141 | //nothing found: repeat until user cancels "repeat from beginning" dialog |
2142 | } while (!askReplaceEnd()); | 2142 | } while (!askReplaceEnd()); |
2143 | deleteReplacePrompt(); | 2143 | deleteReplacePrompt(); |
2144 | } | 2144 | } |
2145 | 2145 | ||
2146 | void KateView::exposeFound(PointStruc &cursor, int slen, int flags, bool replace) { | 2146 | void KateView::exposeFound(PointStruc &cursor, int slen, int flags, bool replace) { |
2147 | int x1, x2, y1, y2, xPos, yPos; | 2147 | int x1, x2, y1, y2, xPos, yPos; |
2148 | 2148 | ||
2149 | VConfig c; | 2149 | VConfig c; |
2150 | myViewInternal->getVConfig(c); | 2150 | myViewInternal->getVConfig(c); |
2151 | myDoc->selectLength(cursor,slen,c.flags); | 2151 | myDoc->selectLength(cursor,slen,c.flags); |
2152 | 2152 | ||
2153 | TextLine::Ptr textLine = myDoc->getTextLine(cursor.y); | 2153 | TextLine::Ptr textLine = myDoc->getTextLine(cursor.y); |
2154 | x1 = myDoc->textWidth(textLine,cursor.x) -10; | 2154 | x1 = myDoc->textWidth(textLine,cursor.x) -10; |
2155 | x2 = myDoc->textWidth(textLine,cursor.x + slen) +20; | 2155 | x2 = myDoc->textWidth(textLine,cursor.x + slen) +20; |
2156 | y1 = myDoc->fontHeight*cursor.y -10; | 2156 | y1 = myDoc->fontHeight*cursor.y -10; |
2157 | y2 = y1 + myDoc->fontHeight +30; | 2157 | y2 = y1 + myDoc->fontHeight +30; |
2158 | 2158 | ||
2159 | xPos = myViewInternal->xPos; | 2159 | xPos = myViewInternal->xPos; |
2160 | yPos = myViewInternal->yPos; | 2160 | yPos = myViewInternal->yPos; |
2161 | 2161 | ||
2162 | if (x1 < 0) x1 = 0; | 2162 | if (x1 < 0) x1 = 0; |
2163 | if (replace) y2 += 90; | 2163 | if (replace) y2 += 90; |
2164 | 2164 | ||
2165 | if (x1 < xPos || x2 > xPos + myViewInternal->width()) { | 2165 | if (x1 < xPos || x2 > xPos + myViewInternal->width()) { |
2166 | xPos = x2 - myViewInternal->width(); | 2166 | xPos = x2 - myViewInternal->width(); |
2167 | } | 2167 | } |
2168 | if (y1 < yPos || y2 > yPos + myViewInternal->height()) { | 2168 | if (y1 < yPos || y2 > yPos + myViewInternal->height()) { |
2169 | xPos = x2 - myViewInternal->width(); | 2169 | xPos = x2 - myViewInternal->width(); |
2170 | yPos = myDoc->fontHeight*cursor.y - height()/3; | 2170 | yPos = myDoc->fontHeight*cursor.y - height()/3; |
2171 | } | 2171 | } |
2172 | myViewInternal->setPos(xPos, yPos); | 2172 | myViewInternal->setPos(xPos, yPos); |
2173 | myViewInternal->updateView(flags);// | ufPos,xPos,yPos); | 2173 | myViewInternal->updateView(flags);// | ufPos,xPos,yPos); |
2174 | myDoc->updateViews(this); | 2174 | myDoc->updateViews(this); |
2175 | } | 2175 | } |
2176 | 2176 | ||
2177 | void KateView::deleteReplacePrompt() { | 2177 | void KateView::deleteReplacePrompt() { |
2178 | myDoc->setPseudoModal(0L); | 2178 | myDoc->setPseudoModal(0L); |
2179 | } | 2179 | } |
2180 | 2180 | ||
2181 | bool KateView::askReplaceEnd() { | 2181 | bool KateView::askReplaceEnd() { |
2182 | QString str; | 2182 | QString str; |
2183 | int query; | 2183 | int query; |
2184 | 2184 | ||
2185 | myDoc->updateViews(); | 2185 | myDoc->updateViews(); |
2186 | if (s.flags & KateView::sfFinished) { | 2186 | if (s.flags & KateView::sfFinished) { |
2187 | // replace finished | 2187 | // replace finished |
2188 | str = i18n("%1 replacement(s) made").arg(replaces); | 2188 | str = i18n("%1 replacement(s) made").arg(replaces); |
2189 | KMessageBox::information(this, str, i18n("Replace")); | 2189 | KMessageBox::information(this, str, i18n("Replace")); |
2190 | return true; | 2190 | return true; |
2191 | } | 2191 | } |
2192 | 2192 | ||
2193 | // ask for continue | 2193 | // ask for continue |
2194 | if (!(s.flags & KateView::sfBackward)) { | 2194 | if (!(s.flags & KateView::sfBackward)) { |
2195 | // forward search | 2195 | // forward search |
2196 | str = i18n("%1 replacement(s) made.\n" | 2196 | str = i18n("%1 replacement(s) made.\n" |
2197 | "End of document reached.\n" | 2197 | "End of document reached.\n" |
2198 | "Continue from the beginning?").arg(replaces); | 2198 | "Continue from the beginning?").arg(replaces); |
2199 | query = KMessageBox::questionYesNo(this, str, i18n("Replace"), | 2199 | query = KMessageBox::questionYesNo(this, str, i18n("Replace"), |
2200 | i18n("Continue"), i18n("Stop")); | 2200 | i18n("Continue"), i18n("Stop")); |
2201 | } else { | 2201 | } else { |
2202 | // backward search | 2202 | // backward search |
2203 | str = i18n("%1 replacement(s) made.\n" | 2203 | str = i18n("%1 replacement(s) made.\n" |
2204 | "Beginning of document reached.\n" | 2204 | "Beginning of document reached.\n" |
2205 | "Continue from the end?").arg(replaces); | 2205 | "Continue from the end?").arg(replaces); |
2206 | query = KMessageBox::questionYesNo(this, str, i18n("Replace"), | 2206 | query = KMessageBox::questionYesNo(this, str, i18n("Replace"), |
2207 | i18n("Continue"), i18n("Stop")); | 2207 | i18n("Continue"), i18n("Stop")); |
2208 | } | 2208 | } |
2209 | replaces = 0; | 2209 | replaces = 0; |
2210 | continueSearch(s); | 2210 | continueSearch(s); |
2211 | return (query == KMessageBox::No); | 2211 | return (query == KMessageBox::No); |
2212 | } | 2212 | } |
2213 | 2213 | ||
2214 | void KateView::replaceSlot() { | 2214 | void KateView::replaceSlot() { |
2215 | doReplaceAction(replacePrompt->result(),true); | 2215 | doReplaceAction(replacePrompt->result(),true); |
2216 | } | 2216 | } |
2217 | 2217 | ||
2218 | void KateView::installPopup(QPopupMenu *rmb_Menu) | 2218 | void KateView::installPopup(QPopupMenu *rmb_Menu) |
2219 | { | 2219 | { |
2220 | rmbMenu = rmb_Menu; | 2220 | rmbMenu = rmb_Menu; |
2221 | } | 2221 | } |
2222 | 2222 | ||
2223 | void KateView::readConfig() | 2223 | void KateView::readConfig() |
2224 | { | 2224 | { |
2225 | KConfig *config = KGlobal::config(); | 2225 | KateConfig *config = KGlobal::config(); |
2226 | config->setGroup("Kate View"); | 2226 | config->setGroup("Kate View"); |
2227 | 2227 | ||
2228 | searchFlags = config->readNumEntry("SearchFlags", KateView::sfPrompt); | 2228 | searchFlags = config->readNumEntry("SearchFlags", KateView::sfPrompt); |
2229 | configFlags = config->readNumEntry("ConfigFlags", configFlags) & ~KateView::cfMark; | 2229 | configFlags = config->readNumEntry("ConfigFlags", configFlags) & ~KateView::cfMark; |
2230 | 2230 | ||
2231 | config->sync(); | 2231 | // config->sync(); |
2232 | } | 2232 | } |
2233 | 2233 | ||
2234 | void KateView::writeConfig() | 2234 | void KateView::writeConfig() |
2235 | { | 2235 | { |
2236 | KConfig *config = KGlobal::config(); | 2236 | KateConfig *config = KGlobal::config(); |
2237 | config->setGroup("Kate View"); | 2237 | config->setGroup("Kate View"); |
2238 | 2238 | ||
2239 | config->writeEntry("SearchFlags",searchFlags); | 2239 | config->writeEntry("SearchFlags",searchFlags); |
2240 | config->writeEntry("ConfigFlags",configFlags); | 2240 | config->writeEntry("ConfigFlags",configFlags); |
2241 | 2241 | ||
2242 | config->sync(); | 2242 | // config->sync(); |
2243 | } | 2243 | } |
2244 | 2244 | ||
2245 | void KateView::readSessionConfig(KConfig *config) | 2245 | void KateView::readSessionConfig(KateConfig *config) |
2246 | { | 2246 | { |
2247 | PointStruc cursor; | 2247 | PointStruc cursor; |
2248 | 2248 | ||
2249 | myViewInternal->xPos = config->readNumEntry("XPos"); | 2249 | myViewInternal->xPos = config->readNumEntry("XPos"); |
2250 | myViewInternal->yPos = config->readNumEntry("YPos"); | 2250 | myViewInternal->yPos = config->readNumEntry("YPos"); |
2251 | cursor.x = config->readNumEntry("CursorX"); | 2251 | cursor.x = config->readNumEntry("CursorX"); |
2252 | cursor.y = config->readNumEntry("CursorY"); | 2252 | cursor.y = config->readNumEntry("CursorY"); |
2253 | myViewInternal->updateCursor(cursor); | 2253 | myViewInternal->updateCursor(cursor); |
2254 | myIconBorder = config->readBoolEntry("IconBorder on"); | 2254 | myIconBorder = config->readBoolEntry("IconBorder on"); |
2255 | setIconBorder(myIconBorder); | 2255 | setIconBorder(myIconBorder); |
2256 | } | 2256 | } |
2257 | 2257 | ||
2258 | void KateView::writeSessionConfig(KConfig *config) | 2258 | void KateView::writeSessionConfig(KateConfig *config) |
2259 | { | 2259 | { |
2260 | config->writeEntry("XPos",myViewInternal->xPos); | 2260 | config->writeEntry("XPos",myViewInternal->xPos); |
2261 | config->writeEntry("YPos",myViewInternal->yPos); | 2261 | config->writeEntry("YPos",myViewInternal->yPos); |
2262 | config->writeEntry("CursorX",myViewInternal->cursor.x); | 2262 | config->writeEntry("CursorX",myViewInternal->cursor.x); |
2263 | config->writeEntry("CursorY",myViewInternal->cursor.y); | 2263 | config->writeEntry("CursorY",myViewInternal->cursor.y); |
2264 | config->writeEntry("IconBorder on", myIconBorder); | 2264 | config->writeEntry("IconBorder on", myIconBorder); |
2265 | } | 2265 | } |
2266 | 2266 | ||
2267 | void KateView::configDialog() | 2267 | void KateView::configDialog() |
2268 | { | 2268 | { |
2269 | 2269 | ||
2270 | #warning fixme | 2270 | #warning fixme |
2271 | 2271 | ||
2272 | #if 1 | 2272 | #if 1 |
2273 | KDialogBase *kd = new KDialogBase(KDialogBase::IconList, | 2273 | KDialogBase *kd = new KDialogBase(KDialogBase::IconList, |
2274 | i18n("Configure Editor"), | 2274 | i18n("Configure Editor"), |
2275 | KDialogBase::Ok | KDialogBase::Cancel | | 2275 | KDialogBase::Ok | KDialogBase::Cancel | |
2276 | KDialogBase::Help , | 2276 | KDialogBase::Help , |
2277 | KDialogBase::Ok, this, "tabdialog"); | 2277 | KDialogBase::Ok, this, "tabdialog"); |
2278 | 2278 | ||
2279 | // color options | 2279 | // color options |
2280 | QFrame *page=kd->addPage(i18n("Colors")); | 2280 | QFrame *page=kd->addPage(i18n("Colors")); |
2281 | (new QVBoxLayout(page))->setAutoAdd(true); | 2281 | (new QVBoxLayout(page))->setAutoAdd(true); |
2282 | ColorConfig *colorConfig = new ColorConfig(page); | 2282 | ColorConfig *colorConfig = new ColorConfig(page); |
2283 | QColor* colors = getColors(); | 2283 | QColor* colors = getColors(); |
2284 | colorConfig->setColors(colors); | 2284 | colorConfig->setColors(colors); |
2285 | 2285 | ||
2286 | page = kd->addPage(i18n("Fonts")); | 2286 | page = kd->addPage(i18n("Fonts")); |
2287 | (new QVBoxLayout(page))->setAutoAdd(true); | 2287 | (new QVBoxLayout(page))->setAutoAdd(true); |
2288 | 2288 | ||
2289 | FontConfig *fontConfig = new FontConfig(page); | 2289 | FontConfig *fontConfig = new FontConfig(page); |
2290 | fontConfig->setFont (myDoc->getFont()); | 2290 | fontConfig->setFont (myDoc->getFont()); |
2291 | 2291 | ||
2292 | // indent options | 2292 | // indent options |
2293 | page=kd->addPage(i18n("Indent")); | 2293 | page=kd->addPage(i18n("Indent")); |
2294 | (new QVBoxLayout(page))->setAutoAdd(true); | 2294 | (new QVBoxLayout(page))->setAutoAdd(true); |
2295 | 2295 | ||
2296 | IndentConfigTab *indentConfig = new IndentConfigTab(page, this); | 2296 | IndentConfigTab *indentConfig = new IndentConfigTab(page, this); |
2297 | 2297 | ||
2298 | // select options | 2298 | // select options |
2299 | page=kd->addPage(i18n("Select")); | 2299 | page=kd->addPage(i18n("Select")); |
2300 | (new QVBoxLayout(page))->setAutoAdd(true); | 2300 | (new QVBoxLayout(page))->setAutoAdd(true); |
2301 | 2301 | ||
2302 | SelectConfigTab *selectConfig = new SelectConfigTab(page, this); | 2302 | SelectConfigTab *selectConfig = new SelectConfigTab(page, this); |
2303 | 2303 | ||
2304 | // edit options | 2304 | // edit options |
2305 | page=kd->addPage(i18n("Edit")); | 2305 | page=kd->addPage(i18n("Edit")); |
2306 | (new QVBoxLayout(page))->setAutoAdd(true); | 2306 | (new QVBoxLayout(page))->setAutoAdd(true); |
2307 | 2307 | ||
2308 | EditConfigTab *editConfig = new EditConfigTab(page, this); | 2308 | EditConfigTab *editConfig = new EditConfigTab(page, this); |
2309 | 2309 | ||
2310 | 2310 | ||
2311 | 2311 | ||
2312 | HighlightDialogPage *hlPage; | 2312 | HighlightDialogPage *hlPage; |
2313 | HlManager *hlManager; | 2313 | HlManager *hlManager; |
2314 | HlDataList hlDataList; | 2314 | HlDataList hlDataList; |
2315 | ItemStyleList defaultStyleList; | 2315 | ItemStyleList defaultStyleList; |
2316 | 2316 | ||
2317 | hlManager = HlManager::self(); | 2317 | hlManager = HlManager::self(); |
2318 | 2318 | ||
2319 | defaultStyleList.setAutoDelete(true); | 2319 | defaultStyleList.setAutoDelete(true); |
2320 | hlManager->getDefaults(defaultStyleList); | 2320 | hlManager->getDefaults(defaultStyleList); |
2321 | 2321 | ||
2322 | hlDataList.setAutoDelete(true); | 2322 | hlDataList.setAutoDelete(true); |
2323 | //this gets the data from the KConfig object | 2323 | //this gets the data from the KateConfig object |
2324 | hlManager->getHlDataList(hlDataList); | 2324 | hlManager->getHlDataList(hlDataList); |
2325 | 2325 | ||
2326 | page=kd->addPage(i18n("Highlighting")); | 2326 | page=kd->addPage(i18n("Highlighting")); |
2327 | (new QVBoxLayout(page))->setAutoAdd(true); | 2327 | (new QVBoxLayout(page))->setAutoAdd(true); |
2328 | 2328 | ||
2329 | hlPage = new HighlightDialogPage(hlManager, &defaultStyleList, &hlDataList, 0, page); | 2329 | hlPage = new HighlightDialogPage(hlManager, &defaultStyleList, &hlDataList, 0, page); |
2330 | kd->showMaximized(); | 2330 | kd->showMaximized(); |
2331 | if (kd->exec()) { | 2331 | if (kd->exec()) { |
2332 | // color options | 2332 | // color options |
2333 | colorConfig->getColors(colors); | 2333 | colorConfig->getColors(colors); |
2334 | myDoc->setFont (fontConfig->getFont()); | 2334 | myDoc->setFont (fontConfig->getFont()); |
2335 | 2335 | ||
2336 | applyColors(); | 2336 | applyColors(); |
2337 | // indent options | 2337 | // indent options |
2338 | indentConfig->getData(this); | 2338 | indentConfig->getData(this); |
2339 | // select options | 2339 | // select options |
2340 | selectConfig->getData(this); | 2340 | selectConfig->getData(this); |
2341 | // edit options | 2341 | // edit options |
2342 | editConfig->getData(this); | 2342 | editConfig->getData(this); |
2343 | // spell checker | 2343 | // spell checker |
2344 | hlManager->setHlDataList(hlDataList); | 2344 | hlManager->setHlDataList(hlDataList); |
2345 | hlManager->setDefaults(defaultStyleList); | 2345 | hlManager->setDefaults(defaultStyleList); |
2346 | hlPage->saveData(); | 2346 | hlPage->saveData(); |
2347 | } | 2347 | } |
2348 | 2348 | ||
2349 | // delete kd; | 2349 | // delete kd; |
2350 | 2350 | ||
2351 | #endif | 2351 | #endif |
2352 | } | 2352 | } |
2353 | 2353 | ||
2354 | int KateView::getHl() { | 2354 | int KateView::getHl() { |
2355 | return myDoc->highlightNum(); | 2355 | return myDoc->highlightNum(); |
2356 | } | 2356 | } |
2357 | 2357 | ||
2358 | void KateView::setDontChangeHlOnSave() | 2358 | void KateView::setDontChangeHlOnSave() |
2359 | { | 2359 | { |
2360 | myDoc->setDontChangeHlOnSave(); | 2360 | myDoc->setDontChangeHlOnSave(); |
2361 | } | 2361 | } |
2362 | 2362 | ||
2363 | void KateView::setHl(int n) { | 2363 | void KateView::setHl(int n) { |
2364 | myDoc->setHighlight(n); | 2364 | myDoc->setHighlight(n); |
2365 | myDoc->setDontChangeHlOnSave(); | 2365 | myDoc->setDontChangeHlOnSave(); |
2366 | myDoc->updateViews(); | 2366 | myDoc->updateViews(); |
2367 | } | 2367 | } |
2368 | 2368 | ||
2369 | int KateView::getEol() { | 2369 | int KateView::getEol() { |
2370 | return myDoc->eolMode; | 2370 | return myDoc->eolMode; |
2371 | } | 2371 | } |
2372 | 2372 | ||
2373 | void KateView::setEol(int eol) { | 2373 | void KateView::setEol(int eol) { |
2374 | if (isReadOnly()) | 2374 | if (isReadOnly()) |
2375 | return; | 2375 | return; |
2376 | 2376 | ||
2377 | myDoc->eolMode = eol; | 2377 | myDoc->eolMode = eol; |
2378 | myDoc->setModified(true); | 2378 | myDoc->setModified(true); |
2379 | } | 2379 | } |
2380 | 2380 | ||
2381 | 2381 | ||
2382 | 2382 | ||
2383 | void KateView::paintEvent(QPaintEvent *e) { | 2383 | void KateView::paintEvent(QPaintEvent *e) { |
2384 | int x, y; | 2384 | int x, y; |
2385 | 2385 | ||
2386 | QRect updateR = e->rect(); // update rectangle | 2386 | QRect updateR = e->rect(); // update rectangle |
2387 | // debug("Update rect = ( %i, %i, %i, %i )", | 2387 | // debug("Update rect = ( %i, %i, %i, %i )", |
2388 | // updateR.x(),updateR.y(), updateR.width(), updateR.height() ); | 2388 | // updateR.x(),updateR.y(), updateR.width(), updateR.height() ); |
2389 | 2389 | ||
2390 | int ux1 = updateR.x(); | 2390 | int ux1 = updateR.x(); |
2391 | int uy1 = updateR.y(); | 2391 | int uy1 = updateR.y(); |
2392 | int ux2 = ux1 + updateR.width(); | 2392 | int ux2 = ux1 + updateR.width(); |
2393 | int uy2 = uy1 + updateR.height(); | 2393 | int uy2 = uy1 + updateR.height(); |
2394 | 2394 | ||
2395 | QPainter paint; | 2395 | QPainter paint; |
2396 | paint.begin(this); | 2396 | paint.begin(this); |
2397 | 2397 | ||
2398 | QColorGroup g = colorGroup(); | 2398 | QColorGroup g = colorGroup(); |
2399 | x = width(); | 2399 | x = width(); |
2400 | y = height(); | 2400 | y = height(); |
2401 | 2401 | ||
2402 | paint.setPen(g.dark()); | 2402 | paint.setPen(g.dark()); |
2403 | if (uy1 <= 0) paint.drawLine(0,0,x-2,0); | 2403 | if (uy1 <= 0) paint.drawLine(0,0,x-2,0); |
2404 | if (ux1 <= 0) paint.drawLine(0,1,0,y-2); | 2404 | if (ux1 <= 0) paint.drawLine(0,1,0,y-2); |
2405 | 2405 | ||
2406 | paint.setPen(black); | 2406 | paint.setPen(black); |
2407 | if (uy1 <= 1) paint.drawLine(1,1,x-3,1); | 2407 | if (uy1 <= 1) paint.drawLine(1,1,x-3,1); |
2408 | if (ux1 <= 1) paint.drawLine(1,2,1,y-3); | 2408 | if (ux1 <= 1) paint.drawLine(1,2,1,y-3); |
2409 | 2409 | ||
2410 | paint.setPen(g.midlight()); | 2410 | paint.setPen(g.midlight()); |
2411 | if (uy2 >= y-1) paint.drawLine(1,y-2,x-3,y-2); | 2411 | if (uy2 >= y-1) paint.drawLine(1,y-2,x-3,y-2); |
2412 | if (ux2 >= x-1) paint.drawLine(x-2,1,x-2,y-2); | 2412 | if (ux2 >= x-1) paint.drawLine(x-2,1,x-2,y-2); |
2413 | 2413 | ||
2414 | paint.setPen(g.light()); | 2414 | paint.setPen(g.light()); |
2415 | if (uy2 >= y) paint.drawLine(0,y-1,x-2,y-1); | 2415 | if (uy2 >= y) paint.drawLine(0,y-1,x-2,y-1); |
2416 | if (ux2 >= x) paint.drawLine(x-1,0,x-1,y-1); | 2416 | if (ux2 >= x) paint.drawLine(x-1,0,x-1,y-1); |
2417 | 2417 | ||
2418 | x -= 2 + 16; | 2418 | x -= 2 + 16; |
2419 | y -= 2 + 16; | 2419 | y -= 2 + 16; |
2420 | if (ux2 > x && uy2 > y) { | 2420 | if (ux2 > x && uy2 > y) { |
2421 | paint.fillRect(x,y,16,16,g.background()); | 2421 | paint.fillRect(x,y,16,16,g.background()); |
2422 | } | 2422 | } |
2423 | paint.end(); | 2423 | paint.end(); |
2424 | } | 2424 | } |
2425 | 2425 | ||
2426 | void KateView::resizeEvent(QResizeEvent *) { | 2426 | void KateView::resizeEvent(QResizeEvent *) { |
2427 | 2427 | ||
2428 | // debug("Resize %d, %d",e->size().width(),e->size().height()); | 2428 | // debug("Resize %d, %d",e->size().width(),e->size().height()); |
2429 | 2429 | ||
2430 | //myViewInternal->resize(width() -20, height() -20); | 2430 | //myViewInternal->resize(width() -20, height() -20); |
2431 | myViewInternal->tagAll(); | 2431 | myViewInternal->tagAll(); |
2432 | myViewInternal->updateView(0/*ufNoScroll*/); | 2432 | myViewInternal->updateView(0/*ufNoScroll*/); |
2433 | } | 2433 | } |
2434 | 2434 | ||
2435 | 2435 | ||
2436 | // Applies a new pattern to the search context. | 2436 | // Applies a new pattern to the search context. |
2437 | void SConfig::setPattern(QString &newPattern) { | 2437 | void SConfig::setPattern(QString &newPattern) { |
2438 | bool regExp = (flags & KateView::sfRegularExpression); | 2438 | bool regExp = (flags & KateView::sfRegularExpression); |
2439 | 2439 | ||
2440 | m_pattern = newPattern; | 2440 | m_pattern = newPattern; |
2441 | if (regExp) { | 2441 | if (regExp) { |
2442 | m_regExp.setCaseSensitive(flags & KateView::sfCaseSensitive); | 2442 | m_regExp.setCaseSensitive(flags & KateView::sfCaseSensitive); |
2443 | m_regExp.setPattern(m_pattern); | 2443 | m_regExp.setPattern(m_pattern); |
2444 | } | 2444 | } |
2445 | } | 2445 | } |
2446 | 2446 | ||
2447 | // Applies the search context to the given string, and returns whether a match was found. If one is, | 2447 | // Applies the search context to the given string, and returns whether a match was found. If one is, |
2448 | // the length of the string matched is also returned. | 2448 | // the length of the string matched is also returned. |
2449 | int SConfig::search(QString &text, int index) { | 2449 | int SConfig::search(QString &text, int index) { |
2450 | bool regExp = (flags & KateView::sfRegularExpression); | 2450 | bool regExp = (flags & KateView::sfRegularExpression); |
2451 | bool caseSensitive = (flags & KateView::sfCaseSensitive); | 2451 | bool caseSensitive = (flags & KateView::sfCaseSensitive); |
2452 | 2452 | ||
2453 | if (flags & KateView::sfBackward) { | 2453 | if (flags & KateView::sfBackward) { |
2454 | if (regExp) { | 2454 | if (regExp) { |
2455 | index = text.findRev(m_regExp, index); | 2455 | index = text.findRev(m_regExp, index); |
2456 | } | 2456 | } |
2457 | else { | 2457 | else { |
2458 | index = text.findRev(m_pattern, index, caseSensitive); | 2458 | index = text.findRev(m_pattern, index, caseSensitive); |
2459 | } | 2459 | } |
2460 | } | 2460 | } |
2461 | else { | 2461 | else { |
2462 | if (regExp) { | 2462 | if (regExp) { |
2463 | index = text.find(m_regExp, index); | 2463 | index = text.find(m_regExp, index); |
2464 | } | 2464 | } |
2465 | else { | 2465 | else { |
2466 | index = text.find(m_pattern, index, caseSensitive); | 2466 | index = text.find(m_pattern, index, caseSensitive); |
2467 | } | 2467 | } |
2468 | } | 2468 | } |
2469 | 2469 | ||
2470 | // Work out the matched length. | 2470 | // Work out the matched length. |
2471 | if (index != -1) | 2471 | if (index != -1) |
2472 | { | 2472 | { |
2473 | if (regExp) { | 2473 | if (regExp) { |
2474 | m_regExp.match(text, index, &matchedLength, false); | 2474 | m_regExp.match(text, index, &matchedLength, false); |
2475 | } | 2475 | } |
2476 | else { | 2476 | else { |
2477 | matchedLength = m_pattern.length(); | 2477 | matchedLength = m_pattern.length(); |
2478 | } | 2478 | } |
2479 | } | 2479 | } |
2480 | return index; | 2480 | return index; |
2481 | } | 2481 | } |
2482 | 2482 | ||
2483 | void KateView::setActive (bool b) | 2483 | void KateView::setActive (bool b) |
2484 | { | 2484 | { |
2485 | active = b; | 2485 | active = b; |
2486 | } | 2486 | } |
2487 | 2487 | ||
2488 | bool KateView::isActive () | 2488 | bool KateView::isActive () |
2489 | { | 2489 | { |
2490 | return active; | 2490 | return active; |
2491 | } | 2491 | } |
2492 | 2492 | ||
2493 | void KateView::setFocus () | 2493 | void KateView::setFocus () |
2494 | { | 2494 | { |
2495 | QWidget::setFocus (); | 2495 | QWidget::setFocus (); |
2496 | 2496 | ||
2497 | emit gotFocus (this); | 2497 | emit gotFocus (this); |
2498 | } | 2498 | } |
2499 | 2499 | ||
2500 | bool KateView::eventFilter (QObject *object, QEvent *event) | 2500 | bool KateView::eventFilter (QObject *object, QEvent *event) |
2501 | { | 2501 | { |
2502 | 2502 | ||
2503 | if ( (event->type() == QEvent::FocusIn) ) | 2503 | if ( (event->type() == QEvent::FocusIn) ) |
2504 | emit gotFocus (this); | 2504 | emit gotFocus (this); |
2505 | 2505 | ||
2506 | if ( (event->type() == QEvent::KeyPress) ) | 2506 | if ( (event->type() == QEvent::KeyPress) ) |
2507 | { | 2507 | { |
2508 | QKeyEvent * ke=(QKeyEvent *)event; | 2508 | QKeyEvent * ke=(QKeyEvent *)event; |
2509 | 2509 | ||
2510 | if ((ke->key()==Qt::Key_Tab) || (ke->key()==Qt::Key_BackTab)) | 2510 | if ((ke->key()==Qt::Key_Tab) || (ke->key()==Qt::Key_BackTab)) |
2511 | { | 2511 | { |
2512 | myViewInternal->keyPressEvent(ke); | 2512 | myViewInternal->keyPressEvent(ke); |
2513 | return true; | 2513 | return true; |
2514 | } | 2514 | } |
2515 | } | 2515 | } |
2516 | return QWidget::eventFilter (object, event); | 2516 | return QWidget::eventFilter (object, event); |
2517 | } | 2517 | } |
2518 | 2518 | ||
2519 | void KateView::findAgain (bool back) | 2519 | void KateView::findAgain (bool back) |
2520 | { | 2520 | { |
2521 | bool b= (searchFlags & sfBackward) > 0; | 2521 | bool b= (searchFlags & sfBackward) > 0; |
2522 | initSearch(s, (searchFlags & ((b==back)?~sfBackward:~0) & ~sfFromBeginning) // clear flag for forward searching | 2522 | initSearch(s, (searchFlags & ((b==back)?~sfBackward:~0) & ~sfFromBeginning) // clear flag for forward searching |
2523 | | sfPrompt | sfAgain | ((b!=back)?sfBackward:0) ); | 2523 | | sfPrompt | sfAgain | ((b!=back)?sfBackward:0) ); |
2524 | if (s.flags & sfReplace) | 2524 | if (s.flags & sfReplace) |
2525 | replaceAgain(); | 2525 | replaceAgain(); |
2526 | else | 2526 | else |
2527 | KateView::findAgain(s); | 2527 | KateView::findAgain(s); |
2528 | } | 2528 | } |
2529 | 2529 | ||
2530 | void KateView::slotEditCommand () | 2530 | void KateView::slotEditCommand () |
2531 | { | 2531 | { |
2532 | #warning fixme | 2532 | #warning fixme |
2533 | /* | 2533 | /* |
2534 | bool ok; | 2534 | bool ok; |
2535 | QString cmd = KLineEditDlg::getText("Editing Command", "", &ok, this); | 2535 | QString cmd = KLineEditDlg::getText("Editing Command", "", &ok, this); |
2536 | 2536 | ||
2537 | if (ok) | 2537 | if (ok) |
2538 | myDoc->cmd()->execCmd (cmd, this);*/ | 2538 | myDoc->cmd()->execCmd (cmd, this);*/ |
2539 | } | 2539 | } |
2540 | 2540 | ||
2541 | void KateView::setIconBorder (bool enable) | 2541 | void KateView::setIconBorder (bool enable) |
2542 | { | 2542 | { |
2543 | myIconBorder = enable; | 2543 | myIconBorder = enable; |
2544 | 2544 | ||
2545 | if (myIconBorder) | 2545 | if (myIconBorder) |
2546 | { | 2546 | { |
2547 | myViewInternal->move(myViewInternal->iconBorderWidth+2, 2); | 2547 | myViewInternal->move(myViewInternal->iconBorderWidth+2, 2); |
2548 | myViewInternal->leftBorder->show(); | 2548 | myViewInternal->leftBorder->show(); |
2549 | } | 2549 | } |
2550 | else | 2550 | else |
2551 | { | 2551 | { |
2552 | myViewInternal->leftBorder->hide(); | 2552 | myViewInternal->leftBorder->hide(); |
2553 | myViewInternal->move(2, 2); | 2553 | myViewInternal->move(2, 2); |
2554 | } | 2554 | } |
2555 | } | 2555 | } |
2556 | 2556 | ||
2557 | void KateView::toggleIconBorder () | 2557 | void KateView::toggleIconBorder () |
2558 | { | 2558 | { |
2559 | setIconBorder (!myIconBorder); | 2559 | setIconBorder (!myIconBorder); |
2560 | } | 2560 | } |
2561 | 2561 | ||
2562 | void KateView::gotoMark (Kate::Mark *mark) | 2562 | void KateView::gotoMark (Kate::Mark *mark) |
2563 | { | 2563 | { |
2564 | PointStruc cursor; | 2564 | PointStruc cursor; |
2565 | 2565 | ||
2566 | cursor.x = 0; | 2566 | cursor.x = 0; |
2567 | cursor.y = mark->line; | 2567 | cursor.y = mark->line; |
2568 | myDoc->needPreHighlight(cursor.y); | 2568 | myDoc->needPreHighlight(cursor.y); |
2569 | myViewInternal->updateCursor(cursor); | 2569 | myViewInternal->updateCursor(cursor); |
2570 | myViewInternal->center(); | 2570 | myViewInternal->center(); |
2571 | myViewInternal->updateView(KateView::ufUpdateOnScroll); | 2571 | myViewInternal->updateView(KateView::ufUpdateOnScroll); |
2572 | myDoc->updateViews(this); | 2572 | myDoc->updateViews(this); |
2573 | } | 2573 | } |
2574 | 2574 | ||
2575 | void KateView::toggleBookmark () | 2575 | void KateView::toggleBookmark () |
2576 | { | 2576 | { |
2577 | TextLine::Ptr line = myDoc->getTextLine (currentLine()); | 2577 | TextLine::Ptr line = myDoc->getTextLine (currentLine()); |
2578 | 2578 | ||
2579 | if (line->mark()&KateDocument::Bookmark) | 2579 | if (line->mark()&KateDocument::Bookmark) |
2580 | line->delMark(KateDocument::Bookmark); | 2580 | line->delMark(KateDocument::Bookmark); |
2581 | else | 2581 | else |
2582 | line->addMark(KateDocument::Bookmark); | 2582 | line->addMark(KateDocument::Bookmark); |
2583 | 2583 | ||
2584 | myDoc->tagLines (currentLine(), currentLine()); | 2584 | myDoc->tagLines (currentLine(), currentLine()); |
2585 | myDoc->updateViews(); | 2585 | myDoc->updateViews(); |
2586 | } | 2586 | } |
2587 | 2587 | ||
2588 | void KateView::clearBookmarks() | 2588 | void KateView::clearBookmarks() |
2589 | { | 2589 | { |
2590 | QList<Kate::Mark> list = myDoc->marks(); | 2590 | QList<Kate::Mark> list = myDoc->marks(); |
2591 | for (int i=0; (uint) i < list.count(); i++) | 2591 | for (int i=0; (uint) i < list.count(); i++) |
2592 | { | 2592 | { |
2593 | if (list.at(i)->type&KateDocument::Bookmark) | 2593 | if (list.at(i)->type&KateDocument::Bookmark) |
2594 | { | 2594 | { |
2595 | myDoc->getTextLine(list.at(i)->line)->delMark(KateDocument::Bookmark); | 2595 | myDoc->getTextLine(list.at(i)->line)->delMark(KateDocument::Bookmark); |
2596 | myDoc->tagLines(list.at(i)->line, list.at(i)->line); | 2596 | myDoc->tagLines(list.at(i)->line, list.at(i)->line); |
2597 | } | 2597 | } |
2598 | } | 2598 | } |
2599 | 2599 | ||
2600 | myDoc->updateViews(); | 2600 | myDoc->updateViews(); |
2601 | } | 2601 | } |
2602 | 2602 | ||
2603 | void KateView::bookmarkMenuAboutToShow() | 2603 | void KateView::bookmarkMenuAboutToShow() |
2604 | { | 2604 | { |
2605 | #warning fixme | 2605 | #warning fixme |
2606 | #if 0 | 2606 | #if 0 |
2607 | bookmarkMenu->popupMenu()->clear (); | 2607 | bookmarkMenu->popupMenu()->clear (); |
2608 | bookmarkToggle->plug (bookmarkMenu->popupMenu()); | 2608 | bookmarkToggle->plug (bookmarkMenu->popupMenu()); |
2609 | bookmarkClear->plug (bookmarkMenu->popupMenu()); | 2609 | bookmarkClear->plug (bookmarkMenu->popupMenu()); |
2610 | bookmarkMenu->popupMenu()->insertSeparator (); | 2610 | bookmarkMenu->popupMenu()->insertSeparator (); |
2611 | 2611 | ||
2612 | list = myDoc->marks(); | 2612 | list = myDoc->marks(); |
2613 | for (int i=0; (uint) i < list.count(); i++) | 2613 | for (int i=0; (uint) i < list.count(); i++) |
2614 | { | 2614 | { |
2615 | if (list.at(i)->type&KateDocument::Bookmark) | 2615 | if (list.at(i)->type&KateDocument::Bookmark) |
2616 | { | 2616 | { |
2617 | QString bText = textLine(list.at(i)->line); | 2617 | QString bText = textLine(list.at(i)->line); |
2618 | bText.truncate(32); | 2618 | bText.truncate(32); |
2619 | bText.append ("..."); | 2619 | bText.append ("..."); |
2620 | bookmarkMenu->popupMenu()->insertItem ( QString("%1 - \"%2\"").arg(list.at(i)->line).arg(bText), this, SLOT (gotoBookmark(int)), 0, i ); | 2620 | bookmarkMenu->popupMenu()->insertItem ( QString("%1 - \"%2\"").arg(list.at(i)->line).arg(bText), this, SLOT (gotoBookmark(int)), 0, i ); |
2621 | } | 2621 | } |
2622 | } | 2622 | } |
2623 | #endif | 2623 | #endif |
2624 | } | 2624 | } |
2625 | 2625 | ||
2626 | void KateView::gotoBookmark (int n) | 2626 | void KateView::gotoBookmark (int n) |
2627 | { | 2627 | { |
2628 | gotoMark (list.at(n)); | 2628 | gotoMark (list.at(n)); |
2629 | } | 2629 | } |
2630 | 2630 | ||
2631 | int KateView::getHlCount () | 2631 | int KateView::getHlCount () |
2632 | { | 2632 | { |
2633 | return HlManager::self()->highlights(); | 2633 | return HlManager::self()->highlights(); |
2634 | } | 2634 | } |
2635 | 2635 | ||
2636 | QString KateView::getHlName (int z) | 2636 | QString KateView::getHlName (int z) |
2637 | { | 2637 | { |
2638 | return HlManager::self()->hlName(z); | 2638 | return HlManager::self()->hlName(z); |
2639 | } | 2639 | } |
2640 | 2640 | ||
2641 | QString KateView::getHlSection (int z) | 2641 | QString KateView::getHlSection (int z) |
2642 | { | 2642 | { |
2643 | return HlManager::self()->hlSection (z); | 2643 | return HlManager::self()->hlSection (z); |
2644 | } | 2644 | } |
2645 | 2645 | ||
2646 | void KateView::slotIncFontSizes () | 2646 | void KateView::slotIncFontSizes () |
2647 | { | 2647 | { |
2648 | QFont font = myDoc->getFont(); | 2648 | QFont font = myDoc->getFont(); |
2649 | font.setPointSize (font.pointSize()+2); | 2649 | font.setPointSize (font.pointSize()+2); |
2650 | myDoc->setFont (font); | 2650 | myDoc->setFont (font); |
2651 | } | 2651 | } |
2652 | 2652 | ||
2653 | void KateView::slotDecFontSizes () | 2653 | void KateView::slotDecFontSizes () |
2654 | { | 2654 | { |
2655 | QFont font = myDoc->getFont(); | 2655 | QFont font = myDoc->getFont(); |
2656 | font.setPointSize (font.pointSize()-2); | 2656 | font.setPointSize (font.pointSize()-2); |
2657 | myDoc->setFont (font); | 2657 | myDoc->setFont (font); |
2658 | } | 2658 | } |
2659 | 2659 | ||
2660 | const char*bookmark_xpm[]={ | 2660 | const char*bookmark_xpm[]={ |
2661 | "12 16 4 1", | 2661 | "12 16 4 1", |
2662 | "b c #808080", | 2662 | "b c #808080", |
2663 | "a c #000080", | 2663 | "a c #000080", |
2664 | "# c #0000ff", | 2664 | "# c #0000ff", |
2665 | ". c None", | 2665 | ". c None", |
2666 | "............", | 2666 | "............", |
2667 | "............", | 2667 | "............", |
2668 | "........###.", | 2668 | "........###.", |
2669 | ".......#...a", | 2669 | ".......#...a", |
2670 | "......#.##.a", | 2670 | "......#.##.a", |
2671 | ".....#.#..aa", | 2671 | ".....#.#..aa", |
2672 | "....#.#...a.", | 2672 | "....#.#...a.", |
2673 | "...#.#.a.a..", | 2673 | "...#.#.a.a..", |
2674 | "..#.#.a.a...", | 2674 | "..#.#.a.a...", |
2675 | ".#.#.a.a....", | 2675 | ".#.#.a.a....", |
2676 | "#.#.a.a.....", | 2676 | "#.#.a.a.....", |
2677 | "#.#a.a...bbb", | 2677 | "#.#a.a...bbb", |
2678 | "#...a..bbb..", | 2678 | "#...a..bbb..", |
2679 | ".aaa.bbb....", | 2679 | ".aaa.bbb....", |
2680 | "............", | 2680 | "............", |
2681 | "............"}; | 2681 | "............"}; |
2682 | 2682 | ||
2683 | const char* breakpoint_xpm[]={ | 2683 | const char* breakpoint_xpm[]={ |
2684 | "11 16 6 1", | 2684 | "11 16 6 1", |
2685 | "c c #c6c6c6", | 2685 | "c c #c6c6c6", |
2686 | ". c None", | 2686 | ". c None", |
2687 | "# c #000000", | 2687 | "# c #000000", |
2688 | "d c #840000", | 2688 | "d c #840000", |
2689 | "a c #ffffff", | 2689 | "a c #ffffff", |
2690 | "b c #ff0000", | 2690 | "b c #ff0000", |
2691 | "...........", | 2691 | "...........", |
2692 | "...........", | 2692 | "...........", |
2693 | "...#####...", | 2693 | "...#####...", |
2694 | "..#aaaaa#..", | 2694 | "..#aaaaa#..", |
2695 | ".#abbbbbb#.", | 2695 | ".#abbbbbb#.", |
2696 | "#abbbbbbbb#", | 2696 | "#abbbbbbbb#", |
2697 | "#abcacacbd#", | 2697 | "#abcacacbd#", |
2698 | "#abbbbbbbb#", | 2698 | "#abbbbbbbb#", |
2699 | "#abcacacbd#", | 2699 | "#abcacacbd#", |
2700 | "#abbbbbbbb#", | 2700 | "#abbbbbbbb#", |
2701 | ".#bbbbbbb#.", | 2701 | ".#bbbbbbb#.", |
2702 | "..#bdbdb#..", | 2702 | "..#bdbdb#..", |
2703 | "...#####...", | 2703 | "...#####...", |
2704 | "...........", | 2704 | "...........", |
2705 | "...........", | 2705 | "...........", |
2706 | "..........."}; | 2706 | "..........."}; |
2707 | 2707 | ||
2708 | const char*breakpoint_bl_xpm[]={ | 2708 | const char*breakpoint_bl_xpm[]={ |
2709 | "11 16 7 1", | 2709 | "11 16 7 1", |
2710 | "a c #c0c0ff", | 2710 | "a c #c0c0ff", |
2711 | "# c #000000", | 2711 | "# c #000000", |
2712 | "c c #0000c0", | 2712 | "c c #0000c0", |
2713 | "e c #0000ff", | 2713 | "e c #0000ff", |
2714 | "b c #dcdcdc", | 2714 | "b c #dcdcdc", |
2715 | "d c #ffffff", | 2715 | "d c #ffffff", |
2716 | ". c None", | 2716 | ". c None", |
2717 | "...........", | 2717 | "...........", |
2718 | "...........", | 2718 | "...........", |
2719 | "...#####...", | 2719 | "...#####...", |
2720 | "..#ababa#..", | 2720 | "..#ababa#..", |
2721 | ".#bcccccc#.", | 2721 | ".#bcccccc#.", |
2722 | "#acccccccc#", | 2722 | "#acccccccc#", |
2723 | "#bcadadace#", | 2723 | "#bcadadace#", |
2724 | "#acccccccc#", | 2724 | "#acccccccc#", |
2725 | "#bcadadace#", | 2725 | "#bcadadace#", |
2726 | "#acccccccc#", | 2726 | "#acccccccc#", |
2727 | ".#ccccccc#.", | 2727 | ".#ccccccc#.", |
2728 | "..#cecec#..", | 2728 | "..#cecec#..", |
2729 | "...#####...", | 2729 | "...#####...", |
2730 | "...........", | 2730 | "...........", |
2731 | "...........", | 2731 | "...........", |
2732 | "..........."}; | 2732 | "..........."}; |
2733 | 2733 | ||
2734 | const char*breakpoint_gr_xpm[]={ | 2734 | const char*breakpoint_gr_xpm[]={ |
2735 | "11 16 6 1", | 2735 | "11 16 6 1", |
2736 | "c c #c6c6c6", | 2736 | "c c #c6c6c6", |
2737 | "d c #2c2c2c", | 2737 | "d c #2c2c2c", |
2738 | "# c #000000", | 2738 | "# c #000000", |
2739 | ". c None", | 2739 | ". c None", |
2740 | "a c #ffffff", | 2740 | "a c #ffffff", |
2741 | "b c #555555", | 2741 | "b c #555555", |
2742 | "...........", | 2742 | "...........", |
2743 | "...........", | 2743 | "...........", |
2744 | "...#####...", | 2744 | "...#####...", |
2745 | "..#aaaaa#..", | 2745 | "..#aaaaa#..", |
2746 | ".#abbbbbb#.", | 2746 | ".#abbbbbb#.", |
2747 | "#abbbbbbbb#", | 2747 | "#abbbbbbbb#", |
2748 | "#abcacacbd#", | 2748 | "#abcacacbd#", |
2749 | "#abbbbbbbb#", | 2749 | "#abbbbbbbb#", |
2750 | "#abcacacbd#", | 2750 | "#abcacacbd#", |
2751 | "#abbbbbbbb#", | 2751 | "#abbbbbbbb#", |
2752 | ".#bbbbbbb#.", | 2752 | ".#bbbbbbb#.", |
2753 | "..#bdbdb#..", | 2753 | "..#bdbdb#..", |
2754 | "...#####...", | 2754 | "...#####...", |
2755 | "...........", | 2755 | "...........", |
2756 | "...........", | 2756 | "...........", |
2757 | "..........."}; | 2757 | "..........."}; |
2758 | 2758 | ||
2759 | const char*ddd_xpm[]={ | 2759 | const char*ddd_xpm[]={ |
2760 | "11 16 4 1", | 2760 | "11 16 4 1", |
2761 | "a c #00ff00", | 2761 | "a c #00ff00", |
2762 | "b c #000000", | 2762 | "b c #000000", |
2763 | ". c None", | 2763 | ". c None", |
2764 | "# c #00c000", | 2764 | "# c #00c000", |
2765 | "...........", | 2765 | "...........", |
2766 | "...........", | 2766 | "...........", |
2767 | "...........", | 2767 | "...........", |
2768 | "#a.........", | 2768 | "#a.........", |
2769 | "#aaa.......", | 2769 | "#aaa.......", |
2770 | "#aaaaa.....", | 2770 | "#aaaaa.....", |
2771 | "#aaaaaaa...", | 2771 | "#aaaaaaa...", |
2772 | "#aaaaaaaaa.", | 2772 | "#aaaaaaaaa.", |
2773 | "#aaaaaaa#b.", | 2773 | "#aaaaaaa#b.", |
2774 | "#aaaaa#b...", | 2774 | "#aaaaa#b...", |
2775 | "#aaa#b.....", | 2775 | "#aaa#b.....", |
2776 | "#a#b.......", | 2776 | "#a#b.......", |
2777 | "#b.........", | 2777 | "#b.........", |
2778 | "...........", | 2778 | "...........", |
2779 | "...........", | 2779 | "...........", |
2780 | "..........."}; | 2780 | "..........."}; |
2781 | 2781 | ||
2782 | 2782 | ||
2783 | 2783 | ||
2784 | KateIconBorder::KateIconBorder(KateView *view, KateViewInternal *internalView) | 2784 | KateIconBorder::KateIconBorder(KateView *view, KateViewInternal *internalView) |
2785 | : QWidget(view), myView(view), myInternalView(internalView) | 2785 | : QWidget(view), myView(view), myInternalView(internalView) |
2786 | { | 2786 | { |
2787 | lmbSetsBreakpoints = true; | 2787 | lmbSetsBreakpoints = true; |
2788 | } | 2788 | } |
2789 | 2789 | ||
2790 | KateIconBorder::~KateIconBorder() | 2790 | KateIconBorder::~KateIconBorder() |
2791 | { | 2791 | { |
2792 | } | 2792 | } |
2793 | 2793 | ||
2794 | void KateIconBorder::paintLine(int i) | 2794 | void KateIconBorder::paintLine(int i) |
2795 | { | 2795 | { |
2796 | if (!myView->myIconBorder) return; | 2796 | if (!myView->myIconBorder) return; |
2797 | 2797 | ||
2798 | QPainter p(this); | 2798 | QPainter p(this); |
2799 | 2799 | ||
2800 | int fontHeight = myView->doc()->fontHeight; | 2800 | int fontHeight = myView->doc()->fontHeight; |
2801 | int y = i*fontHeight - myInternalView->yPos; | 2801 | int y = i*fontHeight - myInternalView->yPos; |
2802 | p.fillRect(0, y, myInternalView->iconBorderWidth-2, fontHeight, colorGroup().background()); | 2802 | p.fillRect(0, y, myInternalView->iconBorderWidth-2, fontHeight, colorGroup().background()); |
2803 | p.setPen(white); | 2803 | p.setPen(white); |
2804 | p.drawLine(myInternalView->iconBorderWidth-2, y, myInternalView->iconBorderWidth-2, y + fontHeight); | 2804 | p.drawLine(myInternalView->iconBorderWidth-2, y, myInternalView->iconBorderWidth-2, y + fontHeight); |
2805 | p.setPen(QColor(colorGroup().background()).dark()); | 2805 | p.setPen(QColor(colorGroup().background()).dark()); |
2806 | p.drawLine(myInternalView->iconBorderWidth-1, y, myInternalView->iconBorderWidth-1, y + fontHeight); | 2806 | p.drawLine(myInternalView->iconBorderWidth-1, y, myInternalView->iconBorderWidth-1, y + fontHeight); |
2807 | 2807 | ||
2808 | TextLine *line = myView->doc()->getTextLine(i); | 2808 | TextLine *line = myView->doc()->getTextLine(i); |
2809 | if (!line) | 2809 | if (!line) |
2810 | return; | 2810 | return; |
2811 | 2811 | ||
2812 | if (line->mark()&KateDocument::Bookmark) | 2812 | if (line->mark()&KateDocument::Bookmark) |
2813 | p.drawPixmap(2, y, QPixmap(bookmark_xpm)); /* | 2813 | p.drawPixmap(2, y, QPixmap(bookmark_xpm)); /* |
2814 | if (line && (line->breakpointId() != -1)) { | 2814 | if (line && (line->breakpointId() != -1)) { |
2815 | if (!line->breakpointEnabled()) | 2815 | if (!line->breakpointEnabled()) |
2816 | p.drawPixmap(2, y, QPixmap(breakpoint_gr_xpm)); | 2816 | p.drawPixmap(2, y, QPixmap(breakpoint_gr_xpm)); |
2817 | else if (line->breakpointPending()) | 2817 | else if (line->breakpointPending()) |
2818 | p.drawPixmap(2, y, QPixmap(breakpoint_bl_xpm)); | 2818 | p.drawPixmap(2, y, QPixmap(breakpoint_bl_xpm)); |
2819 | else | 2819 | else |
2820 | p.drawPixmap(2, y, QPixmap(breakpoint_xpm)); | 2820 | p.drawPixmap(2, y, QPixmap(breakpoint_xpm)); |
2821 | } | 2821 | } |
2822 | if (line->isExecutionPoint()) | 2822 | if (line->isExecutionPoint()) |
2823 | p.drawPixmap(2, y, QPixmap(ddd_xpm)); */ | 2823 | p.drawPixmap(2, y, QPixmap(ddd_xpm)); */ |
2824 | } | 2824 | } |
2825 | 2825 | ||
2826 | 2826 | ||
2827 | void KateIconBorder::paintEvent(QPaintEvent* e) | 2827 | void KateIconBorder::paintEvent(QPaintEvent* e) |
2828 | { | 2828 | { |
2829 | if (!myView->myIconBorder) return; | 2829 | if (!myView->myIconBorder) return; |
2830 | 2830 | ||
2831 | int lineStart = 0; | 2831 | int lineStart = 0; |
2832 | int lineEnd = 0; | 2832 | int lineEnd = 0; |
2833 | 2833 | ||
2834 | QRect updateR = e->rect(); | 2834 | QRect updateR = e->rect(); |
2835 | 2835 | ||
2836 | KateDocument *doc = myView->doc(); | 2836 | KateDocument *doc = myView->doc(); |
2837 | int h = doc->fontHeight; | 2837 | int h = doc->fontHeight; |
2838 | int yPos = myInternalView->yPos; | 2838 | int yPos = myInternalView->yPos; |
2839 | if (h) { | 2839 | if (h) { |
2840 | lineStart = (yPos + updateR.y()) / h; | 2840 | lineStart = (yPos + updateR.y()) / h; |
2841 | lineEnd = QMAX((yPos + updateR.y() + updateR.height()) / h, (int)doc->numLines()); | 2841 | lineEnd = QMAX((yPos + updateR.y() + updateR.height()) / h, (int)doc->numLines()); |
2842 | } | 2842 | } |
2843 | 2843 | ||
2844 | for(int i = lineStart; i <= lineEnd; ++i) | 2844 | for(int i = lineStart; i <= lineEnd; ++i) |
2845 | paintLine(i); | 2845 | paintLine(i); |
2846 | } | 2846 | } |
2847 | 2847 | ||
2848 | 2848 | ||
2849 | void KateIconBorder::mousePressEvent(QMouseEvent* e) | 2849 | void KateIconBorder::mousePressEvent(QMouseEvent* e) |
2850 | { | 2850 | { |
2851 | myInternalView->placeCursor( 0, e->y(), 0 ); | 2851 | myInternalView->placeCursor( 0, e->y(), 0 ); |
2852 | 2852 | ||
2853 | KateDocument *doc = myView->doc(); | 2853 | KateDocument *doc = myView->doc(); |
2854 | int cursorOnLine = (e->y() + myInternalView->yPos) / doc->fontHeight; | 2854 | int cursorOnLine = (e->y() + myInternalView->yPos) / doc->fontHeight; |
2855 | TextLine *line = doc->getTextLine(cursorOnLine); | 2855 | TextLine *line = doc->getTextLine(cursorOnLine); |
2856 | 2856 | ||
2857 | switch (e->button()) { | 2857 | switch (e->button()) { |
2858 | case LeftButton: | 2858 | case LeftButton: |
2859 | if (!line) | 2859 | if (!line) |
2860 | break; | 2860 | break; |
2861 | else | 2861 | else |
2862 | { | 2862 | { |
2863 | if (line->mark()&KateDocument::Bookmark) | 2863 | if (line->mark()&KateDocument::Bookmark) |
2864 | line->delMark (KateDocument::Bookmark); | 2864 | line->delMark (KateDocument::Bookmark); |
2865 | else | 2865 | else |
2866 | line->addMark (KateDocument::Bookmark); | 2866 | line->addMark (KateDocument::Bookmark); |
2867 | 2867 | ||
2868 | doc->tagLines(cursorOnLine, cursorOnLine); | 2868 | doc->tagLines(cursorOnLine, cursorOnLine); |
2869 | doc->updateViews(); | 2869 | doc->updateViews(); |
2870 | } | 2870 | } |
2871 | break; | 2871 | break; |
2872 | /* case RightButton: | 2872 | /* case RightButton: |
2873 | { | 2873 | { |
2874 | if (!line) | 2874 | if (!line) |
2875 | break; | 2875 | break; |
2876 | KPopupMenu popup; | 2876 | KPopupMenu popup; |
2877 | popup.setCheckable(true); | 2877 | popup.setCheckable(true); |
2878 | popup.insertTitle(i18n("Breakpoints/Bookmarks")); | 2878 | popup.insertTitle(i18n("Breakpoints/Bookmarks")); |
2879 | int idToggleBookmark = popup.insertItem(i18n("Toggle bookmark")); | 2879 | int idToggleBookmark = popup.insertItem(i18n("Toggle bookmark")); |
2880 | popup.insertSeparator(); | 2880 | popup.insertSeparator(); |
2881 | int idToggleBreakpoint = popup.insertItem(i18n("Toggle breakpoint")); | 2881 | int idToggleBreakpoint = popup.insertItem(i18n("Toggle breakpoint")); |
2882 | int idEditBreakpoint = popup.insertItem(i18n("Edit breakpoint")); | 2882 | int idEditBreakpoint = popup.insertItem(i18n("Edit breakpoint")); |
2883 | int idEnableBreakpoint = popup.insertItem(i18n("Disable breakpoint")); | 2883 | int idEnableBreakpoint = popup.insertItem(i18n("Disable breakpoint")); |
2884 | popup.insertSeparator(); | 2884 | popup.insertSeparator(); |
2885 | popup.insertSeparator(); | 2885 | popup.insertSeparator(); |
2886 | int idLmbSetsBreakpoints = popup.insertItem(i18n("LMB sets breakpoints")); | 2886 | int idLmbSetsBreakpoints = popup.insertItem(i18n("LMB sets breakpoints")); |
2887 | int idLmbSetsBookmarks = popup.insertItem(i18n("LMB sets bookmarks")); | 2887 | int idLmbSetsBookmarks = popup.insertItem(i18n("LMB sets bookmarks")); |
2888 | 2888 | ||
2889 | popup.setItemChecked(idLmbSetsBreakpoints, lmbSetsBreakpoints); | 2889 | popup.setItemChecked(idLmbSetsBreakpoints, lmbSetsBreakpoints); |
2890 | popup.setItemChecked(idLmbSetsBookmarks, !lmbSetsBreakpoints); | 2890 | popup.setItemChecked(idLmbSetsBookmarks, !lmbSetsBreakpoints); |
2891 | 2891 | ||
2892 | if (line->breakpointId() == -1) { | 2892 | if (line->breakpointId() == -1) { |
2893 | popup.setItemEnabled(idEditBreakpoint, false); | 2893 | popup.setItemEnabled(idEditBreakpoint, false); |
2894 | popup.setItemEnabled(idEnableBreakpoint, false); | 2894 | popup.setItemEnabled(idEnableBreakpoint, false); |
2895 | popup.changeItem(idEnableBreakpoint, i18n("Enable breakpoint")); | 2895 | popup.changeItem(idEnableBreakpoint, i18n("Enable breakpoint")); |
2896 | } | 2896 | } |
2897 | int res = popup.exec(mapToGlobal(e->pos())); | 2897 | int res = popup.exec(mapToGlobal(e->pos())); |
2898 | if (res == idToggleBookmark) { | 2898 | if (res == idToggleBookmark) { |
2899 | line->toggleBookmark(); | 2899 | line->toggleBookmark(); |
2900 | doc->tagLines(cursorOnLine, cursorOnLine); | 2900 | doc->tagLines(cursorOnLine, cursorOnLine); |
2901 | doc->updateViews(); | 2901 | doc->updateViews(); |
2902 | } else if (res == idToggleBreakpoint) | 2902 | } else if (res == idToggleBreakpoint) |
2903 | emit myView->toggledBreakpoint(cursorOnLine); | 2903 | emit myView->toggledBreakpoint(cursorOnLine); |
2904 | else if (res == idEditBreakpoint) | 2904 | else if (res == idEditBreakpoint) |
2905 | emit myView->editedBreakpoint(cursorOnLine); | 2905 | emit myView->editedBreakpoint(cursorOnLine); |
2906 | else if (res == idEnableBreakpoint) | 2906 | else if (res == idEnableBreakpoint) |
2907 | emit myView->toggledBreakpointEnabled(cursorOnLine+1); | 2907 | emit myView->toggledBreakpointEnabled(cursorOnLine+1); |
2908 | else if (res == idLmbSetsBreakpoints || res == idLmbSetsBookmarks) | 2908 | else if (res == idLmbSetsBreakpoints || res == idLmbSetsBookmarks) |
2909 | lmbSetsBreakpoints = !lmbSetsBreakpoints; | 2909 | lmbSetsBreakpoints = !lmbSetsBreakpoints; |
2910 | break; | 2910 | break; |
2911 | } | 2911 | } |
2912 | case MidButton: | 2912 | case MidButton: |
2913 | line->toggleBookmark(); | 2913 | line->toggleBookmark(); |
2914 | doc->tagLines(cursorOnLine, cursorOnLine); | 2914 | doc->tagLines(cursorOnLine, cursorOnLine); |
2915 | doc->updateViews(); | 2915 | doc->updateViews(); |
2916 | break; */ | 2916 | break; */ |
2917 | default: | 2917 | default: |
2918 | break; | 2918 | break; |
2919 | } | 2919 | } |
2920 | } | 2920 | } |
2921 | 2921 | ||
2922 | 2922 | ||
2923 | 2923 | ||
diff --git a/noncore/apps/tinykate/libkate/view/kateview.h b/noncore/apps/tinykate/libkate/view/kateview.h index 2e78a3a..858e8a1 100644 --- a/noncore/apps/tinykate/libkate/view/kateview.h +++ b/noncore/apps/tinykate/libkate/view/kateview.h | |||
@@ -1,865 +1,866 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | kateview.h - description | 2 | kateview.h - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Jan 15 2001 | 4 | begin : Mon Jan 15 2001 |
5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann | 5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann |
6 | (C) 2002 by Joseph Wenninger | 6 | (C) 2002 by Joseph Wenninger |
7 | email : crossfire@babylon2k.de | 7 | email : crossfire@babylon2k.de |
8 | jowenn@kde.org | 8 | jowenn@kde.org |
9 | ***************************************************************************/ | 9 | ***************************************************************************/ |
10 | 10 | ||
11 | /*************************************************************************** | 11 | /*************************************************************************** |
12 | * * | 12 | * * |
13 | * This program is free software; you can redistribute it and/or modify * | 13 | * This program is free software; you can redistribute it and/or modify * |
14 | * it under the terms of the GNU General Public License as published by * | 14 | * it under the terms of the GNU General Public License as published by * |
15 | * the Free Software Foundation; either version 2 of the License, or * | 15 | * the Free Software Foundation; either version 2 of the License, or * |
16 | * (at your option) any later version. * | 16 | * (at your option) any later version. * |
17 | * * | 17 | * * |
18 | ***************************************************************************/ | 18 | ***************************************************************************/ |
19 | 19 | ||
20 | /* | 20 | /* |
21 | Copyright (C) 1998, 1999 Jochen Wilhelmy | 21 | Copyright (C) 1998, 1999 Jochen Wilhelmy |
22 | digisnap@cs.tu-berlin.de | 22 | digisnap@cs.tu-berlin.de |
23 | 23 | ||
24 | This library is free software; you can redistribute it and/or | 24 | This library is free software; you can redistribute it and/or |
25 | modify it under the terms of the GNU Library General Public | 25 | modify it under the terms of the GNU Library General Public |
26 | License as published by the Free Software Foundation; either | 26 | License as published by the Free Software Foundation; either |
27 | version 2 of the License, or (at your option) any later version. | 27 | version 2 of the License, or (at your option) any later version. |
28 | 28 | ||
29 | This library is distributed in the hope that it will be useful, | 29 | This library is distributed in the hope that it will be useful, |
30 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 30 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
31 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 31 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
32 | Library General Public License for more details. | 32 | Library General Public License for more details. |
33 | 33 | ||
34 | You should have received a copy of the GNU Library General Public License | 34 | You should have received a copy of the GNU Library General Public License |
35 | along with this library; see the file COPYING.LIB. If not, write to | 35 | along with this library; see the file COPYING.LIB. If not, write to |
36 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 36 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
37 | Boston, MA 02111-1307, USA. | 37 | Boston, MA 02111-1307, USA. |
38 | */ | 38 | */ |
39 | 39 | ||
40 | #ifndef kate_view_h | 40 | #ifndef kate_view_h |
41 | #define kate_view_h | 41 | #define kate_view_h |
42 | 42 | ||
43 | #include "../interfaces/view.h" | 43 | #include "../interfaces/view.h" |
44 | #include "../interfaces/document.h" | 44 | #include "../interfaces/document.h" |
45 | 45 | ||
46 | #include <qlist.h> | 46 | #include <qlist.h> |
47 | #include <qstring.h> | 47 | #include <qstring.h> |
48 | #include <qdialog.h> | 48 | #include <qdialog.h> |
49 | 49 | ||
50 | 50 | ||
51 | class KateDocument; | 51 | class KateDocument; |
52 | class KateConfig; | ||
52 | class Highlight; | 53 | class Highlight; |
53 | 54 | ||
54 | /* | 55 | /* |
55 | //dialog results | 56 | //dialog results |
56 | const int srYes = QDialog::Accepted; | 57 | const int srYes = QDialog::Accepted; |
57 | const int srNo = 10; | 58 | const int srNo = 10; |
58 | const int srAll = 11; | 59 | const int srAll = 11; |
59 | const int srCancel = QDialog::Rejected; | 60 | const int srCancel = QDialog::Rejected; |
60 | */ | 61 | */ |
61 | // --- config flags --- | 62 | // --- config flags --- |
62 | // indent | 63 | // indent |
63 | 64 | ||
64 | enum Select_flags { | 65 | enum Select_flags { |
65 | selectFlag = 0x100000, | 66 | selectFlag = 0x100000, |
66 | multiSelectFlag = 0x200000 | 67 | multiSelectFlag = 0x200000 |
67 | }; | 68 | }; |
68 | //state commands | 69 | //state commands |
69 | enum State_commands { | 70 | enum State_commands { |
70 | cmToggleInsert = 1, | 71 | cmToggleInsert = 1, |
71 | cmToggleVertical = 2 | 72 | cmToggleVertical = 2 |
72 | }; | 73 | }; |
73 | 74 | ||
74 | class KateViewInternal; | 75 | class KateViewInternal; |
75 | class KateView; | 76 | class KateView; |
76 | 77 | ||
77 | struct PointStruc { | 78 | struct PointStruc { |
78 | int x; | 79 | int x; |
79 | int y; | 80 | int y; |
80 | }; | 81 | }; |
81 | 82 | ||
82 | struct VConfig { | 83 | struct VConfig { |
83 | KateView *view; | 84 | KateView *view; |
84 | PointStruc cursor; | 85 | PointStruc cursor; |
85 | int cXPos; | 86 | int cXPos; |
86 | int flags; | 87 | int flags; |
87 | }; | 88 | }; |
88 | 89 | ||
89 | struct SConfig { | 90 | struct SConfig { |
90 | PointStruc cursor; | 91 | PointStruc cursor; |
91 | PointStruc startCursor; | 92 | PointStruc startCursor; |
92 | int flags; | 93 | int flags; |
93 | 94 | ||
94 | // Set the pattern to be used for searching. | 95 | // Set the pattern to be used for searching. |
95 | void setPattern(QString &newPattern); | 96 | void setPattern(QString &newPattern); |
96 | 97 | ||
97 | // Search the given string. | 98 | // Search the given string. |
98 | int search(QString &text, int index); | 99 | int search(QString &text, int index); |
99 | 100 | ||
100 | // The length of the last match found using pattern or regExp. | 101 | // The length of the last match found using pattern or regExp. |
101 | int matchedLength; | 102 | int matchedLength; |
102 | 103 | ||
103 | private: | 104 | private: |
104 | QString m_pattern; | 105 | QString m_pattern; |
105 | 106 | ||
106 | // The regular expression corresponding to pattern. Only guaranteed valid if | 107 | // The regular expression corresponding to pattern. Only guaranteed valid if |
107 | // flags has sfRegularExpression set. | 108 | // flags has sfRegularExpression set. |
108 | QRegExp m_regExp; | 109 | QRegExp m_regExp; |
109 | }; | 110 | }; |
110 | 111 | ||
111 | struct LineRange { | 112 | struct LineRange { |
112 | int start; | 113 | int start; |
113 | int end; | 114 | int end; |
114 | }; | 115 | }; |
115 | 116 | ||
116 | struct BracketMark { | 117 | struct BracketMark { |
117 | PointStruc cursor; | 118 | PointStruc cursor; |
118 | int sXPos; | 119 | int sXPos; |
119 | int eXPos; | 120 | int eXPos; |
120 | }; | 121 | }; |
121 | 122 | ||
122 | 123 | ||
123 | class KateIconBorder : public QWidget | 124 | class KateIconBorder : public QWidget |
124 | { | 125 | { |
125 | public: | 126 | public: |
126 | KateIconBorder(KateView *view, class KateViewInternal *internalView); | 127 | KateIconBorder(KateView *view, class KateViewInternal *internalView); |
127 | ~KateIconBorder(); | 128 | ~KateIconBorder(); |
128 | 129 | ||
129 | void paintLine(int i); | 130 | void paintLine(int i); |
130 | 131 | ||
131 | protected: | 132 | protected: |
132 | void paintEvent(QPaintEvent* e); | 133 | void paintEvent(QPaintEvent* e); |
133 | void mousePressEvent(QMouseEvent* e); | 134 | void mousePressEvent(QMouseEvent* e); |
134 | 135 | ||
135 | private: | 136 | private: |
136 | 137 | ||
137 | KateView *myView; | 138 | KateView *myView; |
138 | class KateViewInternal *myInternalView; | 139 | class KateViewInternal *myInternalView; |
139 | bool lmbSetsBreakpoints; | 140 | bool lmbSetsBreakpoints; |
140 | }; | 141 | }; |
141 | 142 | ||
142 | class KateViewInternal : public QWidget { | 143 | class KateViewInternal : public QWidget { |
143 | Q_OBJECT | 144 | Q_OBJECT |
144 | friend class KateDocument; | 145 | friend class KateDocument; |
145 | friend class KateView; | 146 | friend class KateView; |
146 | friend class KateIconBorder; | 147 | friend class KateIconBorder; |
147 | 148 | ||
148 | private: | 149 | private: |
149 | long waitForPreHighlight; | 150 | long waitForPreHighlight; |
150 | int iconBorderWidth; | 151 | int iconBorderWidth; |
151 | int iconBorderHeight; | 152 | int iconBorderHeight; |
152 | 153 | ||
153 | protected slots: | 154 | protected slots: |
154 | void slotPreHighlightUpdate(long line); | 155 | void slotPreHighlightUpdate(long line); |
155 | 156 | ||
156 | public: | 157 | public: |
157 | KateViewInternal(KateView *view, KateDocument *doc); | 158 | KateViewInternal(KateView *view, KateDocument *doc); |
158 | ~KateViewInternal(); | 159 | ~KateViewInternal(); |
159 | 160 | ||
160 | virtual void doCursorCommand(VConfig &, int cmdNum); | 161 | virtual void doCursorCommand(VConfig &, int cmdNum); |
161 | virtual void doEditCommand(VConfig &, int cmdNum); | 162 | virtual void doEditCommand(VConfig &, int cmdNum); |
162 | 163 | ||
163 | void cursorLeft(VConfig &); | 164 | void cursorLeft(VConfig &); |
164 | void cursorRight(VConfig &); | 165 | void cursorRight(VConfig &); |
165 | void wordLeft(VConfig &); | 166 | void wordLeft(VConfig &); |
166 | void wordRight(VConfig &); | 167 | void wordRight(VConfig &); |
167 | void home(VConfig &); | 168 | void home(VConfig &); |
168 | void end(VConfig &); | 169 | void end(VConfig &); |
169 | void cursorUp(VConfig &); | 170 | void cursorUp(VConfig &); |
170 | void cursorDown(VConfig &); | 171 | void cursorDown(VConfig &); |
171 | void scrollUp(VConfig &); | 172 | void scrollUp(VConfig &); |
172 | void scrollDown(VConfig &); | 173 | void scrollDown(VConfig &); |
173 | void topOfView(VConfig &); | 174 | void topOfView(VConfig &); |
174 | void bottomOfView(VConfig &); | 175 | void bottomOfView(VConfig &); |
175 | void pageUp(VConfig &); | 176 | void pageUp(VConfig &); |
176 | void pageDown(VConfig &); | 177 | void pageDown(VConfig &); |
177 | void cursorPageUp(VConfig &); | 178 | void cursorPageUp(VConfig &); |
178 | void cursorPageDown(VConfig &); | 179 | void cursorPageDown(VConfig &); |
179 | void top(VConfig &); | 180 | void top(VConfig &); |
180 | void bottom(VConfig &); | 181 | void bottom(VConfig &); |
181 | void top_home(VConfig &c); | 182 | void top_home(VConfig &c); |
182 | void bottom_end(VConfig &c); | 183 | void bottom_end(VConfig &c); |
183 | 184 | ||
184 | protected slots: | 185 | protected slots: |
185 | void changeXPos(int); | 186 | void changeXPos(int); |
186 | void changeYPos(int); | 187 | void changeYPos(int); |
187 | 188 | ||
188 | protected: | 189 | protected: |
189 | void getVConfig(VConfig &); | 190 | void getVConfig(VConfig &); |
190 | void changeState(VConfig &); | 191 | void changeState(VConfig &); |
191 | void insLine(int line); | 192 | void insLine(int line); |
192 | void delLine(int line); | 193 | void delLine(int line); |
193 | void updateCursor(); | 194 | void updateCursor(); |
194 | void updateCursor(PointStruc &newCursor); | 195 | void updateCursor(PointStruc &newCursor); |
195 | void updateCursor(PointStruc &newCursor, int flags); | 196 | void updateCursor(PointStruc &newCursor, int flags); |
196 | void clearDirtyCache(int height); | 197 | void clearDirtyCache(int height); |
197 | void tagLines(int start, int end, int x1, int x2); | 198 | void tagLines(int start, int end, int x1, int x2); |
198 | void tagAll(); | 199 | void tagAll(); |
199 | void setPos(int x, int y); | 200 | void setPos(int x, int y); |
200 | void center(); | 201 | void center(); |
201 | 202 | ||
202 | void updateView(int flags); | 203 | void updateView(int flags); |
203 | 204 | ||
204 | void paintTextLines(int xPos, int yPos); | 205 | void paintTextLines(int xPos, int yPos); |
205 | void paintCursor(); | 206 | void paintCursor(); |
206 | void paintBracketMark(); | 207 | void paintBracketMark(); |
207 | 208 | ||
208 | void placeCursor(int x, int y, int flags = 0); | 209 | void placeCursor(int x, int y, int flags = 0); |
209 | bool isTargetSelected(int x, int y); | 210 | bool isTargetSelected(int x, int y); |
210 | 211 | ||
211 | // void doDrag(); | 212 | // void doDrag(); |
212 | 213 | ||
213 | virtual void focusInEvent(QFocusEvent *); | 214 | virtual void focusInEvent(QFocusEvent *); |
214 | virtual void focusOutEvent(QFocusEvent *); | 215 | virtual void focusOutEvent(QFocusEvent *); |
215 | virtual void keyPressEvent(QKeyEvent *e); | 216 | virtual void keyPressEvent(QKeyEvent *e); |
216 | virtual void mousePressEvent(QMouseEvent *); | 217 | virtual void mousePressEvent(QMouseEvent *); |
217 | virtual void mouseDoubleClickEvent(QMouseEvent *); | 218 | virtual void mouseDoubleClickEvent(QMouseEvent *); |
218 | virtual void mouseReleaseEvent(QMouseEvent *); | 219 | virtual void mouseReleaseEvent(QMouseEvent *); |
219 | virtual void mouseMoveEvent(QMouseEvent *); | 220 | virtual void mouseMoveEvent(QMouseEvent *); |
220 | virtual void wheelEvent( QWheelEvent *e ); | 221 | virtual void wheelEvent( QWheelEvent *e ); |
221 | virtual void paintEvent(QPaintEvent *); | 222 | virtual void paintEvent(QPaintEvent *); |
222 | virtual void resizeEvent(QResizeEvent *); | 223 | virtual void resizeEvent(QResizeEvent *); |
223 | virtual void timerEvent(QTimerEvent *); | 224 | virtual void timerEvent(QTimerEvent *); |
224 | 225 | ||
225 | 226 | ||
226 | KateView *myView; | 227 | KateView *myView; |
227 | KateDocument *myDoc; | 228 | KateDocument *myDoc; |
228 | QScrollBar *xScroll; | 229 | QScrollBar *xScroll; |
229 | QScrollBar *yScroll; | 230 | QScrollBar *yScroll; |
230 | KateIconBorder *leftBorder; | 231 | KateIconBorder *leftBorder; |
231 | 232 | ||
232 | int xPos; | 233 | int xPos; |
233 | int yPos; | 234 | int yPos; |
234 | 235 | ||
235 | int mouseX; | 236 | int mouseX; |
236 | int mouseY; | 237 | int mouseY; |
237 | int scrollX; | 238 | int scrollX; |
238 | int scrollY; | 239 | int scrollY; |
239 | int scrollTimer; | 240 | int scrollTimer; |
240 | 241 | ||
241 | PointStruc cursor; | 242 | PointStruc cursor; |
242 | bool cursorOn; | 243 | bool cursorOn; |
243 | int cursorTimer; | 244 | int cursorTimer; |
244 | int cXPos; | 245 | int cXPos; |
245 | int cOldXPos; | 246 | int cOldXPos; |
246 | 247 | ||
247 | int startLine; | 248 | int startLine; |
248 | int endLine; | 249 | int endLine; |
249 | 250 | ||
250 | bool exposeCursor; | 251 | bool exposeCursor; |
251 | int updateState; | 252 | int updateState; |
252 | int numLines; | 253 | int numLines; |
253 | LineRange *lineRanges; | 254 | LineRange *lineRanges; |
254 | int newXPos; | 255 | int newXPos; |
255 | int newYPos; | 256 | int newYPos; |
256 | 257 | ||
257 | QPixmap *drawBuffer; | 258 | QPixmap *drawBuffer; |
258 | 259 | ||
259 | BracketMark bm; | 260 | BracketMark bm; |
260 | 261 | ||
261 | }; | 262 | }; |
262 | 263 | ||
263 | /** | 264 | /** |
264 | The KateView text editor widget. It has many options, document/view | 265 | The KateView text editor widget. It has many options, document/view |
265 | architecture and syntax highlight. | 266 | architecture and syntax highlight. |
266 | @author Jochen Wilhelmy | 267 | @author Jochen Wilhelmy |
267 | */ | 268 | */ |
268 | 269 | ||
269 | class KateView : public Kate::View | 270 | class KateView : public Kate::View |
270 | { | 271 | { |
271 | Q_OBJECT | 272 | Q_OBJECT |
272 | friend class KateViewInternal; | 273 | friend class KateViewInternal; |
273 | friend class KateDocument; | 274 | friend class KateDocument; |
274 | friend class KateIconBorder; | 275 | friend class KateIconBorder; |
275 | 276 | ||
276 | public: | 277 | public: |
277 | KateView(KateDocument *doc=0L, QWidget *parent = 0L, const char * name = 0); | 278 | KateView(KateDocument *doc=0L, QWidget *parent = 0L, const char * name = 0); |
278 | ~KateView(); | 279 | ~KateView(); |
279 | 280 | ||
280 | virtual void setCursorPosition( int line, int col, bool mark = false ); | 281 | virtual void setCursorPosition( int line, int col, bool mark = false ); |
281 | virtual void getCursorPosition( int *line, int *col ); | 282 | virtual void getCursorPosition( int *line, int *col ); |
282 | 283 | ||
283 | virtual bool isOverwriteMode() const; | 284 | virtual bool isOverwriteMode() const; |
284 | virtual void setOverwriteMode( bool b ); | 285 | virtual void setOverwriteMode( bool b ); |
285 | 286 | ||
286 | //status and config functions | 287 | //status and config functions |
287 | /** | 288 | /** |
288 | Returns the current line number, that is the line the cursor is on. | 289 | Returns the current line number, that is the line the cursor is on. |
289 | For the first line it returns 0. Signal newCurPos() is emitted on | 290 | For the first line it returns 0. Signal newCurPos() is emitted on |
290 | cursor position changes. | 291 | cursor position changes. |
291 | */ | 292 | */ |
292 | int currentLine(); | 293 | int currentLine(); |
293 | /** | 294 | /** |
294 | Returns the current column number. It handles tab's correctly. | 295 | Returns the current column number. It handles tab's correctly. |
295 | For the first column it returns 0. | 296 | For the first column it returns 0. |
296 | */ | 297 | */ |
297 | int currentColumn(); | 298 | int currentColumn(); |
298 | /** | 299 | /** |
299 | Returns the number of the character, that the cursor is on (cursor x) | 300 | Returns the number of the character, that the cursor is on (cursor x) |
300 | */ | 301 | */ |
301 | int currentCharNum(); | 302 | int currentCharNum(); |
302 | /** | 303 | /** |
303 | Sets the current cursor position | 304 | Sets the current cursor position |
304 | */ | 305 | */ |
305 | void setCursorPositionInternal(int line, int col); | 306 | void setCursorPositionInternal(int line, int col); |
306 | /** | 307 | /** |
307 | Returns the config flags. See the cfXXX constants in the .h file. | 308 | Returns the config flags. See the cfXXX constants in the .h file. |
308 | */ | 309 | */ |
309 | int config();// {return configFlags;} | 310 | int config();// {return configFlags;} |
310 | /** | 311 | /** |
311 | Sets the config flags | 312 | Sets the config flags |
312 | */ | 313 | */ |
313 | void setConfig(int); | 314 | void setConfig(int); |
314 | 315 | ||
315 | int tabWidth(); | 316 | int tabWidth(); |
316 | void setTabWidth(int); | 317 | void setTabWidth(int); |
317 | void setEncoding (QString e); | 318 | void setEncoding (QString e); |
318 | int undoSteps(); | 319 | int undoSteps(); |
319 | void setUndoSteps(int); | 320 | void setUndoSteps(int); |
320 | 321 | ||
321 | // bool isOverwriteMode(); | 322 | // bool isOverwriteMode(); |
322 | /** | 323 | /** |
323 | Returns true if the document is in read only mode. | 324 | Returns true if the document is in read only mode. |
324 | */ | 325 | */ |
325 | bool isReadOnly(); | 326 | bool isReadOnly(); |
326 | /** | 327 | /** |
327 | Returns true if the document has been modified. | 328 | Returns true if the document has been modified. |
328 | */ | 329 | */ |
329 | bool isModified(); | 330 | bool isModified(); |
330 | /** | 331 | /** |
331 | Sets the read-only flag of the document | 332 | Sets the read-only flag of the document |
332 | */ | 333 | */ |
333 | void setReadOnly(bool); | 334 | void setReadOnly(bool); |
334 | /** | 335 | /** |
335 | Sets the modification status of the document | 336 | Sets the modification status of the document |
336 | */ | 337 | */ |
337 | void setModified(bool m = true); | 338 | void setModified(bool m = true); |
338 | /** | 339 | /** |
339 | Returns true if this editor is the only owner of its document | 340 | Returns true if this editor is the only owner of its document |
340 | */ | 341 | */ |
341 | bool isLastView(); | 342 | bool isLastView(); |
342 | /** | 343 | /** |
343 | Returns the document object | 344 | Returns the document object |
344 | */ | 345 | */ |
345 | KateDocument *doc(); | 346 | KateDocument *doc(); |
346 | 347 | ||
347 | /* | 348 | /* |
348 | Bit 0 : undo possible, Bit 1 : redo possible. | 349 | Bit 0 : undo possible, Bit 1 : redo possible. |
349 | Used to enable/disable undo/redo menu items and toolbar buttons | 350 | Used to enable/disable undo/redo menu items and toolbar buttons |
350 | */ | 351 | */ |
351 | int undoState(); | 352 | int undoState(); |
352 | /** | 353 | /** |
353 | Returns the type of the next undo group. | 354 | Returns the type of the next undo group. |
354 | */ | 355 | */ |
355 | int nextUndoType(); | 356 | int nextUndoType(); |
356 | /** | 357 | /** |
357 | Returns the type of the next redo group. | 358 | Returns the type of the next redo group. |
358 | */ | 359 | */ |
359 | int nextRedoType(); | 360 | int nextRedoType(); |
360 | /** | 361 | /** |
361 | Returns a list of all available undo types, in undo order. | 362 | Returns a list of all available undo types, in undo order. |
362 | */ | 363 | */ |
363 | void undoTypeList(QValueList<int> &lst); | 364 | void undoTypeList(QValueList<int> &lst); |
364 | /** | 365 | /** |
365 | Returns a list of all available redo types, in redo order. | 366 | Returns a list of all available redo types, in redo order. |
366 | */ | 367 | */ |
367 | void redoTypeList(QValueList<int> &lst); | 368 | void redoTypeList(QValueList<int> &lst); |
368 | /** | 369 | /** |
369 | Returns a short text description of the given undo type, | 370 | Returns a short text description of the given undo type, |
370 | which is obtained with nextUndoType(), nextRedoType(), undoTypeList(), and redoTypeList(), | 371 | which is obtained with nextUndoType(), nextRedoType(), undoTypeList(), and redoTypeList(), |
371 | suitable for display in a menu entry. It is not translated; | 372 | suitable for display in a menu entry. It is not translated; |
372 | use i18n() before displaying this string. | 373 | use i18n() before displaying this string. |
373 | */ | 374 | */ |
374 | const char * undoTypeName(int undoType); | 375 | const char * undoTypeName(int undoType); |
375 | 376 | ||
376 | QColor* getColors(); | 377 | QColor* getColors(); |
377 | void applyColors(); | 378 | void applyColors(); |
378 | 379 | ||
379 | 380 | ||
380 | public slots: | 381 | public slots: |
381 | void slotUpdate(); | 382 | void slotUpdate(); |
382 | void slotFileStatusChanged(); | 383 | void slotFileStatusChanged(); |
383 | void slotNewUndo(); | 384 | void slotNewUndo(); |
384 | void slotHighlightChanged(); | 385 | void slotHighlightChanged(); |
385 | 386 | ||
386 | public slots: | 387 | public slots: |
387 | /** | 388 | /** |
388 | Toggles Insert mode | 389 | Toggles Insert mode |
389 | */ | 390 | */ |
390 | void toggleInsert(); | 391 | void toggleInsert(); |
391 | /** | 392 | /** |
392 | Toggles "Vertical Selections" option | 393 | Toggles "Vertical Selections" option |
393 | */ | 394 | */ |
394 | void toggleVertical(); | 395 | void toggleVertical(); |
395 | signals: | 396 | signals: |
396 | /** | 397 | /** |
397 | The cursor position has changed. Get the values with currentLine() | 398 | The cursor position has changed. Get the values with currentLine() |
398 | and currentColumn() | 399 | and currentColumn() |
399 | */ | 400 | */ |
400 | void newCurPos(); | 401 | void newCurPos(); |
401 | /** | 402 | /** |
402 | Modified flag or config flags have changed | 403 | Modified flag or config flags have changed |
403 | */ | 404 | */ |
404 | void newStatus(); | 405 | void newStatus(); |
405 | /** | 406 | /** |
406 | The undo/redo enable status has changed | 407 | The undo/redo enable status has changed |
407 | */ | 408 | */ |
408 | void newUndo(); | 409 | void newUndo(); |
409 | /** | 410 | /** |
410 | The marked text state has changed. This can be used to enable/disable | 411 | The marked text state has changed. This can be used to enable/disable |
411 | cut and copy | 412 | cut and copy |
412 | */ | 413 | */ |
413 | void newMarkStatus(); | 414 | void newMarkStatus(); |
414 | 415 | ||
415 | // emitted when saving a remote URL with KIO::NetAccess. In that case we have to disable the UI. | 416 | // emitted when saving a remote URL with KIO::NetAccess. In that case we have to disable the UI. |
416 | void enableUI( bool enable ); | 417 | void enableUI( bool enable ); |
417 | 418 | ||
418 | protected: | 419 | protected: |
419 | virtual void keyPressEvent( QKeyEvent *ev ); | 420 | virtual void keyPressEvent( QKeyEvent *ev ); |
420 | 421 | ||
421 | int configFlags; | 422 | int configFlags; |
422 | 423 | ||
423 | /* | 424 | /* |
424 | * Check if the given URL already exists. Currently used by both save() and saveAs() | 425 | * Check if the given URL already exists. Currently used by both save() and saveAs() |
425 | * | 426 | * |
426 | * Asks the user for permission and returns the message box result and defaults to | 427 | * Asks the user for permission and returns the message box result and defaults to |
427 | * KMessageBox::Yes in case of doubt | 428 | * KMessageBox::Yes in case of doubt |
428 | */ | 429 | */ |
429 | 430 | ||
430 | //text access | 431 | //text access |
431 | public: | 432 | public: |
432 | /** | 433 | /** |
433 | Gets the number of text lines; | 434 | Gets the number of text lines; |
434 | */ | 435 | */ |
435 | int numLines(); | 436 | int numLines(); |
436 | /** | 437 | /** |
437 | Gets the complete document content as string | 438 | Gets the complete document content as string |
438 | */ | 439 | */ |
439 | QString text(); | 440 | QString text(); |
440 | /** | 441 | /** |
441 | Gets the text line where the cursor is on | 442 | Gets the text line where the cursor is on |
442 | */ | 443 | */ |
443 | QString currentTextLine(); | 444 | QString currentTextLine(); |
444 | /** | 445 | /** |
445 | Gets a text line | 446 | Gets a text line |
446 | */ | 447 | */ |
447 | QString textLine(int num); | 448 | QString textLine(int num); |
448 | /** | 449 | /** |
449 | Gets the word where the cursor is on | 450 | Gets the word where the cursor is on |
450 | */ | 451 | */ |
451 | QString currentWord(); | 452 | QString currentWord(); |
452 | /** | 453 | /** |
453 | Gets the word at position x, y. Can be used to find | 454 | Gets the word at position x, y. Can be used to find |
454 | the word under the mouse cursor | 455 | the word under the mouse cursor |
455 | */ | 456 | */ |
456 | QString word(int x, int y); | 457 | QString word(int x, int y); |
457 | /** | 458 | /** |
458 | Discard old text without warning and set new text | 459 | Discard old text without warning and set new text |
459 | */ | 460 | */ |
460 | void setText(const QString &); | 461 | void setText(const QString &); |
461 | /** | 462 | /** |
462 | Insert text at the current cursor position. If length is a positive | 463 | Insert text at the current cursor position. If length is a positive |
463 | number, it restricts the number of inserted characters | 464 | number, it restricts the number of inserted characters |
464 | */ | 465 | */ |
465 | virtual void insertText(const QString &, bool mark = false); | 466 | virtual void insertText(const QString &, bool mark = false); |
466 | /** | 467 | /** |
467 | Queries if there is marked text | 468 | Queries if there is marked text |
468 | */ | 469 | */ |
469 | bool hasMarkedText(); | 470 | bool hasMarkedText(); |
470 | /** | 471 | /** |
471 | Gets the marked text as string | 472 | Gets the marked text as string |
472 | */ | 473 | */ |
473 | QString markedText(); | 474 | QString markedText(); |
474 | 475 | ||
475 | public: | 476 | public: |
476 | enum fileResult { OK, CANCEL, RETRY, ERROR }; | 477 | enum fileResult { OK, CANCEL, RETRY, ERROR }; |
477 | 478 | ||
478 | /** | 479 | /** |
479 | Returns true if the current document can be | 480 | Returns true if the current document can be |
480 | discarded. If the document is modified, the user is asked if he wants | 481 | discarded. If the document is modified, the user is asked if he wants |
481 | to save it. On "cancel" the function returns false. | 482 | to save it. On "cancel" the function returns false. |
482 | */ | 483 | */ |
483 | bool canDiscard(); | 484 | bool canDiscard(); |
484 | 485 | ||
485 | public slots: | 486 | public slots: |
486 | /** | 487 | /** |
487 | Flushes the document of the text widget. The user is given | 488 | Flushes the document of the text widget. The user is given |
488 | a chance to save the current document if the current document has | 489 | a chance to save the current document if the current document has |
489 | been modified. | 490 | been modified. |
490 | */ | 491 | */ |
491 | void flush (); | 492 | void flush (); |
492 | /** | 493 | /** |
493 | Saves the file if necessary under the current file name. If the current file | 494 | Saves the file if necessary under the current file name. If the current file |
494 | name is Untitled, as it is after a call to newFile(), this routing will | 495 | name is Untitled, as it is after a call to newFile(), this routing will |
495 | call saveAs(). | 496 | call saveAs(). |
496 | */ | 497 | */ |
497 | fileResult save(); | 498 | fileResult save(); |
498 | /** | 499 | /** |
499 | Allows the user to save the file under a new name. This starts the | 500 | Allows the user to save the file under a new name. This starts the |
500 | automatic highlight selection. | 501 | automatic highlight selection. |
501 | */ | 502 | */ |
502 | fileResult saveAs(); | 503 | fileResult saveAs(); |
503 | /** | 504 | /** |
504 | Moves the marked text into the clipboard | 505 | Moves the marked text into the clipboard |
505 | */ | 506 | */ |
506 | void cut() {doEditCommand(KateView::cmCut);} | 507 | void cut() {doEditCommand(KateView::cmCut);} |
507 | /** | 508 | /** |
508 | Copies the marked text into the clipboard | 509 | Copies the marked text into the clipboard |
509 | */ | 510 | */ |
510 | void copy() {doEditCommand(KateView::cmCopy);} | 511 | void copy() {doEditCommand(KateView::cmCopy);} |
511 | /** | 512 | /** |
512 | Inserts text from the clipboard at the actual cursor position | 513 | Inserts text from the clipboard at the actual cursor position |
513 | */ | 514 | */ |
514 | void paste() {doEditCommand(KateView::cmPaste);} | 515 | void paste() {doEditCommand(KateView::cmPaste);} |
515 | /** | 516 | /** |
516 | Undoes the last operation. The number of undo steps is configurable | 517 | Undoes the last operation. The number of undo steps is configurable |
517 | */ | 518 | */ |
518 | void undo() {doEditCommand(KateView::cmUndo);} | 519 | void undo() {doEditCommand(KateView::cmUndo);} |
519 | /** | 520 | /** |
520 | Repeats an operation which has been undone before. | 521 | Repeats an operation which has been undone before. |
521 | */ | 522 | */ |
522 | void redo() {doEditCommand(KateView::cmRedo);} | 523 | void redo() {doEditCommand(KateView::cmRedo);} |
523 | /** | 524 | /** |
524 | Undoes <count> operations. | 525 | Undoes <count> operations. |
525 | Called by slot undo(). | 526 | Called by slot undo(). |
526 | */ | 527 | */ |
527 | void undoMultiple(int count); | 528 | void undoMultiple(int count); |
528 | /** | 529 | /** |
529 | Repeats <count> operation which have been undone before. | 530 | Repeats <count> operation which have been undone before. |
530 | Called by slot redo(). | 531 | Called by slot redo(). |
531 | */ | 532 | */ |
532 | void redoMultiple(int count); | 533 | void redoMultiple(int count); |
533 | /** | 534 | /** |
534 | Displays the undo history dialog | 535 | Displays the undo history dialog |
535 | */ | 536 | */ |
536 | void undoHistory(); | 537 | void undoHistory(); |
537 | /** | 538 | /** |
538 | Moves the current line or the selection one position to the right | 539 | Moves the current line or the selection one position to the right |
539 | */ | 540 | */ |
540 | void indent() {doEditCommand(KateView::cmIndent);}; | 541 | void indent() {doEditCommand(KateView::cmIndent);}; |
541 | /** | 542 | /** |
542 | Moves the current line or the selection one position to the left | 543 | Moves the current line or the selection one position to the left |
543 | */ | 544 | */ |
544 | void unIndent() {doEditCommand(KateView::cmUnindent);}; | 545 | void unIndent() {doEditCommand(KateView::cmUnindent);}; |
545 | /** | 546 | /** |
546 | Optimizes the selected indentation, replacing tabs and spaces as needed | 547 | Optimizes the selected indentation, replacing tabs and spaces as needed |
547 | */ | 548 | */ |
548 | void cleanIndent() {doEditCommand(KateView::cmCleanIndent);}; | 549 | void cleanIndent() {doEditCommand(KateView::cmCleanIndent);}; |
549 | /** | 550 | /** |
550 | Selects all text | 551 | Selects all text |
551 | */ | 552 | */ |
552 | void selectAll() {doEditCommand(KateView::cmSelectAll);} | 553 | void selectAll() {doEditCommand(KateView::cmSelectAll);} |
553 | /** | 554 | /** |
554 | Deselects all text | 555 | Deselects all text |
555 | */ | 556 | */ |
556 | void deselectAll() {doEditCommand(KateView::cmDeselectAll);} | 557 | void deselectAll() {doEditCommand(KateView::cmDeselectAll);} |
557 | /** | 558 | /** |
558 | Inverts the current selection | 559 | Inverts the current selection |
559 | */ | 560 | */ |
560 | void invertSelection() {doEditCommand(KateView::cmInvertSelection);} | 561 | void invertSelection() {doEditCommand(KateView::cmInvertSelection);} |
561 | /** | 562 | /** |
562 | comments out current line | 563 | comments out current line |
563 | */ | 564 | */ |
564 | void comment() {doEditCommand(KateView::cmComment);}; | 565 | void comment() {doEditCommand(KateView::cmComment);}; |
565 | /** | 566 | /** |
566 | removes comment signs in the current line | 567 | removes comment signs in the current line |
567 | */ | 568 | */ |
568 | void uncomment() {doEditCommand(KateView::cmUncomment);}; | 569 | void uncomment() {doEditCommand(KateView::cmUncomment);}; |
569 | 570 | ||
570 | void keyReturn() {doEditCommand(KateView::cmReturn);}; | 571 | void keyReturn() {doEditCommand(KateView::cmReturn);}; |
571 | void keyDelete() {doEditCommand(KateView::cmDelete);}; | 572 | void keyDelete() {doEditCommand(KateView::cmDelete);}; |
572 | void backspace() {doEditCommand(KateView::cmBackspace);}; | 573 | void backspace() {doEditCommand(KateView::cmBackspace);}; |
573 | void killLine() {doEditCommand(KateView::cmKillLine);}; | 574 | void killLine() {doEditCommand(KateView::cmKillLine);}; |
574 | 575 | ||
575 | // cursor commands... | 576 | // cursor commands... |
576 | 577 | ||
577 | void cursorLeft() {doCursorCommand(KateView::cmLeft);}; | 578 | void cursorLeft() {doCursorCommand(KateView::cmLeft);}; |
578 | void shiftCursorLeft() {doCursorCommand(KateView::cmLeft | selectFlag);}; | 579 | void shiftCursorLeft() {doCursorCommand(KateView::cmLeft | selectFlag);}; |
579 | void cursorRight() {doCursorCommand(KateView::cmRight);} | 580 | void cursorRight() {doCursorCommand(KateView::cmRight);} |
580 | void shiftCursorRight() {doCursorCommand(KateView::cmRight | selectFlag);} | 581 | void shiftCursorRight() {doCursorCommand(KateView::cmRight | selectFlag);} |
581 | void wordLeft() {doCursorCommand(KateView::cmWordLeft);}; | 582 | void wordLeft() {doCursorCommand(KateView::cmWordLeft);}; |
582 | void shiftWordLeft() {doCursorCommand(KateView::cmWordLeft | selectFlag);}; | 583 | void shiftWordLeft() {doCursorCommand(KateView::cmWordLeft | selectFlag);}; |
583 | void wordRight() {doCursorCommand(KateView::cmWordRight);}; | 584 | void wordRight() {doCursorCommand(KateView::cmWordRight);}; |
584 | void shiftWordRight() {doCursorCommand(KateView::cmWordRight | selectFlag);}; | 585 | void shiftWordRight() {doCursorCommand(KateView::cmWordRight | selectFlag);}; |
585 | void home() {doCursorCommand(KateView::cmHome);}; | 586 | void home() {doCursorCommand(KateView::cmHome);}; |
586 | void shiftHome() {doCursorCommand(KateView::cmHome | selectFlag);}; | 587 | void shiftHome() {doCursorCommand(KateView::cmHome | selectFlag);}; |
587 | void end() {doCursorCommand(KateView::cmEnd);}; | 588 | void end() {doCursorCommand(KateView::cmEnd);}; |
588 | void shiftEnd() {doCursorCommand(KateView::cmEnd | selectFlag);}; | 589 | void shiftEnd() {doCursorCommand(KateView::cmEnd | selectFlag);}; |
589 | void up() {doCursorCommand(KateView::cmUp);}; | 590 | void up() {doCursorCommand(KateView::cmUp);}; |
590 | void shiftUp() {doCursorCommand(KateView::cmUp | selectFlag);}; | 591 | void shiftUp() {doCursorCommand(KateView::cmUp | selectFlag);}; |
591 | void down() {doCursorCommand(KateView::cmDown);}; | 592 | void down() {doCursorCommand(KateView::cmDown);}; |
592 | void shiftDown() {doCursorCommand(KateView::cmDown | selectFlag);}; | 593 | void shiftDown() {doCursorCommand(KateView::cmDown | selectFlag);}; |
593 | void scrollUp() {doCursorCommand(KateView::cmScrollUp);}; | 594 | void scrollUp() {doCursorCommand(KateView::cmScrollUp);}; |
594 | void scrollDown() {doCursorCommand(KateView::cmScrollDown);}; | 595 | void scrollDown() {doCursorCommand(KateView::cmScrollDown);}; |
595 | void topOfView() {doCursorCommand(KateView::cmTopOfView);}; | 596 | void topOfView() {doCursorCommand(KateView::cmTopOfView);}; |
596 | void bottomOfView() {doCursorCommand(KateView::cmBottomOfView);}; | 597 | void bottomOfView() {doCursorCommand(KateView::cmBottomOfView);}; |
597 | void pageUp() {doCursorCommand(KateView::cmPageUp);}; | 598 | void pageUp() {doCursorCommand(KateView::cmPageUp);}; |
598 | void shiftPageUp() {doCursorCommand(KateView::cmPageUp | selectFlag);}; | 599 | void shiftPageUp() {doCursorCommand(KateView::cmPageUp | selectFlag);}; |
599 | void pageDown() {doCursorCommand(KateView::cmPageDown);}; | 600 | void pageDown() {doCursorCommand(KateView::cmPageDown);}; |
600 | void shiftPageDown() {doCursorCommand(KateView::cmPageDown | selectFlag);}; | 601 | void shiftPageDown() {doCursorCommand(KateView::cmPageDown | selectFlag);}; |
601 | void top() {doCursorCommand(KateView::cmTop);}; | 602 | void top() {doCursorCommand(KateView::cmTop);}; |
602 | void shiftTop() {doCursorCommand(KateView::cmTop | selectFlag);}; | 603 | void shiftTop() {doCursorCommand(KateView::cmTop | selectFlag);}; |
603 | void bottom() {doCursorCommand(KateView::cmBottom);}; | 604 | void bottom() {doCursorCommand(KateView::cmBottom);}; |
604 | void shiftBottom() {doCursorCommand(KateView::cmBottom | selectFlag);}; | 605 | void shiftBottom() {doCursorCommand(KateView::cmBottom | selectFlag);}; |
605 | 606 | ||
606 | //search/replace functions | 607 | //search/replace functions |
607 | public slots: | 608 | public slots: |
608 | /** | 609 | /** |
609 | Presents a search dialog to the user | 610 | Presents a search dialog to the user |
610 | */ | 611 | */ |
611 | void find(); | 612 | void find(); |
612 | /** | 613 | /** |
613 | Presents a replace dialog to the user | 614 | Presents a replace dialog to the user |
614 | */ | 615 | */ |
615 | void replace(); | 616 | void replace(); |
616 | 617 | ||
617 | /** | 618 | /** |
618 | Presents a "Goto Line" dialog to the user | 619 | Presents a "Goto Line" dialog to the user |
619 | */ | 620 | */ |
620 | void gotoLine(); | 621 | void gotoLine(); |
621 | protected: | 622 | protected: |
622 | void initSearch(SConfig &, int flags); | 623 | void initSearch(SConfig &, int flags); |
623 | void continueSearch(SConfig &); | 624 | void continueSearch(SConfig &); |
624 | void findAgain(SConfig &); | 625 | void findAgain(SConfig &); |
625 | void replaceAgain(); | 626 | void replaceAgain(); |
626 | void doReplaceAction(int result, bool found = false); | 627 | void doReplaceAction(int result, bool found = false); |
627 | void exposeFound(PointStruc &cursor, int slen, int flags, bool replace); | 628 | void exposeFound(PointStruc &cursor, int slen, int flags, bool replace); |
628 | void deleteReplacePrompt(); | 629 | void deleteReplacePrompt(); |
629 | bool askReplaceEnd(); | 630 | bool askReplaceEnd(); |
630 | protected slots: | 631 | protected slots: |
631 | void replaceSlot(); | 632 | void replaceSlot(); |
632 | protected: | 633 | protected: |
633 | int searchFlags; | 634 | int searchFlags; |
634 | int replaces; | 635 | int replaces; |
635 | SConfig s; | 636 | SConfig s; |
636 | QDialog *replacePrompt; | 637 | QDialog *replacePrompt; |
637 | 638 | ||
638 | //right mouse button popup menu & bookmark menu | 639 | //right mouse button popup menu & bookmark menu |
639 | public: | 640 | public: |
640 | /** | 641 | /** |
641 | Install a Popup Menu. The Popup Menu will be activated on | 642 | Install a Popup Menu. The Popup Menu will be activated on |
642 | a right mouse button press event. | 643 | a right mouse button press event. |
643 | */ | 644 | */ |
644 | void installPopup(QPopupMenu *rmb_Menu); | 645 | void installPopup(QPopupMenu *rmb_Menu); |
645 | 646 | ||
646 | protected: | 647 | protected: |
647 | QPopupMenu *rmbMenu; | 648 | QPopupMenu *rmbMenu; |
648 | 649 | ||
649 | signals: | 650 | signals: |
650 | void bookAddChanged(bool enabled); | 651 | void bookAddChanged(bool enabled); |
651 | void bookClearChanged(bool enabled); | 652 | void bookClearChanged(bool enabled); |
652 | 653 | ||
653 | //config file / session management functions | 654 | //config file / session management functions |
654 | public: | 655 | public: |
655 | /** | 656 | /** |
656 | Reads config entries | 657 | Reads config entries |
657 | */ | 658 | */ |
658 | void readConfig(); | 659 | void readConfig(); |
659 | /** | 660 | /** |
660 | Writes config entries i | 661 | Writes config entries i |
661 | */ | 662 | */ |
662 | void writeConfig(); | 663 | void writeConfig(); |
663 | /** | 664 | /** |
664 | Reads session config out of the KConfig object. This also includes | 665 | Reads session config out of the KateConfig object. This also includes |
665 | the actual cursor position and the bookmarks. | 666 | the actual cursor position and the bookmarks. |
666 | */ | 667 | */ |
667 | void readSessionConfig(KConfig *); | 668 | void readSessionConfig(KateConfig *); |
668 | /** | 669 | /** |
669 | Writes session config into the KConfig object | 670 | Writes session config into the KateConfig object |
670 | */ | 671 | */ |
671 | void writeSessionConfig(KConfig *); | 672 | void writeSessionConfig(KateConfig *); |
672 | 673 | ||
673 | 674 | ||
674 | public: | 675 | public: |
675 | void setDontChangeHlOnSave(); | 676 | void setDontChangeHlOnSave(); |
676 | 677 | ||
677 | 678 | ||
678 | // syntax highlight | 679 | // syntax highlight |
679 | public slots: | 680 | public slots: |
680 | /** | 681 | /** |
681 | Presents the setup dialog to the user | 682 | Presents the setup dialog to the user |
682 | */ | 683 | */ |
683 | void configDialog (); | 684 | void configDialog (); |
684 | /** | 685 | /** |
685 | Gets the highlight number | 686 | Gets the highlight number |
686 | */ | 687 | */ |
687 | int getHl(); | 688 | int getHl(); |
688 | /** | 689 | /** |
689 | Sets the highlight number n | 690 | Sets the highlight number n |
690 | */ | 691 | */ |
691 | void setHl(int n); | 692 | void setHl(int n); |
692 | /** | 693 | /** |
693 | Get the end of line mode (Unix, Macintosh or Dos) | 694 | Get the end of line mode (Unix, Macintosh or Dos) |
694 | */ | 695 | */ |
695 | int getEol(); | 696 | int getEol(); |
696 | /** | 697 | /** |
697 | Set the end of line mode (Unix, Macintosh or Dos) | 698 | Set the end of line mode (Unix, Macintosh or Dos) |
698 | */ | 699 | */ |
699 | void setEol(int); | 700 | void setEol(int); |
700 | 701 | ||
701 | //internal | 702 | //internal |
702 | protected: | 703 | protected: |
703 | virtual void paintEvent(QPaintEvent *); | 704 | virtual void paintEvent(QPaintEvent *); |
704 | virtual void resizeEvent(QResizeEvent *); | 705 | virtual void resizeEvent(QResizeEvent *); |
705 | 706 | ||
706 | void doCursorCommand(int cmdNum); | 707 | void doCursorCommand(int cmdNum); |
707 | void doEditCommand(int cmdNum); | 708 | void doEditCommand(int cmdNum); |
708 | 709 | ||
709 | KateViewInternal *myViewInternal; | 710 | KateViewInternal *myViewInternal; |
710 | KateDocument *myDoc; | 711 | KateDocument *myDoc; |
711 | 712 | ||
712 | 713 | ||
713 | // some kwriteview stuff | 714 | // some kwriteview stuff |
714 | protected: | 715 | protected: |
715 | void insLine(int line) { myViewInternal->insLine(line); }; | 716 | void insLine(int line) { myViewInternal->insLine(line); }; |
716 | void delLine(int line) { myViewInternal->delLine(line); }; | 717 | void delLine(int line) { myViewInternal->delLine(line); }; |
717 | void updateCursor() { myViewInternal->updateCursor(); }; | 718 | void updateCursor() { myViewInternal->updateCursor(); }; |
718 | void updateCursor(PointStruc &newCursor) { myViewInternal->updateCursor(newCursor); }; | 719 | void updateCursor(PointStruc &newCursor) { myViewInternal->updateCursor(newCursor); }; |
719 | void updateCursor(PointStruc &newCursor, int flags) { myViewInternal->updateCursor(newCursor, flags); }; | 720 | void updateCursor(PointStruc &newCursor, int flags) { myViewInternal->updateCursor(newCursor, flags); }; |
720 | 721 | ||
721 | void clearDirtyCache(int height) { myViewInternal->clearDirtyCache(height); }; | 722 | void clearDirtyCache(int height) { myViewInternal->clearDirtyCache(height); }; |
722 | void tagLines(int start, int end, int x1, int x2) { myViewInternal->tagLines(start, end, x1, x2); }; | 723 | void tagLines(int start, int end, int x1, int x2) { myViewInternal->tagLines(start, end, x1, x2); }; |
723 | void tagAll() { myViewInternal->tagAll(); }; | 724 | void tagAll() { myViewInternal->tagAll(); }; |
724 | void setPos(int x, int y) { myViewInternal->setPos(x, y); }; | 725 | void setPos(int x, int y) { myViewInternal->setPos(x, y); }; |
725 | void center() { myViewInternal->center(); }; | 726 | void center() { myViewInternal->center(); }; |
726 | 727 | ||
727 | void updateView(int flags) { myViewInternal->updateView(flags); }; | 728 | void updateView(int flags) { myViewInternal->updateView(flags); }; |
728 | 729 | ||
729 | 730 | ||
730 | 731 | ||
731 | public: | 732 | public: |
732 | enum Config_flags { | 733 | enum Config_flags { |
733 | cfAutoIndent= 0x1, | 734 | cfAutoIndent= 0x1, |
734 | cfBackspaceIndents= 0x2, | 735 | cfBackspaceIndents= 0x2, |
735 | cfWordWrap= 0x4, | 736 | cfWordWrap= 0x4, |
736 | cfReplaceTabs= 0x8, | 737 | cfReplaceTabs= 0x8, |
737 | cfRemoveSpaces = 0x10, | 738 | cfRemoveSpaces = 0x10, |
738 | cfWrapCursor= 0x20, | 739 | cfWrapCursor= 0x20, |
739 | cfAutoBrackets= 0x40, | 740 | cfAutoBrackets= 0x40, |
740 | cfPersistent= 0x80, | 741 | cfPersistent= 0x80, |
741 | cfKeepSelection= 0x100, | 742 | cfKeepSelection= 0x100, |
742 | cfVerticalSelect= 0x200, | 743 | cfVerticalSelect= 0x200, |
743 | cfDelOnInput= 0x400, | 744 | cfDelOnInput= 0x400, |
744 | cfXorSelect= 0x800, | 745 | cfXorSelect= 0x800, |
745 | cfOvr= 0x1000, | 746 | cfOvr= 0x1000, |
746 | cfMark= 0x2000, | 747 | cfMark= 0x2000, |
747 | cfGroupUndo= 0x4000, | 748 | cfGroupUndo= 0x4000, |
748 | cfKeepIndentProfile= 0x8000, | 749 | cfKeepIndentProfile= 0x8000, |
749 | cfKeepExtraSpaces= 0x10000, | 750 | cfKeepExtraSpaces= 0x10000, |
750 | cfMouseAutoCopy= 0x20000, | 751 | cfMouseAutoCopy= 0x20000, |
751 | cfSingleSelection= 0x40000, | 752 | cfSingleSelection= 0x40000, |
752 | cfTabIndents= 0x80000, | 753 | cfTabIndents= 0x80000, |
753 | cfPageUDMovesCursor= 0x100000, | 754 | cfPageUDMovesCursor= 0x100000, |
754 | cfShowTabs= 0x200000, | 755 | cfShowTabs= 0x200000, |
755 | cfSpaceIndent= 0x400000, | 756 | cfSpaceIndent= 0x400000, |
756 | cfSmartHome = 0x800000}; | 757 | cfSmartHome = 0x800000}; |
757 | 758 | ||
758 | enum Dialog_results { | 759 | enum Dialog_results { |
759 | srYes=QDialog::Accepted, | 760 | srYes=QDialog::Accepted, |
760 | srNo=10, | 761 | srNo=10, |
761 | srAll, | 762 | srAll, |
762 | srCancel=QDialog::Rejected}; | 763 | srCancel=QDialog::Rejected}; |
763 | 764 | ||
764 | //search flags | 765 | //search flags |
765 | enum Search_flags { | 766 | enum Search_flags { |
766 | sfCaseSensitive=1, | 767 | sfCaseSensitive=1, |
767 | sfWholeWords=2, | 768 | sfWholeWords=2, |
768 | sfFromBeginning=4, | 769 | sfFromBeginning=4, |
769 | sfBackward=8, | 770 | sfBackward=8, |
770 | sfSelected=16, | 771 | sfSelected=16, |
771 | sfPrompt=32, | 772 | sfPrompt=32, |
772 | sfReplace=64, | 773 | sfReplace=64, |
773 | sfAgain=128, | 774 | sfAgain=128, |
774 | sfWrapped=256, | 775 | sfWrapped=256, |
775 | sfFinished=512, | 776 | sfFinished=512, |
776 | sfRegularExpression=1024}; | 777 | sfRegularExpression=1024}; |
777 | 778 | ||
778 | //update flags | 779 | //update flags |
779 | enum Update_flags { | 780 | enum Update_flags { |
780 | ufDocGeometry=1, | 781 | ufDocGeometry=1, |
781 | ufUpdateOnScroll=2, | 782 | ufUpdateOnScroll=2, |
782 | ufPos=4}; | 783 | ufPos=4}; |
783 | 784 | ||
784 | //load flags | 785 | //load flags |
785 | enum Load_flags { | 786 | enum Load_flags { |
786 | lfInsert=1, | 787 | lfInsert=1, |
787 | lfNewFile=2, | 788 | lfNewFile=2, |
788 | lfNoAutoHl=4}; | 789 | lfNoAutoHl=4}; |
789 | 790 | ||
790 | //cursor movement commands | 791 | //cursor movement commands |
791 | enum Cursor_commands | 792 | enum Cursor_commands |
792 | { cmLeft,cmRight,cmWordLeft,cmWordRight, | 793 | { cmLeft,cmRight,cmWordLeft,cmWordRight, |
793 | cmHome,cmEnd,cmUp,cmDown, | 794 | cmHome,cmEnd,cmUp,cmDown, |
794 | cmScrollUp,cmScrollDown,cmTopOfView,cmBottomOfView, | 795 | cmScrollUp,cmScrollDown,cmTopOfView,cmBottomOfView, |
795 | cmPageUp,cmPageDown,cmCursorPageUp,cmCursorPageDown, | 796 | cmPageUp,cmPageDown,cmCursorPageUp,cmCursorPageDown, |
796 | cmTop,cmBottom}; | 797 | cmTop,cmBottom}; |
797 | //edit commands | 798 | //edit commands |
798 | enum Edit_commands { | 799 | enum Edit_commands { |
799 | cmReturn=1,cmDelete,cmBackspace,cmKillLine,cmUndo, | 800 | cmReturn=1,cmDelete,cmBackspace,cmKillLine,cmUndo, |
800 | cmRedo,cmCut,cmCopy,cmPaste,cmIndent,cmUnindent,cmCleanIndent, | 801 | cmRedo,cmCut,cmCopy,cmPaste,cmIndent,cmUnindent,cmCleanIndent, |
801 | cmSelectAll,cmDeselectAll,cmInvertSelection,cmComment, | 802 | cmSelectAll,cmDeselectAll,cmInvertSelection,cmComment, |
802 | cmUncomment}; | 803 | cmUncomment}; |
803 | //find commands | 804 | //find commands |
804 | enum Find_commands { cmFind=1,cmReplace,cmFindAgain,cmGotoLine}; | 805 | enum Find_commands { cmFind=1,cmReplace,cmFindAgain,cmGotoLine}; |
805 | 806 | ||
806 | public: | 807 | public: |
807 | void setActive (bool b); | 808 | void setActive (bool b); |
808 | bool isActive (); | 809 | bool isActive (); |
809 | 810 | ||
810 | private: | 811 | private: |
811 | bool active; | 812 | bool active; |
812 | bool myIconBorder; | 813 | bool myIconBorder; |
813 | QList<Kate::Mark> list; | 814 | QList<Kate::Mark> list; |
814 | 815 | ||
815 | public slots: | 816 | public slots: |
816 | virtual void setFocus (); | 817 | virtual void setFocus (); |
817 | void findAgain(bool back=false); | 818 | void findAgain(bool back=false); |
818 | void findAgain () { findAgain(false); }; | 819 | void findAgain () { findAgain(false); }; |
819 | void findPrev () { findAgain(true); }; | 820 | void findPrev () { findAgain(true); }; |
820 | 821 | ||
821 | protected: | 822 | protected: |
822 | bool eventFilter(QObject* o, QEvent* e); | 823 | bool eventFilter(QObject* o, QEvent* e); |
823 | 824 | ||
824 | signals: | 825 | signals: |
825 | void gotFocus (KateView *); | 826 | void gotFocus (KateView *); |
826 | 827 | ||
827 | public slots: | 828 | public slots: |
828 | void slotEditCommand (); | 829 | void slotEditCommand (); |
829 | void setIconBorder (bool enable); | 830 | void setIconBorder (bool enable); |
830 | void toggleIconBorder (); | 831 | void toggleIconBorder (); |
831 | void gotoMark (Kate::Mark *mark); | 832 | void gotoMark (Kate::Mark *mark); |
832 | void toggleBookmark (); | 833 | void toggleBookmark (); |
833 | void clearBookmarks (); | 834 | void clearBookmarks (); |
834 | 835 | ||
835 | public: | 836 | public: |
836 | bool iconBorder() { return myIconBorder; } ; | 837 | bool iconBorder() { return myIconBorder; } ; |
837 | 838 | ||
838 | private slots: | 839 | private slots: |
839 | void bookmarkMenuAboutToShow(); | 840 | void bookmarkMenuAboutToShow(); |
840 | void gotoBookmark (int n); | 841 | void gotoBookmark (int n); |
841 | 842 | ||
842 | public: | 843 | public: |
843 | Kate::Document *getDoc () | 844 | Kate::Document *getDoc () |
844 | { return (Kate::Document*) myDoc; }; | 845 | { return (Kate::Document*) myDoc; }; |
845 | 846 | ||
846 | public slots: | 847 | public slots: |
847 | int getHlCount (); | 848 | int getHlCount (); |
848 | QString getHlName (int); | 849 | QString getHlName (int); |
849 | QString getHlSection (int); | 850 | QString getHlSection (int); |
850 | 851 | ||
851 | void slotIncFontSizes (); | 852 | void slotIncFontSizes (); |
852 | void slotDecFontSizes (); | 853 | void slotDecFontSizes (); |
853 | 854 | ||
854 | protected: | 855 | protected: |
855 | uint myViewID; | 856 | uint myViewID; |
856 | static uint uniqueID; | 857 | static uint uniqueID; |
857 | }; | 858 | }; |
858 | 859 | ||
859 | #endif | 860 | #endif |
860 | 861 | ||
861 | 862 | ||
862 | 863 | ||
863 | 864 | ||
864 | 865 | ||
865 | 866 | ||
diff --git a/noncore/apps/tinykate/tinykate.cpp b/noncore/apps/tinykate/tinykate.cpp index 6164fa5..aecc1bd 100644 --- a/noncore/apps/tinykate/tinykate.cpp +++ b/noncore/apps/tinykate/tinykate.cpp | |||
@@ -1,258 +1,268 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | tinykate.cpp | 2 | tinykate.cpp |
3 | Tiny KATE mainwindow | 3 | Tiny KATE mainwindow |
4 | ------------------- | 4 | ------------------- |
5 | begin : November 2002 | 5 | begin : November 2002 |
6 | copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> | 6 | copyright : (C) 2002 by Joseph Wenninger <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. * | 13 | * the Free Software Foundation. * |
14 | * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * | 14 | * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | #include <qwidget.h> | 17 | #include <qwidget.h> |
18 | #include <qaction.h> | 18 | #include <qaction.h> |
19 | #include <qlayout.h> | 19 | #include <qlayout.h> |
20 | #include <qpe/qpetoolbar.h> | 20 | #include <qpe/qpetoolbar.h> |
21 | #include <qpe/qpemenubar.h> | 21 | #include <qpe/qpemenubar.h> |
22 | #include <qpe/resource.h> | 22 | #include <qpe/resource.h> |
23 | #include <qpe/global.h> | 23 | #include <qpe/global.h> |
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | 25 | ||
26 | #include <opie/ofiledialog.h> | 26 | #include <opie/ofiledialog.h> |
27 | 27 | ||
28 | #include "tinykate.h" | 28 | #include "tinykate.h" |
29 | #include "pics/file-new.xpm" | 29 | #include "pics/file-new.xpm" |
30 | #include "pics/file-open.xpm" | 30 | #include "pics/file-open.xpm" |
31 | #include "pics/file-save.xpm" | 31 | #include "pics/file-save.xpm" |
32 | #include "pics/edit-undo.xpm" | 32 | #include "pics/edit-undo.xpm" |
33 | #include "pics/edit-redo.xpm" | 33 | #include "pics/edit-redo.xpm" |
34 | 34 | ||
35 | #include <katedocument.h> | 35 | #include <katedocument.h> |
36 | #include <katehighlight.h> | 36 | #include <katehighlight.h> |
37 | #include <kateview.h> | 37 | #include <kateview.h> |
38 | #include <kglobal.h> | ||
38 | 39 | ||
39 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | 40 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : |
40 | QMainWindow( parent, name, f ) | 41 | QMainWindow( parent, name, f ) |
41 | { | 42 | { |
42 | nextUnnamed=0; | 43 | nextUnnamed=0; |
43 | currentView=0; | 44 | currentView=0; |
44 | viewCount=0; | 45 | viewCount=0; |
45 | setCaption(tr("TinyKATE")); | 46 | setCaption(tr("TinyKATE")); |
47 | KGlobal::setAppName("TinyKATE"); | ||
46 | 48 | ||
47 | setToolBarsMovable(FALSE); | 49 | setToolBarsMovable(FALSE); |
48 | 50 | ||
49 | QPEToolBar *bar = new QPEToolBar( this ); | 51 | QPEToolBar *bar = new QPEToolBar( this ); |
50 | bar->setHorizontalStretchable( TRUE ); | 52 | bar->setHorizontalStretchable( TRUE ); |
51 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 53 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
52 | mb->setMargin( 0 ); | 54 | mb->setMargin( 0 ); |
53 | 55 | ||
54 | tabwidget=new OTabWidget(this); | 56 | tabwidget=new OTabWidget(this); |
55 | setCentralWidget(tabwidget); | 57 | setCentralWidget(tabwidget); |
56 | connect(tabwidget,SIGNAL(currentChanged( QWidget *)),this,SLOT(slotCurrentChanged(QWidget *))); | 58 | connect(tabwidget,SIGNAL(currentChanged( QWidget *)),this,SLOT(slotCurrentChanged(QWidget *))); |
57 | 59 | ||
58 | //FILE ACTIONS | 60 | //FILE ACTIONS |
59 | QPopupMenu *popup = new QPopupMenu( this ); | 61 | QPopupMenu *popup = new QPopupMenu( this ); |
60 | 62 | ||
61 | // Action for creating a new document | 63 | // Action for creating a new document |
62 | QAction *a = new QAction( tr( "New" ), QPixmap((const char**)file_new_xpm ), QString::null, 0, this, 0 ); | 64 | QAction *a = new QAction( tr( "New" ), QPixmap((const char**)file_new_xpm ), QString::null, 0, this, 0 ); |
63 | a->addTo( popup ); | 65 | a->addTo( popup ); |
64 | connect(a, SIGNAL(activated()), this, SLOT(slotNew())); | 66 | connect(a, SIGNAL(activated()), this, SLOT(slotNew())); |
65 | 67 | ||
66 | // Action for opening an exisiting document | 68 | // Action for opening an exisiting document |
67 | a = new QAction( tr( "Open" ), QPixmap((const char**)file_open_xpm), QString::null, 0, this, 0 ); | 69 | a = new QAction( tr( "Open" ), QPixmap((const char**)file_open_xpm), QString::null, 0, this, 0 ); |
68 | a->addTo(popup); | 70 | a->addTo(popup); |
69 | connect(a, SIGNAL(activated()), this, SLOT(slotOpen())); | 71 | connect(a, SIGNAL(activated()), this, SLOT(slotOpen())); |
70 | 72 | ||
71 | 73 | ||
72 | // Action for saving document | 74 | // Action for saving document |
73 | a = new QAction( tr( "Save" ), QPixmap((const char**)file_save_xpm), QString::null, 0, this, 0 ); | 75 | a = new QAction( tr( "Save" ), QPixmap((const char**)file_save_xpm), QString::null, 0, this, 0 ); |
74 | a->addTo(popup); | 76 | a->addTo(popup); |
75 | connect(a, SIGNAL(activated()), this, SLOT(slotSave())); | 77 | connect(a, SIGNAL(activated()), this, SLOT(slotSave())); |
76 | 78 | ||
77 | // Action for saving document to a new name | 79 | // Action for saving document to a new name |
78 | a = new QAction( tr( "Save As" ), QPixmap((const char**)file_save_xpm), QString::null, 0, this, 0 ); | 80 | a = new QAction( tr( "Save As" ), QPixmap((const char**)file_save_xpm), QString::null, 0, this, 0 ); |
79 | a->addTo(popup); | 81 | a->addTo(popup); |
80 | connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs())); | 82 | connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs())); |
81 | 83 | ||
82 | // Action for closing the currently active document | 84 | // Action for closing the currently active document |
83 | a = new QAction( tr( "Close" ), QPixmap(), QString::null, 0, this, 0 ); | 85 | a = new QAction( tr( "Close" ), QPixmap(), QString::null, 0, this, 0 ); |
84 | a->addTo(popup); | 86 | a->addTo(popup); |
85 | connect(a, SIGNAL(activated()), this, SLOT(slotClose())); | 87 | connect(a, SIGNAL(activated()), this, SLOT(slotClose())); |
86 | 88 | ||
87 | 89 | ||
88 | mb->insertItem(tr("File"),popup); | 90 | mb->insertItem(tr("File"),popup); |
89 | 91 | ||
90 | //EDIT ACTIONS | 92 | //EDIT ACTIONS |
91 | 93 | ||
92 | // Action for cutting text | 94 | // Action for cutting text |
93 | editCut = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); | 95 | editCut = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); |
94 | editCut->addTo( bar ); | 96 | editCut->addTo( bar ); |
95 | 97 | ||
96 | // Action for Copying text | 98 | // Action for Copying text |
97 | editCopy = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); | 99 | editCopy = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); |
98 | editCopy->addTo( bar ); | 100 | editCopy->addTo( bar ); |
99 | 101 | ||
100 | // Action for pasting text | 102 | // Action for pasting text |
101 | editPaste = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); | 103 | editPaste = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); |
102 | editPaste->addTo( bar ); | 104 | editPaste->addTo( bar ); |
103 | 105 | ||
104 | 106 | ||
105 | // Action for finding / replacing text | 107 | // Action for finding / replacing text |
106 | editFindReplace = new QAction( tr( "Find/Replace" ), Resource::loadPixmap("find"), QString::null, 0, this, 0 ); | 108 | editFindReplace = new QAction( tr( "Find/Replace" ), Resource::loadPixmap("find"), QString::null, 0, this, 0 ); |
107 | editFindReplace->addTo( bar ); | 109 | editFindReplace->addTo( bar ); |
108 | 110 | ||
109 | // Action for undo | 111 | // Action for undo |
110 | editUndo = new QAction( tr( "Undo" ), QPixmap((const char**)edit_undo_xpm), QString::null, 0, this, 0 ); | 112 | editUndo = new QAction( tr( "Undo" ), QPixmap((const char**)edit_undo_xpm), QString::null, 0, this, 0 ); |
111 | editUndo->addTo( bar ); | 113 | editUndo->addTo( bar ); |
112 | 114 | ||
113 | // Action for redo | 115 | // Action for redo |
114 | editRedo = new QAction( tr( "Redo" ), QPixmap((const char**)edit_redo_xpm), QString::null, 0, this, 0 ); | 116 | editRedo = new QAction( tr( "Redo" ), QPixmap((const char**)edit_redo_xpm), QString::null, 0, this, 0 ); |
115 | editRedo->addTo( bar ); | 117 | editRedo->addTo( bar ); |
116 | 118 | ||
117 | //VIEW ACITONS | 119 | //VIEW ACITONS |
118 | popup = new QPopupMenu( this ); | 120 | popup = new QPopupMenu( this ); |
119 | 121 | ||
120 | viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); | 122 | viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); |
121 | viewIncFontSizes->addTo( popup ); | 123 | viewIncFontSizes->addTo( popup ); |
122 | 124 | ||
123 | viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); | 125 | viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); |
124 | viewDecFontSizes->addTo( popup ); | 126 | viewDecFontSizes->addTo( popup ); |
125 | 127 | ||
126 | mb->insertItem(tr("View"),popup); | 128 | mb->insertItem(tr("View"),popup); |
127 | 129 | ||
128 | 130 | ||
129 | 131 | ||
130 | popup = new QPopupMenu( this ); | 132 | popup = new QPopupMenu( this ); |
131 | mb->insertItem(tr("Utils"),popup); | 133 | mb->insertItem(tr("Utils"),popup); |
132 | 134 | ||
133 | //Highlight management | 135 | //Highlight management |
134 | hlmenu=new QPopupMenu(this); | 136 | hlmenu=new QPopupMenu(this); |
135 | HlManager *hlm=HlManager::self(); | 137 | HlManager *hlm=HlManager::self(); |
136 | for (int i=0;i<hlm->highlights();i++) | 138 | for (int i=0;i<hlm->highlights();i++) |
137 | { | 139 | { |
138 | hlmenu->insertItem(hlm->hlName(i),i); | 140 | hlmenu->insertItem(hlm->hlName(i),i); |
139 | } | 141 | } |
140 | popup->insertItem(tr("Highlighting"),hlmenu); | 142 | popup->insertItem(tr("Highlighting"),hlmenu); |
141 | 143 | ||
142 | 144 | ||
143 | utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); | 145 | utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); |
144 | utilSettings->addTo( popup); | 146 | utilSettings->addTo( popup); |
145 | 147 | ||
146 | if( qApp->argc() > 1) open(qApp->argv()[1]); | 148 | if( qApp->argc() > 1) open(qApp->argv()[1]); |
147 | else slotNew(); | 149 | else slotNew(); |
148 | 150 | ||
149 | } | 151 | } |
150 | 152 | ||
153 | TinyKate::~TinyKate( ) | ||
154 | { | ||
155 | qWarning("TinyKate destructor\n"); | ||
156 | if( KGlobal::config() != 0 ) { | ||
157 | qWarning("deleting KateConfig object..\n"); | ||
158 | delete KGlobal::config(); | ||
159 | } | ||
160 | } | ||
151 | 161 | ||
152 | void TinyKate::slotOpen( ) | 162 | void TinyKate::slotOpen( ) |
153 | { | 163 | { |
154 | QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, | 164 | QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, |
155 | QPEApplication::documentDir()); | 165 | QPEApplication::documentDir()); |
156 | if (!filename.isEmpty()) { | 166 | if (!filename.isEmpty()) { |
157 | open(filename); | 167 | open(filename); |
158 | } | 168 | } |
159 | } | 169 | } |
160 | 170 | ||
161 | void TinyKate::open(const QString & filename) | 171 | void TinyKate::open(const QString & filename) |
162 | { | 172 | { |
163 | KateDocument *kd= new KateDocument(false, false, this,0,this); | 173 | KateDocument *kd= new KateDocument(false, false, this,0,this); |
164 | KTextEditor::View *kv; | 174 | KTextEditor::View *kv; |
165 | QFileInfo fi(filename); | 175 | QFileInfo fi(filename); |
166 | QString filenamed = fi.fileName(); | 176 | QString filenamed = fi.fileName(); |
167 | tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed ); | 177 | tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed ); |
168 | qDebug(filename); | 178 | qDebug(filename); |
169 | 179 | ||
170 | kd->setDocName( filenamed); | 180 | kd->setDocName( filenamed); |
171 | kd->open( filename ); | 181 | kd->open( filename ); |
172 | viewCount++; | 182 | viewCount++; |
173 | } | 183 | } |
174 | 184 | ||
175 | void TinyKate::slotCurrentChanged( QWidget * view) | 185 | void TinyKate::slotCurrentChanged( QWidget * view) |
176 | { | 186 | { |
177 | if (currentView) { | 187 | if (currentView) { |
178 | 188 | ||
179 | disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); | 189 | disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); |
180 | disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); | 190 | disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); |
181 | disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); | 191 | disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); |
182 | disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); | 192 | disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); |
183 | disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); | 193 | disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); |
184 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | 194 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); |
185 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | 195 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); |
186 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); | 196 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); |
187 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); | 197 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); |
188 | } | 198 | } |
189 | 199 | ||
190 | currentView=(KTextEditor::View*)view; | 200 | currentView=(KTextEditor::View*)view; |
191 | 201 | ||
192 | connect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); | 202 | connect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); |
193 | connect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); | 203 | connect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); |
194 | connect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); | 204 | connect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); |
195 | connect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); | 205 | connect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); |
196 | connect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); | 206 | connect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); |
197 | connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | 207 | connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); |
198 | connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | 208 | connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); |
199 | connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); | 209 | connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); |
200 | connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); | 210 | connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); |
201 | 211 | ||
202 | } | 212 | } |
203 | 213 | ||
204 | void TinyKate::slotNew( ) | 214 | void TinyKate::slotNew( ) |
205 | { | 215 | { |
206 | KateDocument *kd= new KateDocument(false, false, this,0,this); | 216 | KateDocument *kd= new KateDocument(false, false, this,0,this); |
207 | KTextEditor::View *kv; | 217 | KTextEditor::View *kv; |
208 | tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), | 218 | tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), |
209 | "tinykate/tinykate", | 219 | "tinykate/tinykate", |
210 | tr("Unnamed %1").arg(nextUnnamed++)); | 220 | tr("Unnamed %1").arg(nextUnnamed++)); |
211 | viewCount++; | 221 | viewCount++; |
212 | } | 222 | } |
213 | 223 | ||
214 | void TinyKate::slotClose( ) | 224 | void TinyKate::slotClose( ) |
215 | { | 225 | { |
216 | if (currentView==0) return; | 226 | if (currentView==0) return; |
217 | KTextEditor::View *dv=currentView; | 227 | KTextEditor::View *dv=currentView; |
218 | currentView=0; | 228 | currentView=0; |
219 | tabwidget->removePage(dv); | 229 | tabwidget->removePage(dv); |
220 | delete dv->document(); | 230 | delete dv->document(); |
221 | viewCount--; | 231 | viewCount--; |
222 | if (!viewCount) slotNew(); | 232 | if (!viewCount) slotNew(); |
223 | } | 233 | } |
224 | 234 | ||
225 | void TinyKate::slotSave() { | 235 | void TinyKate::slotSave() { |
226 | // feel free to make this how you want | 236 | // feel free to make this how you want |
227 | if (currentView==0) return; | 237 | if (currentView==0) return; |
228 | 238 | ||
229 | // KateView *kv = (KateView*) currentView; | 239 | // KateView *kv = (KateView*) currentView; |
230 | KateDocument *kd = (KateDocument*) currentView->document(); | 240 | KateDocument *kd = (KateDocument*) currentView->document(); |
231 | // qDebug("saving file "+kd->docName()); | 241 | // qDebug("saving file "+kd->docName()); |
232 | if( kd->docName().isEmpty()) | 242 | if( kd->docName().isEmpty()) |
233 | slotSaveAs(); | 243 | slotSaveAs(); |
234 | else | 244 | else |
235 | kd->saveFile(); | 245 | kd->saveFile(); |
236 | // kv->save(); | 246 | // kv->save(); |
237 | // kd->saveFile(); | 247 | // kd->saveFile(); |
238 | } | 248 | } |
239 | 249 | ||
240 | void TinyKate::slotSaveAs() { | 250 | void TinyKate::slotSaveAs() { |
241 | if (currentView==0) return; | 251 | if (currentView==0) return; |
242 | KateDocument *kd = (KateDocument*) currentView->document(); | 252 | KateDocument *kd = (KateDocument*) currentView->document(); |
243 | 253 | ||
244 | QString filename=OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, | 254 | QString filename=OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, |
245 | QPEApplication::documentDir()); | 255 | QPEApplication::documentDir()); |
246 | if (!filename.isEmpty()) { | 256 | if (!filename.isEmpty()) { |
247 | qDebug("saving file "+filename); | 257 | qDebug("saving file "+filename); |
248 | QFileInfo fi(filename); | 258 | QFileInfo fi(filename); |
249 | QString filenamed = fi.fileName(); | 259 | QString filenamed = fi.fileName(); |
250 | kd->setDocFile( filename); | 260 | kd->setDocFile( filename); |
251 | kd->setDocName( filenamed); | 261 | kd->setDocName( filenamed); |
252 | kd->saveFile(); | 262 | kd->saveFile(); |
253 | // KTextEditor::View *dv = currentView; | 263 | // KTextEditor::View *dv = currentView; |
254 | // tabwidget->changeTab( dv, filenamed); | 264 | // tabwidget->changeTab( dv, filenamed); |
255 | // need to change tab label here | 265 | // need to change tab label here |
256 | } | 266 | } |
257 | 267 | ||
258 | } | 268 | } |
diff --git a/noncore/apps/tinykate/tinykate.h b/noncore/apps/tinykate/tinykate.h index 7b61bae..bb32f98 100644 --- a/noncore/apps/tinykate/tinykate.h +++ b/noncore/apps/tinykate/tinykate.h | |||
@@ -1,67 +1,68 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | tinykate.h | 2 | tinykate.h |
3 | Tiny KATE mainwindow | 3 | Tiny KATE mainwindow |
4 | ------------------- | 4 | ------------------- |
5 | begin : November 2002 | 5 | begin : November 2002 |
6 | copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> | 6 | copyright : (C) 2002 by Joseph Wenninger <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. * | 13 | * the Free Software Foundation. * |
14 | * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * | 14 | * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | 17 | ||
18 | #ifndef __TINYKATE_H__ | 18 | #ifndef __TINYKATE_H__ |
19 | #define __TINYKATE_H__ | 19 | #define __TINYKATE_H__ |
20 | 20 | ||
21 | 21 | ||
22 | #include <qmainwindow.h> | 22 | #include <qmainwindow.h> |
23 | #include <opie/otabwidget.h> | 23 | #include <opie/otabwidget.h> |
24 | #include <ktexteditor.h> | 24 | #include <ktexteditor.h> |
25 | 25 | ||
26 | class QAction; | 26 | class QAction; |
27 | class QPopupMenu; | 27 | class QPopupMenu; |
28 | 28 | ||
29 | class TinyKate : public QMainWindow | 29 | class TinyKate : public QMainWindow |
30 | { | 30 | { |
31 | Q_OBJECT | 31 | Q_OBJECT |
32 | public: | 32 | public: |
33 | TinyKate( QWidget *parent=0, const char *name=0, WFlags f = 0); | 33 | TinyKate( QWidget *parent=0, const char *name=0, WFlags f = 0); |
34 | ~TinyKate( ); | ||
34 | 35 | ||
35 | public slots: | 36 | public slots: |
36 | QString currentFileName; | ||
37 | void slotNew(); | 37 | void slotNew(); |
38 | 38 | ||
39 | protected slots: | 39 | protected slots: |
40 | void slotOpen(); | 40 | void slotOpen(); |
41 | void slotClose(); | 41 | void slotClose(); |
42 | void slotCurrentChanged(QWidget *); | 42 | void slotCurrentChanged(QWidget *); |
43 | void slotSave(); | 43 | void slotSave(); |
44 | void slotSaveAs(); | 44 | void slotSaveAs(); |
45 | protected: | 45 | protected: |
46 | void open(const QString&); | 46 | void open(const QString&); |
47 | private: | 47 | private: |
48 | QString currentFileName; | ||
48 | OTabWidget *tabwidget; | 49 | OTabWidget *tabwidget; |
49 | KTextEditor::View *currentView; | 50 | KTextEditor::View *currentView; |
50 | 51 | ||
51 | QAction *editCopy; | 52 | QAction *editCopy; |
52 | QAction *editCut; | 53 | QAction *editCut; |
53 | QAction *editPaste; | 54 | QAction *editPaste; |
54 | QAction *editUndo; | 55 | QAction *editUndo; |
55 | QAction *editRedo; | 56 | QAction *editRedo; |
56 | QAction *editFindReplace; | 57 | QAction *editFindReplace; |
57 | QAction *viewIncFontSizes; | 58 | QAction *viewIncFontSizes; |
58 | QAction *viewDecFontSizes; | 59 | QAction *viewDecFontSizes; |
59 | QAction *utilSettings; | 60 | QAction *utilSettings; |
60 | 61 | ||
61 | QPopupMenu *hlmenu; | 62 | QPopupMenu *hlmenu; |
62 | uint nextUnnamed; | 63 | uint nextUnnamed; |
63 | uint viewCount; | 64 | uint viewCount; |
64 | }; | 65 | }; |
65 | 66 | ||
66 | 67 | ||
67 | #endif // __TINYKATE_H__ | 68 | #endif // __TINYKATE_H__ |
diff --git a/noncore/apps/tinykate/tinykate.pro b/noncore/apps/tinykate/tinykate.pro index 61b60a6..632bd49 100644 --- a/noncore/apps/tinykate/tinykate.pro +++ b/noncore/apps/tinykate/tinykate.pro | |||
@@ -1,20 +1,22 @@ | |||
1 | TEMPLATE= app | 1 | TEMPLATE= app |
2 | CONFIG = qt warn_on release | 2 | CONFIG = qt warn_on release |
3 | DESTDIR = $(OPIEDIR)/bin | 3 | DESTDIR = $(OPIEDIR)/bin |
4 | HEADERS = tinykate.h | 4 | HEADERS = tinykate.h |
5 | SOURCES = tinykate.cpp main.cpp | 5 | SOURCES = tinykate.cpp main.cpp |
6 | INTERFACES= | 6 | INTERFACES= |
7 | INCLUDEPATH+= $(OPIEDIR)/include $(OPIEDIR)/noncore/apps/tinykate/libkate/microkde \ | 7 | INCLUDEPATH+= $(OPIEDIR)/include \ |
8 | $(OPIEDIR)/noncore/apps/tinykate/libkate \ | ||
9 | $(OPIEDIR)/noncore/apps/tinykate/libkate/microkde \ | ||
8 | $(OPIEDIR)/noncore/apps/tinykate/libkate/document \ | 10 | $(OPIEDIR)/noncore/apps/tinykate/libkate/document \ |
9 | $(OPIEDIR)/noncore/apps/tinykate/libkate/view \ | 11 | $(OPIEDIR)/noncore/apps/tinykate/libkate/view \ |
10 | $(OPIEDIR)/noncore/apps/tinykate/libkate/interfaces \ | 12 | $(OPIEDIR)/noncore/apps/tinykate/libkate/interfaces \ |
11 | $(OPIEDIR)/noncore/apps/tinykate/libkate/ktexteditor \ | 13 | $(OPIEDIR)/noncore/apps/tinykate/libkate/ktexteditor \ |
12 | $(OPIEDIR)/noncore/apps/tinykate/libkate/qt3back | 14 | $(OPIEDIR)/noncore/apps/tinykate/libkate/qt3back |
13 | 15 | ||
14 | DEPENDPATH+= $(OPIEDIR)/include | 16 | DEPENDPATH+= $(OPIEDIR)/include |
15 | LIBS += -lqpe -ltinykate -lopie | 17 | LIBS += -lqpe -ltinykate -lopie |
16 | TARGET = tinykate | 18 | TARGET = tinykate |
17 | 19 | ||
18 | 20 | ||
19 | 21 | ||
20 | include ( $(OPIEDIR)/include.pro ) | 22 | include ( $(OPIEDIR)/include.pro ) |