-rw-r--r-- | core/apps/textedit/textedit.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index dafe1dc..f031a0f 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -784,183 +784,186 @@ bool TextEdit::saveAs() | |||
784 | docname = pt.left( i ); | 784 | docname = pt.left( i ); |
785 | // remove "." at the beginning | 785 | // remove "." at the beginning |
786 | while( docname.startsWith( "." ) ) | 786 | while( docname.startsWith( "." ) ) |
787 | docname = docname.mid( 1 ); | 787 | docname = docname.mid( 1 ); |
788 | docname.replace( QRegExp("/"), "_" ); | 788 | docname.replace( QRegExp("/"), "_" ); |
789 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | 789 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. |
790 | if ( docname.length() > 40 ) | 790 | if ( docname.length() > 40 ) |
791 | docname = docname.left(40); | 791 | docname = docname.left(40); |
792 | if ( docname.isEmpty() ) | 792 | if ( docname.isEmpty() ) |
793 | docname = "Unnamed"; | 793 | docname = "Unnamed"; |
794 | doc->setName(docname); | 794 | doc->setName(docname); |
795 | currentFileName=docname; | 795 | currentFileName=docname; |
796 | } | 796 | } |
797 | } | 797 | } |
798 | 798 | ||
799 | 799 | ||
800 | fileSaveDlg=new fileSaver(this,"Save File As?",TRUE, 0, currentFileName); | 800 | fileSaveDlg=new fileSaver(this,"Save File As?",TRUE, 0, currentFileName); |
801 | qDebug("wanna save filename "+currentFileName); | 801 | qDebug("wanna save filename "+currentFileName); |
802 | fileSaveDlg->exec(); | 802 | fileSaveDlg->exec(); |
803 | if( fileSaveDlg->result() == 1 ) { | 803 | if( fileSaveDlg->result() == 1 ) { |
804 | QString fileNm=fileSaveDlg->selectedFileName; | 804 | QString fileNm=fileSaveDlg->selectedFileName; |
805 | qDebug("saving filename "+fileNm); | 805 | qDebug("saving filename "+fileNm); |
806 | QFileInfo fi(fileNm); | 806 | QFileInfo fi(fileNm); |
807 | currentFileName=fi.fileName(); | 807 | currentFileName=fi.fileName(); |
808 | if(doc) { | 808 | if(doc) { |
809 | // QString file = doc->file(); | 809 | // QString file = doc->file(); |
810 | // doc->removeFiles(); | 810 | // doc->removeFiles(); |
811 | delete doc; | 811 | delete doc; |
812 | DocLnk nf; | 812 | DocLnk nf; |
813 | nf.setType("text/plain"); | 813 | nf.setType("text/plain"); |
814 | nf.setFile( fileNm); | 814 | nf.setFile( fileNm); |
815 | doc = new DocLnk(nf); | 815 | doc = new DocLnk(nf); |
816 | // editor->setText(rt); | 816 | // editor->setText(rt); |
817 | // qDebug("openFile doclnk "+currentFileName); | 817 | // qDebug("openFile doclnk "+currentFileName); |
818 | doc->setName( currentFileName); | 818 | doc->setName( currentFileName); |
819 | updateCaption( currentFileName); | 819 | updateCaption( currentFileName); |
820 | 820 | ||
821 | FileManager fm; | 821 | FileManager fm; |
822 | if ( !fm.saveFile( *doc, rt ) ) { | 822 | if ( !fm.saveFile( *doc, rt ) ) { |
823 | return false; | 823 | return false; |
824 | } | 824 | } |
825 | if( fileSaveDlg->filePermCheck->isChecked() ) { | 825 | if( fileSaveDlg->filePermCheck->isChecked() ) { |
826 | filePermissions *filePerm; | 826 | filePermissions *filePerm; |
827 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm); | 827 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm); |
828 | filePerm->exec(); | 828 | filePerm->exec(); |
829 | 829 | ||
830 | if( filePerm) | 830 | if( filePerm) |
831 | delete filePerm; | 831 | delete filePerm; |
832 | } | 832 | } |
833 | } | 833 | } |
834 | } | 834 | } |
835 | editor->setEdited( FALSE); | 835 | editor->setEdited( FALSE); |
836 | edited1=FALSE; | 836 | edited1=FALSE; |
837 | edited=FALSE; | 837 | edited=FALSE; |
838 | if(caption().left(1)=="*") | 838 | if(caption().left(1)=="*") |
839 | setCaption(caption().right(caption().length()-1)); | 839 | setCaption(caption().right(caption().length()-1)); |
840 | 840 | ||
841 | if(fileSaveDlg) | 841 | if(fileSaveDlg) |
842 | delete fileSaveDlg; | 842 | delete fileSaveDlg; |
843 | return true; | 843 | return true; |
844 | } | 844 | } |
845 | 845 | ||
846 | void TextEdit::clear() | 846 | void TextEdit::clear() |
847 | { | 847 | { |
848 | delete doc; | 848 | delete doc; |
849 | doc = 0; | 849 | doc = 0; |
850 | editor->clear(); | 850 | editor->clear(); |
851 | } | 851 | } |
852 | 852 | ||
853 | void TextEdit::updateCaption( const QString &name ) | 853 | void TextEdit::updateCaption( const QString &name ) |
854 | { | 854 | { |
855 | if ( !doc ) | 855 | if ( !doc ) |
856 | setCaption( tr("Text Editor") ); | 856 | setCaption( tr("Text Editor") ); |
857 | else { | 857 | else { |
858 | QString s = name; | 858 | QString s = name; |
859 | if ( s.isNull() ) | 859 | if ( s.isNull() ) |
860 | s = doc->name(); | 860 | s = doc->name(); |
861 | if ( s.isEmpty() ) { | 861 | if ( s.isEmpty() ) { |
862 | s = tr( "Unnamed" ); | 862 | s = tr( "Unnamed" ); |
863 | currentFileName=s; | 863 | currentFileName=s; |
864 | } | 864 | } |
865 | 865 | ||
866 | setCaption( s + " - " + tr("Text Editor") ); | 866 | setCaption( s + " - " + tr("Text Editor") ); |
867 | } | 867 | } |
868 | } | 868 | } |
869 | 869 | ||
870 | void TextEdit::setDocument(const QString& fileref) | 870 | void TextEdit::setDocument(const QString& fileref) |
871 | { | 871 | { |
872 | bFromDocView = TRUE; | 872 | bFromDocView = TRUE; |
873 | qDebug("setDocument "+fileref); | 873 | qDebug("setDocument "+fileref); |
874 | bFromDocView = TRUE; | 874 | bFromDocView = TRUE; |
875 | if(fileref.find(".desktop",0,TRUE) == -1) { | 875 | if(fileref.find(".desktop",0,TRUE) == -1) { |
876 | openFile(fileref); | 876 | openFile(fileref); |
877 | } else { | 877 | } else { |
878 | openFile(DocLnk(fileref)); | 878 | openFile(DocLnk(fileref)); |
879 | } | 879 | } |
880 | editor->setEdited(TRUE); | ||
881 | edited1=FALSE; | ||
882 | edited=TRUE; | ||
880 | } | 883 | } |
881 | 884 | ||
882 | void TextEdit::closeEvent( QCloseEvent *e ) | 885 | void TextEdit::closeEvent( QCloseEvent *e ) |
883 | { | 886 | { |
884 | if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { | 887 | if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { |
885 | e->ignore(); | 888 | e->ignore(); |
886 | repaint(); | 889 | repaint(); |
887 | // fileRevert(); | 890 | // fileRevert(); |
888 | 891 | ||
889 | } else { | 892 | } else { |
890 | bFromDocView = FALSE; | 893 | bFromDocView = FALSE; |
891 | e->accept(); | 894 | e->accept(); |
892 | } | 895 | } |
893 | } | 896 | } |
894 | 897 | ||
895 | void TextEdit::accept() | 898 | void TextEdit::accept() |
896 | { | 899 | { |
897 | QString file = doc->file(); | 900 | QString file = doc->file(); |
898 | if (file.find("_.txt",0,TRUE) ==-1) | 901 | if (file.find("_.txt",0,TRUE) ==-1) |
899 | save(); | 902 | save(); |
900 | else { | 903 | else { |
901 | QFile(file).remove(); | 904 | QFile(file).remove(); |
902 | } | 905 | } |
903 | exit(0); | 906 | exit(0); |
904 | 907 | ||
905 | } | 908 | } |
906 | 909 | ||
907 | void TextEdit::changeFont() { | 910 | void TextEdit::changeFont() { |
908 | FontDatabase fdb; | 911 | FontDatabase fdb; |
909 | QFont defaultFont=editor->font(); | 912 | QFont defaultFont=editor->font(); |
910 | QFontInfo fontInfo(defaultFont); | 913 | QFontInfo fontInfo(defaultFont); |
911 | Config cfg("TextEdit"); | 914 | Config cfg("TextEdit"); |
912 | cfg.setGroup("Font"); | 915 | cfg.setGroup("Font"); |
913 | QString family = cfg.readEntry("Family", fontInfo.family()); | 916 | QString family = cfg.readEntry("Family", fontInfo.family()); |
914 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 917 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
915 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 918 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
916 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 919 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
917 | 920 | ||
918 | defaultFont = fdb.font(family,style,i_size,charSet); | 921 | defaultFont = fdb.font(family,style,i_size,charSet); |
919 | 922 | ||
920 | FontDialog *fontDlg; | 923 | FontDialog *fontDlg; |
921 | fontDlg=new FontDialog(this,"FontDialog",TRUE); | 924 | fontDlg=new FontDialog(this,"FontDialog",TRUE); |
922 | 925 | ||
923 | fontDlg->exec(); | 926 | fontDlg->exec(); |
924 | 927 | ||
925 | QFont myFont=fontDlg->selectedFont; | 928 | QFont myFont=fontDlg->selectedFont; |
926 | editor->setFont( myFont); | 929 | editor->setFont( myFont); |
927 | delete fontDlg; | 930 | delete fontDlg; |
928 | 931 | ||
929 | } | 932 | } |
930 | 933 | ||
931 | void TextEdit::editDelete() | 934 | void TextEdit::editDelete() |
932 | { | 935 | { |
933 | switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) { | 936 | switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) { |
934 | case 0: | 937 | case 0: |
935 | if(doc) { | 938 | if(doc) { |
936 | doc->removeFiles(); | 939 | doc->removeFiles(); |
937 | clear(); | 940 | clear(); |
938 | setCaption( tr("Text Editor") ); | 941 | setCaption( tr("Text Editor") ); |
939 | } | 942 | } |
940 | break; | 943 | break; |
941 | case 1: | 944 | case 1: |
942 | // exit | 945 | // exit |
943 | break; | 946 | break; |
944 | }; | 947 | }; |
945 | } | 948 | } |
946 | 949 | ||
947 | void TextEdit::changeStartConfig( bool b ) { | 950 | void TextEdit::changeStartConfig( bool b ) { |
948 | 951 | ||
949 | Config cfg("TextEdit"); | 952 | Config cfg("TextEdit"); |
950 | cfg.setGroup("View"); | 953 | cfg.setGroup("View"); |
951 | if(b) { | 954 | if(b) { |
952 | qDebug("bool"); | 955 | qDebug("bool"); |
953 | cfg.writeEntry("startNew","TRUE"); | 956 | cfg.writeEntry("startNew","TRUE"); |
954 | } else { | 957 | } else { |
955 | cfg.writeEntry("startNew","FALSE"); | 958 | cfg.writeEntry("startNew","FALSE"); |
956 | } | 959 | } |
957 | update(); | 960 | update(); |
958 | } | 961 | } |
959 | 962 | ||
960 | void TextEdit::editorChanged() { | 963 | void TextEdit::editorChanged() { |
961 | if(editor->edited() && edited && !edited1) { | 964 | if(editor->edited() && edited && !edited1) { |
962 | setCaption( "*"+caption()); | 965 | setCaption( "*"+caption()); |
963 | edited1=TRUE; | 966 | edited1=TRUE; |
964 | } | 967 | } |
965 | edited=TRUE; | 968 | edited=TRUE; |
966 | } | 969 | } |