summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 571df27..cabeb20 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -727,131 +727,132 @@ void TextEdit::openFile( const QString &f ) {
727 openFile(nf); 727 openFile(nf);
728 728
729 odebug << "openFile string "+currentFileName << oendl; 729 odebug << "openFile string "+currentFileName << oendl;
730 730
731 showEditTools(); 731 showEditTools();
732 // Show filename in caption 732 // Show filename in caption
733 QString name = filer; 733 QString name = filer;
734 int sep = name.findRev( '/' ); 734 int sep = name.findRev( '/' );
735 if ( sep > 0 ) 735 if ( sep > 0 )
736 name = name.mid( sep+1 ); 736 name = name.mid( sep+1 );
737 updateCaption( name ); 737 updateCaption( name );
738} 738}
739 739
740void TextEdit::openFile( const DocLnk &f ) { 740void TextEdit::openFile( const DocLnk &f ) {
741// clear(); 741// clear();
742// bFromDocView = true; 742// bFromDocView = true;
743 FileManager fm; 743 FileManager fm;
744 QString txt; 744 QString txt;
745 currentFileName=f.file(); 745 currentFileName=f.file();
746 odebug << "openFile doclnk " + currentFileName << oendl; 746 odebug << "openFile doclnk " + currentFileName << oendl;
747 if ( !fm.loadFile( f, txt ) ) { 747 if ( !fm.loadFile( f, txt ) ) {
748 // ####### could be a new file 748 // ####### could be a new file
749 odebug << "Cannot open file" << oendl; 749 odebug << "Cannot open file" << oendl;
750 } 750 }
751// fileNew(); 751// fileNew();
752 if ( doc ) 752 if ( doc )
753 delete doc; 753 delete doc;
754 doc = new DocLnk(f); 754 doc = new DocLnk(f);
755 editor->setText(txt); 755 editor->setText(txt);
756 editor->setEdited( false); 756 editor->setEdited( false);
757 edited1=false; 757 edited1=false;
758 edited=false; 758 edited=false;
759 759
760 doc->setName(currentFileName); 760 doc->setName(currentFileName);
761 updateCaption(); 761 updateCaption();
762 setTimer(); 762 setTimer();
763} 763}
764 764
765void TextEdit::showEditTools() { 765void TextEdit::showEditTools() {
766 menu->show(); 766 menu->show();
767 editBar->show(); 767 editBar->show();
768 if(!useSearchBar) 768 if(!useSearchBar)
769 searchBar->hide(); 769 searchBar->hide();
770 else 770 else
771 searchBar->show(); 771 searchBar->show();
772 setWState (WState_Reserved1 ); 772 setWState (WState_Reserved1 );
773} 773}
774 774
775/*! 775/*!
776 unprompted save */ 776 unprompted save */
777bool TextEdit::save() { 777bool TextEdit::save() {
778 QString name, file; 778 QString name, file;
779 odebug << "saveAsFile " + currentFileName << oendl; 779 odebug << "saveAsFile " + currentFileName << oendl;
780 if(currentFileName.isEmpty()) { 780 if(currentFileName.isEmpty()) {
781 saveAs(); 781 saveAs();
782 return false; 782 return false;
783 } 783 }
784 name = currentFileName; 784 name = currentFileName;
785 if(doc) { 785 if(doc) {
786 file = doc->file(); 786 file = doc->file();
787 odebug << "saver file "+file << oendl; 787 odebug << "saver file "+file << oendl;
788 name = doc->name(); 788 name = doc->name();
789 odebug << "File named "+name << oendl; 789 odebug << "File named "+name << oendl;
790 } else { 790 } else {
791 name = file = currentFileName; 791 file = currentFileName;
792 name = QFileInfo(currentFileName).baseName();
792 } 793 }
793 794
794 QString rt = editor->text(); 795 QString rt = editor->text();
795 if( !rt.isEmpty() ) { 796 if( !rt.isEmpty() ) {
796 if(name.isEmpty()) { 797 if(name.isEmpty()) {
797 saveAs(); 798 saveAs();
798 } else { 799 } else {
799 currentFileName = name; 800 currentFileName = name;
800 odebug << "saveFile "+currentFileName << oendl; 801 odebug << "saveFile "+currentFileName << oendl;
801 802
802 struct stat buf; 803 struct stat buf;
803 mode_t mode; 804 mode_t mode;
804 stat(file.latin1(), &buf); 805 stat(file.latin1(), &buf);
805 mode = buf.st_mode; 806 mode = buf.st_mode;
806 807
807 if(!fileIs) { 808 if(!fileIs) {
808 doc->setName( name); 809 doc->setName( name);
809 FileManager fm; 810 FileManager fm;
810 if ( !fm.saveFile( *doc, rt ) ) { 811 if ( !fm.saveFile( *doc, rt ) ) {
811 QMessageBox::message(tr("Text Edit"),tr("Save Failed")); 812 QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
812 return false; 813 return false;
813 } 814 }
814 } else { 815 } else {
815 odebug << "regular save file" << oendl; 816 odebug << "regular save file" << oendl;
816 QFile f(file); 817 QFile f(file);
817 if( f.open(IO_WriteOnly)) { 818 if( f.open(IO_WriteOnly)) {
818 QCString crt = rt.utf8(); 819 QCString crt = rt.utf8();
819 f.writeBlock(crt,crt.length()); 820 f.writeBlock(crt,crt.length());
820 } else { 821 } else {
821 QMessageBox::message(tr("Text Edit"),tr("Write Failed")); 822 QMessageBox::message(tr("Text Edit"),tr("Write Failed"));
822 return false; 823 return false;
823 } 824 }
824 825
825 } 826 }
826 editor->setEdited( false); 827 editor->setEdited( false);
827 edited1=false; 828 edited1=false;
828 edited=false; 829 edited=false;
829 if(caption().left(1)=="*") 830 if(caption().left(1)=="*")
830 setCaption(caption().right(caption().length()-1)); 831 setCaption(caption().right(caption().length()-1));
831 832
832 833
833 chmod( file.latin1(), mode); 834 chmod( file.latin1(), mode);
834 } 835 }
835 return true; 836 return true;
836 } 837 }
837 return false; 838 return false;
838} 839}
839 840
840/*! 841/*!
841 prompted save */ 842 prompted save */
842bool TextEdit::saveAs() { 843bool TextEdit::saveAs() {
843 844
844 if(caption() == tr("Text Editor")) 845 if(caption() == tr("Text Editor"))
845 return false; 846 return false;
846 odebug << "saveAsFile " + currentFileName << oendl; 847 odebug << "saveAsFile " + currentFileName << oendl;
847 // case of nothing to save... 848 // case of nothing to save...
848// if ( !doc && !currentFileName.isEmpty()) { 849// if ( !doc && !currentFileName.isEmpty()) {
849// //|| !bFromDocView) 850// //|| !bFromDocView)
850// odebug << "no doc" << oendl; 851// odebug << "no doc" << oendl;
851// return true; 852// return true;
852// } 853// }
853// if ( !editor->edited() ) { 854// if ( !editor->edited() ) {
854// delete doc; 855// delete doc;
855// doc = 0; 856// doc = 0;
856// return true; 857// return true;
857// } 858// }
@@ -863,129 +864,129 @@ bool TextEdit::saveAs() {
863 || currentFileName == tr("Unnamed") 864 || currentFileName == tr("Unnamed")
864 || currentFileName == tr("Text Editor")) { 865 || currentFileName == tr("Text Editor")) {
865 odebug << "do silly TT filename thing" << oendl; 866 odebug << "do silly TT filename thing" << oendl;
866// if ( doc && doc->name().isEmpty() ) { 867// if ( doc && doc->name().isEmpty() ) {
867 QString pt = rt.simplifyWhiteSpace(); 868 QString pt = rt.simplifyWhiteSpace();
868 int i = pt.find( ' ' ); 869 int i = pt.find( ' ' );
869 QString docname = pt; 870 QString docname = pt;
870 if ( i > 0 ) 871 if ( i > 0 )
871 docname = pt.left( i ); 872 docname = pt.left( i );
872 // remove "." at the beginning 873 // remove "." at the beginning
873 while( docname.startsWith( "." ) ) 874 while( docname.startsWith( "." ) )
874 docname = docname.mid( 1 ); 875 docname = docname.mid( 1 );
875 docname.replace( QRegExp("/"), "_" ); 876 docname.replace( QRegExp("/"), "_" );
876 // cut the length. filenames longer than that 877 // cut the length. filenames longer than that
877 //don't make sense and something goes wrong when they get too long. 878 //don't make sense and something goes wrong when they get too long.
878 if ( docname.length() > 40 ) 879 if ( docname.length() > 40 )
879 docname = docname.left(40); 880 docname = docname.left(40);
880 if ( docname.isEmpty() ) 881 if ( docname.isEmpty() )
881 docname = tr("Unnamed"); 882 docname = tr("Unnamed");
882 if(doc) doc->setName(docname); 883 if(doc) doc->setName(docname);
883 currentFileName=docname; 884 currentFileName=docname;
884// } 885// }
885// else 886// else
886// odebug << "hmmmmmm" << oendl; 887// odebug << "hmmmmmm" << oendl;
887 } 888 }
888 889
889 890
890 QMap<QString, QStringList> map; 891 QMap<QString, QStringList> map;
891 map.insert(tr("All"), QStringList() ); 892 map.insert(tr("All"), QStringList() );
892 QStringList text; 893 QStringList text;
893 text << "text/*"; 894 text << "text/*";
894 map.insert(tr("Text"), text ); 895 map.insert(tr("Text"), text );
895 text << "*"; 896 text << "*";
896 map.insert(tr("All"), text ); 897 map.insert(tr("All"), text );
897 898
898 QFileInfo cuFi( currentFileName); 899 QFileInfo cuFi( currentFileName);
899 QString filee = cuFi.fileName(); 900 QString filee = cuFi.fileName();
900 QString dire = cuFi.dirPath(); 901 QString dire = cuFi.dirPath();
901 if(dire==".") 902 if(dire==".")
902 dire = QPEApplication::documentDir(); 903 dire = QPEApplication::documentDir();
903 QString str; 904 QString str;
904 if( !featureAutoSave) { 905 if( !featureAutoSave) {
905 str = OFileDialog::getSaveFileName( 2, 906 str = OFileDialog::getSaveFileName( 2,
906 dire, 907 dire,
907 filee, map); 908 filee, map);
908 } else 909 } else
909 str=currentFileName; 910 str=currentFileName;
910 911
911 if(!str.isEmpty()) { 912 if(!str.isEmpty()) {
912 QString fileNm=str; 913 QString fileNm=str;
913 914
914 odebug << "saving filename "+fileNm << oendl; 915 odebug << "saving filename "+fileNm << oendl;
915 QFileInfo fi(fileNm); 916 QFileInfo fi(fileNm);
916 currentFileName=fi.fileName(); 917 currentFileName=fi.fileName();
917 if(doc) 918 if(doc)
918// QString file = doc->file(); 919// QString file = doc->file();
919// doc->removeFiles(); 920// doc->removeFiles();
920 delete doc; 921 delete doc;
921 DocLnk nf; 922 DocLnk nf;
922 nf.setType("text/plain"); 923 nf.setType("text/plain");
923 nf.setFile( fileNm); 924 nf.setFile( fileNm);
924 doc = new DocLnk(nf); 925 doc = new DocLnk(nf);
925// editor->setText(rt); 926// editor->setText(rt);
926 odebug << "Saving file as "+currentFileName << oendl; 927 odebug << "Saving file as "+currentFileName << oendl;
927 doc->setName( currentFileName); 928 doc->setName( fi.baseName() /*currentFileName*/);
928 updateCaption( currentFileName); 929 updateCaption( currentFileName);
929 930
930 FileManager fm; 931 FileManager fm;
931 if ( !fm.saveFile( *doc, rt ) ) { 932 if ( !fm.saveFile( *doc, rt ) ) {
932 QMessageBox::message(tr("Text Edit"),tr("Save Failed")); 933 QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
933 return false; 934 return false;
934 } 935 }
935 936
936 if( filePerms ) { 937 if( filePerms ) {
937 filePermissions *filePerm; 938 filePermissions *filePerm;
938 filePerm = new filePermissions(this, 939 filePerm = new filePermissions(this,
939 tr("Permissions"),true, 940 tr("Permissions"),true,
940 0,(const QString &)fileNm); 941 0,(const QString &)fileNm);
941 QPEApplication::execDialog( filePerm ); 942 QPEApplication::execDialog( filePerm );
942 943
943 if( filePerm) 944 if( filePerm)
944 delete filePerm; 945 delete filePerm;
945 } 946 }
946// } 947// }
947 editor->setEdited( false); 948 editor->setEdited( false);
948 edited1 = false; 949 edited1 = false;
949 edited = false; 950 edited = false;
950 if(caption().left(1)=="*") 951 if(caption().left(1)=="*")
951 setCaption(caption().right(caption().length()-1)); 952 setCaption(caption().right(caption().length()-1));
952 953
953 return true; 954 return true;
954 } 955 }
955 odebug << "returning false" << oendl; 956 odebug << "returning false" << oendl;
956 currentFileName = ""; 957 currentFileName = "";
957 return false; 958 return false;
958} //end saveAs 959} //end saveAs
959 960
960void TextEdit::clear() { 961void TextEdit::clear() {
961 delete doc; 962 delete doc;
962 doc = 0; 963 doc = 0;
963 editor->clear(); 964 editor->clear();
964} 965}
965 966
966void TextEdit::updateCaption( const QString &name ) { 967void TextEdit::updateCaption( const QString &name ) {
967 968
968 if ( name.isEmpty() ) 969 if ( name.isEmpty() )
969 setCaption( tr("Text Editor") ); 970 setCaption( tr("Text Editor") );
970 else { 971 else {
971 QString s = name; 972 QString s = name;
972 if ( s.isNull() ) 973 if ( s.isNull() )
973 s = doc->name(); 974 s = doc->name();
974 if ( s.isEmpty() ) { 975 if ( s.isEmpty() ) {
975 s = tr( "Unnamed" ); 976 s = tr( "Unnamed" );
976 currentFileName=s; 977 currentFileName=s;
977 } 978 }
978// if(s.left(1) == "/") 979// if(s.left(1) == "/")
979// s = s.right(s.length()-1); 980// s = s.right(s.length()-1);
980 setCaption( tr("%1 - Text Editor").arg( s ) ); 981 setCaption( tr("%1 - Text Editor").arg( s ) );
981 } 982 }
982} 983}
983 984
984void TextEdit::setDocument(const QString& fileref) { 985void TextEdit::setDocument(const QString& fileref) {
985 if(fileref != "Unnamed") { 986 if(fileref != "Unnamed") {
986 currentFileName=fileref; 987 currentFileName=fileref;
987 odebug << "setDocument" << oendl; 988 odebug << "setDocument" << oendl;
988 QFileInfo fi(currentFileName); 989 QFileInfo fi(currentFileName);
989 odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl; 990 odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl;
990 if( (fi.baseName().left(1)).isEmpty() ) { 991 if( (fi.baseName().left(1)).isEmpty() ) {
991 openDotFile(currentFileName); 992 openDotFile(currentFileName);