-rw-r--r-- | noncore/apps/tinykate/libkate/view/kateview.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/noncore/apps/tinykate/libkate/view/kateview.cpp b/noncore/apps/tinykate/libkate/view/kateview.cpp index 8f3a25e..6453458 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 | 49 | ||
50 | #include <qfocusdata.h> | 50 | #include <qfocusdata.h> |
51 | #include <kdebug.h> | 51 | #include <kdebug.h> |
52 | #include <kapplication.h> | 52 | #include <kapplication.h> |
53 | #include <qscrollbar.h> | 53 | #include <qscrollbar.h> |
54 | #include <qiodevice.h> | 54 | #include <qiodevice.h> |
55 | #include <qpopupmenu.h> | 55 | #include <qpopupmenu.h> |
56 | #include <kpopupmenu.h> | 56 | #include <kpopupmenu.h> |
57 | #include <qkeycode.h> | 57 | #include <qkeycode.h> |
58 | #include <qintdict.h> | 58 | #include <qintdict.h> |
59 | #include <kconfig.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 | 1244 | ||
1245 | if (myDoc && !myDoc->m_bSingleViewMode) | 1245 | if (myDoc && !myDoc->m_bSingleViewMode) |
1246 | myDoc->removeView( this ); | 1246 | myDoc->removeView( this ); |
1247 | 1247 | ||
1248 | delete myViewInternal; | 1248 | delete myViewInternal; |
1249 | 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 | KConfig *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 | KConfig *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(KConfig *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(KConfig *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 KConfig 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 | 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 | ||