-rw-r--r-- | core/apps/textedit/textedit.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 8b3c4c6..af427ac 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -784,305 +784,306 @@ bool TextEdit::save() { | |||
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 */ |
834 | bool TextEdit::saveAs() { | 834 | bool TextEdit::saveAs() { |
835 | if(caption() == tr("Text Editor")) | 835 | if(caption() == tr("Text Editor")) |
836 | return false; | 836 | return false; |
837 | qDebug("saveAsFile " + currentFileName); | 837 | qDebug("saveAsFile " + currentFileName); |
838 | // case of nothing to save... | 838 | // case of nothing to save... |
839 | // if ( !doc && !currentFileName.isEmpty()) { | 839 | // if ( !doc && !currentFileName.isEmpty()) { |
840 | // //|| !bFromDocView) | 840 | // //|| !bFromDocView) |
841 | // qDebug("no doc"); | 841 | // qDebug("no doc"); |
842 | // return true; | 842 | // return true; |
843 | // } | 843 | // } |
844 | // if ( !editor->edited() ) { | 844 | // if ( !editor->edited() ) { |
845 | // delete doc; | 845 | // delete doc; |
846 | // doc = 0; | 846 | // doc = 0; |
847 | // return true; | 847 | // return true; |
848 | // } | 848 | // } |
849 | 849 | ||
850 | QString rt = editor->text(); | 850 | QString rt = editor->text(); |
851 | qDebug(currentFileName); | 851 | qDebug(currentFileName); |
852 | 852 | ||
853 | if( currentFileName.isEmpty() | 853 | if( currentFileName.isEmpty() |
854 | || currentFileName == tr("Unnamed") | 854 | || currentFileName == tr("Unnamed") |
855 | || currentFileName == tr("Text Editor")) { | 855 | || currentFileName == tr("Text Editor")) { |
856 | qDebug("do silly TT filename thing"); | 856 | qDebug("do silly TT filename thing"); |
857 | // if ( doc && doc->name().isEmpty() ) { | 857 | // if ( doc && doc->name().isEmpty() ) { |
858 | QString pt = rt.simplifyWhiteSpace(); | 858 | QString pt = rt.simplifyWhiteSpace(); |
859 | int i = pt.find( ' ' ); | 859 | int i = pt.find( ' ' ); |
860 | QString docname = pt; | 860 | QString docname = pt; |
861 | if ( i > 0 ) | 861 | if ( i > 0 ) |
862 | docname = pt.left( i ); | 862 | docname = pt.left( i ); |
863 | // remove "." at the beginning | 863 | // remove "." at the beginning |
864 | while( docname.startsWith( "." ) ) | 864 | while( docname.startsWith( "." ) ) |
865 | docname = docname.mid( 1 ); | 865 | docname = docname.mid( 1 ); |
866 | docname.replace( QRegExp("/"), "_" ); | 866 | docname.replace( QRegExp("/"), "_" ); |
867 | // cut the length. filenames longer than that | 867 | // cut the length. filenames longer than that |
868 | //don't make sense and something goes wrong when they get too long. | 868 | //don't make sense and something goes wrong when they get too long. |
869 | if ( docname.length() > 40 ) | 869 | if ( docname.length() > 40 ) |
870 | docname = docname.left(40); | 870 | docname = docname.left(40); |
871 | if ( docname.isEmpty() ) | 871 | if ( docname.isEmpty() ) |
872 | docname = tr("Unnamed"); | 872 | docname = tr("Unnamed"); |
873 | if(doc) doc->setName(docname); | 873 | if(doc) doc->setName(docname); |
874 | currentFileName=docname; | 874 | currentFileName=docname; |
875 | // } | 875 | // } |
876 | // else | 876 | // else |
877 | // qDebug("hmmmmmm"); | 877 | // qDebug("hmmmmmm"); |
878 | } | 878 | } |
879 | 879 | ||
880 | 880 | ||
881 | QMap<QString, QStringList> map; | 881 | QMap<QString, QStringList> map; |
882 | map.insert(tr("All"), QStringList() ); | 882 | map.insert(tr("All"), QStringList() ); |
883 | QStringList text; | 883 | QStringList text; |
884 | text << "text/*"; | 884 | text << "text/*"; |
885 | map.insert(tr("Text"), text ); | 885 | map.insert(tr("Text"), text ); |
886 | text << "*"; | 886 | text << "*"; |
887 | map.insert(tr("All"), text ); | 887 | map.insert(tr("All"), text ); |
888 | 888 | ||
889 | QFileInfo cuFi( currentFileName); | 889 | QFileInfo cuFi( currentFileName); |
890 | QString filee = cuFi.fileName(); | 890 | QString filee = cuFi.fileName(); |
891 | QString dire = cuFi.dirPath(); | 891 | QString dire = cuFi.dirPath(); |
892 | if(dire==".") | 892 | if(dire==".") |
893 | dire = QPEApplication::documentDir(); | 893 | dire = QPEApplication::documentDir(); |
894 | QString str = OFileDialog::getSaveFileName( 2, | 894 | QString str = OFileDialog::getSaveFileName( 2, |
895 | dire, | 895 | dire, |
896 | filee, map); | 896 | filee, map); |
897 | 897 | ||
898 | if(!str.isEmpty()) { | 898 | if(!str.isEmpty()) { |
899 | QString fileNm=str; | 899 | QString fileNm=str; |
900 | 900 | ||
901 | qDebug("saving filename "+fileNm); | 901 | qDebug("saving filename "+fileNm); |
902 | QFileInfo fi(fileNm); | 902 | QFileInfo fi(fileNm); |
903 | currentFileName=fi.fileName(); | 903 | currentFileName=fi.fileName(); |
904 | if(doc) | 904 | if(doc) |
905 | // QString file = doc->file(); | 905 | // QString file = doc->file(); |
906 | // doc->removeFiles(); | 906 | // doc->removeFiles(); |
907 | delete doc; | 907 | delete doc; |
908 | DocLnk nf; | 908 | DocLnk nf; |
909 | nf.setType("text/plain"); | 909 | nf.setType("text/plain"); |
910 | nf.setFile( fileNm); | 910 | nf.setFile( fileNm); |
911 | doc = new DocLnk(nf); | 911 | doc = new DocLnk(nf); |
912 | // editor->setText(rt); | 912 | // editor->setText(rt); |
913 | qDebug("Saving file as "+currentFileName); | 913 | qDebug("Saving file as "+currentFileName); |
914 | doc->setName( currentFileName); | 914 | doc->setName( currentFileName); |
915 | updateCaption( currentFileName); | 915 | updateCaption( currentFileName); |
916 | 916 | ||
917 | FileManager fm; | 917 | FileManager fm; |
918 | if ( !fm.saveFile( *doc, rt ) ) { | 918 | if ( !fm.saveFile( *doc, rt ) ) { |
919 | return false; | 919 | return false; |
920 | } | 920 | } |
921 | 921 | ||
922 | if( filePerms ) { | 922 | if( filePerms ) { |
923 | filePermissions *filePerm; | 923 | filePermissions *filePerm; |
924 | filePerm = new filePermissions(this, | 924 | filePerm = new filePermissions(this, |
925 | tr("Permissions"),true, | 925 | tr("Permissions"),true, |
926 | 0,(const QString &)fileNm); | 926 | 0,(const QString &)fileNm); |
927 | filePerm->showMaximized(); | 927 | filePerm->showMaximized(); |
928 | filePerm->exec(); | 928 | filePerm->exec(); |
929 | 929 | ||
930 | if( filePerm) | 930 | if( filePerm) |
931 | delete filePerm; | 931 | delete filePerm; |
932 | } | 932 | } |
933 | // } | 933 | // } |
934 | editor->setEdited( false); | 934 | editor->setEdited( false); |
935 | edited1 = false; | 935 | edited1 = false; |
936 | edited = false; | 936 | edited = false; |
937 | if(caption().left(1)=="*") | 937 | if(caption().left(1)=="*") |
938 | setCaption(caption().right(caption().length()-1)); | 938 | setCaption(caption().right(caption().length()-1)); |
939 | 939 | ||
940 | return true; | 940 | return true; |
941 | } | 941 | } |
942 | qDebug("returning false"); | 942 | qDebug("returning false"); |
943 | return false; | 943 | return false; |
944 | } //end saveAs | 944 | } //end saveAs |
945 | 945 | ||
946 | void TextEdit::clear() { | 946 | void TextEdit::clear() { |
947 | delete doc; | 947 | delete doc; |
948 | doc = 0; | 948 | doc = 0; |
949 | editor->clear(); | 949 | editor->clear(); |
950 | } | 950 | } |
951 | 951 | ||
952 | void TextEdit::updateCaption( const QString &name ) { | 952 | void TextEdit::updateCaption( const QString &name ) { |
953 | 953 | ||
954 | if ( name.isEmpty() ) | 954 | if ( name.isEmpty() ) |
955 | setCaption( tr("Text Editor") ); | 955 | setCaption( tr("Text Editor") ); |
956 | else { | 956 | else { |
957 | QString s = name; | 957 | QString s = name; |
958 | if ( s.isNull() ) | 958 | if ( s.isNull() ) |
959 | s = doc->name(); | 959 | s = doc->name(); |
960 | if ( s.isEmpty() ) { | 960 | if ( s.isEmpty() ) { |
961 | s = tr( "Unnamed" ); | 961 | s = tr( "Unnamed" ); |
962 | currentFileName=s; | 962 | currentFileName=s; |
963 | } | 963 | } |
964 | // if(s.left(1) == "/") | 964 | // if(s.left(1) == "/") |
965 | // s = s.right(s.length()-1); | 965 | // s = s.right(s.length()-1); |
966 | setCaption( s + " - " + tr("Text Editor") ); | 966 | setCaption( s + " - " + tr("Text Editor") ); |
967 | } | 967 | } |
968 | } | 968 | } |
969 | 969 | ||
970 | void TextEdit::setDocument(const QString& fileref) { | 970 | void TextEdit::setDocument(const QString& fileref) { |
971 | if(fileref != "Unnamed") { | 971 | if(fileref != "Unnamed") { |
972 | currentFileName=fileref; | 972 | currentFileName=fileref; |
973 | qDebug("setDocument"); | 973 | qDebug("setDocument"); |
974 | QFileInfo fi(currentFileName); | 974 | QFileInfo fi(currentFileName); |
975 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); | 975 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); |
976 | if(fi.baseName().left(1) == "") { | 976 | if( (fi.baseName().left(1)).isEmpty() ) { |
977 | // openDotFile(currentFileName); | 977 | openDotFile(currentFileName); |
978 | |||
978 | } else { | 979 | } else { |
979 | qDebug("setDoc open"); | 980 | qDebug("setDoc open"); |
980 | bFromDocView = true; | 981 | bFromDocView = true; |
981 | openFile(fileref); | 982 | openFile(fileref); |
982 | editor->setEdited(true); | 983 | editor->setEdited(true); |
983 | edited1=false; | 984 | edited1=false; |
984 | edited=true; | 985 | edited=true; |
985 | // fromSetDocument=false; | 986 | // fromSetDocument=false; |
986 | // doSearchBar(); | 987 | // doSearchBar(); |
987 | } | 988 | } |
988 | } | 989 | } |
989 | updateCaption( currentFileName); | 990 | updateCaption( currentFileName); |
990 | } | 991 | } |
991 | 992 | ||
992 | void TextEdit::changeFont() { | 993 | void TextEdit::changeFont() { |
993 | QDialog *d = new QDialog ( this, "FontDialog", true ); | 994 | QDialog *d = new QDialog ( this, "FontDialog", true ); |
994 | d-> setCaption ( tr( "Choose font" )); | 995 | d-> setCaption ( tr( "Choose font" )); |
995 | QBoxLayout *lay = new QVBoxLayout ( d ); | 996 | QBoxLayout *lay = new QVBoxLayout ( d ); |
996 | OFontSelector *ofs = new OFontSelector ( true, d ); | 997 | OFontSelector *ofs = new OFontSelector ( true, d ); |
997 | lay-> addWidget ( ofs ); | 998 | lay-> addWidget ( ofs ); |
998 | ofs-> setSelectedFont ( editor-> font ( )); | 999 | ofs-> setSelectedFont ( editor-> font ( )); |
999 | 1000 | ||
1000 | d-> showMaximized ( ); | 1001 | d-> showMaximized ( ); |
1001 | if ( d-> exec ( ) == QDialog::Accepted ) | 1002 | if ( d-> exec ( ) == QDialog::Accepted ) |
1002 | editor-> setFont ( ofs-> selectedFont ( )); | 1003 | editor-> setFont ( ofs-> selectedFont ( )); |
1003 | delete d; | 1004 | delete d; |
1004 | 1005 | ||
1005 | } | 1006 | } |
1006 | 1007 | ||
1007 | void TextEdit::editDelete() { | 1008 | void TextEdit::editDelete() { |
1008 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 1009 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
1009 | tr("Do you really want<BR>to <B>delete</B> " | 1010 | tr("Do you really want<BR>to <B>delete</B> " |
1010 | "the current file\nfrom the disk?<BR>This is " | 1011 | "the current file\nfrom the disk?<BR>This is " |
1011 | "<B>irreversable!!</B>"), | 1012 | "<B>irreversable!!</B>"), |
1012 | tr("Yes"),tr("No"),0,0,1) ) { | 1013 | tr("Yes"),tr("No"),0,0,1) ) { |
1013 | case 0: | 1014 | case 0: |
1014 | if(doc) { | 1015 | if(doc) { |
1015 | doc->removeFiles(); | 1016 | doc->removeFiles(); |
1016 | clear(); | 1017 | clear(); |
1017 | setCaption( tr("Text Editor") ); | 1018 | setCaption( tr("Text Editor") ); |
1018 | } | 1019 | } |
1019 | break; | 1020 | break; |
1020 | case 1: | 1021 | case 1: |
1021 | // exit | 1022 | // exit |
1022 | break; | 1023 | break; |
1023 | }; | 1024 | }; |
1024 | } | 1025 | } |
1025 | 1026 | ||
1026 | void TextEdit::changeStartConfig( bool b ) { | 1027 | void TextEdit::changeStartConfig( bool b ) { |
1027 | startWithNew=b; | 1028 | startWithNew=b; |
1028 | Config cfg("TextEdit"); | 1029 | Config cfg("TextEdit"); |
1029 | cfg.setGroup("View"); | 1030 | cfg.setGroup("View"); |
1030 | cfg.writeEntry("startNew",b); | 1031 | cfg.writeEntry("startNew",b); |
1031 | update(); | 1032 | update(); |
1032 | } | 1033 | } |
1033 | 1034 | ||
1034 | void TextEdit::editorChanged() { | 1035 | void TextEdit::editorChanged() { |
1035 | // qDebug("editor changed"); | 1036 | // qDebug("editor changed"); |
1036 | if( /*editor->edited() &&*/ /*edited && */!edited1) { | 1037 | if( /*editor->edited() &&*/ /*edited && */!edited1) { |
1037 | setCaption( "*"+caption()); | 1038 | setCaption( "*"+caption()); |
1038 | edited1=true; | 1039 | edited1=true; |
1039 | } | 1040 | } |
1040 | edited=true; | 1041 | edited=true; |
1041 | } | 1042 | } |
1042 | 1043 | ||
1043 | void TextEdit::receive(const QCString&msg, const QByteArray &data) { | 1044 | void TextEdit::receive(const QCString&msg, const QByteArray &data) { |
1044 | qDebug("QCop "+msg); | 1045 | qDebug("QCop "+msg); |
1045 | if ( msg == "setDocument(QString)" ) { | 1046 | if ( msg == "setDocument(QString)" ) { |
1046 | qDebug("bugger all"); | 1047 | qDebug("bugger all"); |
1047 | 1048 | ||
1048 | } | 1049 | } |
1049 | 1050 | ||
1050 | } | 1051 | } |
1051 | 1052 | ||
1052 | void TextEdit::doAbout() { | 1053 | void TextEdit::doAbout() { |
1053 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" | 1054 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" |
1054 | "2000 Trolltech AS, and<BR>" | 1055 | "2000 Trolltech AS, and<BR>" |
1055 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" | 1056 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" |
1056 | "and is licensed under the GPL")); | 1057 | "and is licensed under the GPL")); |
1057 | } | 1058 | } |
1058 | 1059 | ||
1059 | void TextEdit::doPrompt(bool b) { | 1060 | void TextEdit::doPrompt(bool b) { |
1060 | promptExit=b; | 1061 | promptExit=b; |
1061 | Config cfg("TextEdit"); | 1062 | Config cfg("TextEdit"); |
1062 | cfg.setGroup ( "View" ); | 1063 | cfg.setGroup ( "View" ); |
1063 | cfg.writeEntry ( "PromptExit", b); | 1064 | cfg.writeEntry ( "PromptExit", b); |
1064 | } | 1065 | } |
1065 | 1066 | ||
1066 | void TextEdit::doDesktop(bool b) { | 1067 | void TextEdit::doDesktop(bool b) { |
1067 | openDesktop=b; | 1068 | openDesktop=b; |
1068 | Config cfg("TextEdit"); | 1069 | Config cfg("TextEdit"); |
1069 | cfg.setGroup ( "View" ); | 1070 | cfg.setGroup ( "View" ); |
1070 | cfg.writeEntry ( "OpenDesktop", b); | 1071 | cfg.writeEntry ( "OpenDesktop", b); |
1071 | } | 1072 | } |
1072 | 1073 | ||
1073 | void TextEdit::doFilePerms(bool b) { | 1074 | void TextEdit::doFilePerms(bool b) { |
1074 | filePerms=b; | 1075 | filePerms=b; |
1075 | Config cfg("TextEdit"); | 1076 | Config cfg("TextEdit"); |
1076 | cfg.setGroup ( "View" ); | 1077 | cfg.setGroup ( "View" ); |
1077 | cfg.writeEntry ( "FilePermissions", b); | 1078 | cfg.writeEntry ( "FilePermissions", b); |
1078 | } | 1079 | } |
1079 | 1080 | ||
1080 | void TextEdit::editPasteTimeDate() { | 1081 | void TextEdit::editPasteTimeDate() { |
1081 | #ifndef QT_NO_CLIPBOARD | 1082 | #ifndef QT_NO_CLIPBOARD |
1082 | QClipboard *cb = QApplication::clipboard(); | 1083 | QClipboard *cb = QApplication::clipboard(); |
1083 | QDateTime dt = QDateTime::currentDateTime(); | 1084 | QDateTime dt = QDateTime::currentDateTime(); |
1084 | cb->setText( dt.toString()); | 1085 | cb->setText( dt.toString()); |
1085 | editor->paste(); | 1086 | editor->paste(); |
1086 | #endif | 1087 | #endif |
1087 | } | 1088 | } |
1088 | 1089 | ||