-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 | |||
@@ -688,279 +688,282 @@ void TextEdit::openFile( const DocLnk &f ) | |||
688 | fileNew(); | 688 | fileNew(); |
689 | if ( doc ) | 689 | if ( doc ) |
690 | delete doc; | 690 | delete doc; |
691 | doc = new DocLnk(f); | 691 | doc = new DocLnk(f); |
692 | editor->setText(txt); | 692 | editor->setText(txt); |
693 | editor->setEdited( FALSE); | 693 | editor->setEdited( FALSE); |
694 | edited1=FALSE; | 694 | edited1=FALSE; |
695 | edited=FALSE; | 695 | edited=FALSE; |
696 | 696 | ||
697 | qDebug("openFile doclnk "+currentFileName); | 697 | qDebug("openFile doclnk "+currentFileName); |
698 | doc->setName(currentFileName); | 698 | doc->setName(currentFileName); |
699 | updateCaption(); | 699 | updateCaption(); |
700 | } | 700 | } |
701 | 701 | ||
702 | void TextEdit::showEditTools() | 702 | void TextEdit::showEditTools() |
703 | { | 703 | { |
704 | // if ( !doc ) | 704 | // if ( !doc ) |
705 | // close(); | 705 | // close(); |
706 | // clear(); | 706 | // clear(); |
707 | fileSelector->hide(); | 707 | fileSelector->hide(); |
708 | menu->show(); | 708 | menu->show(); |
709 | editBar->show(); | 709 | editBar->show(); |
710 | if ( searchVisible ) | 710 | if ( searchVisible ) |
711 | searchBar->show(); | 711 | searchBar->show(); |
712 | // updateCaption(); | 712 | // updateCaption(); |
713 | editorStack->raiseWidget( editor ); | 713 | editorStack->raiseWidget( editor ); |
714 | setWState (WState_Reserved1 ); | 714 | setWState (WState_Reserved1 ); |
715 | } | 715 | } |
716 | 716 | ||
717 | /*! | 717 | /*! |
718 | unprompted save */ | 718 | unprompted save */ |
719 | bool TextEdit::save() | 719 | bool TextEdit::save() |
720 | { | 720 | { |
721 | QString file = doc->file(); | 721 | QString file = doc->file(); |
722 | qDebug(file); | 722 | qDebug(file); |
723 | QString name= doc->name(); | 723 | QString name= doc->name(); |
724 | qDebug(name); | 724 | qDebug(name); |
725 | QString rt = editor->text(); | 725 | QString rt = editor->text(); |
726 | if( !rt.isEmpty() ) { | 726 | if( !rt.isEmpty() ) { |
727 | if(name.isEmpty()) { | 727 | if(name.isEmpty()) { |
728 | saveAs(); | 728 | saveAs(); |
729 | } else { | 729 | } else { |
730 | currentFileName= name ; | 730 | currentFileName= name ; |
731 | qDebug("saveFile "+currentFileName); | 731 | qDebug("saveFile "+currentFileName); |
732 | 732 | ||
733 | struct stat buf; | 733 | struct stat buf; |
734 | mode_t mode; | 734 | mode_t mode; |
735 | stat(file.latin1(), &buf); | 735 | stat(file.latin1(), &buf); |
736 | mode = buf.st_mode; | 736 | mode = buf.st_mode; |
737 | 737 | ||
738 | doc->setName( name); | 738 | doc->setName( name); |
739 | FileManager fm; | 739 | FileManager fm; |
740 | if ( !fm.saveFile( *doc, rt ) ) { | 740 | if ( !fm.saveFile( *doc, rt ) ) { |
741 | return false; | 741 | return false; |
742 | } | 742 | } |
743 | editor->setEdited( FALSE); | 743 | editor->setEdited( FALSE); |
744 | edited1=FALSE; | 744 | edited1=FALSE; |
745 | edited=FALSE; | 745 | edited=FALSE; |
746 | setCaption(caption().right(caption().length()-1)); | 746 | setCaption(caption().right(caption().length()-1)); |
747 | 747 | ||
748 | 748 | ||
749 | chmod( file.latin1(), mode); | 749 | chmod( file.latin1(), mode); |
750 | } | 750 | } |
751 | return true; | 751 | return true; |
752 | } | 752 | } |
753 | return false; | 753 | return false; |
754 | } | 754 | } |
755 | 755 | ||
756 | /*! | 756 | /*! |
757 | prompted save */ | 757 | prompted save */ |
758 | bool TextEdit::saveAs() | 758 | bool TextEdit::saveAs() |
759 | { | 759 | { |
760 | // qDebug("saveAsFile "+currentFileName); | 760 | // qDebug("saveAsFile "+currentFileName); |
761 | 761 | ||
762 | // case of nothing to save... /// there's always something to save | 762 | // case of nothing to save... /// there's always something to save |
763 | // if ( !doc )//|| !bFromDocView) | 763 | // if ( !doc )//|| !bFromDocView) |
764 | // { | 764 | // { |
765 | // qDebug("no doc"); | 765 | // qDebug("no doc"); |
766 | // return true; | 766 | // return true; |
767 | // } | 767 | // } |
768 | if ( !editor->edited() ) { | 768 | if ( !editor->edited() ) { |
769 | delete doc; | 769 | delete doc; |
770 | doc = 0; | 770 | doc = 0; |
771 | return true; | 771 | return true; |
772 | } | 772 | } |
773 | 773 | ||
774 | QString rt = editor->text(); | 774 | QString rt = editor->text(); |
775 | qDebug(currentFileName); | 775 | qDebug(currentFileName); |
776 | 776 | ||
777 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { | 777 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { |
778 | qDebug("do silly TT filename thing"); | 778 | qDebug("do silly TT filename thing"); |
779 | if ( doc->name().isEmpty() ) { | 779 | if ( doc->name().isEmpty() ) { |
780 | QString pt = rt.simplifyWhiteSpace(); | 780 | QString pt = rt.simplifyWhiteSpace(); |
781 | int i = pt.find( ' ' ); | 781 | int i = pt.find( ' ' ); |
782 | QString docname = pt; | 782 | QString docname = pt; |
783 | if ( i > 0 ) | 783 | if ( i > 0 ) |
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 | } |