summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp40
-rw-r--r--core/apps/textedit/textedit.h2
2 files changed, 33 insertions, 9 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 84888c1..19449cb 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -337,32 +337,34 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
337 font->insertSeparator(); 337 font->insertSeparator();
338#endif 338#endif
339 339
340 QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); 340 QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 );
341 connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); 341 connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) );
342 wa->setToggleAction(TRUE); 342 wa->setToggleAction(TRUE);
343 wa->addTo( font ); 343 wa->addTo( font );
344 344
345 font->insertSeparator(); 345 font->insertSeparator();
346 font->insertItem(tr("Font"), this, SLOT(changeFont()) ); 346 font->insertItem(tr("Font"), this, SLOT(changeFont()) );
347 347
348 font->insertSeparator(); 348 font->insertSeparator();
349 nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); 349 nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 );
350 connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); 350 connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) );
351 nStart->setToggleAction(TRUE); 351 nStart->setToggleAction(TRUE);
352 nStart->addTo( font ); 352 nStart->addTo( font );
353 font->insertSeparator();
354 font->insertItem(tr("About"), this, SLOT( doAbout()) );
353 355
354 mb->insertItem( tr( "File" ), file ); 356 mb->insertItem( tr( "File" ), file );
355 mb->insertItem( tr( "Edit" ), edit ); 357 mb->insertItem( tr( "Edit" ), edit );
356 mb->insertItem( tr( "View" ), font ); 358 mb->insertItem( tr( "View" ), font );
357 359
358 searchBar = new QPEToolBar(this); 360 searchBar = new QPEToolBar(this);
359 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); 361 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE );
360 362
361 searchBar->setHorizontalStretchable( TRUE ); 363 searchBar->setHorizontalStretchable( TRUE );
362 364
363 searchEdit = new QLineEdit( searchBar, "searchEdit" ); 365 searchEdit = new QLineEdit( searchBar, "searchEdit" );
364 searchBar->setStretchableWidget( searchEdit ); 366 searchBar->setStretchableWidget( searchEdit );
365 connect( searchEdit, SIGNAL( textChanged( const QString & ) ), 367 connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
366 this, SLOT( search() ) ); 368 this, SLOT( search() ) );
367 369
368 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); 370 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
@@ -399,32 +401,33 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
399 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); 401 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
400 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); 402 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
401 403
402 defaultFont = fdb.font(family,style,i_size,charSet); 404 defaultFont = fdb.font(family,style,i_size,charSet);
403 editor->setFont( defaultFont); 405 editor->setFont( defaultFont);
404 406
405 wa->setOn(wrap); 407 wa->setOn(wrap);
406 updateCaption(); 408 updateCaption();
407 409
408 cfg.setGroup("View"); 410 cfg.setGroup("View");
409 if(cfg.readEntry("startNew","TRUE") == "TRUE") { 411 if(cfg.readEntry("startNew","TRUE") == "TRUE") {
410 nStart->setOn(TRUE); 412 nStart->setOn(TRUE);
411 fileNew(); 413 fileNew();
412 } else { 414 } else {
413 fileOpen(); 415 fileOpen();
414 } 416 }
417
415 viewSelection = cfg.readNumEntry( "FileView", 0 ); 418 viewSelection = cfg.readNumEntry( "FileView", 0 );
416} 419}
417 420
418void TextEdit::cleanUp() 421void TextEdit::cleanUp()
419{ 422{
420// save(); 423// save();
421 Config cfg("TextEdit"); 424 Config cfg("TextEdit");
422 cfg.setGroup("View"); 425 cfg.setGroup("View");
423 QFont f = editor->font(); 426 QFont f = editor->font();
424 cfg.writeEntry("FontSize",f.pointSize()); 427 cfg.writeEntry("FontSize",f.pointSize());
425 cfg.writeEntry("Bold",f.bold()); 428 cfg.writeEntry("Bold",f.bold());
426 cfg.writeEntry("Italic",f.italic()); 429 cfg.writeEntry("Italic",f.italic());
427 cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); 430 cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth);
428 cfg.writeEntry( "FileView", viewSelection ); 431 cfg.writeEntry( "FileView", viewSelection );
429 432
430} 433}
@@ -491,63 +494,63 @@ void TextEdit::setWordWrap(bool y)
491 editor->setEdited( state ); 494 editor->setEdited( state );
492} 495}
493 496
494void TextEdit::fileNew() 497void TextEdit::fileNew()
495{ 498{
496// if( !bFromDocView ) { 499// if( !bFromDocView ) {
497// saveAs(); 500// saveAs();
498// } 501// }
499 newFile(DocLnk()); 502 newFile(DocLnk());
500} 503}
501 504
502void TextEdit::fileOpen() 505void TextEdit::fileOpen()
503{ 506{
504 Config cfg("TextEdit"); 507 Config cfg("TextEdit");
505 cfg.setGroup("View"); 508 cfg.setGroup("View");
506 bool b=FALSE; 509 bool b=FALSE;
507 if(cfg.readEntry("useOldFileDialog") == "TRUE") 510 if(cfg.readEntry("useOldFileDialog") == "TRUE")
508 b=TRUE; 511 b=TRUE;
509 if(!b) { 512 if(!b) {
510 QString str = OFileDialog::getOpenFileName( 1,"/","", "text/plain", this ); 513 QString str = OFileDialog::getOpenFileName( 1,"/","", "text/plain", this );
511 if(!str.isEmpty() ) 514 if(!str.isEmpty() )
512 openFile( str ); 515 openFile( str );
513 } else { 516 } else {
514 QString str; 517 QString str;
515 browseForFiles = new fileBrowser(this,tr("Open File"),TRUE,0, "text/*"); // 518 browseForFiles = new fileBrowser(this,tr("Open File"),TRUE,0, "text/*"); //
516 browseForFiles->setFileView( viewSelection ); 519 browseForFiles->setFileView( viewSelection );
517 browseForFiles->showMaximized(); 520 browseForFiles->showMaximized();
518// if( result != -1 ) 521// if( result != -1 )
519 522
520 if( browseForFiles->exec() != -1 ) { 523 if( browseForFiles->exec() != -1 ) {
521 QString selFile = browseForFiles->selectedFileName; 524 QString selFile = browseForFiles->selectedFileName;
522 QStringList fileList = browseForFiles->fileList; 525 QStringList fileList = browseForFiles->fileList;
523 qDebug(selFile); 526 qDebug(selFile);
524 QStringList::ConstIterator f; 527 QStringList::ConstIterator f;
525 QString fileTemp; 528 QString fileTemp;
526 for ( f = fileList.begin(); f != fileList.end(); f++ ) { 529 for ( f = fileList.begin(); f != fileList.end(); f++ ) {
527 fileTemp = *f; 530 fileTemp = *f;
528 fileTemp.right( fileTemp.length()-5); 531 fileTemp.right( fileTemp.length()-5);
529 QString fileName = fileTemp; 532 QString fileName = fileTemp;
530 if( fileName != "Unnamed" || fileName != "Empty Text" ) { 533 if( fileName != "Unnamed" || fileName != "Empty Text" ) {
531 currentFileName = fileName; 534 currentFileName = fileName;
532 qDebug("please open "+currentFileName); 535 qDebug("please open "+currentFileName);
533 openFile(str ); 536 openFile(currentFileName );
534 } 537 }
535 } 538 }
536 viewSelection = browseForFiles->SelectionCombo->currentItem(); 539 viewSelection = browseForFiles->SelectionCombo->currentItem();
537 } 540 }
538 delete browseForFiles; 541 delete browseForFiles;
539 editor->setEdited( FALSE); 542 editor->setEdited( FALSE);
540 edited1=FALSE; 543 edited1=FALSE;
541 edited=FALSE; 544 edited=FALSE;
542 if(caption().left(1)=="*") 545 if(caption().left(1)=="*")
543 setCaption(caption().right(caption().length()-1)); 546 setCaption(caption().right(caption().length()-1));
544 doSearchBar(); 547 doSearchBar();
545 } 548 }
546} 549}
547 550
548void TextEdit::doSearchBar() 551void TextEdit::doSearchBar()
549{ 552{
550 Config cfg("TextEdit"); 553 Config cfg("TextEdit");
551 cfg.setGroup("View"); 554 cfg.setGroup("View");
552 if(cfg.readEntry("SearchBar","Closed") != "Opened") 555 if(cfg.readEntry("SearchBar","Closed") != "Opened")
553 searchBar->hide(); 556 searchBar->hide();
@@ -650,34 +653,36 @@ void TextEdit::openFile( const QString &f )
650{ 653{
651 qDebug("filename is "+ f); 654 qDebug("filename is "+ f);
652 QString filer; 655 QString filer;
653// bFromDocView = TRUE; 656// bFromDocView = TRUE;
654 if(f.find(".desktop",0,TRUE) != -1) { 657 if(f.find(".desktop",0,TRUE) != -1) {
655 switch ( QMessageBox::warning(this,tr("Text Editor"), 658 switch ( QMessageBox::warning(this,tr("Text Editor"),
656 tr("Text Editor has detected\n you selected a .desktop file.\nOpen .desktop file or linked file?"), 659 tr("Text Editor has detected\n you selected a .desktop file.\nOpen .desktop file or linked file?"),
657 tr(".desktop File"),tr("Linked Document"),0,1,1) ) { 660 tr(".desktop File"),tr("Linked Document"),0,1,1) ) {
658 case 0: 661 case 0:
659 filer = f; 662 filer = f;
660 break; 663 break;
661 case 1: 664 case 1:
662 DocLnk sf(f); 665 DocLnk sf(f);
663 filer = sf.file(); 666 filer = sf.file();
664 break; 667 break;
665 } 668 }
666 } else 669 } else {
667 filer = f; 670 filer = f;
671 fileIs = TRUE;
672 }
668 673
669 DocLnk nf; 674 DocLnk nf;
670 nf.setType("text/plain"); 675 nf.setType("text/plain");
671 nf.setFile(filer); 676 nf.setFile(filer);
672 currentFileName=filer; 677 currentFileName=filer;
673 QFileInfo fi( currentFileName); 678 QFileInfo fi( currentFileName);
674 nf.setName(fi.baseName()); 679 nf.setName(fi.baseName());
675 qDebug("openFile string "+currentFileName); 680 qDebug("openFile string "+currentFileName);
676 681
677 openFile(nf); 682 openFile(nf);
678 showEditTools(); 683 showEditTools();
679 // Show filename in caption 684 // Show filename in caption
680 QString name = filer; 685 QString name = filer;
681 int sep = name.findRev( '/' ); 686 int sep = name.findRev( '/' );
682 if ( sep > 0 ) 687 if ( sep > 0 )
683 name = name.mid( sep+1 ); 688 name = name.mid( sep+1 );
@@ -729,37 +734,48 @@ bool TextEdit::save()
729 QString file = doc->file(); 734 QString file = doc->file();
730 qDebug("saver file "+file); 735 qDebug("saver file "+file);
731 QString name= doc->name(); 736 QString name= doc->name();
732 qDebug("File named "+name); 737 qDebug("File named "+name);
733 QString rt = editor->text(); 738 QString rt = editor->text();
734 if( !rt.isEmpty() ) { 739 if( !rt.isEmpty() ) {
735 if(name.isEmpty()) { 740 if(name.isEmpty()) {
736 saveAs(); 741 saveAs();
737 } else { 742 } else {
738 currentFileName= name ; 743 currentFileName= name ;
739 qDebug("saveFile "+currentFileName); 744 qDebug("saveFile "+currentFileName);
740 745
741 struct stat buf; 746 struct stat buf;
742 mode_t mode; 747 mode_t mode;
743 stat(file.latin1(), &buf); 748 stat(file.latin1(), &buf);
744 mode = buf.st_mode; 749 mode = buf.st_mode;
745 750 if(!fileIs) {
746 doc->setName( name); 751 doc->setName( name);
747 FileManager fm; 752 FileManager fm;
748 if ( !fm.saveFile( *doc, rt ) ) { 753 if ( !fm.saveFile( *doc, rt ) ) {
749 return false; 754 return false;
755 }
756 } else {
757 qDebug("regular save file");
758 QFile f(file);
759 if( f.open(IO_WriteOnly)) {
760 f.writeBlock(rt,rt.length());
761 } else {
762 QMessageBox::message("Text Edit","Write Failed");
763 return false;
764 }
765
750 } 766 }
751 editor->setEdited( FALSE); 767 editor->setEdited( FALSE);
752 edited1=FALSE; 768 edited1=FALSE;
753 edited=FALSE; 769 edited=FALSE;
754 if(caption().left(1)=="*") 770 if(caption().left(1)=="*")
755 setCaption(caption().right(caption().length()-1)); 771 setCaption(caption().right(caption().length()-1));
756 772
757 773
758 chmod( file.latin1(), mode); 774 chmod( file.latin1(), mode);
759 } 775 }
760 return true; 776 return true;
761 } 777 }
762 return false; 778 return false;
763} 779}
764 780
765/*! 781/*!
@@ -956,16 +972,22 @@ void TextEdit::changeStartConfig( bool b ) {
956 972
957void TextEdit::editorChanged() { 973void TextEdit::editorChanged() {
958 if(editor->edited() && edited && !edited1) { 974 if(editor->edited() && edited && !edited1) {
959 setCaption( "*"+caption()); 975 setCaption( "*"+caption());
960 edited1=TRUE; 976 edited1=TRUE;
961 } 977 }
962 edited=TRUE; 978 edited=TRUE;
963} 979}
964 980
965void TextEdit::receive(const QCString&msg, const QByteArray&) { 981void TextEdit::receive(const QCString&msg, const QByteArray&) {
966 qDebug("QCop "+msg); 982 qDebug("QCop "+msg);
967 if ( msg == "setDocument(QString)" ) { 983 if ( msg == "setDocument(QString)" ) {
968 qDebug("bugger all"); 984 qDebug("bugger all");
969 } 985 }
970 986
971} 987}
988void TextEdit::doAbout() {
989 QMessageBox::about(0,"Text Edit","Text Edit is copyright\n"
990 "2000 Trolltech AS, and\n"
991 "2002 by L.J.Potter \nljp@llornkcor.com\n"
992 "and is licensed under the GPL");
993}
diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h
index edc6fe3..9d27ab0 100644
--- a/core/apps/textedit/textedit.h
+++ b/core/apps/textedit/textedit.h
@@ -52,35 +52,37 @@ class TextEdit : public QMainWindow
52{ 52{
53 Q_OBJECT 53 Q_OBJECT
54 54
55public: 55public:
56 TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); 56 TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
57 ~TextEdit(); 57 ~TextEdit();
58 58
59 QPopupMenu *font; 59 QPopupMenu *font;
60 QAction *nStart, *nFileDlgOpt; 60 QAction *nStart, *nFileDlgOpt;
61 bool edited, edited1; 61 bool edited, edited1;
62 void openFile( const QString & ); 62 void openFile( const QString & );
63 QCopChannel * channel; 63 QCopChannel * channel;
64public slots: 64public slots:
65 void editorChanged(); 65 void editorChanged();
66void receive(const QCString&, const QByteArray&); 66void receive(const QCString&, const QByteArray&);
67protected: 67protected:
68 bool fileIs;
68 void closeEvent( QCloseEvent *e ); 69 void closeEvent( QCloseEvent *e );
69 void doSearchBar(); 70 void doSearchBar();
70private slots: 71private slots:
72 void doAbout();
71 void setDocument(const QString&); 73 void setDocument(const QString&);
72 void changeFont(); 74 void changeFont();
73 void fileNew(); 75 void fileNew();
74 void fileRevert(); 76 void fileRevert();
75 void fileOpen(); 77 void fileOpen();
76 void changeStartConfig(bool); 78 void changeStartConfig(bool);
77 bool save(); 79 bool save();
78 bool saveAs(); 80 bool saveAs();
79 void cleanUp(); 81 void cleanUp();
80 82
81 83
82 void editCut(); 84 void editCut();
83 void editCopy(); 85 void editCopy();
84 void editPaste(); 86 void editPaste();
85 void editFind(); 87 void editFind();
86 void editDelete(); 88 void editDelete();