summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-11-09 00:55:56 (UTC)
committer llornkcor <llornkcor>2002-11-09 00:55:56 (UTC)
commit84e685e0c2922899dcdd69cfc23ecbccbf855af4 (patch) (unidiff)
tree1a3d34d261c5ebc4982d3b9276e63ebae57d8d39
parent028753a6a3857cdcf7476e537de1cd5c471424c4 (diff)
downloadopie-84e685e0c2922899dcdd69cfc23ecbccbf855af4.zip
opie-84e685e0c2922899dcdd69cfc23ecbccbf855af4.tar.gz
opie-84e685e0c2922899dcdd69cfc23ecbccbf855af4.tar.bz2
fix for #435
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index f38ea53..e3b8361 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -643,331 +643,338 @@ void TextEdit::openFile( const QString &f ) {
643 switch ( QMessageBox::warning(this,tr("Text Editor"), 643 switch ( QMessageBox::warning(this,tr("Text Editor"),
644 tr("Text Editor has detected<BR>you selected a <B>.desktop</B> 644 tr("Text Editor has detected<BR>you selected a <B>.desktop</B>
645file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), 645file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"),
646 tr(".desktop File"),tr("Linked Document"),0,1,1) ) { 646 tr(".desktop File"),tr("Linked Document"),0,1,1) ) {
647 case 0: 647 case 0:
648 filer = f; 648 filer = f;
649 break; 649 break;
650 case 1: 650 case 1:
651 DocLnk sf(f); 651 DocLnk sf(f);
652 filer = sf.file(); 652 filer = sf.file();
653 break; 653 break;
654 } 654 }
655 } else { 655 } else {
656 DocLnk sf(f); 656 DocLnk sf(f);
657 filer = sf.file(); 657 filer = sf.file();
658 if(filer.right(1) == "/") 658 if(filer.right(1) == "/")
659 filer = f; 659 filer = f;
660 } 660 }
661 661
662 DocLnk nf; 662 DocLnk nf;
663 nf.setType("text/plain"); 663 nf.setType("text/plain");
664 nf.setFile(filer); 664 nf.setFile(filer);
665 currentFileName=filer; 665 currentFileName=filer;
666 QFileInfo fi( currentFileName); 666 QFileInfo fi( currentFileName);
667 nf.setName(fi.baseName()); 667 nf.setName(fi.baseName());
668 qDebug("openFile string "+currentFileName); 668 qDebug("openFile string "+currentFileName);
669 669
670 openFile(nf); 670 openFile(nf);
671 showEditTools(); 671 showEditTools();
672 // Show filename in caption 672 // Show filename in caption
673 QString name = filer; 673 QString name = filer;
674 int sep = name.findRev( '/' ); 674 int sep = name.findRev( '/' );
675 if ( sep > 0 ) 675 if ( sep > 0 )
676 name = name.mid( sep+1 ); 676 name = name.mid( sep+1 );
677 updateCaption( name ); 677 updateCaption( name );
678} 678}
679 679
680void TextEdit::openFile( const DocLnk &f ) { 680void TextEdit::openFile( const DocLnk &f ) {
681// clear(); 681// clear();
682// bFromDocView = TRUE; 682// bFromDocView = TRUE;
683 FileManager fm; 683 FileManager fm;
684 QString txt; 684 QString txt;
685 currentFileName=f.file(); 685 currentFileName=f.file();
686 qDebug("openFile doclnk " + currentFileName); 686 qDebug("openFile doclnk " + currentFileName);
687 if ( !fm.loadFile( f, txt ) ) { 687 if ( !fm.loadFile( f, txt ) ) {
688 // ####### could be a new file 688 // ####### could be a new file
689 qDebug( "Cannot open file" ); 689 qDebug( "Cannot open file" );
690 } 690 }
691// fileNew(); 691// fileNew();
692 if ( doc ) 692 if ( doc )
693 delete doc; 693 delete doc;
694 doc = new DocLnk(f); 694 doc = new DocLnk(f);
695 editor->setText(txt); 695 editor->setText(txt);
696 editor->setEdited( FALSE); 696 editor->setEdited( FALSE);
697 edited1=FALSE; 697 edited1=FALSE;
698 edited=FALSE; 698 edited=FALSE;
699 699
700 doc->setName(currentFileName); 700 doc->setName(currentFileName);
701 updateCaption(); 701 updateCaption();
702} 702}
703 703
704void TextEdit::showEditTools() { 704void TextEdit::showEditTools() {
705// if ( !doc ) 705// if ( !doc )
706// close(); 706// close();
707// clear(); 707// clear();
708 menu->show(); 708 menu->show();
709 editBar->show(); 709 editBar->show();
710 if ( searchVisible ) 710 if ( searchVisible )
711 searchBar->show(); 711 searchBar->show();
712// updateCaption(); 712// updateCaption();
713 setWState (WState_Reserved1 ); 713 setWState (WState_Reserved1 );
714} 714}
715 715
716/*! 716/*!
717 unprompted save */ 717 unprompted save */
718bool TextEdit::save() { 718bool TextEdit::save() {
719 QString file = doc->file(); 719 QString file = doc->file();
720 qDebug("saver file "+file); 720 qDebug("saver file "+file);
721 QString name= doc->name(); 721 QString name= doc->name();
722 qDebug("File named "+name); 722 qDebug("File named "+name);
723 QString rt = editor->text(); 723 QString rt = editor->text();
724 if( !rt.isEmpty() ) { 724 if( !rt.isEmpty() ) {
725 if(name.isEmpty()) { 725 if(name.isEmpty()) {
726 saveAs(); 726 saveAs();
727 } else { 727 } else {
728 currentFileName= name ; 728 currentFileName= name ;
729 qDebug("saveFile "+currentFileName); 729 qDebug("saveFile "+currentFileName);
730 730
731 struct stat buf; 731 struct stat buf;
732 mode_t mode; 732 mode_t mode;
733 stat(file.latin1(), &buf); 733 stat(file.latin1(), &buf);
734 mode = buf.st_mode; 734 mode = buf.st_mode;
735 735
736 if(!fileIs) { 736 if(!fileIs) {
737 doc->setName( name); 737 doc->setName( name);
738 FileManager fm; 738 FileManager fm;
739 if ( !fm.saveFile( *doc, rt ) ) { 739 if ( !fm.saveFile( *doc, rt ) ) {
740 return false; 740 return false;
741 } 741 }
742 } else { 742 } else {
743 qDebug("regular save file"); 743 qDebug("regular save file");
744 QFile f(file); 744 QFile f(file);
745 if( f.open(IO_WriteOnly)) { 745 if( f.open(IO_WriteOnly)) {
746 QCString crt = rt.utf8(); 746 QCString crt = rt.utf8();
747 f.writeBlock(crt,crt.length()); 747 f.writeBlock(crt,crt.length());
748 } else { 748 } else {
749 QMessageBox::message(tr("Text Edit"),tr("Write Failed")); 749 QMessageBox::message(tr("Text Edit"),tr("Write Failed"));
750 return false; 750 return false;
751 } 751 }
752 752
753 } 753 }
754 editor->setEdited( FALSE); 754 editor->setEdited( FALSE);
755 edited1=FALSE; 755 edited1=FALSE;
756 edited=FALSE; 756 edited=FALSE;
757 if(caption().left(1)=="*") 757 if(caption().left(1)=="*")
758 setCaption(caption().right(caption().length()-1)); 758 setCaption(caption().right(caption().length()-1));
759 759
760 760
761 chmod( file.latin1(), mode); 761 chmod( file.latin1(), mode);
762 } 762 }
763 return true; 763 return true;
764 } 764 }
765 return false; 765 return false;
766} 766}
767 767
768/*! 768/*!
769 prompted save */ 769 prompted save */
770bool TextEdit::saveAs() { 770bool TextEdit::saveAs() {
771 qDebug("saveAsFile "+currentFileName); 771 qDebug("saveAsFile " + currentFileName);
772 // case of nothing to save... 772 // case of nothing to save...
773 if ( !doc ) { 773 if ( !doc ) {
774//|| !bFromDocView) 774//|| !bFromDocView)
775 qDebug("no doc"); 775 qDebug("no doc");
776 return true; 776 return true;
777 } 777 }
778 if ( !editor->edited() ) { 778 if ( !editor->edited() ) {
779 delete doc; 779 delete doc;
780 doc = 0; 780 doc = 0;
781 return true; 781 return true;
782 } 782 }
783 783
784 QString rt = editor->text(); 784 QString rt = editor->text();
785 qDebug(currentFileName); 785 qDebug(currentFileName);
786 786
787 if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { 787 if( currentFileName.isEmpty()
788 || currentFileName == tr("Unnamed")
789 || currentFileName == tr("Text Editor")) {
788// qDebug("do silly TT filename thing"); 790// qDebug("do silly TT filename thing");
789 if ( doc->name().isEmpty() ) { 791 if ( doc->name().isEmpty() ) {
790 QString pt = rt.simplifyWhiteSpace(); 792 QString pt = rt.simplifyWhiteSpace();
791 int i = pt.find( ' ' ); 793 int i = pt.find( ' ' );
792 QString docname = pt; 794 QString docname = pt;
793 if ( i > 0 ) 795 if ( i > 0 )
794 docname = pt.left( i ); 796 docname = pt.left( i );
795 // remove "." at the beginning 797 // remove "." at the beginning
796 while( docname.startsWith( "." ) ) 798 while( docname.startsWith( "." ) )
797 docname = docname.mid( 1 ); 799 docname = docname.mid( 1 );
798 docname.replace( QRegExp("/"), "_" ); 800 docname.replace( QRegExp("/"), "_" );
799 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. 801 // cut the length. filenames longer than that
802 //don't make sense and something goes wrong when they get too long.
800 if ( docname.length() > 40 ) 803 if ( docname.length() > 40 )
801 docname = docname.left(40); 804 docname = docname.left(40);
802 if ( docname.isEmpty() ) 805 if ( docname.isEmpty() )
803 docname = tr("Unnamed"); 806 docname = tr("Unnamed");
804 doc->setName(docname); 807 doc->setName(docname);
805 currentFileName=docname; 808 currentFileName=docname;
806 } 809 }
807 } 810 }
808 811
809 QMap<QString, QStringList> map; 812 QMap<QString, QStringList> map;
810 map.insert(tr("All"), QStringList() ); 813 map.insert(tr("All"), QStringList() );
811 QStringList text; 814 QStringList text;
812 text << "text/*"; 815 text << "text/*";
813 map.insert(tr("Text"), text ); 816 map.insert(tr("Text"), text );
814 text << "*"; 817 text << "*";
815 map.insert(tr("All"), text ); 818 map.insert(tr("All"), text );
816 819// if(currentFileName
817 QString str = OFileDialog::getSaveFileName( 2,QPEApplication::documentDir(), QString::null, map); 820 QString str = OFileDialog::getSaveFileName( 2,
821 QPEApplication::documentDir(),
822 currentFileName, map);
818 823
819 if(!str.isEmpty() ) { 824 if(!str.isEmpty() ) {
820 QString fileNm=str; 825 QString fileNm=str;
821 826
822 qDebug("saving filename "+fileNm); 827 qDebug("saving filename "+fileNm);
823 QFileInfo fi(fileNm); 828 QFileInfo fi(fileNm);
824 currentFileName=fi.fileName(); 829 currentFileName=fi.fileName();
825 if(doc) { 830 if(doc) {
826// QString file = doc->file(); 831// QString file = doc->file();
827// doc->removeFiles(); 832// doc->removeFiles();
828 delete doc; 833 delete doc;
829 DocLnk nf; 834 DocLnk nf;
830 nf.setType("text/plain"); 835 nf.setType("text/plain");
831 nf.setFile( fileNm); 836 nf.setFile( fileNm);
832 doc = new DocLnk(nf); 837 doc = new DocLnk(nf);
833// editor->setText(rt); 838// editor->setText(rt);
834// qDebug("openFile doclnk "+currentFileName); 839// qDebug("openFile doclnk "+currentFileName);
835 doc->setName( currentFileName); 840 doc->setName( currentFileName);
836 updateCaption( currentFileName); 841 updateCaption( currentFileName);
837 842
838 FileManager fm; 843 FileManager fm;
839 if ( !fm.saveFile( *doc, rt ) ) { 844 if ( !fm.saveFile( *doc, rt ) ) {
840 return false; 845 return false;
841 } 846 }
842 847
843 if( filePerms ) { 848 if( filePerms ) {
844 filePermissions *filePerm; 849 filePermissions *filePerm;
845 filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); 850 filePerm = new filePermissions(this,
851 tr("Permissions"),true,
852 0,(const QString &)fileNm);
846 filePerm->showMaximized(); 853 filePerm->showMaximized();
847 filePerm->exec(); 854 filePerm->exec();
848 855
849 if( filePerm) 856 if( filePerm)
850 delete filePerm; 857 delete filePerm;
851 } 858 }
852 } 859 }
853 editor->setEdited( false); 860 editor->setEdited( false);
854 edited1 = false; 861 edited1 = false;
855 edited = false; 862 edited = false;
856 if(caption().left(1)=="*") 863 if(caption().left(1)=="*")
857 setCaption(caption().right(caption().length()-1)); 864 setCaption(caption().right(caption().length()-1));
858 865
859 return true; 866 return true;
860 } 867 }
861 qDebug("returning false"); 868 qDebug("returning false");
862 return false; 869 return false;
863} //end saveAs 870} //end saveAs
864 871
865void TextEdit::clear() { 872void TextEdit::clear() {
866 delete doc; 873 delete doc;
867 doc = 0; 874 doc = 0;
868 editor->clear(); 875 editor->clear();
869} 876}
870 877
871void TextEdit::updateCaption( const QString &name ) { 878void TextEdit::updateCaption( const QString &name ) {
872 if ( !doc ) 879 if ( !doc )
873 setCaption( tr("Text Editor") ); 880 setCaption( tr("Text Editor") );
874 else { 881 else {
875 QString s = name; 882 QString s = name;
876 if ( s.isNull() ) 883 if ( s.isNull() )
877 s = doc->name(); 884 s = doc->name();
878 if ( s.isEmpty() ) { 885 if ( s.isEmpty() ) {
879 s = tr( "Unnamed" ); 886 s = tr( "Unnamed" );
880 currentFileName=s; 887 currentFileName=s;
881 } 888 }
882 if(s.left(1) == "/") 889 if(s.left(1) == "/")
883 s = s.right(s.length()-1); 890 s = s.right(s.length()-1);
884 setCaption( s + " - " + tr("Text Editor") ); 891 setCaption( s + " - " + tr("Text Editor") );
885 } 892 }
886} 893}
887 894
888void TextEdit::setDocument(const QString& fileref) { 895void TextEdit::setDocument(const QString& fileref) {
889 bFromDocView = TRUE; 896 bFromDocView = TRUE;
890 openFile(fileref); 897 openFile(fileref);
891 editor->setEdited(TRUE); 898 editor->setEdited(TRUE);
892 edited1=FALSE; 899 edited1=FALSE;
893 edited=TRUE; 900 edited=TRUE;
894 doSearchBar(); 901 doSearchBar();
895} 902}
896 903
897void TextEdit::closeEvent( QCloseEvent *e ) { 904void TextEdit::closeEvent( QCloseEvent *e ) {
898 bFromDocView = FALSE; 905 bFromDocView = FALSE;
899 e->accept(); 906 e->accept();
900} 907}
901 908
902void TextEdit::changeFont() { 909void TextEdit::changeFont() {
903 QDialog *d = new QDialog ( this, "FontDialog", true ); 910 QDialog *d = new QDialog ( this, "FontDialog", true );
904 d-> setCaption ( tr( "Choose font" )); 911 d-> setCaption ( tr( "Choose font" ));
905 QBoxLayout *lay = new QVBoxLayout ( d ); 912 QBoxLayout *lay = new QVBoxLayout ( d );
906 OFontSelector *ofs = new OFontSelector ( true, d ); 913 OFontSelector *ofs = new OFontSelector ( true, d );
907 lay-> addWidget ( ofs ); 914 lay-> addWidget ( ofs );
908 ofs-> setSelectedFont ( editor-> font ( )); 915 ofs-> setSelectedFont ( editor-> font ( ));
909 916
910 d-> showMaximized ( ); 917 d-> showMaximized ( );
911 if ( d-> exec ( ) == QDialog::Accepted ) 918 if ( d-> exec ( ) == QDialog::Accepted )
912 editor-> setFont ( ofs-> selectedFont ( )); 919 editor-> setFont ( ofs-> selectedFont ( ));
913 delete d; 920 delete d;
914 921
915} 922}
916 923
917void TextEdit::editDelete() { 924void TextEdit::editDelete() {
918 switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Do you really want<BR>to <B>delete</B> the current file\nfrom the disk?<BR>This is <B>irreversable!!</B>"),tr("Yes"),tr("No"),0,0,1) ) { 925 switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Do you really want<BR>to <B>delete</B> the current file\nfrom the disk?<BR>This is <B>irreversable!!</B>"),tr("Yes"),tr("No"),0,0,1) ) {
919 case 0: 926 case 0:
920 if(doc) { 927 if(doc) {
921 doc->removeFiles(); 928 doc->removeFiles();
922 clear(); 929 clear();
923 setCaption( tr("Text Editor") ); 930 setCaption( tr("Text Editor") );
924 } 931 }
925 break; 932 break;
926 case 1: 933 case 1:
927 // exit 934 // exit
928 break; 935 break;
929 }; 936 };
930} 937}
931 938
932void TextEdit::changeStartConfig( bool b ) { 939void TextEdit::changeStartConfig( bool b ) {
933 940
934 Config cfg("TextEdit"); 941 Config cfg("TextEdit");
935 cfg.setGroup("View"); 942 cfg.setGroup("View");
936 if(b) { 943 if(b) {
937 qDebug("bool"); 944 qDebug("bool");
938 cfg.writeEntry("startNew","TRUE"); 945 cfg.writeEntry("startNew","TRUE");
939 } else { 946 } else {
940 cfg.writeEntry("startNew","FALSE"); 947 cfg.writeEntry("startNew","FALSE");
941 } 948 }
942 update(); 949 update();
943} 950}
944 951
945void TextEdit::editorChanged() { 952void TextEdit::editorChanged() {
946 if(editor->edited() && edited && !edited1) { 953 if(editor->edited() && edited && !edited1) {
947 setCaption( "*"+caption()); 954 setCaption( "*"+caption());
948 edited1=TRUE; 955 edited1=TRUE;
949 } 956 }
950 edited=TRUE; 957 edited=TRUE;
951} 958}
952 959
953void TextEdit::receive(const QCString&msg, const QByteArray&) { 960void TextEdit::receive(const QCString&msg, const QByteArray&) {
954 qDebug("QCop "+msg); 961 qDebug("QCop "+msg);
955 if ( msg == "setDocument(QString)" ) { 962 if ( msg == "setDocument(QString)" ) {
956 qDebug("bugger all"); 963 qDebug("bugger all");
957 } 964 }
958 965
959} 966}
960void TextEdit::doAbout() { 967void TextEdit::doAbout() {
961 QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" 968 QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>"
962 "2000 Trolltech AS, and<BR>" 969 "2000 Trolltech AS, and<BR>"
963 "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" 970 "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>"
964 "and is licensed under the GPL")); 971 "and is licensed under the GPL"));
965} 972}
966 973
967void TextEdit::doPrompt(bool b) { 974void TextEdit::doPrompt(bool b) {
968 promptExit=b; 975 promptExit=b;
969 Config cfg("TextEdit"); 976 Config cfg("TextEdit");
970 cfg.setGroup ( "View" ); 977 cfg.setGroup ( "View" );
971 cfg.writeEntry ( "PromptExit", b); 978 cfg.writeEntry ( "PromptExit", b);
972} 979}
973 980