summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index b81f3b4..ce868d6 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -673,522 +673,526 @@ void TextEdit::openDotFile( const QString &f ) {
673 673
674 qDebug("openFile dotfile " + currentFileName); 674 qDebug("openFile dotfile " + currentFileName);
675 QString txt; 675 QString txt;
676 QFile file(f); 676 QFile file(f);
677 file.open(IO_ReadWrite); 677 file.open(IO_ReadWrite);
678 QTextStream t(&file); 678 QTextStream t(&file);
679 while ( !t.atEnd()) { 679 while ( !t.atEnd()) {
680 txt+=t.readLine()+"\n"; 680 txt+=t.readLine()+"\n";
681 } 681 }
682 editor->setText(txt); 682 editor->setText(txt);
683 editor->setEdited( false); 683 editor->setEdited( false);
684 edited1=false; 684 edited1=false;
685 edited=false; 685 edited=false;
686 686
687 687
688 } 688 }
689 updateCaption( currentFileName); 689 updateCaption( currentFileName);
690} 690}
691 691
692void TextEdit::openFile( const QString &f ) { 692void TextEdit::openFile( const QString &f ) {
693 qDebug("filename is "+ f); 693 qDebug("filename is "+ f);
694 QString filer; 694 QString filer;
695 QFileInfo fi( f); 695 QFileInfo fi( f);
696// bFromDocView = true; 696// bFromDocView = true;
697 if(f.find(".desktop",0,true) != -1 && !openDesktop ) { 697 if(f.find(".desktop",0,true) != -1 && !openDesktop ) {
698 switch ( QMessageBox::warning(this,tr("Text Editor"), 698 switch ( QMessageBox::warning(this,tr("Text Editor"),
699 tr("Text Editor has detected<BR>you selected a <B>.desktop</B> 699 tr("Text Editor has detected<BR>you selected a <B>.desktop</B>
700file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), 700file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"),
701 tr(".desktop File"),tr("Linked Document"),0,1,1) ) { 701 tr(".desktop File"),tr("Linked Document"),0,1,1) ) {
702 case 0: 702 case 0:
703 filer = f; 703 filer = f;
704 break; 704 break;
705 case 1: 705 case 1:
706 DocLnk sf(f); 706 DocLnk sf(f);
707 filer = sf.file(); 707 filer = sf.file();
708 break; 708 break;
709 } 709 }
710 } else if(fi.baseName().left(1) == "") { 710 } else if(fi.baseName().left(1) == "") {
711 currentFileName=f; 711 currentFileName=f;
712 openDotFile(currentFileName); 712 openDotFile(currentFileName);
713 } else { 713 } else {
714 DocLnk sf(f); 714 DocLnk sf(f);
715 filer = sf.file(); 715 filer = sf.file();
716 if(filer.right(1) == "/") 716 if(filer.right(1) == "/")
717 filer = f; 717 filer = f;
718 718
719 DocLnk nf; 719 DocLnk nf;
720 nf.setType("text/plain"); 720 nf.setType("text/plain");
721 nf.setFile(filer); 721 nf.setFile(filer);
722 currentFileName=filer; 722 currentFileName=filer;
723 723
724 nf.setName(fi.baseName()); 724 nf.setName(fi.baseName());
725 openFile(nf); 725 openFile(nf);
726 726
727 qDebug("openFile string "+currentFileName); 727 qDebug("openFile string "+currentFileName);
728 728
729 } 729 }
730 showEditTools(); 730 showEditTools();
731 // Show filename in caption 731 // Show filename in caption
732 QString name = filer; 732 QString name = filer;
733 int sep = name.findRev( '/' ); 733 int sep = name.findRev( '/' );
734 if ( sep > 0 ) 734 if ( sep > 0 )
735 name = name.mid( sep+1 ); 735 name = name.mid( sep+1 );
736 updateCaption( name ); 736 updateCaption( name );
737} 737}
738 738
739void TextEdit::openFile( const DocLnk &f ) { 739void TextEdit::openFile( const DocLnk &f ) {
740// clear(); 740// clear();
741// bFromDocView = true; 741// bFromDocView = true;
742 FileManager fm; 742 FileManager fm;
743 QString txt; 743 QString txt;
744 currentFileName=f.file(); 744 currentFileName=f.file();
745 qDebug("openFile doclnk " + currentFileName); 745 qDebug("openFile doclnk " + currentFileName);
746 if ( !fm.loadFile( f, txt ) ) { 746 if ( !fm.loadFile( f, txt ) ) {
747 // ####### could be a new file 747 // ####### could be a new file
748 qDebug( "Cannot open file" ); 748 qDebug( "Cannot open file" );
749 } 749 }
750// fileNew(); 750// fileNew();
751 if ( doc ) 751 if ( doc )
752 delete doc; 752 delete doc;
753 doc = new DocLnk(f); 753 doc = new DocLnk(f);
754 editor->setText(txt); 754 editor->setText(txt);
755 editor->setEdited( false); 755 editor->setEdited( false);
756 edited1=false; 756 edited1=false;
757 edited=false; 757 edited=false;
758 758
759 doc->setName(currentFileName); 759 doc->setName(currentFileName);
760 updateCaption(); 760 updateCaption();
761 setTimer(); 761 setTimer();
762} 762}
763 763
764void TextEdit::showEditTools() { 764void TextEdit::showEditTools() {
765 menu->show(); 765 menu->show();
766 editBar->show(); 766 editBar->show();
767 if(!useSearchBar) 767 if(!useSearchBar)
768 searchBar->hide(); 768 searchBar->hide();
769 else 769 else
770 searchBar->show(); 770 searchBar->show();
771 setWState (WState_Reserved1 ); 771 setWState (WState_Reserved1 );
772} 772}
773 773
774/*! 774/*!
775 unprompted save */ 775 unprompted save */
776bool TextEdit::save() { 776bool TextEdit::save() {
777 qDebug("saveAsFile " + currentFileName); 777 qDebug("saveAsFile " + currentFileName);
778 if(currentFileName.isEmpty()) { 778 if(currentFileName.isEmpty()) {
779 saveAs(); 779 saveAs();
780 return false; 780 return false;
781 } 781 }
782 782
783 QString file = doc->file(); 783 QString file = doc->file();
784 qDebug("saver file "+file); 784 qDebug("saver file "+file);
785 QString name= doc->name(); 785 QString name= doc->name();
786 qDebug("File named "+name); 786 qDebug("File named "+name);
787 QString rt = editor->text(); 787 QString rt = editor->text();
788 if( !rt.isEmpty() ) { 788 if( !rt.isEmpty() ) {
789 if(name.isEmpty()) { 789 if(name.isEmpty()) {
790 saveAs(); 790 saveAs();
791 } else { 791 } else {
792 currentFileName= name ; 792 currentFileName= name ;
793 qDebug("saveFile "+currentFileName); 793 qDebug("saveFile "+currentFileName);
794 794
795 struct stat buf; 795 struct stat buf;
796 mode_t mode; 796 mode_t mode;
797 stat(file.latin1(), &buf); 797 stat(file.latin1(), &buf);
798 mode = buf.st_mode; 798 mode = buf.st_mode;
799 799
800 if(!fileIs) { 800 if(!fileIs) {
801 doc->setName( name); 801 doc->setName( name);
802 FileManager fm; 802 FileManager fm;
803 if ( !fm.saveFile( *doc, rt ) ) { 803 if ( !fm.saveFile( *doc, rt ) ) {
804 return false; 804 return false;
805 } 805 }
806 } else { 806 } else {
807 qDebug("regular save file"); 807 qDebug("regular save file");
808 QFile f(file); 808 QFile f(file);
809 if( f.open(IO_WriteOnly)) { 809 if( f.open(IO_WriteOnly)) {
810 QCString crt = rt.utf8(); 810 QCString crt = rt.utf8();
811 f.writeBlock(crt,crt.length()); 811 f.writeBlock(crt,crt.length());
812 } else { 812 } else {
813 QMessageBox::message(tr("Text Edit"),tr("Write Failed")); 813 QMessageBox::message(tr("Text Edit"),tr("Write Failed"));
814 return false; 814 return false;
815 } 815 }
816 816
817 } 817 }
818 editor->setEdited( false); 818 editor->setEdited( false);
819 edited1=false; 819 edited1=false;
820 edited=false; 820 edited=false;
821 if(caption().left(1)=="*") 821 if(caption().left(1)=="*")
822 setCaption(caption().right(caption().length()-1)); 822 setCaption(caption().right(caption().length()-1));
823 823
824 824
825 chmod( file.latin1(), mode); 825 chmod( file.latin1(), mode);
826 } 826 }
827 return true; 827 return true;
828 } 828 }
829 return false; 829 return false;
830} 830}
831 831
832/*! 832/*!
833 prompted save */ 833 prompted save */
834bool TextEdit::saveAs() { 834bool TextEdit::saveAs() {
835 835
836 if(caption() == tr("Text Editor")) 836 if(caption() == tr("Text Editor"))
837 return false; 837 return false;
838 qDebug("saveAsFile " + currentFileName); 838 qDebug("saveAsFile " + currentFileName);
839 // case of nothing to save... 839 // case of nothing to save...
840// if ( !doc && !currentFileName.isEmpty()) { 840// if ( !doc && !currentFileName.isEmpty()) {
841// //|| !bFromDocView) 841// //|| !bFromDocView)
842// qDebug("no doc"); 842// qDebug("no doc");
843// return true; 843// return true;
844// } 844// }
845// if ( !editor->edited() ) { 845// if ( !editor->edited() ) {
846// delete doc; 846// delete doc;
847// doc = 0; 847// doc = 0;
848// return true; 848// return true;
849// } 849// }
850 850
851 QString rt = editor->text(); 851 QString rt = editor->text();
852 qDebug(currentFileName); 852 qDebug(currentFileName);
853 853
854 if( currentFileName.isEmpty() 854 if( currentFileName.isEmpty()
855 || currentFileName == tr("Unnamed") 855 || currentFileName == tr("Unnamed")
856 || currentFileName == tr("Text Editor")) { 856 || currentFileName == tr("Text Editor")) {
857 qDebug("do silly TT filename thing"); 857 qDebug("do silly TT filename thing");
858// if ( doc && doc->name().isEmpty() ) { 858// if ( doc && doc->name().isEmpty() ) {
859 QString pt = rt.simplifyWhiteSpace(); 859 QString pt = rt.simplifyWhiteSpace();
860 int i = pt.find( ' ' ); 860 int i = pt.find( ' ' );
861 QString docname = pt; 861 QString docname = pt;
862 if ( i > 0 ) 862 if ( i > 0 )
863 docname = pt.left( i ); 863 docname = pt.left( i );
864 // remove "." at the beginning 864 // remove "." at the beginning
865 while( docname.startsWith( "." ) ) 865 while( docname.startsWith( "." ) )
866 docname = docname.mid( 1 ); 866 docname = docname.mid( 1 );
867 docname.replace( QRegExp("/"), "_" ); 867 docname.replace( QRegExp("/"), "_" );
868 // cut the length. filenames longer than that 868 // cut the length. filenames longer than that
869 //don't make sense and something goes wrong when they get too long. 869 //don't make sense and something goes wrong when they get too long.
870 if ( docname.length() > 40 ) 870 if ( docname.length() > 40 )
871 docname = docname.left(40); 871 docname = docname.left(40);
872 if ( docname.isEmpty() ) 872 if ( docname.isEmpty() )
873 docname = tr("Unnamed"); 873 docname = tr("Unnamed");
874 if(doc) doc->setName(docname); 874 if(doc) doc->setName(docname);
875 currentFileName=docname; 875 currentFileName=docname;
876// } 876// }
877// else 877// else
878// qDebug("hmmmmmm"); 878// qDebug("hmmmmmm");
879 } 879 }
880 880
881 881
882 QMap<QString, QStringList> map; 882 QMap<QString, QStringList> map;
883 map.insert(tr("All"), QStringList() ); 883 map.insert(tr("All"), QStringList() );
884 QStringList text; 884 QStringList text;
885 text << "text/*"; 885 text << "text/*";
886 map.insert(tr("Text"), text ); 886 map.insert(tr("Text"), text );
887 text << "*"; 887 text << "*";
888 map.insert(tr("All"), text ); 888 map.insert(tr("All"), text );
889 889
890 QFileInfo cuFi( currentFileName); 890 QFileInfo cuFi( currentFileName);
891 QString filee = cuFi.fileName(); 891 QString filee = cuFi.fileName();
892 QString dire = cuFi.dirPath(); 892 QString dire = cuFi.dirPath();
893 if(dire==".") 893 if(dire==".")
894 dire = QPEApplication::documentDir(); 894 dire = QPEApplication::documentDir();
895 QString str; 895 QString str;
896 if( !featureAutoSave) 896 if( !featureAutoSave)
897 { 897 {
898 str = OFileDialog::getSaveFileName( 2, 898 str = OFileDialog::getSaveFileName( 2,
899 dire, 899 dire,
900 filee, map); 900 filee, map);
901 } 901 }
902 else 902 else
903 str=currentFileName; 903 str=currentFileName;
904 if(!str.isEmpty()) { 904 if(!str.isEmpty()) {
905 QString fileNm=str; 905 QString fileNm=str;
906 906
907 qDebug("saving filename "+fileNm); 907 qDebug("saving filename "+fileNm);
908 QFileInfo fi(fileNm); 908 QFileInfo fi(fileNm);
909 currentFileName=fi.fileName(); 909 currentFileName=fi.fileName();
910 if(doc) 910 if(doc)
911// QString file = doc->file(); 911// QString file = doc->file();
912// doc->removeFiles(); 912// doc->removeFiles();
913 delete doc; 913 delete doc;
914 DocLnk nf; 914 DocLnk nf;
915 nf.setType("text/plain"); 915 nf.setType("text/plain");
916 nf.setFile( fileNm); 916 nf.setFile( fileNm);
917 doc = new DocLnk(nf); 917 doc = new DocLnk(nf);
918// editor->setText(rt); 918// editor->setText(rt);
919 qDebug("Saving file as "+currentFileName); 919 qDebug("Saving file as "+currentFileName);
920 doc->setName( currentFileName); 920 doc->setName( currentFileName);
921 updateCaption( currentFileName); 921 updateCaption( currentFileName);
922 922
923 FileManager fm; 923 FileManager fm;
924 if ( !fm.saveFile( *doc, rt ) ) { 924 if ( !fm.saveFile( *doc, rt ) ) {
925 return false; 925 return false;
926 } 926 }
927 927
928 if( filePerms ) { 928 if( filePerms ) {
929 filePermissions *filePerm; 929 filePermissions *filePerm;
930 filePerm = new filePermissions(this, 930 filePerm = new filePermissions(this,
931 tr("Permissions"),true, 931 tr("Permissions"),true,
932 0,(const QString &)fileNm); 932 0,(const QString &)fileNm);
933 filePerm->showMaximized(); 933 filePerm->showMaximized();
934 filePerm->exec(); 934 filePerm->exec();
935 935
936 if( filePerm) 936 if( filePerm)
937 delete filePerm; 937 delete filePerm;
938 } 938 }
939// } 939// }
940 editor->setEdited( false); 940 editor->setEdited( false);
941 edited1 = false; 941 edited1 = false;
942 edited = false; 942 edited = false;
943 if(caption().left(1)=="*") 943 if(caption().left(1)=="*")
944 setCaption(caption().right(caption().length()-1)); 944 setCaption(caption().right(caption().length()-1));
945 945
946 return true; 946 return true;
947 } 947 }
948 qDebug("returning false"); 948 qDebug("returning false");
949 return false; 949 return false;
950} //end saveAs 950} //end saveAs
951 951
952void TextEdit::clear() { 952void TextEdit::clear() {
953 delete doc; 953 delete doc;
954 doc = 0; 954 doc = 0;
955 editor->clear(); 955 editor->clear();
956} 956}
957 957
958void TextEdit::updateCaption( const QString &name ) { 958void TextEdit::updateCaption( const QString &name ) {
959 959
960 if ( name.isEmpty() ) 960 if ( name.isEmpty() )
961 setCaption( tr("Text Editor") ); 961 setCaption( tr("Text Editor") );
962 else { 962 else {
963 QString s = name; 963 QString s = name;
964 if ( s.isNull() ) 964 if ( s.isNull() )
965 s = doc->name(); 965 s = doc->name();
966 if ( s.isEmpty() ) { 966 if ( s.isEmpty() ) {
967 s = tr( "Unnamed" ); 967 s = tr( "Unnamed" );
968 currentFileName=s; 968 currentFileName=s;
969 } 969 }
970// if(s.left(1) == "/") 970// if(s.left(1) == "/")
971// s = s.right(s.length()-1); 971// s = s.right(s.length()-1);
972 setCaption( s + " - " + tr("Text Editor") ); 972 setCaption( s + " - " + tr("Text Editor") );
973 } 973 }
974} 974}
975 975
976void TextEdit::setDocument(const QString& fileref) { 976void TextEdit::setDocument(const QString& fileref) {
977 if(fileref != "Unnamed") { 977 if(fileref != "Unnamed") {
978 currentFileName=fileref; 978 currentFileName=fileref;
979 qDebug("setDocument"); 979 qDebug("setDocument");
980 QFileInfo fi(currentFileName); 980 QFileInfo fi(currentFileName);
981 qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); 981 qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName);
982 if( (fi.baseName().left(1)).isEmpty() ) { 982 if( (fi.baseName().left(1)).isEmpty() ) {
983 openDotFile(currentFileName); 983 openDotFile(currentFileName);
984 984
985 } else { 985 } else {
986 qDebug("setDoc open"); 986 qDebug("setDoc open");
987 bFromDocView = true; 987 bFromDocView = true;
988 openFile(fileref); 988 openFile(fileref);
989 editor->setEdited(true); 989 editor->setEdited(true);
990 edited1=false; 990 edited1=false;
991 edited=true; 991 edited=true;
992 // fromSetDocument=false; 992 // fromSetDocument=false;
993 // doSearchBar(); 993 // doSearchBar();
994 } 994 }
995 } 995 }
996 updateCaption( currentFileName); 996 updateCaption( currentFileName);
997} 997}
998 998
999void TextEdit::changeFont() { 999void TextEdit::changeFont() {
1000 QDialog *d = new QDialog ( this, "FontDialog", true ); 1000 QDialog *d = new QDialog ( this, "FontDialog", true );
1001 d-> setCaption ( tr( "Choose font" )); 1001 d-> setCaption ( tr( "Choose font" ));
1002 QBoxLayout *lay = new QVBoxLayout ( d ); 1002 QBoxLayout *lay = new QVBoxLayout ( d );
1003 OFontSelector *ofs = new OFontSelector ( true, d ); 1003 OFontSelector *ofs = new OFontSelector ( true, d );
1004 lay-> addWidget ( ofs ); 1004 lay-> addWidget ( ofs );
1005 ofs-> setSelectedFont ( editor-> font ( )); 1005 ofs-> setSelectedFont ( editor-> font ( ));
1006 1006
1007 d-> showMaximized ( ); 1007 d-> showMaximized ( );
1008 if ( d-> exec ( ) == QDialog::Accepted ) 1008 if ( d-> exec ( ) == QDialog::Accepted )
1009 editor-> setFont ( ofs-> selectedFont ( )); 1009 editor-> setFont ( ofs-> selectedFont ( ));
1010 delete d; 1010 delete d;
1011 1011
1012} 1012}
1013 1013
1014void TextEdit::editDelete() { 1014void TextEdit::editDelete() {
1015 switch ( QMessageBox::warning(this,tr("Text Editor"), 1015 switch ( QMessageBox::warning(this,tr("Text Editor"),
1016 tr("Do you really want<BR>to <B>delete</B> " 1016 tr("Do you really want<BR>to <B>delete</B> "
1017 "the current file\nfrom the disk?<BR>This is " 1017 "the current file\nfrom the disk?<BR>This is "
1018 "<B>irreversable!!</B>"), 1018 "<B>irreversable!!</B>"),
1019 tr("Yes"),tr("No"),0,0,1) ) { 1019 tr("Yes"),tr("No"),0,0,1) ) {
1020 case 0: 1020 case 0:
1021 if(doc) { 1021 if(doc) {
1022 doc->removeFiles(); 1022 doc->removeFiles();
1023 clear(); 1023 clear();
1024 setCaption( tr("Text Editor") ); 1024 setCaption( tr("Text Editor") );
1025 } 1025 }
1026 break; 1026 break;
1027 case 1: 1027 case 1:
1028 // exit 1028 // exit
1029 break; 1029 break;
1030 }; 1030 };
1031} 1031}
1032 1032
1033void TextEdit::changeStartConfig( bool b ) { 1033void TextEdit::changeStartConfig( bool b ) {
1034 startWithNew=b; 1034 startWithNew=b;
1035 Config cfg("TextEdit"); 1035 Config cfg("TextEdit");
1036 cfg.setGroup("View"); 1036 cfg.setGroup("View");
1037 cfg.writeEntry("startNew",b); 1037 cfg.writeEntry("startNew",b);
1038 update(); 1038 update();
1039} 1039}
1040 1040
1041void TextEdit::editorChanged() { 1041void TextEdit::editorChanged() {
1042// qDebug("editor changed"); 1042// qDebug("editor changed");
1043 if( /*editor->edited() &&*/ /*edited && */!edited1) { 1043 if( /*editor->edited() &&*/ /*edited && */!edited1) {
1044 setCaption( "*"+caption()); 1044 setCaption( "*"+caption());
1045 edited1=true; 1045 edited1=true;
1046 } 1046 }
1047 edited=true; 1047 edited=true;
1048} 1048}
1049 1049
1050void TextEdit::receive(const QCString&msg, const QByteArray &) { 1050void TextEdit::receive(const QCString&msg, const QByteArray &) {
1051 qDebug("QCop "+msg); 1051 qDebug("QCop "+msg);
1052 if ( msg == "setDocument(QString)" ) { 1052 if ( msg == "setDocument(QString)" ) {
1053 qDebug("bugger all"); 1053 qDebug("bugger all");
1054 1054
1055 } 1055 }
1056 1056
1057} 1057}
1058 1058
1059void TextEdit::doAbout() { 1059void TextEdit::doAbout() {
1060 QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" 1060 QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>"
1061 "2000 Trolltech AS, and<BR>" 1061 "2000 Trolltech AS, and<BR>"
1062 "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" 1062 "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>"
1063 "and is licensed under the GPL")); 1063 "and is licensed under the GPL"));
1064} 1064}
1065 1065
1066void TextEdit::doPrompt(bool b) { 1066void TextEdit::doPrompt(bool b) {
1067 promptExit=b; 1067 promptExit=b;
1068 Config cfg("TextEdit"); 1068 Config cfg("TextEdit");
1069 cfg.setGroup ( "View" ); 1069 cfg.setGroup ( "View" );
1070 cfg.writeEntry ( "PromptExit", b); 1070 cfg.writeEntry ( "PromptExit", b);
1071} 1071}
1072 1072
1073void TextEdit::doDesktop(bool b) { 1073void TextEdit::doDesktop(bool b) {
1074 openDesktop=b; 1074 openDesktop=b;
1075 Config cfg("TextEdit"); 1075 Config cfg("TextEdit");
1076 cfg.setGroup ( "View" ); 1076 cfg.setGroup ( "View" );
1077 cfg.writeEntry ( "OpenDesktop", b); 1077 cfg.writeEntry ( "OpenDesktop", b);
1078} 1078}
1079 1079
1080void TextEdit::doFilePerms(bool b) { 1080void TextEdit::doFilePerms(bool b) {
1081 filePerms=b; 1081 filePerms=b;
1082 Config cfg("TextEdit"); 1082 Config cfg("TextEdit");
1083 cfg.setGroup ( "View" ); 1083 cfg.setGroup ( "View" );
1084 cfg.writeEntry ( "FilePermissions", b); 1084 cfg.writeEntry ( "FilePermissions", b);
1085} 1085}
1086 1086
1087void TextEdit::editPasteTimeDate() { 1087void TextEdit::editPasteTimeDate() {
1088#ifndef QT_NO_CLIPBOARD 1088#ifndef QT_NO_CLIPBOARD
1089 QClipboard *cb = QApplication::clipboard(); 1089 QClipboard *cb = QApplication::clipboard();
1090 QDateTime dt = QDateTime::currentDateTime(); 1090 QDateTime dt = QDateTime::currentDateTime();
1091 cb->setText( dt.toString()); 1091 cb->setText( dt.toString());
1092 editor->paste(); 1092 editor->paste();
1093#endif 1093#endif
1094} 1094}
1095 1095
1096int TextEdit::savePrompt() 1096int TextEdit::savePrompt()
1097{ 1097{
1098 switch( QMessageBox::information( 0, (tr("Textedit")), 1098 switch( QMessageBox::information( 0, (tr("Textedit")),
1099 (tr("Textedit detected\n" 1099 (tr("Textedit detected\n"
1100 "you have unsaved changes\n" 1100 "you have unsaved changes\n"
1101 "Go ahead and save?\n")), 1101 "Go ahead and save?\n")),
1102 (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) 1102 (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) )
1103 { 1103 {
1104 case 0: 1104 case 0:
1105 { 1105 {
1106 return 1; 1106 return 1;
1107 } 1107 }
1108 break; 1108 break;
1109 1109
1110 case 1: 1110 case 1:
1111 { 1111 {
1112 return 2; 1112 return 2;
1113 } 1113 }
1114 break; 1114 break;
1115 1115
1116 case 2: 1116 case 2:
1117 { 1117 {
1118 return -1; 1118 return -1;
1119 } 1119 }
1120 break; 1120 break;
1121 }; 1121 };
1122 1122
1123 return 0; 1123 return 0;
1124} 1124}
1125 1125
1126void TextEdit::timerCrank() 1126void TextEdit::timerCrank()
1127{ 1127{
1128 if(featureAutoSave && edited1) 1128 if(featureAutoSave && edited1)
1129 { 1129 {
1130 if(currentFileName.isEmpty()) 1130 if(currentFileName.isEmpty())
1131 { 1131 {
1132 currentFileName = QDir::homeDirPath()+"/textedit.tmp"; 1132 currentFileName = QDir::homeDirPath()+"/textedit.tmp";
1133 saveAs(); 1133 saveAs();
1134 } 1134 }
1135 else 1135 else
1136 { 1136 {
1137// qDebug("autosave"); 1137// qDebug("autosave");
1138 save(); 1138 save();
1139 } 1139 }
1140 setTimer(); 1140 setTimer();
1141 } 1141 }
1142} 1142}
1143 1143
1144void TextEdit::doTimer(bool b) 1144void TextEdit::doTimer(bool b)
1145{ 1145{
1146 Config cfg("TextEdit"); 1146 Config cfg("TextEdit");
1147 cfg.setGroup ( "View" ); 1147 cfg.setGroup ( "View" );
1148 cfg.writeEntry ( "autosave", b); 1148 cfg.writeEntry ( "autosave", b);
1149 featureAutoSave = b; 1149 featureAutoSave = b;
1150 nAutoSave->setOn(b); 1150 nAutoSave->setOn(b);
1151 if(b) 1151 if(b)
1152 { 1152 {
1153// qDebug("doTimer true"); 1153// qDebug("doTimer true");
1154 setTimer(); 1154 setTimer();
1155 } 1155 }
1156// else 1156// else
1157// qDebug("doTimer false"); 1157// qDebug("doTimer false");
1158} 1158}
1159 1159
1160void TextEdit::setTimer() 1160void TextEdit::setTimer()
1161{ 1161{
1162if(featureAutoSave) 1162if(featureAutoSave)
1163 { 1163 {
1164// qDebug("setting autosave"); 1164// qDebug("setting autosave");
1165 QTimer *timer = new QTimer(this ); 1165 QTimer *timer = new QTimer(this );
1166 connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); 1166 connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) );
1167 timer->start( 300000, true); //5 minutes 1167 timer->start( 300000, true); //5 minutes
1168 } 1168 }
1169} 1169}
1170 1170
1171void TextEdit::gotoLine() { 1171void TextEdit::gotoLine() {
1172 1172
1173 QWidget *d = QApplication::desktop(); 1173 QWidget *d = QApplication::desktop();
1174 gotoEdit = new QLineEdit( 0, "Goto line"); 1174 gotoEdit = new QLineEdit( 0, "Goto line");
1175 1175
1176 gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2)); 1176 gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2));
1177 gotoEdit->setFrame(true); 1177 gotoEdit->setFrame(true);
1178 gotoEdit->show(); 1178 gotoEdit->show();
1179 connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); 1179 connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto()));
1180} 1180}
1181 1181
1182void TextEdit::doGoto() { 1182void TextEdit::doGoto() {
1183 QString number = gotoEdit->text(); 1183 QString number = gotoEdit->text();
1184 gotoEdit->hide(); 1184 gotoEdit->hide();
1185 if(gotoEdit) delete gotoEdit; 1185 if(gotoEdit) {
1186 delete gotoEdit;
1187 gotoEdit = 0;
1188 }
1189
1186 bool ok; 1190 bool ok;
1187 int lineNumber = number.toInt(&ok, 10); 1191 int lineNumber = number.toInt(&ok, 10);
1188 if(editor->numLines() < lineNumber) 1192 if(editor->numLines() < lineNumber)
1189 QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); 1193 QMessageBox::message(tr("Text Edit"),tr("Not enough lines"));
1190 else 1194 else
1191 { 1195 {
1192 editor->setCursorPosition(lineNumber, 0, false); 1196 editor->setCursorPosition(lineNumber, 0, false);
1193 } 1197 }
1194} 1198}