summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/libkate/document/katedocument.cpp10
-rw-r--r--noncore/apps/tinykate/libkate/document/katedocument.h11
2 files changed, 15 insertions, 6 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.cpp b/noncore/apps/tinykate/libkate/document/katedocument.cpp
index 10bc976..df1de8d 100644
--- a/noncore/apps/tinykate/libkate/document/katedocument.cpp
+++ b/noncore/apps/tinykate/libkate/document/katedocument.cpp
@@ -139,384 +139,385 @@ KateDocument::KateDocument(bool bSingleViewMode, bool bBrowserView,
139 QWidget *parentWidget, const char *widgetName, 139 QWidget *parentWidget, const char *widgetName,
140 QObject *, const char *) 140 QObject *, const char *)
141 : Kate::Document (), 141 : Kate::Document (),
142 myFont(KGlobalSettings::generalFont()), myFontBold(KGlobalSettings::generalFont()), myFontItalic(KGlobalSettings::generalFont()), myFontBI(KGlobalSettings::generalFont()), 142 myFont(KGlobalSettings::generalFont()), myFontBold(KGlobalSettings::generalFont()), myFontItalic(KGlobalSettings::generalFont()), myFontBI(KGlobalSettings::generalFont()),
143 myFontMetrics (myFont), myFontMetricsBold (myFontBold), myFontMetricsItalic (myFontItalic), myFontMetricsBI (myFontBI), 143 myFontMetrics (myFont), myFontMetricsBold (myFontBold), myFontMetricsItalic (myFontItalic), myFontMetricsBI (myFontBI),
144 hlManager(HlManager::self ()) 144 hlManager(HlManager::self ())
145{ 145{
146 146
147 d(this)->hlSetByUser = false; 147 d(this)->hlSetByUser = false;
148 PreHighlightedTill=0; 148 PreHighlightedTill=0;
149 RequestPreHighlightTill=0; 149 RequestPreHighlightTill=0;
150 150
151 m_bSingleViewMode=bSingleViewMode; 151 m_bSingleViewMode=bSingleViewMode;
152 m_bBrowserView = bBrowserView; 152 m_bBrowserView = bBrowserView;
153 153
154 m_url = QString::null; 154 m_url = QString::null;
155 155
156 // NOTE: QFont::CharSet doesn't provide all the charsets KDE supports 156 // NOTE: QFont::CharSet doesn't provide all the charsets KDE supports
157 // (esp. it doesn't distinguish between UTF-8 and iso10646-1) 157 // (esp. it doesn't distinguish between UTF-8 and iso10646-1)
158 158
159 myEncoding = QString::fromLatin1(QTextCodec::codecForLocale()->name()); 159 myEncoding = QString::fromLatin1(QTextCodec::codecForLocale()->name());
160 160
161 maxLength = -1; 161 maxLength = -1;
162 162
163 setFont (KGlobalSettings::generalFont()); 163 setFont (KGlobalSettings::generalFont());
164 164
165 myDocID = uniqueID; 165 myDocID = uniqueID;
166 uniqueID++; 166 uniqueID++;
167 167
168 myDocName = QString (""); 168 myDocName = QString ("");
169 fileInfo = new QFileInfo (); 169 fileInfo = new QFileInfo ();
170 170
171 myCmd = new KateCmd (this); 171 myCmd = new KateCmd (this);
172 172
173 connect(this,SIGNAL(modifiedChanged ()),this,SLOT(slotModChanged ())); 173 connect(this,SIGNAL(modifiedChanged ()),this,SLOT(slotModChanged ()));
174 174
175 buffer = new KWBuffer; 175 buffer = new KWBuffer;
176 connect(buffer, SIGNAL(linesChanged(int)), this, SLOT(slotBufferChanged())); 176 connect(buffer, SIGNAL(linesChanged(int)), this, SLOT(slotBufferChanged()));
177// connect(buffer, SIGNAL(textChanged()), this, SIGNAL(textChanged())); 177// connect(buffer, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
178 connect(buffer, SIGNAL(needHighlight(long,long)),this,SLOT(slotBufferHighlight(long,long))); 178 connect(buffer, SIGNAL(needHighlight(long,long)),this,SLOT(slotBufferHighlight(long,long)));
179 179
180 colors[0] = KGlobalSettings::baseColor(); 180 colors[0] = KGlobalSettings::baseColor();
181 colors[1] = KGlobalSettings::highlightColor(); 181 colors[1] = KGlobalSettings::highlightColor();
182 182
183 m_attribs = new Attribute[maxAttribs]; 183 m_attribs = new Attribute[maxAttribs];
184 184
185 m_highlight = 0L; 185 m_highlight = 0L;
186 tabChars = 8; 186 tabChars = 8;
187 187
188 m_singleSelection = false; 188 m_singleSelection = false;
189 189
190 newDocGeometry = false; 190 newDocGeometry = false;
191 readOnly = false; 191 readOnly = false;
192 newDoc = false; 192 newDoc = false;
193 193
194 modified = false; 194 modified = false;
195 195
196 undoList.setAutoDelete(true); 196 undoList.setAutoDelete(true);
197 undoState = 0; 197 undoState = 0;
198 undoSteps = 50; 198 undoSteps = 50;
199 199
200 pseudoModal = 0L; 200 pseudoModal = 0L;
201 clear(); 201 clear();
202 202
203 setHighlight(0); //calls updateFontData() 203 setHighlight(0); //calls updateFontData()
204 // if the user changes the highlight with the dialog, notify the doc 204 // if the user changes the highlight with the dialog, notify the doc
205 connect(hlManager,SIGNAL(changed()),SLOT(hlChanged())); 205 connect(hlManager,SIGNAL(changed()),SLOT(hlChanged()));
206 206
207 newDocGeometry = false; 207 newDocGeometry = false;
208 208
209 readConfig(); 209 readConfig();
210 210
211 setReadOnly(false); 211 setReadOnly(false);
212} 212}
213 213
214void KateDocument::setDontChangeHlOnSave() 214void KateDocument::setDontChangeHlOnSave()
215{ 215{
216 d(this)->hlSetByUser = true; 216 d(this)->hlSetByUser = true;
217} 217}
218 218
219void KateDocument::setFont (QFont font) 219void KateDocument::setFont (QFont font)
220{ 220{
221 kdDebug()<<"Kate:: setFont"<<endl; 221 kdDebug()<<"Kate:: setFont"<<endl;
222 int oldwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 222 int oldwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0
223 myFont = font; 223 myFont = font;
224 myFontBold = QFont (font); 224 myFontBold = QFont (font);
225 myFontBold.setBold (true); 225 myFontBold.setBold (true);
226 226
227 myFontItalic = QFont (font); 227 myFontItalic = QFont (font);
228 myFontItalic.setItalic (true); 228 myFontItalic.setItalic (true);
229 229
230 myFontBI = QFont (font); 230 myFontBI = QFont (font);
231 myFontBI.setBold (true); 231 myFontBI.setBold (true);
232 myFontBI.setItalic (true); 232 myFontBI.setItalic (true);
233 233
234 myFontMetrics = CachedFontMetrics (myFont); 234 myFontMetrics = CachedFontMetrics (myFont);
235 myFontMetricsBold = CachedFontMetrics (myFontBold); 235 myFontMetricsBold = CachedFontMetrics (myFontBold);
236 myFontMetricsItalic = CachedFontMetrics (myFontItalic); 236 myFontMetricsItalic = CachedFontMetrics (myFontItalic);
237 myFontMetricsBI = CachedFontMetrics (myFontBI); 237 myFontMetricsBI = CachedFontMetrics (myFontBI);
238 int newwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 238 int newwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0
239 maxLength=maxLength*(float)newwidth/(float)oldwidth; //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 239 maxLength=maxLength*(float)newwidth/(float)oldwidth; //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0
240 240
241 updateFontData(); 241 updateFontData();
242 updateViews(); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 242 updateViews(); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0
243 243
244} 244}
245 245
246long KateDocument::needPreHighlight(long till) 246long KateDocument::needPreHighlight(long till)
247{ 247{
248 int max=numLines()-1; 248 int max=numLines()-1;
249 if (till>max) 249 if (till>max)
250 { 250 {
251 till=max; 251 till=max;
252 } 252 }
253 if (PreHighlightedTill>=till) return -1; 253 if (PreHighlightedTill>=till) return -1;
254 254
255 long tmp=RequestPreHighlightTill; 255 long tmp=RequestPreHighlightTill;
256 if (RequestPreHighlightTill<till) 256 if (RequestPreHighlightTill<till)
257 { 257 {
258 RequestPreHighlightTill=till; 258 RequestPreHighlightTill=till;
259 if (tmp<=PreHighlightedTill) QTimer::singleShot(10,this,SLOT(doPreHighlight())); 259 if (tmp<=PreHighlightedTill) QTimer::singleShot(10,this,SLOT(doPreHighlight()));
260 } 260 }
261 return RequestPreHighlightTill; 261 return RequestPreHighlightTill;
262} 262}
263 263
264void KateDocument::doPreHighlight() 264void KateDocument::doPreHighlight()
265{ 265{
266 int from = PreHighlightedTill; 266 int from = PreHighlightedTill;
267 int till = PreHighlightedTill+200; 267 int till = PreHighlightedTill+200;
268 int max = numLines()-1; 268 int max = numLines()-1;
269 if (till > max) 269 if (till > max)
270 { 270 {
271 till = max; 271 till = max;
272 } 272 }
273 PreHighlightedTill = till; 273 PreHighlightedTill = till;
274 updateLines(from,till); 274 updateLines(from,till);
275 emit preHighlightChanged(PreHighlightedTill); 275 emit preHighlightChanged(PreHighlightedTill);
276 if (PreHighlightedTill<RequestPreHighlightTill) 276 if (PreHighlightedTill<RequestPreHighlightTill)
277 QTimer::singleShot(10,this,SLOT(doPreHighlight())); 277 QTimer::singleShot(10,this,SLOT(doPreHighlight()));
278} 278}
279 279
280KateDocument::~KateDocument() 280KateDocument::~KateDocument()
281{ 281{
282 m_highlight->release(); 282 m_highlight->release();
283 283
284 if ( !m_bSingleViewMode ) 284 if ( !m_bSingleViewMode )
285 { 285 {
286 m_views.setAutoDelete( true ); 286 m_views.setAutoDelete( true );
287 m_views.clear(); 287 m_views.clear();
288 m_views.setAutoDelete( false ); 288 m_views.setAutoDelete( false );
289 } 289 }
290 delete_d(this); 290 delete_d(this);
291} 291}
292 292
293void KateDocument::openURL(const QString &filename) 293void KateDocument::openURL(const QString &filename)
294{ 294{
295 295
296 m_file=filename; 296 m_file=filename;
297 fileInfo->setFile (m_file); 297 fileInfo->setFile (m_file);
298 setMTime(); 298 setMTime();
299 299
300 if (!fileInfo->exists() || !fileInfo->isReadable()) 300 if (!fileInfo->exists() || !fileInfo->isReadable())
301 { 301 {
302 qDebug("File doesn't exit or couldn't be read"); 302 qDebug("File doesn't exit or couldn't be read");
303 return ; 303 return ;
304 } 304 }
305 305
306 buffer->clear(); 306 buffer->clear();
307#warning fixme 307#warning fixme
308// buffer->insertFile(0, m_file, KGlobal::charsets()->codecForName(myEncoding)); 308// buffer->insertFile(0, m_file, KGlobal::charsets()->codecForName(myEncoding));
309 qDebug("Telling buffer to open file"); 309 qDebug("Telling buffer to open file");
310 buffer->insertFile(0, m_file, QTextCodec::codecForLocale()); 310 buffer->insertFile(0, m_file, QTextCodec::codecForLocale());
311 311
312 setMTime(); 312 setMTime();
313 313
314 if (myWordWrap) 314 if (myWordWrap)
315 wrapText (myWordWrapAt); 315 wrapText (myWordWrapAt);
316 316
317 int hl = hlManager->wildcardFind( m_file ); 317 int hl = hlManager->wildcardFind( m_file );
318 318
319 setHighlight(hl); 319 setHighlight(hl);
320 320
321 updateLines(); 321 updateLines();
322 updateViews(); 322 updateViews();
323 323
324 emit fileNameChanged(); 324 emit fileNameChanged();
325 325
326 return ; 326 return ;
327} 327}
328 328
329bool KateDocument::saveFile() 329bool KateDocument::saveFile()
330{ 330{
331
331 QFile f( m_file ); 332 QFile f( m_file );
332 if ( !f.open( IO_WriteOnly ) ) 333 if ( !f.open( IO_WriteOnly ) )
333 return false; // Error 334 return false; // Error
334 335
335 QTextStream stream(&f); 336 QTextStream stream(&f);
336 337
337 stream.setEncoding(QTextStream::RawUnicode); // disable Unicode headers 338 stream.setEncoding(QTextStream::RawUnicode); // disable Unicode headers
338#warning fixme 339#warning fixme
339// stream.setCodec(KGlobal::charsets()->codecForName(myEncoding)); 340// stream.setCodec(KGlobal::charsets()->codecForName(myEncoding));
340 stream.setCodec(QTextCodec::codecForLocale()); // this line sets the mapper to the correct codec 341 stream.setCodec(QTextCodec::codecForLocale()); // this line sets the mapper to the correct codec
341 342
342 int maxLine = numLines(); 343 int maxLine = numLines();
343 int line = 0; 344 int line = 0;
344 while(true) 345 while(true)
345 { 346 {
346 stream << getTextLine(line)->getString(); 347 stream << getTextLine(line)->getString();
347 line++; 348 line++;
348 if (line >= maxLine) break; 349 if (line >= maxLine) break;
349 350
350 if (eolMode == KateDocument::eolUnix) stream << "\n"; 351 if (eolMode == KateDocument::eolUnix) stream << "\n";
351 else if (eolMode == KateDocument::eolDos) stream << "\r\n"; 352 else if (eolMode == KateDocument::eolDos) stream << "\r\n";
352 else if (eolMode == KateDocument::eolMacintosh) stream << '\r'; 353 else if (eolMode == KateDocument::eolMacintosh) stream << '\r';
353 }; 354 };
354 f.close(); 355 f.close();
355 356
356 fileInfo->setFile (m_file); 357 fileInfo->setFile (m_file);
357 setMTime(); 358 setMTime();
358 359
359 if (!(d(this)->hlSetByUser)) 360 if (!(d(this)->hlSetByUser))
360 { 361 {
361 int hl = hlManager->wildcardFind( m_file ); 362 int hl = hlManager->wildcardFind( m_file );
362 363
363 setHighlight(hl); 364 setHighlight(hl);
364 } 365 }
365 emit fileNameChanged (); 366 emit fileNameChanged ();
366 367
367 return (f.status() == IO_Ok); 368 return (f.status() == IO_Ok);
368} 369}
369 370
370KTextEditor::View *KateDocument::createView( QWidget *parent, const char *name ) 371KTextEditor::View *KateDocument::createView( QWidget *parent, const char *name )
371{ 372{
372 return new KateView( this, parent, name); 373 return new KateView( this, parent, name);
373} 374}
374 375
375QString KateDocument::textLine( int line ) const 376QString KateDocument::textLine( int line ) const
376{ 377{
377 TextLine::Ptr l = getTextLine( line ); 378 TextLine::Ptr l = getTextLine( line );
378 if ( !l ) 379 if ( !l )
379 return QString(); 380 return QString();
380 381
381 return l->getString(); 382 return l->getString();
382} 383}
383 384
384void KateDocument::replaceLine(const QString& s,int line) 385void KateDocument::replaceLine(const QString& s,int line)
385{ 386{
386 remove_Line(line,false); 387 remove_Line(line,false);
387 insert_Line(s,line,true); 388 insert_Line(s,line,true);
388} 389}
389 390
390void KateDocument::insertLine( const QString &str, int l ) { 391void KateDocument::insertLine( const QString &str, int l ) {
391 insert_Line(str,l,true); 392 insert_Line(str,l,true);
392} 393}
393 394
394void KateDocument::insert_Line(const QString& s,int line, bool update) 395void KateDocument::insert_Line(const QString& s,int line, bool update)
395{ 396{
396 kdDebug(13020)<<"KateDocument::insertLine "<<s<<QString(" %1").arg(line)<<endl; 397 kdDebug(13020)<<"KateDocument::insertLine "<<s<<QString(" %1").arg(line)<<endl;
397 TextLine::Ptr TL=new TextLine(); 398 TextLine::Ptr TL=new TextLine();
398 TL->append(s.unicode(),s.length()); 399 TL->append(s.unicode(),s.length());
399 buffer->insertLine(line,TL); 400 buffer->insertLine(line,TL);
400 if (update) 401 if (update)
401 { 402 {
402 newDocGeometry=true; 403 newDocGeometry=true;
403 updateLines(line); 404 updateLines(line);
404 updateViews(); 405 updateViews();
405 } 406 }
406} 407}
407 408
408void KateDocument::insertAt( const QString &s, int line, int col, bool ) 409void KateDocument::insertAt( const QString &s, int line, int col, bool )
409{ 410{
410 VConfig c; 411 VConfig c;
411 c.view = 0; // ### FIXME 412 c.view = 0; // ### FIXME
412 c.cursor.x = col; 413 c.cursor.x = col;
413 c.cursor.y = line; 414 c.cursor.y = line;
414 c.cXPos = 0; // ### FIXME 415 c.cXPos = 0; // ### FIXME
415 c.flags = 0; // ### FIXME 416 c.flags = 0; // ### FIXME
416 insert( c, s ); 417 insert( c, s );
417} 418}
418 419
419void KateDocument::removeLine( int line ) { 420void KateDocument::removeLine( int line ) {
420 remove_Line(line,true); 421 remove_Line(line,true);
421} 422}
422 423
423void KateDocument::remove_Line(int line,bool update) 424void KateDocument::remove_Line(int line,bool update)
424{ 425{
425 kdDebug(13020)<<"KateDocument::removeLine "<<QString("%1").arg(line)<<endl; 426 kdDebug(13020)<<"KateDocument::removeLine "<<QString("%1").arg(line)<<endl;
426 buffer->removeLine(line); 427 buffer->removeLine(line);
427// newDocGeometry=true; 428// newDocGeometry=true;
428// if line==0) 429// if line==0)
429 if (update) 430 if (update)
430 { 431 {
431 updateLines(line); 432 updateLines(line);
432 updateViews(); 433 updateViews();
433 } 434 }
434} 435}
435 436
436int KateDocument::length() const 437int KateDocument::length() const
437{ 438{
438 return text().length(); 439 return text().length();
439} 440}
440 441
441void KateDocument::setSelection( int , int , int , int ) 442void KateDocument::setSelection( int , int , int , int )
442{ 443{
443} 444}
444 445
445bool KateDocument::hasSelection() const 446bool KateDocument::hasSelection() const
446{ 447{
447 return (selectEnd >= selectStart); 448 return (selectEnd >= selectStart);
448} 449}
449 450
450QString KateDocument::selection() const 451QString KateDocument::selection() const
451{ 452{
452 uint flags = 0; 453 uint flags = 0;
453 TextLine::Ptr textLine; 454 TextLine::Ptr textLine;
454 int len, z, start, end, i; 455 int len, z, start, end, i;
455 456
456 len = 1; 457 len = 1;
457 if (!(flags & KateView::cfVerticalSelect)) { 458 if (!(flags & KateView::cfVerticalSelect)) {
458 for (z = selectStart; z <= selectEnd; z++) { 459 for (z = selectStart; z <= selectEnd; z++) {
459 textLine = getTextLine(z); 460 textLine = getTextLine(z);
460 len += textLine->numSelected(); 461 len += textLine->numSelected();
461 if (textLine->isSelected()) len++; 462 if (textLine->isSelected()) len++;
462 } 463 }
463 QString s; 464 QString s;
464 len = 0; 465 len = 0;
465 for (z = selectStart; z <= selectEnd; z++) { 466 for (z = selectStart; z <= selectEnd; z++) {
466 textLine = getTextLine(z); 467 textLine = getTextLine(z);
467 end = 0; 468 end = 0;
468 do { 469 do {
469 start = textLine->findUnselected(end); 470 start = textLine->findUnselected(end);
470 end = textLine->findSelected(start); 471 end = textLine->findSelected(start);
471 for (i = start; i < end; i++) { 472 for (i = start; i < end; i++) {
472 s[len] = textLine->getChar(i); 473 s[len] = textLine->getChar(i);
473 len++; 474 len++;
474 } 475 }
475 } while (start < end); 476 } while (start < end);
476 if (textLine->isSelected()) { 477 if (textLine->isSelected()) {
477 s[len] = '\n'; 478 s[len] = '\n';
478 len++; 479 len++;
479 } 480 }
480 } 481 }
481// s[len] = '\0'; 482// s[len] = '\0';
482 return s; 483 return s;
483 } else { 484 } else {
484 for (z = selectStart; z <= selectEnd; z++) { 485 for (z = selectStart; z <= selectEnd; z++) {
485 textLine = getTextLine(z); 486 textLine = getTextLine(z);
486 len += textLine->numSelected() + 1; 487 len += textLine->numSelected() + 1;
487 } 488 }
488 QString s; 489 QString s;
489 len = 0; 490 len = 0;
490 for (z = selectStart; z <= selectEnd; z++) { 491 for (z = selectStart; z <= selectEnd; z++) {
491 textLine = getTextLine(z); 492 textLine = getTextLine(z);
492 end = 0; 493 end = 0;
493 do { 494 do {
494 start = textLine->findUnselected(end); 495 start = textLine->findUnselected(end);
495 end = textLine->findSelected(start); 496 end = textLine->findSelected(start);
496 for (i = start; i < end; i++) { 497 for (i = start; i < end; i++) {
497 s[len] = textLine->getChar(i); 498 s[len] = textLine->getChar(i);
498 len++; 499 len++;
499 } 500 }
500 } while (start < end); 501 } while (start < end);
501 s[len] = '\n'; 502 s[len] = '\n';
502 len++; 503 len++;
503 } 504 }
504// s[len] = '\0'; // the final \0 is not counted in length() 505// s[len] = '\0'; // the final \0 is not counted in length()
505 return s; 506 return s;
506 } 507 }
507} 508}
508 509
509int KateDocument::numLines() const 510int KateDocument::numLines() const
510{ 511{
511 return buffer->count(); 512 return buffer->count();
512} 513}
513 514
514 515
515TextLine::Ptr KateDocument::getTextLine(int line) const 516TextLine::Ptr KateDocument::getTextLine(int line) const
516{ 517{
517 // This is a hack to get this stuff working. 518 // This is a hack to get this stuff working.
518 return buffer->line(line); 519 return buffer->line(line);
519} 520}
520 521
521int KateDocument::textLength(int line) { 522int KateDocument::textLength(int line) {
522 TextLine::Ptr textLine = getTextLine(line); 523 TextLine::Ptr textLine = getTextLine(line);
@@ -1736,385 +1737,386 @@ void KateDocument::doComment(VConfig &c, int change)
1736} 1737}
1737 1738
1738 1739
1739QString KateDocument::text() const 1740QString KateDocument::text() const
1740{ 1741{
1741 QString s; 1742 QString s;
1742 1743
1743 for (int i=0; i < buffer->count(); i++) 1744 for (int i=0; i < buffer->count(); i++)
1744 { 1745 {
1745 TextLine::Ptr textLine = buffer->line(i); 1746 TextLine::Ptr textLine = buffer->line(i);
1746 s.insert(s.length(), textLine->getText(), textLine->length()); 1747 s.insert(s.length(), textLine->getText(), textLine->length());
1747 if ( (i < (buffer->count()-1)) ) 1748 if ( (i < (buffer->count()-1)) )
1748 s.append('\n'); 1749 s.append('\n');
1749 } 1750 }
1750 1751
1751 return s; 1752 return s;
1752} 1753}
1753 1754
1754QString KateDocument::getWord(PointStruc &cursor) { 1755QString KateDocument::getWord(PointStruc &cursor) {
1755 int start, end, len; 1756 int start, end, len;
1756 1757
1757 TextLine::Ptr textLine = getTextLine(cursor.y); 1758 TextLine::Ptr textLine = getTextLine(cursor.y);
1758 len = textLine->length(); 1759 len = textLine->length();
1759 start = end = cursor.x; 1760 start = end = cursor.x;
1760 while (start > 0 && m_highlight->isInWord(textLine->getChar(start - 1))) start--; 1761 while (start > 0 && m_highlight->isInWord(textLine->getChar(start - 1))) start--;
1761 while (end < len && m_highlight->isInWord(textLine->getChar(end))) end++; 1762 while (end < len && m_highlight->isInWord(textLine->getChar(end))) end++;
1762 len = end - start; 1763 len = end - start;
1763 return QString(&textLine->getText()[start], len); 1764 return QString(&textLine->getText()[start], len);
1764} 1765}
1765 1766
1766void KateDocument::setText(const QString &s) { 1767void KateDocument::setText(const QString &s) {
1767 int pos; 1768 int pos;
1768 QChar ch; 1769 QChar ch;
1769 1770
1770 clear(); 1771 clear();
1771 1772
1772 int line=1; 1773 int line=1;
1773 1774
1774 TextLine::Ptr textLine = buffer->line(0); 1775 TextLine::Ptr textLine = buffer->line(0);
1775 for (pos = 0; pos <= (int) s.length(); pos++) { 1776 for (pos = 0; pos <= (int) s.length(); pos++) {
1776 ch = s[pos]; 1777 ch = s[pos];
1777 if (ch.isPrint() || ch == '\t') { 1778 if (ch.isPrint() || ch == '\t') {
1778 textLine->append(&ch, 1); 1779 textLine->append(&ch, 1);
1779 } else if (ch == '\n') 1780 } else if (ch == '\n')
1780 { 1781 {
1781 textLine = new TextLine(); 1782 textLine = new TextLine();
1782 buffer->insertLine (line, textLine); 1783 buffer->insertLine (line, textLine);
1783 line++; 1784 line++;
1784 } 1785 }
1785 } 1786 }
1786 updateLines(); 1787 updateLines();
1787} 1788}
1788 1789
1789 1790
1790QString KateDocument::markedText(int flags) { 1791QString KateDocument::markedText(int flags) {
1791 TextLine::Ptr textLine; 1792 TextLine::Ptr textLine;
1792 int len, z, start, end, i; 1793 int len, z, start, end, i;
1793 1794
1794 len = 1; 1795 len = 1;
1795 if (!(flags & KateView::cfVerticalSelect)) { 1796 if (!(flags & KateView::cfVerticalSelect)) {
1796 for (z = selectStart; z <= selectEnd; z++) { 1797 for (z = selectStart; z <= selectEnd; z++) {
1797 textLine = getTextLine(z); 1798 textLine = getTextLine(z);
1798 len += textLine->numSelected(); 1799 len += textLine->numSelected();
1799 if (textLine->isSelected()) len++; 1800 if (textLine->isSelected()) len++;
1800 } 1801 }
1801 QString s; 1802 QString s;
1802 len = 0; 1803 len = 0;
1803 for (z = selectStart; z <= selectEnd; z++) { 1804 for (z = selectStart; z <= selectEnd; z++) {
1804 textLine = getTextLine(z); 1805 textLine = getTextLine(z);
1805 end = 0; 1806 end = 0;
1806 do { 1807 do {
1807 start = textLine->findUnselected(end); 1808 start = textLine->findUnselected(end);
1808 end = textLine->findSelected(start); 1809 end = textLine->findSelected(start);
1809 for (i = start; i < end; i++) { 1810 for (i = start; i < end; i++) {
1810 s[len] = textLine->getChar(i); 1811 s[len] = textLine->getChar(i);
1811 len++; 1812 len++;
1812 } 1813 }
1813 } while (start < end); 1814 } while (start < end);
1814 if (textLine->isSelected()) { 1815 if (textLine->isSelected()) {
1815 s[len] = '\n'; 1816 s[len] = '\n';
1816 len++; 1817 len++;
1817 } 1818 }
1818 } 1819 }
1819// s[len] = '\0'; 1820// s[len] = '\0';
1820 return s; 1821 return s;
1821 } else { 1822 } else {
1822 for (z = selectStart; z <= selectEnd; z++) { 1823 for (z = selectStart; z <= selectEnd; z++) {
1823 textLine = getTextLine(z); 1824 textLine = getTextLine(z);
1824 len += textLine->numSelected() + 1; 1825 len += textLine->numSelected() + 1;
1825 } 1826 }
1826 QString s; 1827 QString s;
1827 len = 0; 1828 len = 0;
1828 for (z = selectStart; z <= selectEnd; z++) { 1829 for (z = selectStart; z <= selectEnd; z++) {
1829 textLine = getTextLine(z); 1830 textLine = getTextLine(z);
1830 end = 0; 1831 end = 0;
1831 do { 1832 do {
1832 start = textLine->findUnselected(end); 1833 start = textLine->findUnselected(end);
1833 end = textLine->findSelected(start); 1834 end = textLine->findSelected(start);
1834 for (i = start; i < end; i++) { 1835 for (i = start; i < end; i++) {
1835 s[len] = textLine->getChar(i); 1836 s[len] = textLine->getChar(i);
1836 len++; 1837 len++;
1837 } 1838 }
1838 } while (start < end); 1839 } while (start < end);
1839 s[len] = '\n'; 1840 s[len] = '\n';
1840 len++; 1841 len++;
1841 } 1842 }
1842// s[len] = '\0'; // the final \0 is not counted in length() 1843// s[len] = '\0'; // the final \0 is not counted in length()
1843 return s; 1844 return s;
1844 } 1845 }
1845} 1846}
1846 1847
1847void KateDocument::delMarkedText(VConfig &c/*, bool undo*/) { 1848void KateDocument::delMarkedText(VConfig &c/*, bool undo*/) {
1848 int end = 0; 1849 int end = 0;
1849 1850
1850 if (selectEnd < selectStart) return; 1851 if (selectEnd < selectStart) return;
1851 1852
1852 // the caller may have already started an undo record for the current action 1853 // the caller may have already started an undo record for the current action
1853// if (undo) 1854// if (undo)
1854 1855
1855 //auto deletion of the marked text occurs not very often and can therefore 1856 //auto deletion of the marked text occurs not very often and can therefore
1856 // be recorded separately 1857 // be recorded separately
1857 recordStart(c, KateActionGroup::ugDelBlock); 1858 recordStart(c, KateActionGroup::ugDelBlock);
1858 1859
1859 for (c.cursor.y = selectEnd; c.cursor.y >= selectStart; c.cursor.y--) { 1860 for (c.cursor.y = selectEnd; c.cursor.y >= selectStart; c.cursor.y--) {
1860 TextLine::Ptr textLine = getTextLine(c.cursor.y); 1861 TextLine::Ptr textLine = getTextLine(c.cursor.y);
1861 1862
1862 c.cursor.x = textLine->length(); 1863 c.cursor.x = textLine->length();
1863 do { 1864 do {
1864 end = textLine->findRevUnselected(c.cursor.x); 1865 end = textLine->findRevUnselected(c.cursor.x);
1865 if (end == 0) break; 1866 if (end == 0) break;
1866 c.cursor.x = textLine->findRevSelected(end); 1867 c.cursor.x = textLine->findRevSelected(end);
1867 recordDelete(c.cursor, end - c.cursor.x); 1868 recordDelete(c.cursor, end - c.cursor.x);
1868 } while (true); 1869 } while (true);
1869 end = c.cursor.x; 1870 end = c.cursor.x;
1870 c.cursor.x = textLine->length(); 1871 c.cursor.x = textLine->length();
1871 if (textLine->isSelected()) recordAction(KateAction::delLine,c.cursor); 1872 if (textLine->isSelected()) recordAction(KateAction::delLine,c.cursor);
1872 } 1873 }
1873 c.cursor.y++; 1874 c.cursor.y++;
1874 /*if (end < c.cursor.x)*/ c.cursor.x = end; 1875 /*if (end < c.cursor.x)*/ c.cursor.x = end;
1875 1876
1876 selectEnd = -1; 1877 selectEnd = -1;
1877 select.x = -1; 1878 select.x = -1;
1878 1879
1879 /*if (undo)*/ recordEnd(c); 1880 /*if (undo)*/ recordEnd(c);
1880} 1881}
1881 1882
1882void KateDocument::tagLineRange(int line, int x1, int x2) { 1883void KateDocument::tagLineRange(int line, int x1, int x2) {
1883 int z; 1884 int z;
1884 1885
1885 for (z = 0; z < (int) views.count(); z++) { 1886 for (z = 0; z < (int) views.count(); z++) {
1886 views.at(z)->tagLines(line, line, x1, x2); 1887 views.at(z)->tagLines(line, line, x1, x2);
1887 } 1888 }
1888} 1889}
1889 1890
1890void KateDocument::tagLines(int start, int end) { 1891void KateDocument::tagLines(int start, int end) {
1891 int z; 1892 int z;
1892 1893
1893 for (z = 0; z < (int) views.count(); z++) { 1894 for (z = 0; z < (int) views.count(); z++) {
1894 views.at(z)->tagLines(start, end, 0, 0xffffff); 1895 views.at(z)->tagLines(start, end, 0, 0xffffff);
1895 } 1896 }
1896} 1897}
1897 1898
1898void KateDocument::tagAll() { 1899void KateDocument::tagAll() {
1899 int z; 1900 int z;
1900 1901
1901 for (z = 0; z < (int) views.count(); z++) { 1902 for (z = 0; z < (int) views.count(); z++) {
1902 views.at(z)->tagAll(); 1903 views.at(z)->tagAll();
1903 } 1904 }
1904} 1905}
1905 1906
1906void KateDocument::updateLines(int startLine, int endLine, int flags, int cursorY) { 1907void KateDocument::updateLines(int startLine, int endLine, int flags, int cursorY) {
1907 TextLine::Ptr textLine; 1908 TextLine::Ptr textLine;
1908 int line, last_line; 1909 int line, last_line;
1909 int ctxNum, endCtx; 1910 int ctxNum, endCtx;
1910// kdDebug(13020)<<"******************KateDocument::updateLines Checkpoint 1"<<endl; 1911// kdDebug(13020)<<"******************KateDocument::updateLines Checkpoint 1"<<endl;
1911 if (buffer->line(startLine)==0) {kdDebug(13020)<<"********************No buffer for line " << startLine << " found**************"<<endl; return;}; 1912 if (buffer->line(startLine)==0) {kdDebug(13020)<<"********************No buffer for line " << startLine << " found**************"<<endl; return;};
1912// kdDebug(13020)<<"KateDocument::updateLines Checkpoint 2"<<endl; 1913// kdDebug(13020)<<"KateDocument::updateLines Checkpoint 2"<<endl;
1913 last_line = lastLine(); 1914 last_line = lastLine();
1914// if (endLine >= last_line) endLine = last_line; 1915// if (endLine >= last_line) endLine = last_line;
1915 1916
1916 line = startLine; 1917 line = startLine;
1917 ctxNum = 0; 1918 ctxNum = 0;
1918 if (line > 0) ctxNum = getTextLine(line - 1)->getContext(); 1919 if (line > 0) ctxNum = getTextLine(line - 1)->getContext();
1919 do { 1920 do {
1920// kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl; 1921// kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl;
1921 textLine = getTextLine(line); 1922 textLine = getTextLine(line);
1922 if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl; 1923 if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl;
1923 if (line <= endLine && line != cursorY) { 1924 if (line <= endLine && line != cursorY) {
1924 if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces(); 1925 if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces();
1925 updateMaxLength(textLine); 1926 updateMaxLength(textLine);
1926 } 1927 }
1927 endCtx = textLine->getContext(); 1928 endCtx = textLine->getContext();
1928 qDebug("DOHIGHLIGHT"); 1929// qDebug("DOHIGHLIGHT");
1930
1929 ctxNum = m_highlight->doHighlight(ctxNum,textLine); 1931 ctxNum = m_highlight->doHighlight(ctxNum,textLine);
1930 textLine->setContext(ctxNum); 1932 textLine->setContext(ctxNum);
1931 line++; 1933 line++;
1932 } while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum)); 1934 } while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum));
1933// kdDebug(13020)<<"updateLines :: while loop left"<<endl; 1935// kdDebug(13020)<<"updateLines :: while loop left"<<endl;
1934 tagLines(startLine, line - 1); 1936 tagLines(startLine, line - 1);
1935} 1937}
1936 1938
1937 1939
1938void KateDocument::updateMaxLength(TextLine::Ptr &textLine) { 1940void KateDocument::updateMaxLength(TextLine::Ptr &textLine) {
1939 int len; 1941 int len;
1940 1942
1941 len = textWidth(textLine,textLine->length()); 1943 len = textWidth(textLine,textLine->length());
1942 1944
1943 if (len > maxLength) { 1945 if (len > maxLength) {
1944 longestLine = textLine; 1946 longestLine = textLine;
1945 maxLength = len; 1947 maxLength = len;
1946 newDocGeometry = true; 1948 newDocGeometry = true;
1947 } else { 1949 } else {
1948 if (!longestLine || (textLine == longestLine && len <= maxLength*3/4)) { 1950 if (!longestLine || (textLine == longestLine && len <= maxLength*3/4)) {
1949 maxLength = -1; 1951 maxLength = -1;
1950 for (int i = 0; i < numLines();i++) { 1952 for (int i = 0; i < numLines();i++) {
1951 textLine = getTextLine(i); 1953 textLine = getTextLine(i);
1952 len = textWidth(textLine,textLine->length()); 1954 len = textWidth(textLine,textLine->length());
1953 if (len > maxLength) { 1955 if (len > maxLength) {
1954 maxLength = len; 1956 maxLength = len;
1955 longestLine = textLine; 1957 longestLine = textLine;
1956 } 1958 }
1957 } 1959 }
1958 newDocGeometry = true; 1960 newDocGeometry = true;
1959 } 1961 }
1960 } 1962 }
1961} 1963}
1962 1964
1963void KateDocument::slotBufferChanged() { 1965void KateDocument::slotBufferChanged() {
1964 newDocGeometry = true; 1966 newDocGeometry = true;
1965 //updateLines();//JW 1967 //updateLines();//JW
1966 updateViews(); 1968 updateViews();
1967} 1969}
1968 1970
1969void KateDocument::slotBufferHighlight(long start,long stop) { 1971void KateDocument::slotBufferHighlight(long start,long stop) {
1970 kdDebug(13020)<<"KateDocument::slotBufferHighlight"<<QString("%1-%2").arg(start).arg(stop)<<endl; 1972 kdDebug(13020)<<"KateDocument::slotBufferHighlight"<<QString("%1-%2").arg(start).arg(stop)<<endl;
1971 updateLines(start,stop); 1973 updateLines(start,stop);
1972// buffer->startLoadTimer(); 1974// buffer->startLoadTimer();
1973} 1975}
1974 1976
1975void KateDocument::updateViews(KateView *exclude) { 1977void KateDocument::updateViews(KateView *exclude) {
1976 KateView *view; 1978 KateView *view;
1977 int flags; 1979 int flags;
1978 bool markState = hasMarkedText(); 1980 bool markState = hasMarkedText();
1979 1981
1980 flags = (newDocGeometry) ? KateView::ufDocGeometry : 0; 1982 flags = (newDocGeometry) ? KateView::ufDocGeometry : 0;
1981 for (view = views.first(); view != 0L; view = views.next() ) { 1983 for (view = views.first(); view != 0L; view = views.next() ) {
1982 if (view != exclude) view->updateView(flags); 1984 if (view != exclude) view->updateView(flags);
1983 1985
1984 // notify every view about the changed mark state.... 1986 // notify every view about the changed mark state....
1985 if (oldMarkState != markState) emit view->newMarkStatus(); 1987 if (oldMarkState != markState) emit view->newMarkStatus();
1986 } 1988 }
1987 oldMarkState = markState; 1989 oldMarkState = markState;
1988 newDocGeometry = false; 1990 newDocGeometry = false;
1989} 1991}
1990 1992
1991QColor &KateDocument::cursorCol(int x, int y) { 1993QColor &KateDocument::cursorCol(int x, int y) {
1992 int attr; 1994 int attr;
1993 Attribute *a; 1995 Attribute *a;
1994 1996
1995 TextLine::Ptr textLine = getTextLine(y); 1997 TextLine::Ptr textLine = getTextLine(y);
1996 attr = textLine->getRawAttr(x); 1998 attr = textLine->getRawAttr(x);
1997 a = &m_attribs[attr & taAttrMask]; 1999 a = &m_attribs[attr & taAttrMask];
1998 if (attr & taSelected) return a->selCol; else return a->col; 2000 if (attr & taSelected) return a->selCol; else return a->col;
1999} 2001}
2000 2002
2001void KateDocument::paintTextLine(QPainter &paint, int line, int xStart, int xEnd, bool showTabs) 2003void KateDocument::paintTextLine(QPainter &paint, int line, int xStart, int xEnd, bool showTabs)
2002{ 2004{
2003 paintTextLine (paint, line, 0, xStart, xEnd, showTabs); 2005 paintTextLine (paint, line, 0, xStart, xEnd, showTabs);
2004} 2006}
2005 2007
2006void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, int xEnd, bool showTabs) 2008void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, int xEnd, bool showTabs)
2007{ 2009{
2008 TextLine::Ptr textLine; 2010 TextLine::Ptr textLine;
2009 int len; 2011 int len;
2010 const QChar *s; 2012 const QChar *s;
2011 int z, x; 2013 int z, x;
2012 QChar ch; 2014 QChar ch;
2013 Attribute *a = 0L; 2015 Attribute *a = 0L;
2014 int attr, nextAttr; 2016 int attr, nextAttr;
2015 int xs; 2017 int xs;
2016 int xc, zc; 2018 int xc, zc;
2017 2019
2018 if (line > lastLine()) { 2020 if (line > lastLine()) {
2019 paint.fillRect(0, y, xEnd - xStart,fontHeight, colors[0]); 2021 paint.fillRect(0, y, xEnd - xStart,fontHeight, colors[0]);
2020 return; 2022 return;
2021 } 2023 }
2022 2024
2023 textLine = getTextLine(line); 2025 textLine = getTextLine(line);
2024 len = textLine->length(); 2026 len = textLine->length();
2025 s = textLine->getText(); 2027 s = textLine->getText();
2026 2028
2027 // skip to first visible character 2029 // skip to first visible character
2028 x = 0; 2030 x = 0;
2029 z = 0; 2031 z = 0;
2030 do { 2032 do {
2031 xc = x; 2033 xc = x;
2032 zc = z; 2034 zc = z;
2033 if (z == len) break; 2035 if (z == len) break;
2034 ch = s[z];//textLine->getChar(z); 2036 ch = s[z];//textLine->getChar(z);
2035 if (ch == '\t') { 2037 if (ch == '\t') {
2036 x += m_tabWidth - (x % m_tabWidth); 2038 x += m_tabWidth - (x % m_tabWidth);
2037 } else { 2039 } else {
2038 a = &m_attribs[textLine->getAttr(z)]; 2040 a = &m_attribs[textLine->getAttr(z)];
2039 2041
2040 if (a->bold && a->italic) 2042 if (a->bold && a->italic)
2041 x += myFontMetricsBI.width(ch); 2043 x += myFontMetricsBI.width(ch);
2042 else if (a->bold) 2044 else if (a->bold)
2043 x += myFontMetricsBold.width(ch); 2045 x += myFontMetricsBold.width(ch);
2044 else if (a->italic) 2046 else if (a->italic)
2045 x += myFontMetricsItalic.width(ch); 2047 x += myFontMetricsItalic.width(ch);
2046 else 2048 else
2047 x += myFontMetrics.width(ch); 2049 x += myFontMetrics.width(ch);
2048 } 2050 }
2049 z++; 2051 z++;
2050 } while (x <= xStart); 2052 } while (x <= xStart);
2051 2053
2052 // draw background 2054 // draw background
2053 xs = xStart; 2055 xs = xStart;
2054 attr = textLine->getRawAttr(zc); 2056 attr = textLine->getRawAttr(zc);
2055 while (x < xEnd) 2057 while (x < xEnd)
2056 { 2058 {
2057 nextAttr = textLine->getRawAttr(z); 2059 nextAttr = textLine->getRawAttr(z);
2058 if ((nextAttr ^ attr) & taSelected) 2060 if ((nextAttr ^ attr) & taSelected)
2059 { 2061 {
2060 if (attr & taSelected) 2062 if (attr & taSelected)
2061 paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[1]); 2063 paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[1]);
2062 else 2064 else
2063 paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[0]); 2065 paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[0]);
2064 2066
2065 xs = x; 2067 xs = x;
2066 attr = nextAttr; 2068 attr = nextAttr;
2067 } 2069 }
2068 2070
2069 if (z == len) break; 2071 if (z == len) break;
2070 2072
2071 ch = s[z];//textLine->getChar(z); 2073 ch = s[z];//textLine->getChar(z);
2072 2074
2073 if (ch == '\t') 2075 if (ch == '\t')
2074 x += m_tabWidth - (x % m_tabWidth); 2076 x += m_tabWidth - (x % m_tabWidth);
2075 else 2077 else
2076 { 2078 {
2077 a = &m_attribs[textLine->getAttr(z)]; 2079 a = &m_attribs[textLine->getAttr(z)];
2078 2080
2079 if (a->bold && a->italic) 2081 if (a->bold && a->italic)
2080 x += myFontMetricsBI.width(ch); 2082 x += myFontMetricsBI.width(ch);
2081 else if (a->bold) 2083 else if (a->bold)
2082 x += myFontMetricsBold.width(ch); 2084 x += myFontMetricsBold.width(ch);
2083 else if (a->italic) 2085 else if (a->italic)
2084 x += myFontMetricsItalic.width(ch); 2086 x += myFontMetricsItalic.width(ch);
2085 else 2087 else
2086 x += myFontMetrics.width(ch); 2088 x += myFontMetrics.width(ch);
2087 } 2089 }
2088 z++; 2090 z++;
2089 } 2091 }
2090 2092
2091 if (attr & taSelected) 2093 if (attr & taSelected)
2092 paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[1]); 2094 paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[1]);
2093 else 2095 else
2094 paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[0]); 2096 paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[0]);
2095 2097
2096 len = z; //reduce length to visible length 2098 len = z; //reduce length to visible length
2097 2099
2098 // draw text 2100 // draw text
2099 x = xc; 2101 x = xc;
2100 z = zc; 2102 z = zc;
2101 y += fontAscent;// -1; 2103 y += fontAscent;// -1;
2102 attr = -1; 2104 attr = -1;
2103 while (z < len) { 2105 while (z < len) {
2104 ch = s[z];//textLine->getChar(z); 2106 ch = s[z];//textLine->getChar(z);
2105 if (ch == '\t') { 2107 if (ch == '\t') {
2106 if (z > zc) { 2108 if (z > zc) {
2107 //this should cause no copy at all 2109 //this should cause no copy at all
2108 QConstString str((QChar *) &s[zc], z - zc /*+1*/); 2110 QConstString str((QChar *) &s[zc], z - zc /*+1*/);
2109 QString s = str.string(); 2111 QString s = str.string();
2110 paint.drawText(x - xStart, y, s); 2112 paint.drawText(x - xStart, y, s);
2111 2113
2112 if (a->bold && a->italic) 2114 if (a->bold && a->italic)
2113 x += myFontMetricsBI.width(s); 2115 x += myFontMetricsBI.width(s);
2114 else if (a->bold) 2116 else if (a->bold)
2115 x += myFontMetricsBold.width(s); 2117 x += myFontMetricsBold.width(s);
2116 else if (a->italic) 2118 else if (a->italic)
2117 x += myFontMetricsItalic.width(s); 2119 x += myFontMetricsItalic.width(s);
2118 else 2120 else
2119 x += myFontMetrics.width(s); 2121 x += myFontMetrics.width(s);
2120 } 2122 }
@@ -2841,329 +2843,335 @@ void KateDocument::undo(VConfig &c, int count) {
2841 needUpdate = true; 2843 needUpdate = true;
2842 2844
2843// if (num == 0) recordReset(); 2845// if (num == 0) recordReset();
2844 } 2846 }
2845 2847
2846 if (needUpdate) { 2848 if (needUpdate) {
2847 // since we told doActionGroup() not to do this stuff, we need to do it now 2849 // since we told doActionGroup() not to do this stuff, we need to do it now
2848 c.view->updateCursor(g->start); 2850 c.view->updateCursor(g->start);
2849 setModified(true); 2851 setModified(true);
2850 newUndo(); 2852 newUndo();
2851 } 2853 }
2852} 2854}
2853 2855
2854void KateDocument::redo(VConfig &c, int count) { 2856void KateDocument::redo(VConfig &c, int count) {
2855 KateActionGroup *g = 0L; 2857 KateActionGroup *g = 0L;
2856 int num; 2858 int num;
2857 bool needUpdate = false; // don't update the cursor until completely done 2859 bool needUpdate = false; // don't update the cursor until completely done
2858 2860
2859 if (count <= 0) return; 2861 if (count <= 0) return;
2860 2862
2861 for (num = 0 ; num < count ; num++) { 2863 for (num = 0 ; num < count ; num++) {
2862 if (currentUndo+1 > (int)undoList.count()) break; 2864 if (currentUndo+1 > (int)undoList.count()) break;
2863 g = undoList.at(currentUndo); 2865 g = undoList.at(currentUndo);
2864 currentUndo++; 2866 currentUndo++;
2865 doActionGroup(g, c.flags, true); // do not setModified() or newUndo() 2867 doActionGroup(g, c.flags, true); // do not setModified() or newUndo()
2866 needUpdate = true; 2868 needUpdate = true;
2867 2869
2868// if (num == 0) recordReset(); 2870// if (num == 0) recordReset();
2869 } 2871 }
2870 2872
2871 if (needUpdate) { 2873 if (needUpdate) {
2872 // since we told doActionGroup() not to do this stuff, we need to do it now 2874 // since we told doActionGroup() not to do this stuff, we need to do it now
2873 c.view->updateCursor(g->end); 2875 c.view->updateCursor(g->end);
2874 setModified(true); 2876 setModified(true);
2875 newUndo(); 2877 newUndo();
2876 } 2878 }
2877} 2879}
2878 2880
2879void KateDocument::clearRedo() { 2881void KateDocument::clearRedo() {
2880 // disable redos 2882 // disable redos
2881 // this was added as an assist to the spell checker 2883 // this was added as an assist to the spell checker
2882 bool deleted = false; 2884 bool deleted = false;
2883 2885
2884 while ((int) undoList.count() > currentUndo) { 2886 while ((int) undoList.count() > currentUndo) {
2885 deleted = true; 2887 deleted = true;
2886 undoList.removeLast(); 2888 undoList.removeLast();
2887 } 2889 }
2888 2890
2889 if (deleted) newUndo(); 2891 if (deleted) newUndo();
2890} 2892}
2891 2893
2892void KateDocument::setUndoSteps(int steps) { 2894void KateDocument::setUndoSteps(int steps) {
2893 if (steps < 5) steps = 5; 2895 if (steps < 5) steps = 5;
2894 undoSteps = steps; 2896 undoSteps = steps;
2895} 2897}
2896 2898
2897void KateDocument::setPseudoModal(QWidget *w) { 2899void KateDocument::setPseudoModal(QWidget *w) {
2898// QWidget *old = pseudoModal; 2900// QWidget *old = pseudoModal;
2899 2901
2900 // (glenebob) 2902 // (glenebob)
2901 // this is a temporary hack to make the spell checker work a little 2903 // this is a temporary hack to make the spell checker work a little
2902 // better - as kspell progresses, this sort of thing should become 2904 // better - as kspell progresses, this sort of thing should become
2903 // obsolete or worked around more cleanly 2905 // obsolete or worked around more cleanly
2904 // this is relied upon *only* by the spell-check code 2906 // this is relied upon *only* by the spell-check code
2905 if (pseudoModal && pseudoModal != (QWidget*)1L) 2907 if (pseudoModal && pseudoModal != (QWidget*)1L)
2906 delete pseudoModal; 2908 delete pseudoModal;
2907 2909
2908// pseudoModal = 0L; 2910// pseudoModal = 0L;
2909// if (old || w) recordReset(); 2911// if (old || w) recordReset();
2910 2912
2911 pseudoModal = w; 2913 pseudoModal = w;
2912} 2914}
2913 2915
2914 2916
2915void KateDocument::newBracketMark(PointStruc &cursor, BracketMark &bm) 2917void KateDocument::newBracketMark(PointStruc &cursor, BracketMark &bm)
2916{ 2918{
2917 TextLine::Ptr textLine; 2919 TextLine::Ptr textLine;
2918 int x, line, count, attr; 2920 int x, line, count, attr;
2919 QChar bracket, opposite, ch; 2921 QChar bracket, opposite, ch;
2920 Attribute *a; 2922 Attribute *a;
2921 2923
2922 bm.eXPos = -1; //mark bracked mark as invalid 2924 bm.eXPos = -1; //mark bracked mark as invalid
2923 x = cursor.x -1; // -1 to look at left side of cursor 2925 x = cursor.x -1; // -1 to look at left side of cursor
2924 if (x < 0) return; 2926 if (x < 0) return;
2925 line = cursor.y; //current line 2927 line = cursor.y; //current line
2926 count = 0; //bracket counter for nested brackets 2928 count = 0; //bracket counter for nested brackets
2927 2929
2928 textLine = getTextLine(line); 2930 textLine = getTextLine(line);
2929 if (!textLine) return; 2931 if (!textLine) return;
2930 2932
2931 bracket = textLine->getChar(x); 2933 bracket = textLine->getChar(x);
2932 attr = textLine->getAttr(x); 2934 attr = textLine->getAttr(x);
2933 2935
2934 if (bracket == '(' || bracket == '[' || bracket == '{') 2936 if (bracket == '(' || bracket == '[' || bracket == '{')
2935 { 2937 {
2936 //get opposite bracket 2938 //get opposite bracket
2937 opposite = ')'; 2939 opposite = ')';
2938 if (bracket == '[') opposite = ']'; 2940 if (bracket == '[') opposite = ']';
2939 if (bracket == '{') opposite = '}'; 2941 if (bracket == '{') opposite = '}';
2940 //get attribute of bracket (opposite bracket must have the same attribute) 2942 //get attribute of bracket (opposite bracket must have the same attribute)
2941 x++; 2943 x++;
2942 while (line - cursor.y < 40) { 2944 while (line - cursor.y < 40) {
2943 //go to next line on end of line 2945 //go to next line on end of line
2944 while (x >= (int) textLine->length()) { 2946 while (x >= (int) textLine->length()) {
2945 line++; 2947 line++;
2946 if (line > lastLine()) return; 2948 if (line > lastLine()) return;
2947 textLine = getTextLine(line); 2949 textLine = getTextLine(line);
2948 x = 0; 2950 x = 0;
2949 } 2951 }
2950 if (textLine->getAttr(x) == attr) { 2952 if (textLine->getAttr(x) == attr) {
2951 //try to find opposite bracked 2953 //try to find opposite bracked
2952 ch = textLine->getChar(x); 2954 ch = textLine->getChar(x);
2953 if (ch == bracket) count++; //same bracket : increase counter 2955 if (ch == bracket) count++; //same bracket : increase counter
2954 if (ch == opposite) { 2956 if (ch == opposite) {
2955 count--; 2957 count--;
2956 if (count < 0) goto found; 2958 if (count < 0) goto found;
2957 } 2959 }
2958 } 2960 }
2959 x++; 2961 x++;
2960 } 2962 }
2961 } 2963 }
2962 else if (bracket == ')' || bracket == ']' || bracket == '}') 2964 else if (bracket == ')' || bracket == ']' || bracket == '}')
2963 { 2965 {
2964 opposite = '('; 2966 opposite = '(';
2965 if (bracket == ']') opposite = '['; 2967 if (bracket == ']') opposite = '[';
2966 if (bracket == '}') opposite = '{'; 2968 if (bracket == '}') opposite = '{';
2967 x--; 2969 x--;
2968 while (cursor.y - line < 20) { 2970 while (cursor.y - line < 20) {
2969 2971
2970 while (x < 0) { 2972 while (x < 0) {
2971 line--; 2973 line--;
2972 if (line < 0) return; 2974 if (line < 0) return;
2973 textLine = getTextLine(line); 2975 textLine = getTextLine(line);
2974 x = textLine->length() -1; 2976 x = textLine->length() -1;
2975 } 2977 }
2976 if (textLine->getAttr(x) == attr) { 2978 if (textLine->getAttr(x) == attr) {
2977 ch = textLine->getChar(x); 2979 ch = textLine->getChar(x);
2978 if (ch == bracket) count++; 2980 if (ch == bracket) count++;
2979 if (ch == opposite) { 2981 if (ch == opposite) {
2980 count--; 2982 count--;
2981 if (count < 0) goto found; 2983 if (count < 0) goto found;
2982 } 2984 }
2983 } 2985 }
2984 x--; 2986 x--;
2985 } 2987 }
2986 } 2988 }
2987 return; 2989 return;
2988 2990
2989found: 2991found:
2990 //cursor position of opposite bracket 2992 //cursor position of opposite bracket
2991 bm.cursor.x = x; 2993 bm.cursor.x = x;
2992 bm.cursor.y = line; 2994 bm.cursor.y = line;
2993 //x position (start and end) of related bracket 2995 //x position (start and end) of related bracket
2994 bm.sXPos = textWidth(textLine, x); 2996 bm.sXPos = textWidth(textLine, x);
2995 a = &m_attribs[attr]; 2997 a = &m_attribs[attr];
2996 2998
2997 if (a->bold && a->italic) 2999 if (a->bold && a->italic)
2998 bm.eXPos = bm.sXPos + myFontMetricsBI.width(bracket); 3000 bm.eXPos = bm.sXPos + myFontMetricsBI.width(bracket);
2999 else if (a->bold) 3001 else if (a->bold)
3000 bm.eXPos = bm.sXPos + myFontMetricsBold.width(bracket); 3002 bm.eXPos = bm.sXPos + myFontMetricsBold.width(bracket);
3001 else if (a->italic) 3003 else if (a->italic)
3002 bm.eXPos = bm.sXPos + myFontMetricsItalic.width(bracket); 3004 bm.eXPos = bm.sXPos + myFontMetricsItalic.width(bracket);
3003 else 3005 else
3004 bm.eXPos = bm.sXPos + myFontMetrics.width(bracket); 3006 bm.eXPos = bm.sXPos + myFontMetrics.width(bracket);
3005} 3007}
3006 3008
3007void KateDocument::clipboardChanged() { //slot 3009void KateDocument::clipboardChanged() { //slot
3008//#if defined(_WS_X11_) 3010//#if defined(_WS_X11_)
3009 if (m_singleSelection) { 3011 if (m_singleSelection) {
3010 disconnect(QApplication::clipboard(), SIGNAL(dataChanged()), 3012 disconnect(QApplication::clipboard(), SIGNAL(dataChanged()),
3011 this, SLOT(clipboardChanged())); 3013 this, SLOT(clipboardChanged()));
3012 deselectAll(); 3014 deselectAll();
3013 updateViews(); 3015 updateViews();
3014 } 3016 }
3015//#endif 3017//#endif
3016} 3018}
3017 3019
3018#if 0 3020#if 0
3019void KateDocument::guiActivateEvent( KParts::GUIActivateEvent *ev ) 3021void KateDocument::guiActivateEvent( KParts::GUIActivateEvent *ev )
3020{ 3022{
3021 KParts::ReadWritePart::guiActivateEvent( ev ); 3023 KParts::ReadWritePart::guiActivateEvent( ev );
3022 if ( ev->activated() ) 3024 if ( ev->activated() )
3023 emit selectionChanged(); 3025 emit selectionChanged();
3024} 3026}
3025#endif 3027#endif
3026 3028
3027void KateDocument::setDocName (QString docName) 3029void KateDocument::setDocName (QString docName)
3028{ 3030{
3029 myDocName = docName; 3031 myDocName = docName;
3030 emit nameChanged (this); 3032 emit nameChanged (this);
3031} 3033}
3032 3034
3035void KateDocument::setDocFile (QString docFile)
3036{
3037 m_file = docFile;
3038 emit fileNameChanged ();
3039}
3040
3033void KateDocument::setMTime() 3041void KateDocument::setMTime()
3034{ 3042{
3035 if (fileInfo && !fileInfo->fileName().isEmpty()) { 3043 if (fileInfo && !fileInfo->fileName().isEmpty()) {
3036 fileInfo->refresh(); 3044 fileInfo->refresh();
3037 mTime = fileInfo->lastModified(); 3045 mTime = fileInfo->lastModified();
3038 } 3046 }
3039} 3047}
3040 3048
3041void KateDocument::isModOnHD(bool forceReload) 3049void KateDocument::isModOnHD(bool forceReload)
3042{ 3050{
3043 if (fileInfo && !fileInfo->fileName().isEmpty()) { 3051 if (fileInfo && !fileInfo->fileName().isEmpty()) {
3044 fileInfo->refresh(); 3052 fileInfo->refresh();
3045 if (fileInfo->lastModified() > mTime) { 3053 if (fileInfo->lastModified() > mTime) {
3046 if ( forceReload || 3054 if ( forceReload ||
3047 (KMessageBox::warningContinueCancel(0, 3055 (KMessageBox::warningContinueCancel(0,
3048 (i18n("The file %1 has changed on disk.\nDo you want to reload it?\n\nIf you cancel you will lose these changes next time you save this file")).arg(m_url), 3056 (i18n("The file %1 has changed on disk.\nDo you want to reload it?\n\nIf you cancel you will lose these changes next time you save this file")).arg(m_url),
3049 i18n("File has changed on Disk"), 3057 i18n("File has changed on Disk"),
3050 i18n("Yes") ) == KMessageBox::Continue) 3058 i18n("Yes") ) == KMessageBox::Continue)
3051 ) 3059 )
3052 reloadFile(); 3060 reloadFile();
3053 else 3061 else
3054 setMTime(); 3062 setMTime();
3055 } 3063 }
3056 } 3064 }
3057} 3065}
3058 3066
3059void KateDocument::reloadFile() 3067void KateDocument::reloadFile()
3060{ 3068{
3061#warning fixme 3069#warning fixme
3062#if 0 3070#if 0
3063 if (fileInfo && !fileInfo->fileName().isEmpty()) { 3071 if (fileInfo && !fileInfo->fileName().isEmpty()) {
3064 KateDocument::openFile(); 3072 KateDocument::openFile();
3065 setMTime(); 3073 setMTime();
3066 } 3074 }
3067#endif 3075#endif
3068} 3076}
3069 3077
3070void KateDocument::slotModChanged() 3078void KateDocument::slotModChanged()
3071{ 3079{
3072 emit modStateChanged (this); 3080 emit modStateChanged (this);
3073} 3081}
3074 3082
3075QList<Kate::Mark> KateDocument::marks () 3083QList<Kate::Mark> KateDocument::marks ()
3076{ 3084{
3077 QList<Kate::Mark> list; 3085 QList<Kate::Mark> list;
3078 TextLine::Ptr line; 3086 TextLine::Ptr line;
3079 3087
3080 for (int i=0; i < numLines(); i++) 3088 for (int i=0; i < numLines(); i++)
3081 { 3089 {
3082 line = getTextLine(i); 3090 line = getTextLine(i);
3083 if (line->mark() != 0) 3091 if (line->mark() != 0)
3084 { 3092 {
3085 Kate::Mark *mark=new Kate::Mark; 3093 Kate::Mark *mark=new Kate::Mark;
3086 mark->line = i; 3094 mark->line = i;
3087 mark->type = line->mark(); 3095 mark->type = line->mark();
3088 list.append (mark); 3096 list.append (mark);
3089 } 3097 }
3090 } 3098 }
3091 3099
3092 return list; 3100 return list;
3093} 3101}
3094 3102
3095void KateDocument::flush () 3103void KateDocument::flush ()
3096{ 3104{
3097 if (isReadOnly()) 3105 if (isReadOnly())
3098 return; 3106 return;
3099 3107
3100 m_url = QString::null; 3108 m_url = QString::null;
3101 fileInfo->setFile (QString()); 3109 fileInfo->setFile (QString());
3102 setMTime(); 3110 setMTime();
3103 3111
3104 clear(); 3112 clear();
3105 updateViews(); 3113 updateViews();
3106 3114
3107 emit fileNameChanged (); 3115 emit fileNameChanged ();
3108} 3116}
3109 3117
3110void KateDocument::open (const QString &name) 3118void KateDocument::open (const QString &name)
3111{ 3119{
3112 openURL (name); 3120 openURL (name);
3113} 3121}
3114 3122
3115void KateDocument::wrapText (uint col) 3123void KateDocument::wrapText (uint col)
3116{ 3124{
3117 int line = 0; 3125 int line = 0;
3118 int z = 0; 3126 int z = 0;
3119 3127
3120 while(true) 3128 while(true)
3121 { 3129 {
3122 TextLine::Ptr l = getTextLine(line); 3130 TextLine::Ptr l = getTextLine(line);
3123 3131
3124 if (l->length() > col) 3132 if (l->length() > col)
3125 { 3133 {
3126 TextLine::Ptr tl = new TextLine(); 3134 TextLine::Ptr tl = new TextLine();
3127 buffer->insertLine(line+1,tl); 3135 buffer->insertLine(line+1,tl);
3128 const QChar *text = l->getText(); 3136 const QChar *text = l->getText();
3129 3137
3130 for (z=col; z>0; z--) 3138 for (z=col; z>0; z--)
3131 { 3139 {
3132 if (z < 1) break; 3140 if (z < 1) break;
3133 if (text[z].isSpace()) break; 3141 if (text[z].isSpace()) break;
3134 } 3142 }
3135 3143
3136 if (z < 1) z=col; 3144 if (z < 1) z=col;
3137 3145
3138 l->wrap (tl, z); 3146 l->wrap (tl, z);
3139 } 3147 }
3140 3148
3141 line++; 3149 line++;
3142 if (line >= numLines()) break; 3150 if (line >= numLines()) break;
3143 }; 3151 };
3144 3152
3145 newDocGeometry=true; 3153 newDocGeometry=true;
3146 updateLines(); 3154 updateLines();
3147 updateViews(); 3155 updateViews();
3148} 3156}
3149 3157
3150void KateDocument::setWordWrap (bool on) 3158void KateDocument::setWordWrap (bool on)
3151{ 3159{
3152 if (on != myWordWrap && on) 3160 if (on != myWordWrap && on)
3153 wrapText (myWordWrapAt); 3161 wrapText (myWordWrapAt);
3154 3162
3155 myWordWrap = on; 3163 myWordWrap = on;
3156} 3164}
3157 3165
3158void KateDocument::setWordWrapAt (uint col) 3166void KateDocument::setWordWrapAt (uint col)
3159{ 3167{
3160 if (myWordWrapAt != col && myWordWrap) 3168 if (myWordWrapAt != col && myWordWrap)
3161 wrapText (myWordWrapAt); 3169 wrapText (myWordWrapAt);
3162 3170
3163 myWordWrapAt = col; 3171 myWordWrapAt = col;
3164} 3172}
3165 3173
3166void KateDocument::applyWordWrap () 3174void KateDocument::applyWordWrap ()
3167{ 3175{
3168 wrapText (myWordWrapAt); 3176 wrapText (myWordWrapAt);
3169} 3177}
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.h b/noncore/apps/tinykate/libkate/document/katedocument.h
index 220d188..356541f 100644
--- a/noncore/apps/tinykate/libkate/document/katedocument.h
+++ b/noncore/apps/tinykate/libkate/document/katedocument.h
@@ -265,305 +265,306 @@ class KateDocument: public Kate::Document
265 protected slots: 265 protected slots:
266 void hlChanged(); 266 void hlChanged();
267 267
268// view interaction 268// view interaction
269 public: 269 public:
270 virtual void addView(KTextEditor::View *); 270 virtual void addView(KTextEditor::View *);
271 virtual void removeView(KTextEditor::View *); 271 virtual void removeView(KTextEditor::View *);
272 bool ownedView(KateView *); 272 bool ownedView(KateView *);
273 bool isLastView(int numViews); 273 bool isLastView(int numViews);
274 274
275 int getTextLineCount() {return numLines();} 275 int getTextLineCount() {return numLines();}
276 276
277 int textWidth(const TextLine::Ptr &, int cursorX); 277 int textWidth(const TextLine::Ptr &, int cursorX);
278 int textWidth(PointStruc &cursor); 278 int textWidth(PointStruc &cursor);
279 int textWidth(bool wrapCursor, PointStruc &cursor, int xPos); 279 int textWidth(bool wrapCursor, PointStruc &cursor, int xPos);
280 int textPos(const TextLine::Ptr &, int xPos); 280 int textPos(const TextLine::Ptr &, int xPos);
281// int textPos(TextLine::Ptr &, int xPos, int &newXPos); 281// int textPos(TextLine::Ptr &, int xPos, int &newXPos);
282 int textWidth(); 282 int textWidth();
283 int textHeight(); 283 int textHeight();
284 284
285 void insert(VConfig &, const QString &); 285 void insert(VConfig &, const QString &);
286 void insertFile(VConfig &, QIODevice &); 286 void insertFile(VConfig &, QIODevice &);
287 287
288 int currentColumn(PointStruc &cursor); 288 int currentColumn(PointStruc &cursor);
289 bool insertChars(VConfig &, const QString &chars); 289 bool insertChars(VConfig &, const QString &chars);
290 void newLine(VConfig &); 290 void newLine(VConfig &);
291 void killLine(VConfig &); 291 void killLine(VConfig &);
292 void backspace(VConfig &); 292 void backspace(VConfig &);
293 void del(VConfig &); 293 void del(VConfig &);
294 void clear(); 294 void clear();
295 void cut(VConfig &); 295 void cut(VConfig &);
296 void copy(int flags); 296 void copy(int flags);
297 void paste(VConfig &); 297 void paste(VConfig &);
298 298
299 void toggleRect(int, int, int, int); 299 void toggleRect(int, int, int, int);
300 void selectTo(VConfig &c, PointStruc &cursor, int cXPos); 300 void selectTo(VConfig &c, PointStruc &cursor, int cXPos);
301 void selectAll(); 301 void selectAll();
302 void deselectAll(); 302 void deselectAll();
303 void invertSelection(); 303 void invertSelection();
304 void selectWord(PointStruc &cursor, int flags); 304 void selectWord(PointStruc &cursor, int flags);
305 void selectLength(PointStruc &cursor, int length, int flags); 305 void selectLength(PointStruc &cursor, int length, int flags);
306 306
307 void indent(VConfig &c) {doIndent(c, 1);} 307 void indent(VConfig &c) {doIndent(c, 1);}
308 void unIndent(VConfig &c) {doIndent(c, -1);} 308 void unIndent(VConfig &c) {doIndent(c, -1);}
309 void cleanIndent(VConfig &c) {doIndent(c, 0);} 309 void cleanIndent(VConfig &c) {doIndent(c, 0);}
310 // called by indent/unIndent/cleanIndent 310 // called by indent/unIndent/cleanIndent
311 // just does some setup and then calls optimizeLeadingSpace() 311 // just does some setup and then calls optimizeLeadingSpace()
312 void doIndent(VConfig &, int change); 312 void doIndent(VConfig &, int change);
313 // optimize leading whitespace on a single line - see kwdoc.cpp for full description 313 // optimize leading whitespace on a single line - see kwdoc.cpp for full description
314 void optimizeLeadingSpace(int line, int flags, int change); 314 void optimizeLeadingSpace(int line, int flags, int change);
315 315
316 void comment(VConfig &c) {doComment(c, 1);} 316 void comment(VConfig &c) {doComment(c, 1);}
317 void unComment(VConfig &c) {doComment(c, -1);} 317 void unComment(VConfig &c) {doComment(c, -1);}
318 void doComment(VConfig &, int change); 318 void doComment(VConfig &, int change);
319 319
320 virtual QString text() const; 320 virtual QString text() const;
321 QString getWord(PointStruc &cursor); 321 QString getWord(PointStruc &cursor);
322 322
323 public slots: 323 public slots:
324 virtual void setText(const QString &); 324 virtual void setText(const QString &);
325 325
326 public: 326 public:
327 long needPreHighlight(long till); 327 long needPreHighlight(long till);
328 bool hasMarkedText() {return (selectEnd >= selectStart);} 328 bool hasMarkedText() {return (selectEnd >= selectStart);}
329 QString markedText(int flags); 329 QString markedText(int flags);
330 void delMarkedText(VConfig &/*, bool undo = true*/); 330 void delMarkedText(VConfig &/*, bool undo = true*/);
331 331
332 void tagLineRange(int line, int x1, int x2); 332 void tagLineRange(int line, int x1, int x2);
333 void tagLines(int start, int end); 333 void tagLines(int start, int end);
334 void tagAll(); 334 void tagAll();
335 void updateLines(int startLine = 0, int endLine = 0xffffff, int flags = 0, int cursorY = -1); 335 void updateLines(int startLine = 0, int endLine = 0xffffff, int flags = 0, int cursorY = -1);
336 void updateMaxLength(TextLine::Ptr &); 336 void updateMaxLength(TextLine::Ptr &);
337 void updateViews(KateView *exclude = 0L); 337 void updateViews(KateView *exclude = 0L);
338 338
339 QColor &cursorCol(int x, int y); 339 QColor &cursorCol(int x, int y);
340 void paintTextLine(QPainter &, int line, int xStart, int xEnd, bool showTabs); 340 void paintTextLine(QPainter &, int line, int xStart, int xEnd, bool showTabs);
341 void paintTextLine(QPainter &, int line, int y, int xStart, int xEnd, bool showTabs); 341 void paintTextLine(QPainter &, int line, int y, int xStart, int xEnd, bool showTabs);
342 342
343 bool doSearch(SConfig &s, const QString &searchFor); 343 bool doSearch(SConfig &s, const QString &searchFor);
344 344
345// internal 345// internal
346 void tagLine(int line); 346 void tagLine(int line);
347 void insLine(int line); 347 void insLine(int line);
348 void delLine(int line); 348 void delLine(int line);
349 void optimizeSelection(); 349 void optimizeSelection();
350 350
351 void doAction(KateAction *); 351 void doAction(KateAction *);
352 void doReplace(KateAction *); 352 void doReplace(KateAction *);
353 void doWordWrap(KateAction *); 353 void doWordWrap(KateAction *);
354 void doWordUnWrap(KateAction *); 354 void doWordUnWrap(KateAction *);
355 void doNewLine(KateAction *); 355 void doNewLine(KateAction *);
356 void doDelLine(KateAction *); 356 void doDelLine(KateAction *);
357 void doInsLine(KateAction *); 357 void doInsLine(KateAction *);
358 void doKillLine(KateAction *); 358 void doKillLine(KateAction *);
359 void newUndo(); 359 void newUndo();
360 360
361 void recordStart(VConfig &, int newUndoType); 361 void recordStart(VConfig &, int newUndoType);
362 void recordStart(KateView *, PointStruc &, int flags, int newUndoType, bool keepModal = false, bool mergeUndo = false); 362 void recordStart(KateView *, PointStruc &, int flags, int newUndoType, bool keepModal = false, bool mergeUndo = false);
363 void recordAction(KateAction::Action, PointStruc &); 363 void recordAction(KateAction::Action, PointStruc &);
364 void recordInsert(VConfig &, const QString &text); 364 void recordInsert(VConfig &, const QString &text);
365 void recordReplace(VConfig &, int len, const QString &text); 365 void recordReplace(VConfig &, int len, const QString &text);
366 void recordInsert(PointStruc &, const QString &text); 366 void recordInsert(PointStruc &, const QString &text);
367 void recordDelete(PointStruc &, int len); 367 void recordDelete(PointStruc &, int len);
368 void recordReplace(PointStruc &, int len, const QString &text); 368 void recordReplace(PointStruc &, int len, const QString &text);
369 void recordEnd(VConfig &); 369 void recordEnd(VConfig &);
370 void recordEnd(KateView *, PointStruc &, int flags); 370 void recordEnd(KateView *, PointStruc &, int flags);
371 void doActionGroup(KateActionGroup *, int flags, bool undo = false); 371 void doActionGroup(KateActionGroup *, int flags, bool undo = false);
372 372
373 int nextUndoType(); 373 int nextUndoType();
374 int nextRedoType(); 374 int nextRedoType();
375 void undoTypeList(QValueList<int> &lst); 375 void undoTypeList(QValueList<int> &lst);
376 void redoTypeList(QValueList<int> &lst); 376 void redoTypeList(QValueList<int> &lst);
377 void undo(VConfig &, int count = 1); 377 void undo(VConfig &, int count = 1);
378 void redo(VConfig &, int count = 1); 378 void redo(VConfig &, int count = 1);
379 void clearRedo(); 379 void clearRedo();
380 void setUndoSteps(int steps); 380 void setUndoSteps(int steps);
381 381
382 void setPseudoModal(QWidget *); 382 void setPseudoModal(QWidget *);
383 383
384 void newBracketMark(PointStruc &, BracketMark &); 384 void newBracketMark(PointStruc &, BracketMark &);
385 385
386 386
387 protected slots: 387 protected slots:
388 void clipboardChanged(); 388 void clipboardChanged();
389 void slotBufferChanged(); 389 void slotBufferChanged();
390 void slotBufferHighlight(long,long); 390 void slotBufferHighlight(long,long);
391 void doPreHighlight(); 391 void doPreHighlight();
392 392
393 private slots: 393 private slots:
394 void slotViewDestroyed(); 394 void slotViewDestroyed();
395 395
396// member variables 396// member variables
397 protected: 397 protected:
398 long PreHighlightedTill; 398 long PreHighlightedTill;
399 long RequestPreHighlightTill; 399 long RequestPreHighlightTill;
400 KWBuffer *buffer; 400 KWBuffer *buffer;
401 QColor colors[2]; 401 QColor colors[2];
402 HlManager *hlManager; 402 HlManager *hlManager;
403 Highlight *m_highlight; 403 Highlight *m_highlight;
404 int m_numAttribs; 404 int m_numAttribs;
405 static const int maxAttribs; 405 static const int maxAttribs;
406 Attribute *m_attribs; 406 Attribute *m_attribs;
407 407
408 int eolMode; 408 int eolMode;
409 409
410 int tabChars; 410 int tabChars;
411 int m_tabWidth; 411 int m_tabWidth;
412 int fontHeight; 412 int fontHeight;
413 int fontAscent; 413 int fontAscent;
414 414
415 QList<KateView> views; 415 QList<KateView> views;
416 bool newDocGeometry; 416 bool newDocGeometry;
417 417
418 TextLine::Ptr longestLine; 418 TextLine::Ptr longestLine;
419 float maxLength; 419 float maxLength;
420 420
421 PointStruc select; 421 PointStruc select;
422 PointStruc anchor; 422 PointStruc anchor;
423 int aXPos; 423 int aXPos;
424 int selectStart; 424 int selectStart;
425 int selectEnd; 425 int selectEnd;
426 bool oldMarkState; 426 bool oldMarkState;
427 bool m_singleSelection; // false: windows-like, true: X11-like 427 bool m_singleSelection; // false: windows-like, true: X11-like
428 428
429 bool readOnly; 429 bool readOnly;
430 bool newDoc; // True if the file is a new document (used to determine whether 430 bool newDoc; // True if the file is a new document (used to determine whether
431 // to check for overwriting files on save) 431 // to check for overwriting files on save)
432 bool modified; 432 bool modified;
433 433
434 bool myWordWrap; 434 bool myWordWrap;
435 uint myWordWrapAt; 435 uint myWordWrapAt;
436 436
437 QList<KateActionGroup> undoList; 437 QList<KateActionGroup> undoList;
438 int currentUndo; 438 int currentUndo;
439 int undoState; 439 int undoState;
440 int undoSteps; 440 int undoSteps;
441 int tagStart; 441 int tagStart;
442 int tagEnd; 442 int tagEnd;
443 int undoCount; //counts merged undo steps 443 int undoCount; //counts merged undo steps
444 444
445 QWidget *pseudoModal; //the replace prompt is pseudo modal 445 QWidget *pseudoModal; //the replace prompt is pseudo modal
446 446
447 public: 447 public:
448 /** Tjecks if the file on disk is newer than document contents. 448 /** Tjecks if the file on disk is newer than document contents.
449 If forceReload is true, the document is reloaded without asking the user, 449 If forceReload is true, the document is reloaded without asking the user,
450 otherwise [default] the user is asked what to do. */ 450 otherwise [default] the user is asked what to do. */
451 void isModOnHD(bool forceReload=false); 451 void isModOnHD(bool forceReload=false);
452 452
453 uint docID () {return myDocID;}; 453 uint docID () {return myDocID;};
454 QString docName () {return myDocName;}; 454 QString docName () {return myDocName;};
455 455
456 void setDocName (QString docName); 456 void setDocName (QString docName);
457 void setDocFile (QString docFile);
457 458
458 public slots: 459 public slots:
459 /** Reloads the current document from disk if possible */ 460 /** Reloads the current document from disk if possible */
460 void reloadFile(); 461 void reloadFile();
461 462
462 private slots: 463 private slots:
463 void slotModChanged (); 464 void slotModChanged ();
464 465
465 private: 466 private:
466 /** updates mTime to reflect file on fs. 467 /** updates mTime to reflect file on fs.
467 called from constructor and from saveFile. */ 468 called from constructor and from saveFile. */
468 void setMTime(); 469 void setMTime();
469 uint myDocID; 470 uint myDocID;
470 QFileInfo* fileInfo; 471 QFileInfo* fileInfo;
471 QDateTime mTime; 472 QDateTime mTime;
472 QString myDocName; 473 QString myDocName;
473 474
474 QString m_url; 475 QString m_url;
475 QString m_file; 476 QString m_file;
476 void openURL(const QString &filename); 477 void openURL(const QString &filename);
477 private: 478 private:
478 KateCmd *myCmd; 479 KateCmd *myCmd;
479 480
480 public: 481 public:
481 KateCmd *cmd () { return myCmd; }; 482 KateCmd *cmd () { return myCmd; };
482 483
483 private: 484 private:
484 QString myEncoding; 485 QString myEncoding;
485 486
486 public: 487 public:
487 void setEncoding (QString e) { myEncoding = e; }; 488 void setEncoding (QString e) { myEncoding = e; };
488 QString encoding() { return myEncoding; }; 489 QString encoding() { return myEncoding; };
489 490
490 void setWordWrap (bool on); 491 void setWordWrap (bool on);
491 bool wordWrap () { return myWordWrap; }; 492 bool wordWrap () { return myWordWrap; };
492 493
493 void setWordWrapAt (uint col); 494 void setWordWrapAt (uint col);
494 uint wordWrapAt () { return myWordWrapAt; }; 495 uint wordWrapAt () { return myWordWrapAt; };
495 496
496 signals: 497 signals:
497 void modStateChanged (KateDocument *doc); 498 void modStateChanged (KateDocument *doc);
498 void nameChanged (KateDocument *doc); 499 void nameChanged (KateDocument *doc);
499 500
500 public: 501 public:
501 QList<Kate::Mark> marks (); 502 QList<Kate::Mark> marks ();
502 503
503 public slots: 504 public slots:
504 // clear buffer/filename - update the views 505 // clear buffer/filename - update the views
505 void flush (); 506 void flush ();
506 507
507 signals: 508 signals:
508 /** 509 /**
509 The file has been saved (perhaps the name has changed). The main window 510 The file has been saved (perhaps the name has changed). The main window
510 can use this to change its caption 511 can use this to change its caption
511 */ 512 */
512 void fileNameChanged (); 513 void fileNameChanged ();
513 514
514 public: 515 public:
515 //end of line settings 516 //end of line settings
516 enum Eol_settings {eolUnix=0,eolDos=1,eolMacintosh=2}; 517 enum Eol_settings {eolUnix=0,eolDos=1,eolMacintosh=2};
517 518
518 // for the DCOP interface 519 // for the DCOP interface
519 public: 520 public:
520 void open (const QString &name=0); 521 void open (const QString &name=0);
521 522
522 public: 523 public:
523 // wrap the text of the document at the column col 524 // wrap the text of the document at the column col
524 void wrapText (uint col); 525 void wrapText (uint col);
525 526
526 public slots: 527 public slots:
527 void applyWordWrap (); 528 void applyWordWrap ();
528 529
529 private: 530 private:
530 531
531 class KateDocPrivate 532 class KateDocPrivate
532 { 533 {
533 public: 534 public:
534 bool hlSetByUser; 535 bool hlSetByUser;
535 }; 536 };
536 537
537 538
538// BCI: Add a real d-pointer in the next BIC release 539// BCI: Add a real d-pointer in the next BIC release
539static QPtrDict<KateDocPrivate>* d_ptr; 540static QPtrDict<KateDocPrivate>* d_ptr;
540static void cleanup_d_ptr() 541static void cleanup_d_ptr()
541 { 542 {
542 delete d_ptr; 543 delete d_ptr;
543 } 544 }
544 545
545KateDocPrivate* d( const KateDocument* foo ) 546KateDocPrivate* d( const KateDocument* foo )
546 { 547 {
547 if ( !d_ptr ) { 548 if ( !d_ptr ) {
548 d_ptr = new QPtrDict<KateDocPrivate>; 549 d_ptr = new QPtrDict<KateDocPrivate>;
549 //qAddPostRoutine( cleanup_d_ptr ); 550 //qAddPostRoutine( cleanup_d_ptr );
550 } 551 }
551 KateDocPrivate* ret = d_ptr->find( (void*) foo ); 552 KateDocPrivate* ret = d_ptr->find( (void*) foo );
552 if ( ! ret ) { 553 if ( ! ret ) {
553 ret = new KateDocPrivate; 554 ret = new KateDocPrivate;
554 d_ptr->replace( (void*) foo, ret ); 555 d_ptr->replace( (void*) foo, ret );
555 } 556 }
556 return ret; 557 return ret;
557 } 558 }
558 559
559void delete_d( const KateDocument* foo ) 560void delete_d( const KateDocument* foo )
560 { 561 {
561 if ( d_ptr ) 562 if ( d_ptr )
562 d_ptr->remove( (void*) foo ); 563 d_ptr->remove( (void*) foo );
563 } 564 }
564 565
565}; 566};
566 567
567#endif 568#endif
568 569
569 570