summaryrefslogtreecommitdiff
path: root/core/apps/textedit
authorllornkcor <llornkcor>2002-08-30 12:16:14 (UTC)
committer llornkcor <llornkcor>2002-08-30 12:16:14 (UTC)
commit73ccaa41947cd22902b96c18f3b96a6f9f3e565c (patch) (unidiff)
treedbddb746c97da59cd0af50e24ac2ef71603ee553 /core/apps/textedit
parent146dfec7bdcac24df009b434d0f4683c53ce7552 (diff)
downloadopie-73ccaa41947cd22902b96c18f3b96a6f9f3e565c.zip
opie-73ccaa41947cd22902b96c18f3b96a6f9f3e565c.tar.gz
opie-73ccaa41947cd22902b96c18f3b96a6f9f3e565c.tar.bz2
fixed canceling saveas dialog return
Diffstat (limited to 'core/apps/textedit') (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp158
1 files changed, 67 insertions, 91 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 107695a..d61da2a 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -363,8 +363,14 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
363 connect( nAdvanced, SIGNAL( toggled(bool) ), this, SLOT( doAdvanced(bool) ) ); 363 connect( nAdvanced, SIGNAL( toggled(bool) ), this, SLOT( doAdvanced(bool) ) );
364 nAdvanced->setToggleAction(TRUE); 364 nAdvanced->setToggleAction(TRUE);
365 nAdvanced->addTo( font ); 365 nAdvanced->addTo( font );
366 if(cfg.readBoolEntry("AdvancedFeatures")) 366
367 nAdvanced->setOn(TRUE); 367 if(cfg.readBoolEntry("AdvancedFeatures")) {
368 qDebug("using advanced features");
369 useAdvancedFeatures = true;
370 nAdvanced->setOn(TRUE);
371 } else
372 useAdvancedFeatures = false;
373
368 font->insertSeparator(); 374 font->insertSeparator();
369 375
370 font->insertItem(tr("About"), this, SLOT( doAbout()) ); 376 font->insertItem(tr("About"), this, SLOT( doAbout()) );
@@ -434,8 +440,10 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
434 viewSelection = cfg.readNumEntry( "FileView", 0 ); 440 viewSelection = cfg.readNumEntry( "FileView", 0 );
435} 441}
436 442
437void TextEdit::cleanUp() 443TextEdit::~TextEdit() {
438{ 444}
445
446void TextEdit::cleanUp() {
439// save(); 447// save();
440 Config cfg("TextEdit"); 448 Config cfg("TextEdit");
441 cfg.setGroup("View"); 449 cfg.setGroup("View");
@@ -445,26 +453,25 @@ void TextEdit::cleanUp()
445 cfg.writeEntry("Italic",f.italic()); 453 cfg.writeEntry("Italic",f.italic());
446 cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); 454 cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth);
447 cfg.writeEntry( "FileView", viewSelection ); 455 cfg.writeEntry( "FileView", viewSelection );
448
449} 456}
450 457
451TextEdit::~TextEdit() 458
452{ 459void TextEdit::accept() {
460 if(edited1)
461 saveAs();
462 exit(0);
453} 463}
454 464
455void TextEdit::zoomIn() 465void TextEdit::zoomIn() {
456{
457 setFontSize(editor->font().pointSize()+1,FALSE); 466 setFontSize(editor->font().pointSize()+1,FALSE);
458} 467}
459 468
460void TextEdit::zoomOut() 469void TextEdit::zoomOut() {
461{
462 setFontSize(editor->font().pointSize()-1,TRUE); 470 setFontSize(editor->font().pointSize()-1,TRUE);
463} 471}
464 472
465 473
466void TextEdit::setFontSize(int sz, bool round_down_not_up) 474void TextEdit::setFontSize(int sz, bool round_down_not_up) {
467{
468 int s=10; 475 int s=10;
469 for (int i=0; i<nfontsizes; i++) { 476 for (int i=0; i<nfontsizes; i++) {
470 if ( fontsize[i] == sz ) { 477 if ( fontsize[i] == sz ) {
@@ -489,37 +496,32 @@ void TextEdit::setFontSize(int sz, bool round_down_not_up)
489 zout->setEnabled(s != fontsize[0]); 496 zout->setEnabled(s != fontsize[0]);
490} 497}
491 498
492void TextEdit::setBold(bool y) 499void TextEdit::setBold(bool y) {
493{
494 QFont f = editor->font(); 500 QFont f = editor->font();
495 f.setBold(y); 501 f.setBold(y);
496 editor->setFont(f); 502 editor->setFont(f);
497} 503}
498 504
499void TextEdit::setItalic(bool y) 505void TextEdit::setItalic(bool y) {
500{
501 QFont f = editor->font(); 506 QFont f = editor->font();
502 f.setItalic(y); 507 f.setItalic(y);
503 editor->setFont(f); 508 editor->setFont(f);
504} 509}
505 510
506void TextEdit::setWordWrap(bool y) 511void TextEdit::setWordWrap(bool y) {
507{
508 bool state = editor->edited(); 512 bool state = editor->edited();
509 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); 513 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
510 editor->setEdited( state ); 514 editor->setEdited( state );
511} 515}
512 516
513void TextEdit::fileNew() 517void TextEdit::fileNew() {
514{
515// if( !bFromDocView ) { 518// if( !bFromDocView ) {
516// saveAs(); 519// saveAs();
517// } 520// }
518 newFile(DocLnk()); 521 newFile(DocLnk());
519} 522}
520 523
521void TextEdit::fileOpen() 524void TextEdit::fileOpen() {
522{
523 Config cfg("TextEdit"); 525 Config cfg("TextEdit");
524 cfg.setGroup("View"); 526 cfg.setGroup("View");
525 // bool b=FALSE; 527 // bool b=FALSE;
@@ -537,8 +539,7 @@ void TextEdit::fileOpen()
537 539
538} 540}
539 541
540void TextEdit::doSearchBar() 542void TextEdit::doSearchBar() {
541{
542 Config cfg("TextEdit"); 543 Config cfg("TextEdit");
543 cfg.setGroup("View"); 544 cfg.setGroup("View");
544 if(cfg.readEntry("SearchBar","Closed") != "Opened") 545 if(cfg.readEntry("SearchBar","Closed") != "Opened")
@@ -546,8 +547,7 @@ void TextEdit::doSearchBar()
546} 547}
547 548
548#if 0 549#if 0
549void TextEdit::slotFind() 550void TextEdit::slotFind() {
550{
551 FindDialog frmFind( tr("Text Editor"), this ); 551 FindDialog frmFind( tr("Text Editor"), this );
552 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), 552 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)),
553 editor, SLOT(slotDoFind( const QString&,bool,bool))); 553 editor, SLOT(slotDoFind( const QString&,bool,bool)));
@@ -565,35 +565,30 @@ void TextEdit::slotFind()
565} 565}
566#endif 566#endif
567 567
568void TextEdit::fileRevert() 568void TextEdit::fileRevert() {
569{
570 clear(); 569 clear();
571 fileOpen(); 570 fileOpen();
572} 571}
573 572
574void TextEdit::editCut() 573void TextEdit::editCut() {
575{
576#ifndef QT_NO_CLIPBOARD 574#ifndef QT_NO_CLIPBOARD
577 editor->cut(); 575 editor->cut();
578#endif 576#endif
579} 577}
580 578
581void TextEdit::editCopy() 579void TextEdit::editCopy() {
582{
583#ifndef QT_NO_CLIPBOARD 580#ifndef QT_NO_CLIPBOARD
584 editor->copy(); 581 editor->copy();
585#endif 582#endif
586} 583}
587 584
588void TextEdit::editPaste() 585void TextEdit::editPaste() {
589{
590#ifndef QT_NO_CLIPBOARD 586#ifndef QT_NO_CLIPBOARD
591 editor->paste(); 587 editor->paste();
592#endif 588#endif
593} 589}
594 590
595void TextEdit::editFind() 591void TextEdit::editFind() {
596{
597 searchBar->show(); 592 searchBar->show();
598 searchVisible = TRUE; 593 searchVisible = TRUE;
599 searchEdit->setFocus(); 594 searchEdit->setFocus();
@@ -603,14 +598,12 @@ void TextEdit::editFind()
603 598
604} 599}
605 600
606void TextEdit::findNext() 601void TextEdit::findNext() {
607{
608 editor->find( searchEdit->text(), FALSE, FALSE ); 602 editor->find( searchEdit->text(), FALSE, FALSE );
609 603
610} 604}
611 605
612void TextEdit::findClose() 606void TextEdit::findClose() {
613{
614 searchVisible = FALSE; 607 searchVisible = FALSE;
615 searchBar->hide(); 608 searchBar->hide();
616 Config cfg("TextEdit"); 609 Config cfg("TextEdit");
@@ -619,13 +612,11 @@ void TextEdit::findClose()
619 cfg.write(); 612 cfg.write();
620} 613}
621 614
622void TextEdit::search() 615void TextEdit::search() {
623{
624 editor->find( searchEdit->text(), FALSE, FALSE ); 616 editor->find( searchEdit->text(), FALSE, FALSE );
625} 617}
626 618
627void TextEdit::newFile( const DocLnk &f ) 619void TextEdit::newFile( const DocLnk &f ) {
628{
629 DocLnk nf = f; 620 DocLnk nf = f;
630 nf.setType("text/plain"); 621 nf.setType("text/plain");
631 clear(); 622 clear();
@@ -638,8 +629,7 @@ void TextEdit::newFile( const DocLnk &f )
638// editor->setEdited( FALSE); 629// editor->setEdited( FALSE);
639} 630}
640 631
641void TextEdit::openFile( const QString &f ) 632void TextEdit::openFile( const QString &f ) {
642{
643 qDebug("filename is "+ f); 633 qDebug("filename is "+ f);
644 QString filer; 634 QString filer;
645// bFromDocView = TRUE; 635// bFromDocView = TRUE;
@@ -678,8 +668,7 @@ void TextEdit::openFile( const QString &f )
678 updateCaption( name ); 668 updateCaption( name );
679} 669}
680 670
681void TextEdit::openFile( const DocLnk &f ) 671void TextEdit::openFile( const DocLnk &f ) {
682{
683// clear(); 672// clear();
684// bFromDocView = TRUE; 673// bFromDocView = TRUE;
685 FileManager fm; 674 FileManager fm;
@@ -703,8 +692,7 @@ void TextEdit::openFile( const DocLnk &f )
703 updateCaption(); 692 updateCaption();
704} 693}
705 694
706void TextEdit::showEditTools() 695void TextEdit::showEditTools() {
707{
708// if ( !doc ) 696// if ( !doc )
709// close(); 697// close();
710// clear(); 698// clear();
@@ -718,8 +706,7 @@ void TextEdit::showEditTools()
718 706
719/*! 707/*!
720 unprompted save */ 708 unprompted save */
721bool TextEdit::save() 709bool TextEdit::save() {
722{
723 QString file = doc->file(); 710 QString file = doc->file();
724 qDebug("saver file "+file); 711 qDebug("saver file "+file);
725 QString name= doc->name(); 712 QString name= doc->name();
@@ -771,15 +758,14 @@ bool TextEdit::save()
771 758
772/*! 759/*!
773 prompted save */ 760 prompted save */
774bool TextEdit::saveAs() 761bool TextEdit::saveAs() {
775{ 762 qDebug("saveAsFile "+currentFileName);
776// qDebug("saveAsFile "+currentFileName); 763 // case of nothing to save...
777 // case of nothing to save... 764 if ( !doc ) {
778 if ( !doc )//|| !bFromDocView) 765//|| !bFromDocView)
779 { 766 qDebug("no doc");
780 qDebug("no doc"); 767 return true;
781 return true; 768 }
782 }
783 if ( !editor->edited() ) { 769 if ( !editor->edited() ) {
784 delete doc; 770 delete doc;
785 doc = 0; 771 doc = 0;
@@ -790,7 +776,7 @@ bool TextEdit::saveAs()
790 qDebug(currentFileName); 776 qDebug(currentFileName);
791 777
792 if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { 778 if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) {
793 qDebug("do silly TT filename thing"); 779// qDebug("do silly TT filename thing");
794 if ( doc->name().isEmpty() ) { 780 if ( doc->name().isEmpty() ) {
795 QString pt = rt.simplifyWhiteSpace(); 781 QString pt = rt.simplifyWhiteSpace();
796 int i = pt.find( ' ' ); 782 int i = pt.find( ' ' );
@@ -818,7 +804,9 @@ bool TextEdit::saveAs()
818 map.insert(tr("Text"), text ); 804 map.insert(tr("Text"), text );
819 text << "*"; 805 text << "*";
820 map.insert(tr("All"), text ); 806 map.insert(tr("All"), text );
807
821 QString str = OFileDialog::getSaveFileName( 2,"/", QString::null, map); 808 QString str = OFileDialog::getSaveFileName( 2,"/", QString::null, map);
809
822 if(!str.isEmpty() ) { 810 if(!str.isEmpty() ) {
823 QString fileNm=str; 811 QString fileNm=str;
824 812
@@ -848,29 +836,29 @@ bool TextEdit::saveAs()
848 filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); 836 filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm);
849 filePerm->exec(); 837 filePerm->exec();
850 838
851 if( filePerm) 839 if( filePerm)
852 delete filePerm; 840 delete filePerm;
853 } 841 }
854 } 842 }
843 editor->setEdited( false);
844 edited1 = false;
845 edited = false;
846 if(caption().left(1)=="*")
847 setCaption(caption().right(caption().length()-1));
848
849 return true;
855 } 850 }
856 editor->setEdited(TRUE); 851 qDebug("returning false");
857 edited1=FALSE; 852 return false;
858 edited=TRUE;
859 if(caption().left(1)=="*")
860 setCaption(caption().right(caption().length()-1));
861
862 return true;
863} //end saveAs 853} //end saveAs
864 854
865void TextEdit::clear() 855void TextEdit::clear() {
866{
867 delete doc; 856 delete doc;
868 doc = 0; 857 doc = 0;
869 editor->clear(); 858 editor->clear();
870} 859}
871 860
872void TextEdit::updateCaption( const QString &name ) 861void TextEdit::updateCaption( const QString &name ) {
873{
874 if ( !doc ) 862 if ( !doc )
875 setCaption( tr("Text Editor") ); 863 setCaption( tr("Text Editor") );
876 else { 864 else {
@@ -887,8 +875,7 @@ void TextEdit::updateCaption( const QString &name )
887 } 875 }
888} 876}
889 877
890void TextEdit::setDocument(const QString& fileref) 878void TextEdit::setDocument(const QString& fileref) {
891{
892 bFromDocView = TRUE; 879 bFromDocView = TRUE;
893 openFile(fileref); 880 openFile(fileref);
894 editor->setEdited(TRUE); 881 editor->setEdited(TRUE);
@@ -897,21 +884,11 @@ void TextEdit::setDocument(const QString& fileref)
897 doSearchBar(); 884 doSearchBar();
898} 885}
899 886
900void TextEdit::closeEvent( QCloseEvent *e ) 887void TextEdit::closeEvent( QCloseEvent *e ) {
901{
902 bFromDocView = FALSE; 888 bFromDocView = FALSE;
903 e->accept(); 889 e->accept();
904} 890}
905 891
906void TextEdit::accept()
907 {
908 //if(caption() !="Unnamed")
909 if(edited1)
910 saveAs();
911 exit(0);
912
913}
914
915void TextEdit::changeFont() { 892void TextEdit::changeFont() {
916 FontDatabase fdb; 893 FontDatabase fdb;
917 QFont defaultFont=editor->font(); 894 QFont defaultFont=editor->font();
@@ -936,8 +913,7 @@ void TextEdit::changeFont() {
936 913
937} 914}
938 915
939void TextEdit::editDelete() 916void TextEdit::editDelete() {
940{
941 switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!"),tr("Yes"),tr("No"),0,0,1) ) { 917 switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!"),tr("Yes"),tr("No"),0,0,1) ) {
942 case 0: 918 case 0:
943 if(doc) { 919 if(doc) {