summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-12-20 13:53:13 (UTC)
committer llornkcor <llornkcor>2002-12-20 13:53:13 (UTC)
commit9c92aad4a3d8d83fa41e25ce58d5103599826a5b (patch) (unidiff)
treec6cbd45f55da507ee1f0e53bebc63d9bb0db94e9
parentb7dafc7fc37d05498cf3ad7b7d0981bf3a341b4a (diff)
downloadopie-9c92aad4a3d8d83fa41e25ce58d5103599826a5b.zip
opie-9c92aad4a3d8d83fa41e25ce58d5103599826a5b.tar.gz
opie-9c92aad4a3d8d83fa41e25ce58d5103599826a5b.tar.bz2
save fix when no name bug #577
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index bd7cfb6..4f4f994 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -534,513 +534,518 @@ void TextEdit::setFontSize(int sz, bool round_down_not_up) {
534 QFont f = editor->font(); 534 QFont f = editor->font();
535 f.setPointSize(s); 535 f.setPointSize(s);
536 editor->setFont(f); 536 editor->setFont(f);
537 537
538 zin->setEnabled(s != fontsize[nfontsizes-1]); 538 zin->setEnabled(s != fontsize[nfontsizes-1]);
539 zout->setEnabled(s != fontsize[0]); 539 zout->setEnabled(s != fontsize[0]);
540} 540}
541 541
542void TextEdit::setBold(bool y) { 542void TextEdit::setBold(bool y) {
543 QFont f = editor->font(); 543 QFont f = editor->font();
544 f.setBold(y); 544 f.setBold(y);
545 editor->setFont(f); 545 editor->setFont(f);
546} 546}
547 547
548void TextEdit::setItalic(bool y) { 548void TextEdit::setItalic(bool y) {
549 QFont f = editor->font(); 549 QFont f = editor->font();
550 f.setItalic(y); 550 f.setItalic(y);
551 editor->setFont(f); 551 editor->setFont(f);
552} 552}
553 553
554void TextEdit::setWordWrap(bool y) { 554void TextEdit::setWordWrap(bool y) {
555 bool state = editor->edited(); 555 bool state = editor->edited();
556 QString captionStr = caption(); 556 QString captionStr = caption();
557 bool b1 = edited1; 557 bool b1 = edited1;
558 bool b2 = edited; 558 bool b2 = edited;
559 559
560 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); 560 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
561 editor->setEdited( state ); 561 editor->setEdited( state );
562 edited1=b1; 562 edited1=b1;
563 edited=b2; 563 edited=b2;
564 setCaption(captionStr); 564 setCaption(captionStr);
565} 565}
566 566
567void TextEdit::setSearchBar(bool b) { 567void TextEdit::setSearchBar(bool b) {
568 useSearchBar=b; 568 useSearchBar=b;
569 Config cfg("TextEdit"); 569 Config cfg("TextEdit");
570 cfg.setGroup("View"); 570 cfg.setGroup("View");
571 cfg.writeEntry ( "SearchBar", b ); 571 cfg.writeEntry ( "SearchBar", b );
572 searchBarAction->setOn(b); 572 searchBarAction->setOn(b);
573 if(b) 573 if(b)
574 searchBar->show(); 574 searchBar->show();
575 else 575 else
576 searchBar->hide(); 576 searchBar->hide();
577 editor->setFocus(); 577 editor->setFocus();
578} 578}
579 579
580void TextEdit::fileNew() { 580void TextEdit::fileNew() {
581// if( !bFromDocView ) { 581// if( !bFromDocView ) {
582// saveAs(); 582// saveAs();
583// } 583// }
584 newFile(DocLnk()); 584 newFile(DocLnk());
585} 585}
586 586
587void TextEdit::fileOpen() { 587void TextEdit::fileOpen() {
588 QMap<QString, QStringList> map; 588 QMap<QString, QStringList> map;
589 map.insert(tr("All"), QStringList() ); 589 map.insert(tr("All"), QStringList() );
590 QStringList text; 590 QStringList text;
591 text << "text/*"; 591 text << "text/*";
592 map.insert(tr("Text"), text ); 592 map.insert(tr("Text"), text );
593 text << "*"; 593 text << "*";
594 map.insert(tr("All"), text ); 594 map.insert(tr("All"), text );
595 QString str = OFileDialog::getOpenFileName( 2, 595 QString str = OFileDialog::getOpenFileName( 2,
596 QPEApplication::documentDir(), 596 QPEApplication::documentDir(),
597 QString::null, map); 597 QString::null, map);
598 if( QFile(str).exists()) 598 if( QFile(str).exists())
599 openFile( str ); 599 openFile( str );
600 else 600 else
601 updateCaption(); 601 updateCaption();
602} 602}
603 603
604void TextEdit::doSearchBar() { 604void TextEdit::doSearchBar() {
605 if(!useSearchBar) 605 if(!useSearchBar)
606 searchBar->hide(); 606 searchBar->hide();
607 else 607 else
608 searchBar->show(); 608 searchBar->show();
609} 609}
610 610
611#if 0 611#if 0
612void TextEdit::slotFind() { 612void TextEdit::slotFind() {
613 FindDialog frmFind( tr("Text Editor"), this ); 613 FindDialog frmFind( tr("Text Editor"), this );
614 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), 614 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)),
615 editor, SLOT(slotDoFind( const QString&,bool,bool))); 615 editor, SLOT(slotDoFind( const QString&,bool,bool)));
616 616
617 //case sensitive, backwards, [category] 617 //case sensitive, backwards, [category]
618 618
619 connect( editor, SIGNAL(notFound()), 619 connect( editor, SIGNAL(notFound()),
620 &frmFind, SLOT(slotNotFound()) ); 620 &frmFind, SLOT(slotNotFound()) );
621 connect( editor, SIGNAL(searchWrapped()), 621 connect( editor, SIGNAL(searchWrapped()),
622 &frmFind, SLOT(slotWrapAround()) ); 622 &frmFind, SLOT(slotWrapAround()) );
623 623
624 frmFind.exec(); 624 frmFind.exec();
625 625
626 626
627} 627}
628#endif 628#endif
629 629
630void TextEdit::fileRevert() { 630void TextEdit::fileRevert() {
631 clear(); 631 clear();
632 fileOpen(); 632 fileOpen();
633} 633}
634 634
635void TextEdit::editCut() { 635void TextEdit::editCut() {
636#ifndef QT_NO_CLIPBOARD 636#ifndef QT_NO_CLIPBOARD
637 editor->cut(); 637 editor->cut();
638#endif 638#endif
639} 639}
640 640
641void TextEdit::editCopy() { 641void TextEdit::editCopy() {
642#ifndef QT_NO_CLIPBOARD 642#ifndef QT_NO_CLIPBOARD
643 editor->copy(); 643 editor->copy();
644#endif 644#endif
645} 645}
646 646
647void TextEdit::editPaste() { 647void TextEdit::editPaste() {
648#ifndef QT_NO_CLIPBOARD 648#ifndef QT_NO_CLIPBOARD
649 editor->paste(); 649 editor->paste();
650#endif 650#endif
651} 651}
652 652
653void TextEdit::editFind() { 653void TextEdit::editFind() {
654 searchBar->show(); 654 searchBar->show();
655 searchEdit->setFocus(); 655 searchEdit->setFocus();
656} 656}
657 657
658void TextEdit::findNext() { 658void TextEdit::findNext() {
659 editor->find( searchEdit->text(), false, false ); 659 editor->find( searchEdit->text(), false, false );
660 660
661} 661}
662 662
663void TextEdit::findClose() { 663void TextEdit::findClose() {
664 searchBar->hide(); 664 searchBar->hide();
665} 665}
666 666
667void TextEdit::search() { 667void TextEdit::search() {
668 editor->find( searchEdit->text(), false, false ); 668 editor->find( searchEdit->text(), false, false );
669} 669}
670 670
671void TextEdit::newFile( const DocLnk &f ) { 671void TextEdit::newFile( const DocLnk &f ) {
672 DocLnk nf = f; 672 DocLnk nf = f;
673 nf.setType("text/plain"); 673 nf.setType("text/plain");
674 clear(); 674 clear();
675 setWState (WState_Reserved1 ); 675 setWState (WState_Reserved1 );
676 editor->setFocus(); 676 editor->setFocus();
677 doc = new DocLnk(nf); 677 doc = new DocLnk(nf);
678 currentFileName = "Unnamed"; 678 currentFileName = "Unnamed";
679 qDebug("newFile "+currentFileName); 679 qDebug("newFile "+currentFileName);
680 updateCaption( currentFileName); 680 updateCaption( currentFileName);
681// editor->setEdited( false); 681// editor->setEdited( false);
682} 682}
683 683
684void TextEdit::openDotFile( const QString &f ) { 684void TextEdit::openDotFile( const QString &f ) {
685 if(!currentFileName.isEmpty()) { 685 if(!currentFileName.isEmpty()) {
686 currentFileName=f; 686 currentFileName=f;
687 687
688 qDebug("openFile dotfile " + currentFileName); 688 qDebug("openFile dotfile " + currentFileName);
689 QString txt; 689 QString txt;
690 QFile file(f); 690 QFile file(f);
691 file.open(IO_ReadWrite); 691 file.open(IO_ReadWrite);
692 QTextStream t(&file); 692 QTextStream t(&file);
693 while ( !t.atEnd()) { 693 while ( !t.atEnd()) {
694 txt+=t.readLine()+"\n"; 694 txt+=t.readLine()+"\n";
695 } 695 }
696 editor->setText(txt); 696 editor->setText(txt);
697 editor->setEdited( false); 697 editor->setEdited( false);
698 edited1=false; 698 edited1=false;
699 edited=false; 699 edited=false;
700 700
701 701
702 } 702 }
703 updateCaption( currentFileName); 703 updateCaption( currentFileName);
704} 704}
705 705
706void TextEdit::openFile( const QString &f ) { 706void TextEdit::openFile( const QString &f ) {
707 qDebug("filename is "+ f); 707 qDebug("filename is "+ f);
708 QString filer; 708 QString filer;
709 QFileInfo fi( f); 709 QFileInfo fi( f);
710// bFromDocView = true; 710// bFromDocView = true;
711 if(f.find(".desktop",0,true) != -1 && !openDesktop ) { 711 if(f.find(".desktop",0,true) != -1 && !openDesktop ) {
712 switch ( QMessageBox::warning(this,tr("Text Editor"), 712 switch ( QMessageBox::warning(this,tr("Text Editor"),
713 tr("Text Editor has detected<BR>you selected a <B>.desktop</B> 713 tr("Text Editor has detected<BR>you selected a <B>.desktop</B>
714file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), 714file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"),
715 tr(".desktop File"),tr("Linked Document"),0,1,1) ) { 715 tr(".desktop File"),tr("Linked Document"),0,1,1) ) {
716 case 0: 716 case 0:
717 filer = f; 717 filer = f;
718 break; 718 break;
719 case 1: 719 case 1:
720 DocLnk sf(f); 720 DocLnk sf(f);
721 filer = sf.file(); 721 filer = sf.file();
722 break; 722 break;
723 } 723 }
724 } else if(fi.baseName().left(1) == "") { 724 } else if(fi.baseName().left(1) == "") {
725 currentFileName=f; 725 currentFileName=f;
726 openDotFile(currentFileName); 726 openDotFile(currentFileName);
727 } else { 727 } else {
728 DocLnk sf(f); 728 DocLnk sf(f);
729 filer = sf.file(); 729 filer = sf.file();
730 if(filer.right(1) == "/") 730 if(filer.right(1) == "/")
731 filer = f; 731 filer = f;
732 } 732 }
733 733
734 DocLnk nf; 734 DocLnk nf;
735 nf.setType("text/plain"); 735 nf.setType("text/plain");
736 nf.setFile(filer); 736 nf.setFile(filer);
737 currentFileName=filer; 737 currentFileName=filer;
738 738
739 nf.setName(fi.baseName()); 739 nf.setName(fi.baseName());
740 openFile(nf); 740 openFile(nf);
741 741
742 qDebug("openFile string "+currentFileName); 742 qDebug("openFile string "+currentFileName);
743 743
744 showEditTools(); 744 showEditTools();
745 // Show filename in caption 745 // Show filename in caption
746 QString name = filer; 746 QString name = filer;
747 int sep = name.findRev( '/' ); 747 int sep = name.findRev( '/' );
748 if ( sep > 0 ) 748 if ( sep > 0 )
749 name = name.mid( sep+1 ); 749 name = name.mid( sep+1 );
750 updateCaption( name ); 750 updateCaption( name );
751} 751}
752 752
753void TextEdit::openFile( const DocLnk &f ) { 753void TextEdit::openFile( const DocLnk &f ) {
754// clear(); 754// clear();
755// bFromDocView = true; 755// bFromDocView = true;
756 FileManager fm; 756 FileManager fm;
757 QString txt; 757 QString txt;
758 currentFileName=f.file(); 758 currentFileName=f.file();
759 qDebug("openFile doclnk " + currentFileName); 759 qDebug("openFile doclnk " + currentFileName);
760 if ( !fm.loadFile( f, txt ) ) { 760 if ( !fm.loadFile( f, txt ) ) {
761 // ####### could be a new file 761 // ####### could be a new file
762 qDebug( "Cannot open file" ); 762 qDebug( "Cannot open file" );
763 } 763 }
764// fileNew(); 764// fileNew();
765 if ( doc ) 765 if ( doc )
766 delete doc; 766 delete doc;
767 doc = new DocLnk(f); 767 doc = new DocLnk(f);
768 editor->setText(txt); 768 editor->setText(txt);
769 editor->setEdited( false); 769 editor->setEdited( false);
770 edited1=false; 770 edited1=false;
771 edited=false; 771 edited=false;
772 772
773 doc->setName(currentFileName); 773 doc->setName(currentFileName);
774 updateCaption(); 774 updateCaption();
775} 775}
776 776
777void TextEdit::showEditTools() { 777void TextEdit::showEditTools() {
778 menu->show(); 778 menu->show();
779 editBar->show(); 779 editBar->show();
780 if(!useSearchBar) 780 if(!useSearchBar)
781 searchBar->hide(); 781 searchBar->hide();
782 else 782 else
783 searchBar->show(); 783 searchBar->show();
784 setWState (WState_Reserved1 ); 784 setWState (WState_Reserved1 );
785} 785}
786 786
787/*! 787/*!
788 unprompted save */ 788 unprompted save */
789bool TextEdit::save() { 789bool TextEdit::save() {
790 QString file = doc->file(); 790 qDebug("saveAsFile " + currentFileName);
791 if(currentFileName.isEmpty()) {
792 saveAs();
793 return;
794 }
795 QString file = doc->file();
791 qDebug("saver file "+file); 796 qDebug("saver file "+file);
792 QString name= doc->name(); 797 QString name= doc->name();
793 qDebug("File named "+name); 798 qDebug("File named "+name);
794 QString rt = editor->text(); 799 QString rt = editor->text();
795 if( !rt.isEmpty() ) { 800 if( !rt.isEmpty() ) {
796 if(name.isEmpty()) { 801 if(name.isEmpty()) {
797 saveAs(); 802 saveAs();
798 } else { 803 } else {
799 currentFileName= name ; 804 currentFileName= name ;
800 qDebug("saveFile "+currentFileName); 805 qDebug("saveFile "+currentFileName);
801 806
802 struct stat buf; 807 struct stat buf;
803 mode_t mode; 808 mode_t mode;
804 stat(file.latin1(), &buf); 809 stat(file.latin1(), &buf);
805 mode = buf.st_mode; 810 mode = buf.st_mode;
806 811
807 if(!fileIs) { 812 if(!fileIs) {
808 doc->setName( name); 813 doc->setName( name);
809 FileManager fm; 814 FileManager fm;
810 if ( !fm.saveFile( *doc, rt ) ) { 815 if ( !fm.saveFile( *doc, rt ) ) {
811 return false; 816 return false;
812 } 817 }
813 } else { 818 } else {
814 qDebug("regular save file"); 819 qDebug("regular save file");
815 QFile f(file); 820 QFile f(file);
816 if( f.open(IO_WriteOnly)) { 821 if( f.open(IO_WriteOnly)) {
817 QCString crt = rt.utf8(); 822 QCString crt = rt.utf8();
818 f.writeBlock(crt,crt.length()); 823 f.writeBlock(crt,crt.length());
819 } else { 824 } else {
820 QMessageBox::message(tr("Text Edit"),tr("Write Failed")); 825 QMessageBox::message(tr("Text Edit"),tr("Write Failed"));
821 return false; 826 return false;
822 } 827 }
823 828
824 } 829 }
825 editor->setEdited( false); 830 editor->setEdited( false);
826 edited1=false; 831 edited1=false;
827 edited=false; 832 edited=false;
828 if(caption().left(1)=="*") 833 if(caption().left(1)=="*")
829 setCaption(caption().right(caption().length()-1)); 834 setCaption(caption().right(caption().length()-1));
830 835
831 836
832 chmod( file.latin1(), mode); 837 chmod( file.latin1(), mode);
833 } 838 }
834 return true; 839 return true;
835 } 840 }
836 return false; 841 return false;
837} 842}
838 843
839/*! 844/*!
840 prompted save */ 845 prompted save */
841bool TextEdit::saveAs() { 846bool TextEdit::saveAs() {
842 if(caption() == tr("Text Editor")) 847 if(caption() == tr("Text Editor"))
843 return false; 848 return false;
844 qDebug("saveAsFile " + currentFileName); 849 qDebug("saveAsFile " + currentFileName);
845 // case of nothing to save... 850 // case of nothing to save...
846// if ( !doc && !currentFileName.isEmpty()) { 851// if ( !doc && !currentFileName.isEmpty()) {
847// //|| !bFromDocView) 852// //|| !bFromDocView)
848// qDebug("no doc"); 853// qDebug("no doc");
849// return true; 854// return true;
850// } 855// }
851// if ( !editor->edited() ) { 856// if ( !editor->edited() ) {
852// delete doc; 857// delete doc;
853// doc = 0; 858// doc = 0;
854// return true; 859// return true;
855// } 860// }
856 861
857 QString rt = editor->text(); 862 QString rt = editor->text();
858 qDebug(currentFileName); 863 qDebug(currentFileName);
859 864
860 if( currentFileName.isEmpty() 865 if( currentFileName.isEmpty()
861 || currentFileName == tr("Unnamed") 866 || currentFileName == tr("Unnamed")
862 || currentFileName == tr("Text Editor")) { 867 || currentFileName == tr("Text Editor")) {
863 qDebug("do silly TT filename thing"); 868 qDebug("do silly TT filename thing");
864// if ( doc && doc->name().isEmpty() ) { 869// if ( doc && doc->name().isEmpty() ) {
865 QString pt = rt.simplifyWhiteSpace(); 870 QString pt = rt.simplifyWhiteSpace();
866 int i = pt.find( ' ' ); 871 int i = pt.find( ' ' );
867 QString docname = pt; 872 QString docname = pt;
868 if ( i > 0 ) 873 if ( i > 0 )
869 docname = pt.left( i ); 874 docname = pt.left( i );
870 // remove "." at the beginning 875 // remove "." at the beginning
871 while( docname.startsWith( "." ) ) 876 while( docname.startsWith( "." ) )
872 docname = docname.mid( 1 ); 877 docname = docname.mid( 1 );
873 docname.replace( QRegExp("/"), "_" ); 878 docname.replace( QRegExp("/"), "_" );
874 // cut the length. filenames longer than that 879 // cut the length. filenames longer than that
875 //don't make sense and something goes wrong when they get too long. 880 //don't make sense and something goes wrong when they get too long.
876 if ( docname.length() > 40 ) 881 if ( docname.length() > 40 )
877 docname = docname.left(40); 882 docname = docname.left(40);
878 if ( docname.isEmpty() ) 883 if ( docname.isEmpty() )
879 docname = tr("Unnamed"); 884 docname = tr("Unnamed");
880 if(doc) doc->setName(docname); 885 if(doc) doc->setName(docname);
881 currentFileName=docname; 886 currentFileName=docname;
882// } 887// }
883// else 888// else
884// qDebug("hmmmmmm"); 889// qDebug("hmmmmmm");
885 } 890 }
886 891
887 892
888 QMap<QString, QStringList> map; 893 QMap<QString, QStringList> map;
889 map.insert(tr("All"), QStringList() ); 894 map.insert(tr("All"), QStringList() );
890 QStringList text; 895 QStringList text;
891 text << "text/*"; 896 text << "text/*";
892 map.insert(tr("Text"), text ); 897 map.insert(tr("Text"), text );
893 text << "*"; 898 text << "*";
894 map.insert(tr("All"), text ); 899 map.insert(tr("All"), text );
895 900
896 QFileInfo cuFi( currentFileName); 901 QFileInfo cuFi( currentFileName);
897 QString filee = cuFi.fileName(); 902 QString filee = cuFi.fileName();
898 QString dire = cuFi.dirPath(); 903 QString dire = cuFi.dirPath();
899 if(dire==".") 904 if(dire==".")
900 dire = QPEApplication::documentDir(); 905 dire = QPEApplication::documentDir();
901 QString str = OFileDialog::getSaveFileName( 2, 906 QString str = OFileDialog::getSaveFileName( 2,
902 dire, 907 dire,
903 filee, map); 908 filee, map);
904 909
905 if(!str.isEmpty()) { 910 if(!str.isEmpty()) {
906 QString fileNm=str; 911 QString fileNm=str;
907 912
908 qDebug("saving filename "+fileNm); 913 qDebug("saving filename "+fileNm);
909 QFileInfo fi(fileNm); 914 QFileInfo fi(fileNm);
910 currentFileName=fi.fileName(); 915 currentFileName=fi.fileName();
911 if(doc) 916 if(doc)
912// QString file = doc->file(); 917// QString file = doc->file();
913// doc->removeFiles(); 918// doc->removeFiles();
914 delete doc; 919 delete doc;
915 DocLnk nf; 920 DocLnk nf;
916 nf.setType("text/plain"); 921 nf.setType("text/plain");
917 nf.setFile( fileNm); 922 nf.setFile( fileNm);
918 doc = new DocLnk(nf); 923 doc = new DocLnk(nf);
919// editor->setText(rt); 924// editor->setText(rt);
920 qDebug("Saving file as "+currentFileName); 925 qDebug("Saving file as "+currentFileName);
921 doc->setName( currentFileName); 926 doc->setName( currentFileName);
922 updateCaption( currentFileName); 927 updateCaption( currentFileName);
923 928
924 FileManager fm; 929 FileManager fm;
925 if ( !fm.saveFile( *doc, rt ) ) { 930 if ( !fm.saveFile( *doc, rt ) ) {
926 return false; 931 return false;
927 } 932 }
928 933
929 if( filePerms ) { 934 if( filePerms ) {
930 filePermissions *filePerm; 935 filePermissions *filePerm;
931 filePerm = new filePermissions(this, 936 filePerm = new filePermissions(this,
932 tr("Permissions"),true, 937 tr("Permissions"),true,
933 0,(const QString &)fileNm); 938 0,(const QString &)fileNm);
934 filePerm->showMaximized(); 939 filePerm->showMaximized();
935 filePerm->exec(); 940 filePerm->exec();
936 941
937 if( filePerm) 942 if( filePerm)
938 delete filePerm; 943 delete filePerm;
939 } 944 }
940// } 945// }
941 editor->setEdited( false); 946 editor->setEdited( false);
942 edited1 = false; 947 edited1 = false;
943 edited = false; 948 edited = false;
944 if(caption().left(1)=="*") 949 if(caption().left(1)=="*")
945 setCaption(caption().right(caption().length()-1)); 950 setCaption(caption().right(caption().length()-1));
946 951
947 return true; 952 return true;
948 } 953 }
949 qDebug("returning false"); 954 qDebug("returning false");
950 return false; 955 return false;
951} //end saveAs 956} //end saveAs
952 957
953void TextEdit::clear() { 958void TextEdit::clear() {
954 delete doc; 959 delete doc;
955 doc = 0; 960 doc = 0;
956 editor->clear(); 961 editor->clear();
957} 962}
958 963
959void TextEdit::updateCaption( const QString &name ) { 964void TextEdit::updateCaption( const QString &name ) {
960 965
961 if ( name.isEmpty() ) 966 if ( name.isEmpty() )
962 setCaption( tr("Text Editor") ); 967 setCaption( tr("Text Editor") );
963 else { 968 else {
964 QString s = name; 969 QString s = name;
965 if ( s.isNull() ) 970 if ( s.isNull() )
966 s = doc->name(); 971 s = doc->name();
967 if ( s.isEmpty() ) { 972 if ( s.isEmpty() ) {
968 s = tr( "Unnamed" ); 973 s = tr( "Unnamed" );
969 currentFileName=s; 974 currentFileName=s;
970 } 975 }
971// if(s.left(1) == "/") 976// if(s.left(1) == "/")
972// s = s.right(s.length()-1); 977// s = s.right(s.length()-1);
973 setCaption( s + " - " + tr("Text Editor") ); 978 setCaption( s + " - " + tr("Text Editor") );
974 } 979 }
975} 980}
976 981
977void TextEdit::setDocument(const QString& fileref) { 982void TextEdit::setDocument(const QString& fileref) {
978 if(fileref != "Unnamed") { 983 if(fileref != "Unnamed") {
979 currentFileName=fileref; 984 currentFileName=fileref;
980 qDebug("setDocument"); 985 qDebug("setDocument");
981 QFileInfo fi(currentFileName); 986 QFileInfo fi(currentFileName);
982 qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); 987 qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName);
983 if( (fi.baseName().left(1)).isEmpty() ) { 988 if( (fi.baseName().left(1)).isEmpty() ) {
984 openDotFile(currentFileName); 989 openDotFile(currentFileName);
985 990
986 } else { 991 } else {
987 qDebug("setDoc open"); 992 qDebug("setDoc open");
988 bFromDocView = true; 993 bFromDocView = true;
989 openFile(fileref); 994 openFile(fileref);
990 editor->setEdited(true); 995 editor->setEdited(true);
991 edited1=false; 996 edited1=false;
992 edited=true; 997 edited=true;
993 // fromSetDocument=false; 998 // fromSetDocument=false;
994 // doSearchBar(); 999 // doSearchBar();
995 } 1000 }
996 } 1001 }
997 updateCaption( currentFileName); 1002 updateCaption( currentFileName);
998} 1003}
999 1004
1000void TextEdit::changeFont() { 1005void TextEdit::changeFont() {
1001 QDialog *d = new QDialog ( this, "FontDialog", true ); 1006 QDialog *d = new QDialog ( this, "FontDialog", true );
1002 d-> setCaption ( tr( "Choose font" )); 1007 d-> setCaption ( tr( "Choose font" ));
1003 QBoxLayout *lay = new QVBoxLayout ( d ); 1008 QBoxLayout *lay = new QVBoxLayout ( d );
1004 OFontSelector *ofs = new OFontSelector ( true, d ); 1009 OFontSelector *ofs = new OFontSelector ( true, d );
1005 lay-> addWidget ( ofs ); 1010 lay-> addWidget ( ofs );
1006 ofs-> setSelectedFont ( editor-> font ( )); 1011 ofs-> setSelectedFont ( editor-> font ( ));
1007 1012
1008 d-> showMaximized ( ); 1013 d-> showMaximized ( );
1009 if ( d-> exec ( ) == QDialog::Accepted ) 1014 if ( d-> exec ( ) == QDialog::Accepted )
1010 editor-> setFont ( ofs-> selectedFont ( )); 1015 editor-> setFont ( ofs-> selectedFont ( ));
1011 delete d; 1016 delete d;
1012 1017
1013} 1018}
1014 1019
1015void TextEdit::editDelete() { 1020void TextEdit::editDelete() {
1016 switch ( QMessageBox::warning(this,tr("Text Editor"), 1021 switch ( QMessageBox::warning(this,tr("Text Editor"),
1017 tr("Do you really want<BR>to <B>delete</B> " 1022 tr("Do you really want<BR>to <B>delete</B> "
1018 "the current file\nfrom the disk?<BR>This is " 1023 "the current file\nfrom the disk?<BR>This is "
1019 "<B>irreversable!!</B>"), 1024 "<B>irreversable!!</B>"),
1020 tr("Yes"),tr("No"),0,0,1) ) { 1025 tr("Yes"),tr("No"),0,0,1) ) {
1021 case 0: 1026 case 0:
1022 if(doc) { 1027 if(doc) {
1023 doc->removeFiles(); 1028 doc->removeFiles();
1024 clear(); 1029 clear();
1025 setCaption( tr("Text Editor") ); 1030 setCaption( tr("Text Editor") );
1026 } 1031 }
1027 break; 1032 break;
1028 case 1: 1033 case 1:
1029 // exit 1034 // exit
1030 break; 1035 break;
1031 }; 1036 };
1032} 1037}
1033 1038
1034void TextEdit::changeStartConfig( bool b ) { 1039void TextEdit::changeStartConfig( bool b ) {
1035 startWithNew=b; 1040 startWithNew=b;
1036 Config cfg("TextEdit"); 1041 Config cfg("TextEdit");
1037 cfg.setGroup("View"); 1042 cfg.setGroup("View");
1038 cfg.writeEntry("startNew",b); 1043 cfg.writeEntry("startNew",b);
1039 update(); 1044 update();
1040} 1045}
1041 1046
1042void TextEdit::editorChanged() { 1047void TextEdit::editorChanged() {
1043// qDebug("editor changed"); 1048// qDebug("editor changed");
1044 if( /*editor->edited() &&*/ /*edited && */!edited1) { 1049 if( /*editor->edited() &&*/ /*edited && */!edited1) {
1045 setCaption( "*"+caption()); 1050 setCaption( "*"+caption());
1046 edited1=true; 1051 edited1=true;