author | llornkcor <llornkcor> | 2003-02-18 19:29:56 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-02-18 19:29:56 (UTC) |
commit | 9f5098a6da637e81f6525482456394a68524dc61 (patch) (unidiff) | |
tree | 85bfd8e545a10d0faa321c174354d0a2302e0591 | |
parent | 4dd3080c36c96c58564a29f1b3d2cf21bfb1eae2 (diff) | |
download | opie-9f5098a6da637e81f6525482456394a68524dc61.zip opie-9f5098a6da637e81f6525482456394a68524dc61.tar.gz opie-9f5098a6da637e81f6525482456394a68524dc61.tar.bz2 |
5 minutes, not 30 seconds
-rw-r--r-- | core/apps/textedit/textedit.cpp | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 1e8ce7f..f571511 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -800,466 +800,463 @@ file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), | |||
800 | filer = sf.file(); | 800 | filer = sf.file(); |
801 | break; | 801 | break; |
802 | } | 802 | } |
803 | } else if(fi.baseName().left(1) == "") { | 803 | } else if(fi.baseName().left(1) == "") { |
804 | currentFileName=f; | 804 | currentFileName=f; |
805 | openDotFile(currentFileName); | 805 | openDotFile(currentFileName); |
806 | } else { | 806 | } else { |
807 | DocLnk sf(f); | 807 | DocLnk sf(f); |
808 | filer = sf.file(); | 808 | filer = sf.file(); |
809 | if(filer.right(1) == "/") | 809 | if(filer.right(1) == "/") |
810 | filer = f; | 810 | filer = f; |
811 | 811 | ||
812 | DocLnk nf; | 812 | DocLnk nf; |
813 | nf.setType("text/plain"); | 813 | nf.setType("text/plain"); |
814 | nf.setFile(filer); | 814 | nf.setFile(filer); |
815 | currentFileName=filer; | 815 | currentFileName=filer; |
816 | 816 | ||
817 | nf.setName(fi.baseName()); | 817 | nf.setName(fi.baseName()); |
818 | openFile(nf); | 818 | openFile(nf); |
819 | 819 | ||
820 | qDebug("openFile string "+currentFileName); | 820 | qDebug("openFile string "+currentFileName); |
821 | 821 | ||
822 | } | 822 | } |
823 | showEditTools(); | 823 | showEditTools(); |
824 | // Show filename in caption | 824 | // Show filename in caption |
825 | QString name = filer; | 825 | QString name = filer; |
826 | int sep = name.findRev( '/' ); | 826 | int sep = name.findRev( '/' ); |
827 | if ( sep > 0 ) | 827 | if ( sep > 0 ) |
828 | name = name.mid( sep+1 ); | 828 | name = name.mid( sep+1 ); |
829 | updateCaption( name ); | 829 | updateCaption( name ); |
830 | } | 830 | } |
831 | 831 | ||
832 | void TextEdit::openFile( const DocLnk &f ) { | 832 | void TextEdit::openFile( const DocLnk &f ) { |
833 | // clear(); | 833 | // clear(); |
834 | // bFromDocView = true; | 834 | // bFromDocView = true; |
835 | FileManager fm; | 835 | FileManager fm; |
836 | QString txt; | 836 | QString txt; |
837 | currentFileName=f.file(); | 837 | currentFileName=f.file(); |
838 | qDebug("openFile doclnk " + currentFileName); | 838 | qDebug("openFile doclnk " + currentFileName); |
839 | if ( !fm.loadFile( f, txt ) ) { | 839 | if ( !fm.loadFile( f, txt ) ) { |
840 | // ####### could be a new file | 840 | // ####### could be a new file |
841 | qDebug( "Cannot open file" ); | 841 | qDebug( "Cannot open file" ); |
842 | } | 842 | } |
843 | // fileNew(); | 843 | // fileNew(); |
844 | if ( doc ) | 844 | if ( doc ) |
845 | delete doc; | 845 | delete doc; |
846 | doc = new DocLnk(f); | 846 | doc = new DocLnk(f); |
847 | editor->setText(txt); | 847 | editor->setText(txt); |
848 | editor->setEdited( false); | 848 | editor->setEdited( false); |
849 | edited1=false; | 849 | edited1=false; |
850 | edited=false; | 850 | edited=false; |
851 | 851 | ||
852 | doc->setName(currentFileName); | 852 | doc->setName(currentFileName); |
853 | updateCaption(); | 853 | updateCaption(); |
854 | setTimer(); | 854 | setTimer(); |
855 | } | 855 | } |
856 | 856 | ||
857 | void TextEdit::showEditTools() { | 857 | void TextEdit::showEditTools() { |
858 | menu->show(); | 858 | menu->show(); |
859 | editBar->show(); | 859 | editBar->show(); |
860 | if(!useSearchBar) | 860 | if(!useSearchBar) |
861 | searchBar->hide(); | 861 | searchBar->hide(); |
862 | else | 862 | else |
863 | searchBar->show(); | 863 | searchBar->show(); |
864 | setWState (WState_Reserved1 ); | 864 | setWState (WState_Reserved1 ); |
865 | } | 865 | } |
866 | 866 | ||
867 | /*! | 867 | /*! |
868 | unprompted save */ | 868 | unprompted save */ |
869 | bool TextEdit::save() { | 869 | bool TextEdit::save() { |
870 | qDebug("saveAsFile " + currentFileName); | 870 | qDebug("saveAsFile " + currentFileName); |
871 | if(currentFileName.isEmpty()) { | 871 | if(currentFileName.isEmpty()) { |
872 | saveAs(); | 872 | saveAs(); |
873 | return false; | 873 | return false; |
874 | } | 874 | } |
875 | 875 | ||
876 | QString file = doc->file(); | 876 | QString file = doc->file(); |
877 | qDebug("saver file "+file); | 877 | qDebug("saver file "+file); |
878 | QString name= doc->name(); | 878 | QString name= doc->name(); |
879 | qDebug("File named "+name); | 879 | qDebug("File named "+name); |
880 | QString rt = editor->text(); | 880 | QString rt = editor->text(); |
881 | if( !rt.isEmpty() ) { | 881 | if( !rt.isEmpty() ) { |
882 | if(name.isEmpty()) { | 882 | if(name.isEmpty()) { |
883 | saveAs(); | 883 | saveAs(); |
884 | } else { | 884 | } else { |
885 | currentFileName= name ; | 885 | currentFileName= name ; |
886 | qDebug("saveFile "+currentFileName); | 886 | qDebug("saveFile "+currentFileName); |
887 | 887 | ||
888 | struct stat buf; | 888 | struct stat buf; |
889 | mode_t mode; | 889 | mode_t mode; |
890 | stat(file.latin1(), &buf); | 890 | stat(file.latin1(), &buf); |
891 | mode = buf.st_mode; | 891 | mode = buf.st_mode; |
892 | 892 | ||
893 | if(!fileIs) { | 893 | if(!fileIs) { |
894 | doc->setName( name); | 894 | doc->setName( name); |
895 | FileManager fm; | 895 | FileManager fm; |
896 | if ( !fm.saveFile( *doc, rt ) ) { | 896 | if ( !fm.saveFile( *doc, rt ) ) { |
897 | return false; | 897 | return false; |
898 | } | 898 | } |
899 | } else { | 899 | } else { |
900 | qDebug("regular save file"); | 900 | qDebug("regular save file"); |
901 | QFile f(file); | 901 | QFile f(file); |
902 | if( f.open(IO_WriteOnly)) { | 902 | if( f.open(IO_WriteOnly)) { |
903 | QCString crt = rt.utf8(); | 903 | QCString crt = rt.utf8(); |
904 | f.writeBlock(crt,crt.length()); | 904 | f.writeBlock(crt,crt.length()); |
905 | } else { | 905 | } else { |
906 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); | 906 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); |
907 | return false; | 907 | return false; |
908 | } | 908 | } |
909 | 909 | ||
910 | } | 910 | } |
911 | editor->setEdited( false); | 911 | editor->setEdited( false); |
912 | edited1=false; | 912 | edited1=false; |
913 | edited=false; | 913 | edited=false; |
914 | if(caption().left(1)=="*") | 914 | if(caption().left(1)=="*") |
915 | setCaption(caption().right(caption().length()-1)); | 915 | setCaption(caption().right(caption().length()-1)); |
916 | 916 | ||
917 | 917 | ||
918 | chmod( file.latin1(), mode); | 918 | chmod( file.latin1(), mode); |
919 | } | 919 | } |
920 | return true; | 920 | return true; |
921 | } | 921 | } |
922 | return false; | 922 | return false; |
923 | } | 923 | } |
924 | 924 | ||
925 | /*! | 925 | /*! |
926 | prompted save */ | 926 | prompted save */ |
927 | bool TextEdit::saveAs() { | 927 | bool TextEdit::saveAs() { |
928 | 928 | ||
929 | if(caption() == tr("Text Editor")) | 929 | if(caption() == tr("Text Editor")) |
930 | return false; | 930 | return false; |
931 | qDebug("saveAsFile " + currentFileName); | 931 | qDebug("saveAsFile " + currentFileName); |
932 | // case of nothing to save... | 932 | // case of nothing to save... |
933 | // if ( !doc && !currentFileName.isEmpty()) { | 933 | // if ( !doc && !currentFileName.isEmpty()) { |
934 | // //|| !bFromDocView) | 934 | // //|| !bFromDocView) |
935 | // qDebug("no doc"); | 935 | // qDebug("no doc"); |
936 | // return true; | 936 | // return true; |
937 | // } | 937 | // } |
938 | // if ( !editor->edited() ) { | 938 | // if ( !editor->edited() ) { |
939 | // delete doc; | 939 | // delete doc; |
940 | // doc = 0; | 940 | // doc = 0; |
941 | // return true; | 941 | // return true; |
942 | // } | 942 | // } |
943 | 943 | ||
944 | QString rt = editor->text(); | 944 | QString rt = editor->text(); |
945 | qDebug(currentFileName); | 945 | qDebug(currentFileName); |
946 | 946 | ||
947 | if( currentFileName.isEmpty() | 947 | if( currentFileName.isEmpty() |
948 | || currentFileName == tr("Unnamed") | 948 | || currentFileName == tr("Unnamed") |
949 | || currentFileName == tr("Text Editor")) { | 949 | || currentFileName == tr("Text Editor")) { |
950 | qDebug("do silly TT filename thing"); | 950 | qDebug("do silly TT filename thing"); |
951 | // if ( doc && doc->name().isEmpty() ) { | 951 | // if ( doc && doc->name().isEmpty() ) { |
952 | QString pt = rt.simplifyWhiteSpace(); | 952 | QString pt = rt.simplifyWhiteSpace(); |
953 | int i = pt.find( ' ' ); | 953 | int i = pt.find( ' ' ); |
954 | QString docname = pt; | 954 | QString docname = pt; |
955 | if ( i > 0 ) | 955 | if ( i > 0 ) |
956 | docname = pt.left( i ); | 956 | docname = pt.left( i ); |
957 | // remove "." at the beginning | 957 | // remove "." at the beginning |
958 | while( docname.startsWith( "." ) ) | 958 | while( docname.startsWith( "." ) ) |
959 | docname = docname.mid( 1 ); | 959 | docname = docname.mid( 1 ); |
960 | docname.replace( QRegExp("/"), "_" ); | 960 | docname.replace( QRegExp("/"), "_" ); |
961 | // cut the length. filenames longer than that | 961 | // cut the length. filenames longer than that |
962 | //don't make sense and something goes wrong when they get too long. | 962 | //don't make sense and something goes wrong when they get too long. |
963 | if ( docname.length() > 40 ) | 963 | if ( docname.length() > 40 ) |
964 | docname = docname.left(40); | 964 | docname = docname.left(40); |
965 | if ( docname.isEmpty() ) | 965 | if ( docname.isEmpty() ) |
966 | docname = tr("Unnamed"); | 966 | docname = tr("Unnamed"); |
967 | if(doc) doc->setName(docname); | 967 | if(doc) doc->setName(docname); |
968 | currentFileName=docname; | 968 | currentFileName=docname; |
969 | // } | 969 | // } |
970 | // else | 970 | // else |
971 | // qDebug("hmmmmmm"); | 971 | // qDebug("hmmmmmm"); |
972 | } | 972 | } |
973 | 973 | ||
974 | 974 | ||
975 | QMap<QString, QStringList> map; | 975 | QMap<QString, QStringList> map; |
976 | map.insert(tr("All"), QStringList() ); | 976 | map.insert(tr("All"), QStringList() ); |
977 | QStringList text; | 977 | QStringList text; |
978 | text << "text/*"; | 978 | text << "text/*"; |
979 | map.insert(tr("Text"), text ); | 979 | map.insert(tr("Text"), text ); |
980 | text << "*"; | 980 | text << "*"; |
981 | map.insert(tr("All"), text ); | 981 | map.insert(tr("All"), text ); |
982 | 982 | ||
983 | QFileInfo cuFi( currentFileName); | 983 | QFileInfo cuFi( currentFileName); |
984 | QString filee = cuFi.fileName(); | 984 | QString filee = cuFi.fileName(); |
985 | QString dire = cuFi.dirPath(); | 985 | QString dire = cuFi.dirPath(); |
986 | if(dire==".") | 986 | if(dire==".") |
987 | dire = QPEApplication::documentDir(); | 987 | dire = QPEApplication::documentDir(); |
988 | QString str; | 988 | QString str; |
989 | if( !featureAutoSave) | 989 | if( !featureAutoSave) |
990 | { | 990 | { |
991 | str = OFileDialog::getSaveFileName( 2, | 991 | str = OFileDialog::getSaveFileName( 2, |
992 | dire, | 992 | dire, |
993 | filee, map); | 993 | filee, map); |
994 | } | 994 | } |
995 | else | 995 | else |
996 | str=currentFileName; | 996 | str=currentFileName; |
997 | if(!str.isEmpty()) { | 997 | if(!str.isEmpty()) { |
998 | QString fileNm=str; | 998 | QString fileNm=str; |
999 | 999 | ||
1000 | qDebug("saving filename "+fileNm); | 1000 | qDebug("saving filename "+fileNm); |
1001 | QFileInfo fi(fileNm); | 1001 | QFileInfo fi(fileNm); |
1002 | currentFileName=fi.fileName(); | 1002 | currentFileName=fi.fileName(); |
1003 | if(doc) | 1003 | if(doc) |
1004 | // QString file = doc->file(); | 1004 | // QString file = doc->file(); |
1005 | // doc->removeFiles(); | 1005 | // doc->removeFiles(); |
1006 | delete doc; | 1006 | delete doc; |
1007 | DocLnk nf; | 1007 | DocLnk nf; |
1008 | nf.setType("text/plain"); | 1008 | nf.setType("text/plain"); |
1009 | nf.setFile( fileNm); | 1009 | nf.setFile( fileNm); |
1010 | doc = new DocLnk(nf); | 1010 | doc = new DocLnk(nf); |
1011 | // editor->setText(rt); | 1011 | // editor->setText(rt); |
1012 | qDebug("Saving file as "+currentFileName); | 1012 | qDebug("Saving file as "+currentFileName); |
1013 | doc->setName( currentFileName); | 1013 | doc->setName( currentFileName); |
1014 | updateCaption( currentFileName); | 1014 | updateCaption( currentFileName); |
1015 | 1015 | ||
1016 | FileManager fm; | 1016 | FileManager fm; |
1017 | if ( !fm.saveFile( *doc, rt ) ) { | 1017 | if ( !fm.saveFile( *doc, rt ) ) { |
1018 | return false; | 1018 | return false; |
1019 | } | 1019 | } |
1020 | 1020 | ||
1021 | if( filePerms ) { | 1021 | if( filePerms ) { |
1022 | filePermissions *filePerm; | 1022 | filePermissions *filePerm; |
1023 | filePerm = new filePermissions(this, | 1023 | filePerm = new filePermissions(this, |
1024 | tr("Permissions"),true, | 1024 | tr("Permissions"),true, |
1025 | 0,(const QString &)fileNm); | 1025 | 0,(const QString &)fileNm); |
1026 | filePerm->showMaximized(); | 1026 | filePerm->showMaximized(); |
1027 | filePerm->exec(); | 1027 | filePerm->exec(); |
1028 | 1028 | ||
1029 | if( filePerm) | 1029 | if( filePerm) |
1030 | delete filePerm; | 1030 | delete filePerm; |
1031 | } | 1031 | } |
1032 | // } | 1032 | // } |
1033 | editor->setEdited( false); | 1033 | editor->setEdited( false); |
1034 | edited1 = false; | 1034 | edited1 = false; |
1035 | edited = false; | 1035 | edited = false; |
1036 | if(caption().left(1)=="*") | 1036 | if(caption().left(1)=="*") |
1037 | setCaption(caption().right(caption().length()-1)); | 1037 | setCaption(caption().right(caption().length()-1)); |
1038 | 1038 | ||
1039 | return true; | 1039 | return true; |
1040 | } | 1040 | } |
1041 | qDebug("returning false"); | 1041 | qDebug("returning false"); |
1042 | return false; | 1042 | return false; |
1043 | } //end saveAs | 1043 | } //end saveAs |
1044 | 1044 | ||
1045 | void TextEdit::clear() { | 1045 | void TextEdit::clear() { |
1046 | delete doc; | 1046 | delete doc; |
1047 | doc = 0; | 1047 | doc = 0; |
1048 | editor->clear(); | 1048 | editor->clear(); |
1049 | } | 1049 | } |
1050 | 1050 | ||
1051 | void TextEdit::updateCaption( const QString &name ) { | 1051 | void TextEdit::updateCaption( const QString &name ) { |
1052 | 1052 | ||
1053 | if ( name.isEmpty() ) | 1053 | if ( name.isEmpty() ) |
1054 | setCaption( tr("Text Editor") ); | 1054 | setCaption( tr("Text Editor") ); |
1055 | else { | 1055 | else { |
1056 | QString s = name; | 1056 | QString s = name; |
1057 | if ( s.isNull() ) | 1057 | if ( s.isNull() ) |
1058 | s = doc->name(); | 1058 | s = doc->name(); |
1059 | if ( s.isEmpty() ) { | 1059 | if ( s.isEmpty() ) { |
1060 | s = tr( "Unnamed" ); | 1060 | s = tr( "Unnamed" ); |
1061 | currentFileName=s; | 1061 | currentFileName=s; |
1062 | } | 1062 | } |
1063 | // if(s.left(1) == "/") | 1063 | // if(s.left(1) == "/") |
1064 | // s = s.right(s.length()-1); | 1064 | // s = s.right(s.length()-1); |
1065 | setCaption( s + " - " + tr("Text Editor") ); | 1065 | setCaption( s + " - " + tr("Text Editor") ); |
1066 | } | 1066 | } |
1067 | } | 1067 | } |
1068 | 1068 | ||
1069 | void TextEdit::setDocument(const QString& fileref) { | 1069 | void TextEdit::setDocument(const QString& fileref) { |
1070 | if(fileref != "Unnamed") { | 1070 | if(fileref != "Unnamed") { |
1071 | currentFileName=fileref; | 1071 | currentFileName=fileref; |
1072 | qDebug("setDocument"); | 1072 | qDebug("setDocument"); |
1073 | QFileInfo fi(currentFileName); | 1073 | QFileInfo fi(currentFileName); |
1074 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); | 1074 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); |
1075 | if( (fi.baseName().left(1)).isEmpty() ) { | 1075 | if( (fi.baseName().left(1)).isEmpty() ) { |
1076 | openDotFile(currentFileName); | 1076 | openDotFile(currentFileName); |
1077 | 1077 | ||
1078 | } else { | 1078 | } else { |
1079 | qDebug("setDoc open"); | 1079 | qDebug("setDoc open"); |
1080 | bFromDocView = true; | 1080 | bFromDocView = true; |
1081 | openFile(fileref); | 1081 | openFile(fileref); |
1082 | editor->setEdited(true); | 1082 | editor->setEdited(true); |
1083 | edited1=false; | 1083 | edited1=false; |
1084 | edited=true; | 1084 | edited=true; |
1085 | // fromSetDocument=false; | 1085 | // fromSetDocument=false; |
1086 | // doSearchBar(); | 1086 | // doSearchBar(); |
1087 | } | 1087 | } |
1088 | } | 1088 | } |
1089 | updateCaption( currentFileName); | 1089 | updateCaption( currentFileName); |
1090 | } | 1090 | } |
1091 | 1091 | ||
1092 | void TextEdit::changeFont() { | 1092 | void TextEdit::changeFont() { |
1093 | QDialog *d = new QDialog ( this, "FontDialog", true ); | 1093 | QDialog *d = new QDialog ( this, "FontDialog", true ); |
1094 | d-> setCaption ( tr( "Choose font" )); | 1094 | d-> setCaption ( tr( "Choose font" )); |
1095 | QBoxLayout *lay = new QVBoxLayout ( d ); | 1095 | QBoxLayout *lay = new QVBoxLayout ( d ); |
1096 | OFontSelector *ofs = new OFontSelector ( true, d ); | 1096 | OFontSelector *ofs = new OFontSelector ( true, d ); |
1097 | lay-> addWidget ( ofs ); | 1097 | lay-> addWidget ( ofs ); |
1098 | ofs-> setSelectedFont ( editor-> font ( )); | 1098 | ofs-> setSelectedFont ( editor-> font ( )); |
1099 | 1099 | ||
1100 | d-> showMaximized ( ); | 1100 | d-> showMaximized ( ); |
1101 | if ( d-> exec ( ) == QDialog::Accepted ) | 1101 | if ( d-> exec ( ) == QDialog::Accepted ) |
1102 | editor-> setFont ( ofs-> selectedFont ( )); | 1102 | editor-> setFont ( ofs-> selectedFont ( )); |
1103 | delete d; | 1103 | delete d; |
1104 | 1104 | ||
1105 | } | 1105 | } |
1106 | 1106 | ||
1107 | void TextEdit::editDelete() { | 1107 | void TextEdit::editDelete() { |
1108 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 1108 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
1109 | tr("Do you really want<BR>to <B>delete</B> " | 1109 | tr("Do you really want<BR>to <B>delete</B> " |
1110 | "the current file\nfrom the disk?<BR>This is " | 1110 | "the current file\nfrom the disk?<BR>This is " |
1111 | "<B>irreversable!!</B>"), | 1111 | "<B>irreversable!!</B>"), |
1112 | tr("Yes"),tr("No"),0,0,1) ) { | 1112 | tr("Yes"),tr("No"),0,0,1) ) { |
1113 | case 0: | 1113 | case 0: |
1114 | if(doc) { | 1114 | if(doc) { |
1115 | doc->removeFiles(); | 1115 | doc->removeFiles(); |
1116 | clear(); | 1116 | clear(); |
1117 | setCaption( tr("Text Editor") ); | 1117 | setCaption( tr("Text Editor") ); |
1118 | } | 1118 | } |
1119 | break; | 1119 | break; |
1120 | case 1: | 1120 | case 1: |
1121 | // exit | 1121 | // exit |
1122 | break; | 1122 | break; |
1123 | }; | 1123 | }; |
1124 | } | 1124 | } |
1125 | 1125 | ||
1126 | void TextEdit::changeStartConfig( bool b ) { | 1126 | void TextEdit::changeStartConfig( bool b ) { |
1127 | startWithNew=b; | 1127 | startWithNew=b; |
1128 | Config cfg("TextEdit"); | 1128 | Config cfg("TextEdit"); |
1129 | cfg.setGroup("View"); | 1129 | cfg.setGroup("View"); |
1130 | cfg.writeEntry("startNew",b); | 1130 | cfg.writeEntry("startNew",b); |
1131 | update(); | 1131 | update(); |
1132 | } | 1132 | } |
1133 | 1133 | ||
1134 | void TextEdit::editorChanged() { | 1134 | void TextEdit::editorChanged() { |
1135 | // qDebug("editor changed"); | 1135 | // qDebug("editor changed"); |
1136 | if( /*editor->edited() &&*/ /*edited && */!edited1) { | 1136 | if( /*editor->edited() &&*/ /*edited && */!edited1) { |
1137 | setCaption( "*"+caption()); | 1137 | setCaption( "*"+caption()); |
1138 | edited1=true; | 1138 | edited1=true; |
1139 | } | 1139 | } |
1140 | edited=true; | 1140 | edited=true; |
1141 | } | 1141 | } |
1142 | 1142 | ||
1143 | void TextEdit::receive(const QCString&msg, const QByteArray &) { | 1143 | void TextEdit::receive(const QCString&msg, const QByteArray &) { |
1144 | qDebug("QCop "+msg); | 1144 | qDebug("QCop "+msg); |
1145 | if ( msg == "setDocument(QString)" ) { | 1145 | if ( msg == "setDocument(QString)" ) { |
1146 | qDebug("bugger all"); | 1146 | qDebug("bugger all"); |
1147 | 1147 | ||
1148 | } | 1148 | } |
1149 | 1149 | ||
1150 | } | 1150 | } |
1151 | 1151 | ||
1152 | void TextEdit::doAbout() { | 1152 | void TextEdit::doAbout() { |
1153 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" | 1153 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" |
1154 | "2000 Trolltech AS, and<BR>" | 1154 | "2000 Trolltech AS, and<BR>" |
1155 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" | 1155 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" |
1156 | "and is licensed under the GPL")); | 1156 | "and is licensed under the GPL")); |
1157 | } | 1157 | } |
1158 | 1158 | ||
1159 | void TextEdit::doPrompt(bool b) { | 1159 | void TextEdit::doPrompt(bool b) { |
1160 | promptExit=b; | 1160 | promptExit=b; |
1161 | Config cfg("TextEdit"); | 1161 | Config cfg("TextEdit"); |
1162 | cfg.setGroup ( "View" ); | 1162 | cfg.setGroup ( "View" ); |
1163 | cfg.writeEntry ( "PromptExit", b); | 1163 | cfg.writeEntry ( "PromptExit", b); |
1164 | } | 1164 | } |
1165 | 1165 | ||
1166 | void TextEdit::doDesktop(bool b) { | 1166 | void TextEdit::doDesktop(bool b) { |
1167 | openDesktop=b; | 1167 | openDesktop=b; |
1168 | Config cfg("TextEdit"); | 1168 | Config cfg("TextEdit"); |
1169 | cfg.setGroup ( "View" ); | 1169 | cfg.setGroup ( "View" ); |
1170 | cfg.writeEntry ( "OpenDesktop", b); | 1170 | cfg.writeEntry ( "OpenDesktop", b); |
1171 | } | 1171 | } |
1172 | 1172 | ||
1173 | void TextEdit::doFilePerms(bool b) { | 1173 | void TextEdit::doFilePerms(bool b) { |
1174 | filePerms=b; | 1174 | filePerms=b; |
1175 | Config cfg("TextEdit"); | 1175 | Config cfg("TextEdit"); |
1176 | cfg.setGroup ( "View" ); | 1176 | cfg.setGroup ( "View" ); |
1177 | cfg.writeEntry ( "FilePermissions", b); | 1177 | cfg.writeEntry ( "FilePermissions", b); |
1178 | } | 1178 | } |
1179 | 1179 | ||
1180 | void TextEdit::editPasteTimeDate() { | 1180 | void TextEdit::editPasteTimeDate() { |
1181 | #ifndef QT_NO_CLIPBOARD | 1181 | #ifndef QT_NO_CLIPBOARD |
1182 | QClipboard *cb = QApplication::clipboard(); | 1182 | QClipboard *cb = QApplication::clipboard(); |
1183 | QDateTime dt = QDateTime::currentDateTime(); | 1183 | QDateTime dt = QDateTime::currentDateTime(); |
1184 | cb->setText( dt.toString()); | 1184 | cb->setText( dt.toString()); |
1185 | editor->paste(); | 1185 | editor->paste(); |
1186 | #endif | 1186 | #endif |
1187 | } | 1187 | } |
1188 | 1188 | ||
1189 | int TextEdit::savePrompt() | 1189 | int TextEdit::savePrompt() |
1190 | { | 1190 | { |
1191 | switch( QMessageBox::information( 0, (tr("Textedit")), | 1191 | switch( QMessageBox::information( 0, (tr("Textedit")), |
1192 | (tr("Textedit detected\n" | 1192 | (tr("Textedit detected\n" |
1193 | "you have unsaved changes\n" | 1193 | "you have unsaved changes\n" |
1194 | "Go ahead and save?\n")), | 1194 | "Go ahead and save?\n")), |
1195 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) | 1195 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) |
1196 | { | 1196 | { |
1197 | case 0: | 1197 | case 0: |
1198 | { | 1198 | { |
1199 | return 1; | 1199 | return 1; |
1200 | } | 1200 | } |
1201 | break; | 1201 | break; |
1202 | 1202 | ||
1203 | case 1: | 1203 | case 1: |
1204 | { | 1204 | { |
1205 | return 2; | 1205 | return 2; |
1206 | } | 1206 | } |
1207 | break; | 1207 | break; |
1208 | 1208 | ||
1209 | case 2: | 1209 | case 2: |
1210 | { | 1210 | { |
1211 | return -1; | 1211 | return -1; |
1212 | } | 1212 | } |
1213 | break; | 1213 | break; |
1214 | }; | 1214 | }; |
1215 | 1215 | ||
1216 | return 0; | 1216 | return 0; |
1217 | } | 1217 | } |
1218 | 1218 | ||
1219 | void TextEdit::timerCrank() | 1219 | void TextEdit::timerCrank() |
1220 | { | 1220 | { |
1221 | if(featureAutoSave) | 1221 | if(featureAutoSave && edited1) |
1222 | { | 1222 | { |
1223 | if( edited1 ) | 1223 | if(currentFileName.isEmpty()) |
1224 | { | 1224 | { |
1225 | if(currentFileName.isEmpty()) | 1225 | currentFileName = QDir::homeDirPath()+"/textedit.tmp"; |
1226 | { | 1226 | saveAs(); |
1227 | currentFileName = QDir::homeDirPath()+"/textedit.tmp"; | ||
1228 | saveAs(); | ||
1229 | } | ||
1230 | else | ||
1231 | { | ||
1232 | qDebug("autosave"); | ||
1233 | save(); | ||
1234 | } | ||
1235 | setTimer(); | ||
1236 | } | 1227 | } |
1228 | else | ||
1229 | { | ||
1230 | // qDebug("autosave"); | ||
1231 | save(); | ||
1232 | } | ||
1233 | setTimer(); | ||
1237 | } | 1234 | } |
1238 | } | 1235 | } |
1239 | 1236 | ||
1240 | void TextEdit::doTimer(bool b) | 1237 | void TextEdit::doTimer(bool b) |
1241 | { | 1238 | { |
1242 | Config cfg("TextEdit"); | 1239 | Config cfg("TextEdit"); |
1243 | cfg.setGroup ( "View" ); | 1240 | cfg.setGroup ( "View" ); |
1244 | cfg.writeEntry ( "autosave", b); | 1241 | cfg.writeEntry ( "autosave", b); |
1245 | featureAutoSave = b; | 1242 | featureAutoSave = b; |
1246 | nAutoSave->setOn(b); | 1243 | nAutoSave->setOn(b); |
1247 | if(b) | 1244 | if(b) |
1248 | { | 1245 | { |
1249 | qDebug("doTimer true"); | 1246 | // qDebug("doTimer true"); |
1250 | setTimer(); | 1247 | setTimer(); |
1251 | } | 1248 | } |
1252 | else | 1249 | // else |
1253 | qDebug("doTimer false"); | 1250 | // qDebug("doTimer false"); |
1254 | } | 1251 | } |
1255 | 1252 | ||
1256 | void TextEdit::setTimer() | 1253 | void TextEdit::setTimer() |
1257 | { | 1254 | { |
1258 | if(featureAutoSave) | 1255 | if(featureAutoSave) |
1259 | { | 1256 | { |
1260 | qDebug("setting autosave"); | 1257 | // qDebug("setting autosave"); |
1261 | QTimer *timer = new QTimer(this ); | 1258 | QTimer *timer = new QTimer(this ); |
1262 | connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); | 1259 | connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); |
1263 | timer->start( 30000/*0*/, true); //5 minutes | 1260 | timer->start( 300000, true); //5 minutes |
1264 | } | 1261 | } |
1265 | } | 1262 | } |