summaryrefslogtreecommitdiff
path: root/noncore
authorllornkcor <llornkcor>2002-12-26 03:48:32 (UTC)
committer llornkcor <llornkcor>2002-12-26 03:48:32 (UTC)
commitf736bf0ae774159a80a97b9492d7624e7caf07a3 (patch) (unidiff)
tree6e66396c264e2d878920ba273487c81abe7a474e /noncore
parent451d6a8692cf65d970b0c582e96e8a59072df191 (diff)
downloadopie-f736bf0ae774159a80a97b9492d7624e7caf07a3.zip
opie-f736bf0ae774159a80a97b9492d7624e7caf07a3.tar.gz
opie-f736bf0ae774159a80a97b9492d7624e7caf07a3.tar.bz2
added setDocFile function to change the filename needs more work
Diffstat (limited to 'noncore') (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
@@ -307,48 +307,49 @@ void KateDocument::openURL(const QString &filename)
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();
@@ -1904,49 +1905,50 @@ void KateDocument::tagAll() {
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());
@@ -3009,48 +3011,54 @@ void KateDocument::clipboardChanged() { //slot
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 }
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
@@ -433,48 +433,49 @@ class KateDocument: public Kate::Document
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:
@@ -507,53 +508,53 @@ class KateDocument: public Kate::Document
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 )