summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp36
1 files changed, 21 insertions, 15 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 086fdb6..1d0df6a 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -650,303 +650,309 @@ void TextEdit::newFile( const DocLnk &f ) {
650 setWState (WState_Reserved1 ); 650 setWState (WState_Reserved1 );
651 editor->setFocus(); 651 editor->setFocus();
652 doc = new DocLnk(nf); 652 doc = new DocLnk(nf);
653 currentFileName = "Unnamed"; 653 currentFileName = "Unnamed";
654 odebug << "newFile "+currentFileName << oendl; 654 odebug << "newFile "+currentFileName << oendl;
655 updateCaption( currentFileName); 655 updateCaption( currentFileName);
656// editor->setEdited( false); 656// editor->setEdited( false);
657} 657}
658 658
659void TextEdit::openDotFile( const QString &f ) { 659void TextEdit::openDotFile( const QString &f ) {
660 if(!currentFileName.isEmpty()) { 660 if(!currentFileName.isEmpty()) {
661 currentFileName=f; 661 currentFileName=f;
662 662
663 odebug << "openFile dotfile " + currentFileName << oendl; 663 odebug << "openFile dotfile " + currentFileName << oendl;
664 QString txt; 664 QString txt;
665 QFile file(f); 665 QFile file(f);
666 file.open(IO_ReadWrite); 666 file.open(IO_ReadWrite);
667 QTextStream t(&file); 667 QTextStream t(&file);
668 while ( !t.atEnd()) { 668 while ( !t.atEnd()) {
669 txt+=t.readLine()+"\n"; 669 txt+=t.readLine()+"\n";
670 } 670 }
671 editor->setText(txt); 671 editor->setText(txt);
672 editor->setEdited( false); 672 editor->setEdited( false);
673 edited1=false; 673 edited1=false;
674 edited=false; 674 edited=false;
675 675
676 676
677 } 677 }
678 updateCaption( currentFileName); 678 updateCaption( currentFileName);
679} 679}
680 680
681void TextEdit::openFile( const QString &f ) { 681void TextEdit::openFile( const QString &f ) {
682 odebug << "filename is "+ f << oendl; 682 odebug << "filename is "+ f << oendl;
683 QString filer; 683 QString filer;
684 QFileInfo fi( f); 684 QFileInfo fi( f);
685// bFromDocView = true; 685// bFromDocView = true;
686 if(f.find(".desktop",0,true) != -1 && !openDesktop ) 686 if(f.find(".desktop",0,true) != -1 && !openDesktop )
687 { 687 {
688 switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) ) 688 switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) )
689 { 689 {
690 case 0: //desktop 690 case 0: //desktop
691 filer = f; 691 filer = f;
692 break; 692 break;
693 case 1: //linked 693 case 1: //linked
694 DocLnk sf(f); 694 DocLnk sf(f);
695 filer = sf.file(); 695 filer = sf.file();
696 break; 696 break;
697 }; 697 };
698 } 698 }
699 else if(fi.baseName().left(1) == "") 699 else if(fi.baseName().left(1) == "")
700 { 700 {
701 odebug << "opening dotfile" << oendl; 701 odebug << "opening dotfile" << oendl;
702 currentFileName=f; 702 currentFileName=f;
703 openDotFile(currentFileName); 703 openDotFile(currentFileName);
704 return; 704 return;
705 } 705 }
706 /* 706 /*
707 * The problem is a file where Config(f).isValid() and it does not 707 * The problem is a file where Config(f).isValid() and it does not
708 * end with .desktop will be treated as desktop file 708 * end with .desktop will be treated as desktop file
709 */ 709 */
710 else if (f.find(".desktop",0,true) != -1 ) 710 else if (f.find(".desktop",0,true) != -1 )
711 { 711 {
712 DocLnk sf(f); 712 DocLnk sf(f);
713 filer = sf.file(); 713 filer = sf.file();
714 if(filer.right(1) == "/") 714 if(filer.right(1) == "/")
715 filer = f; 715 filer = f;
716 716
717 } 717 }
718 else 718 else
719 filer = f; 719 filer = f;
720 720
721 DocLnk nf; 721 DocLnk nf;
722 nf.setType("text/plain"); 722 nf.setType("text/plain");
723 nf.setFile(filer); 723 nf.setFile(filer);
724 currentFileName=filer; 724 currentFileName=filer;
725 725
726 nf.setName(fi.baseName()); 726 nf.setName(fi.baseName());
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 odebug << "saveAsFile " + currentFileName << oendl; 779 odebug << "saveAsFile " + currentFileName << oendl;
779 if(currentFileName.isEmpty()) { 780 if(currentFileName.isEmpty()) {
780 saveAs(); 781 saveAs();
781 return false; 782 return false;
782 } 783 }
783 784 name = currentFileName;
784 QString file = doc->file(); 785 if(doc) {
785 odebug << "saver file "+file << oendl; 786 file = doc->file();
786 QString name= doc->name(); 787 odebug << "saver file "+file << oendl;
787 odebug << "File named "+name << oendl; 788 name = doc->name();
789 odebug << "File named "+name << oendl;
790 } else {
791 name = file = currentFileName;
792 }
793
788 QString rt = editor->text(); 794 QString rt = editor->text();
789 if( !rt.isEmpty() ) { 795 if( !rt.isEmpty() ) {
790 if(name.isEmpty()) { 796 if(name.isEmpty()) {
791 saveAs(); 797 saveAs();
792 } else { 798 } else {
793 currentFileName= name ; 799 currentFileName = name;
794 odebug << "saveFile "+currentFileName << oendl; 800 odebug << "saveFile "+currentFileName << oendl;
795 801
796 struct stat buf; 802 struct stat buf;
797 mode_t mode; 803 mode_t mode;
798 stat(file.latin1(), &buf); 804 stat(file.latin1(), &buf);
799 mode = buf.st_mode; 805 mode = buf.st_mode;
800 806
801 if(!fileIs) { 807 if(!fileIs) {
802 doc->setName( name); 808 doc->setName( name);
803 FileManager fm; 809 FileManager fm;
804 if ( !fm.saveFile( *doc, rt ) ) { 810 if ( !fm.saveFile( *doc, rt ) ) {
805 QMessageBox::message(tr("Text Edit"),tr("Save Failed")); 811 QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
806 return false; 812 return false;
807 } 813 }
808 } else { 814 } else {
809 odebug << "regular save file" << oendl; 815 odebug << "regular save file" << oendl;
810 QFile f(file); 816 QFile f(file);
811 if( f.open(IO_WriteOnly)) { 817 if( f.open(IO_WriteOnly)) {
812 QCString crt = rt.utf8(); 818 QCString crt = rt.utf8();
813 f.writeBlock(crt,crt.length()); 819 f.writeBlock(crt,crt.length());
814 } else { 820 } else {
815 QMessageBox::message(tr("Text Edit"),tr("Write Failed")); 821 QMessageBox::message(tr("Text Edit"),tr("Write Failed"));
816 return false; 822 return false;
817 } 823 }
818 824
819 } 825 }
820 editor->setEdited( false); 826 editor->setEdited( false);
821 edited1=false; 827 edited1=false;
822 edited=false; 828 edited=false;
823 if(caption().left(1)=="*") 829 if(caption().left(1)=="*")
824 setCaption(caption().right(caption().length()-1)); 830 setCaption(caption().right(caption().length()-1));
825 831
826 832
827 chmod( file.latin1(), mode); 833 chmod( file.latin1(), mode);
828 } 834 }
829 return true; 835 return true;
830 } 836 }
831 return false; 837 return false;
832} 838}
833 839
834/*! 840/*!
835 prompted save */ 841 prompted save */
836bool TextEdit::saveAs() { 842bool TextEdit::saveAs() {
837 843
838 if(caption() == tr("Text Editor")) 844 if(caption() == tr("Text Editor"))
839 return false; 845 return false;
840 odebug << "saveAsFile " + currentFileName << oendl; 846 odebug << "saveAsFile " + currentFileName << oendl;
841 // case of nothing to save... 847 // case of nothing to save...
842// if ( !doc && !currentFileName.isEmpty()) { 848// if ( !doc && !currentFileName.isEmpty()) {
843// //|| !bFromDocView) 849// //|| !bFromDocView)
844// odebug << "no doc" << oendl; 850// odebug << "no doc" << oendl;
845// return true; 851// return true;
846// } 852// }
847// if ( !editor->edited() ) { 853// if ( !editor->edited() ) {
848// delete doc; 854// delete doc;
849// doc = 0; 855// doc = 0;
850// return true; 856// return true;
851// } 857// }
852 858
853 QString rt = editor->text(); 859 QString rt = editor->text();
854 odebug << currentFileName << oendl; 860 odebug << currentFileName << oendl;
855 861
856 if( currentFileName.isEmpty() 862 if( currentFileName.isEmpty()
857 || currentFileName == tr("Unnamed") 863 || currentFileName == tr("Unnamed")
858 || currentFileName == tr("Text Editor")) { 864 || currentFileName == tr("Text Editor")) {
859 odebug << "do silly TT filename thing" << oendl; 865 odebug << "do silly TT filename thing" << oendl;
860// if ( doc && doc->name().isEmpty() ) { 866// if ( doc && doc->name().isEmpty() ) {
861 QString pt = rt.simplifyWhiteSpace(); 867 QString pt = rt.simplifyWhiteSpace();
862 int i = pt.find( ' ' ); 868 int i = pt.find( ' ' );
863 QString docname = pt; 869 QString docname = pt;
864 if ( i > 0 ) 870 if ( i > 0 )
865 docname = pt.left( i ); 871 docname = pt.left( i );
866 // remove "." at the beginning 872 // remove "." at the beginning
867 while( docname.startsWith( "." ) ) 873 while( docname.startsWith( "." ) )
868 docname = docname.mid( 1 ); 874 docname = docname.mid( 1 );
869 docname.replace( QRegExp("/"), "_" ); 875 docname.replace( QRegExp("/"), "_" );
870 // cut the length. filenames longer than that 876 // cut the length. filenames longer than that
871 //don't make sense and something goes wrong when they get too long. 877 //don't make sense and something goes wrong when they get too long.
872 if ( docname.length() > 40 ) 878 if ( docname.length() > 40 )
873 docname = docname.left(40); 879 docname = docname.left(40);
874 if ( docname.isEmpty() ) 880 if ( docname.isEmpty() )
875 docname = tr("Unnamed"); 881 docname = tr("Unnamed");
876 if(doc) doc->setName(docname); 882 if(doc) doc->setName(docname);
877 currentFileName=docname; 883 currentFileName=docname;
878// } 884// }
879// else 885// else
880// odebug << "hmmmmmm" << oendl; 886// odebug << "hmmmmmm" << oendl;
881 } 887 }
882 888
883 889
884 QMap<QString, QStringList> map; 890 QMap<QString, QStringList> map;
885 map.insert(tr("All"), QStringList() ); 891 map.insert(tr("All"), QStringList() );
886 QStringList text; 892 QStringList text;
887 text << "text/*"; 893 text << "text/*";
888 map.insert(tr("Text"), text ); 894 map.insert(tr("Text"), text );
889 text << "*"; 895 text << "*";
890 map.insert(tr("All"), text ); 896 map.insert(tr("All"), text );
891 897
892 QFileInfo cuFi( currentFileName); 898 QFileInfo cuFi( currentFileName);
893 QString filee = cuFi.fileName(); 899 QString filee = cuFi.fileName();
894 QString dire = cuFi.dirPath(); 900 QString dire = cuFi.dirPath();
895 if(dire==".") 901 if(dire==".")
896 dire = QPEApplication::documentDir(); 902 dire = QPEApplication::documentDir();
897 QString str; 903 QString str;
898 if( !featureAutoSave) { 904 if( !featureAutoSave) {
899 str = OFileDialog::getSaveFileName( 2, 905 str = OFileDialog::getSaveFileName( 2,
900 dire, 906 dire,
901 filee, map); 907 filee, map);
902 } else 908 } else
903 str=currentFileName; 909 str=currentFileName;
904 910
905 if(!str.isEmpty()) { 911 if(!str.isEmpty()) {
906 QString fileNm=str; 912 QString fileNm=str;
907 913
908 odebug << "saving filename "+fileNm << oendl; 914 odebug << "saving filename "+fileNm << oendl;
909 QFileInfo fi(fileNm); 915 QFileInfo fi(fileNm);
910 currentFileName=fi.fileName(); 916 currentFileName=fi.fileName();
911 if(doc) 917 if(doc)
912// QString file = doc->file(); 918// QString file = doc->file();
913// doc->removeFiles(); 919// doc->removeFiles();
914 delete doc; 920 delete doc;
915 DocLnk nf; 921 DocLnk nf;
916 nf.setType("text/plain"); 922 nf.setType("text/plain");
917 nf.setFile( fileNm); 923 nf.setFile( fileNm);
918 doc = new DocLnk(nf); 924 doc = new DocLnk(nf);
919// editor->setText(rt); 925// editor->setText(rt);
920 odebug << "Saving file as "+currentFileName << oendl; 926 odebug << "Saving file as "+currentFileName << oendl;
921 doc->setName( currentFileName); 927 doc->setName( currentFileName);
922 updateCaption( currentFileName); 928 updateCaption( currentFileName);
923 929
924 FileManager fm; 930 FileManager fm;
925 if ( !fm.saveFile( *doc, rt ) ) { 931 if ( !fm.saveFile( *doc, rt ) ) {
926 QMessageBox::message(tr("Text Edit"),tr("Save Failed")); 932 QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
927 return false; 933 return false;
928 } 934 }
929 935
930 if( filePerms ) { 936 if( filePerms ) {
931 filePermissions *filePerm; 937 filePermissions *filePerm;
932 filePerm = new filePermissions(this, 938 filePerm = new filePermissions(this,
933 tr("Permissions"),true, 939 tr("Permissions"),true,
934 0,(const QString &)fileNm); 940 0,(const QString &)fileNm);
935 QPEApplication::execDialog( filePerm ); 941 QPEApplication::execDialog( filePerm );
936 942
937 if( filePerm) 943 if( filePerm)
938 delete filePerm; 944 delete filePerm;
939 } 945 }
940// } 946// }
941 editor->setEdited( false); 947 editor->setEdited( false);
942 edited1 = false; 948 edited1 = false;
943 edited = false; 949 edited = false;
944 if(caption().left(1)=="*") 950 if(caption().left(1)=="*")
945 setCaption(caption().right(caption().length()-1)); 951 setCaption(caption().right(caption().length()-1));
946 952
947 return true; 953 return true;
948 } 954 }
949 odebug << "returning false" << oendl; 955 odebug << "returning false" << oendl;
950 return false; 956 return false;
951} //end saveAs 957} //end saveAs
952 958