author | llornkcor <llornkcor> | 2002-12-20 13:53:13 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-12-20 13:53:13 (UTC) |
commit | 9c92aad4a3d8d83fa41e25ce58d5103599826a5b (patch) (unidiff) | |
tree | c6cbd45f55da507ee1f0e53bebc63d9bb0db94e9 | |
parent | b7dafc7fc37d05498cf3ad7b7d0981bf3a341b4a (diff) | |
download | opie-9c92aad4a3d8d83fa41e25ce58d5103599826a5b.zip opie-9c92aad4a3d8d83fa41e25ce58d5103599826a5b.tar.gz opie-9c92aad4a3d8d83fa41e25ce58d5103599826a5b.tar.bz2 |
save fix when no name bug #577
-rw-r--r-- | core/apps/textedit/textedit.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index bd7cfb6..4f4f994 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -662,257 +662,262 @@ void TextEdit::findNext() { | |||
662 | 662 | ||
663 | void TextEdit::findClose() { | 663 | void TextEdit::findClose() { |
664 | searchBar->hide(); | 664 | searchBar->hide(); |
665 | } | 665 | } |
666 | 666 | ||
667 | void TextEdit::search() { | 667 | void TextEdit::search() { |
668 | editor->find( searchEdit->text(), false, false ); | 668 | editor->find( searchEdit->text(), false, false ); |
669 | } | 669 | } |
670 | 670 | ||
671 | void TextEdit::newFile( const DocLnk &f ) { | 671 | void TextEdit::newFile( const DocLnk &f ) { |
672 | DocLnk nf = f; | 672 | DocLnk nf = f; |
673 | nf.setType("text/plain"); | 673 | nf.setType("text/plain"); |
674 | clear(); | 674 | clear(); |
675 | setWState (WState_Reserved1 ); | 675 | setWState (WState_Reserved1 ); |
676 | editor->setFocus(); | 676 | editor->setFocus(); |
677 | doc = new DocLnk(nf); | 677 | doc = new DocLnk(nf); |
678 | currentFileName = "Unnamed"; | 678 | currentFileName = "Unnamed"; |
679 | qDebug("newFile "+currentFileName); | 679 | qDebug("newFile "+currentFileName); |
680 | updateCaption( currentFileName); | 680 | updateCaption( currentFileName); |
681 | // editor->setEdited( false); | 681 | // editor->setEdited( false); |
682 | } | 682 | } |
683 | 683 | ||
684 | void TextEdit::openDotFile( const QString &f ) { | 684 | void TextEdit::openDotFile( const QString &f ) { |
685 | if(!currentFileName.isEmpty()) { | 685 | if(!currentFileName.isEmpty()) { |
686 | currentFileName=f; | 686 | currentFileName=f; |
687 | 687 | ||
688 | qDebug("openFile dotfile " + currentFileName); | 688 | qDebug("openFile dotfile " + currentFileName); |
689 | QString txt; | 689 | QString txt; |
690 | QFile file(f); | 690 | QFile file(f); |
691 | file.open(IO_ReadWrite); | 691 | file.open(IO_ReadWrite); |
692 | QTextStream t(&file); | 692 | QTextStream t(&file); |
693 | while ( !t.atEnd()) { | 693 | while ( !t.atEnd()) { |
694 | txt+=t.readLine()+"\n"; | 694 | txt+=t.readLine()+"\n"; |
695 | } | 695 | } |
696 | editor->setText(txt); | 696 | editor->setText(txt); |
697 | editor->setEdited( false); | 697 | editor->setEdited( false); |
698 | edited1=false; | 698 | edited1=false; |
699 | edited=false; | 699 | edited=false; |
700 | 700 | ||
701 | 701 | ||
702 | } | 702 | } |
703 | updateCaption( currentFileName); | 703 | updateCaption( currentFileName); |
704 | } | 704 | } |
705 | 705 | ||
706 | void TextEdit::openFile( const QString &f ) { | 706 | void TextEdit::openFile( const QString &f ) { |
707 | qDebug("filename is "+ f); | 707 | qDebug("filename is "+ f); |
708 | QString filer; | 708 | QString filer; |
709 | QFileInfo fi( f); | 709 | QFileInfo fi( f); |
710 | // bFromDocView = true; | 710 | // bFromDocView = true; |
711 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) { | 711 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) { |
712 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 712 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
713 | tr("Text Editor has detected<BR>you selected a <B>.desktop</B> | 713 | tr("Text Editor has detected<BR>you selected a <B>.desktop</B> |
714 | file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), | 714 | file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), |
715 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { | 715 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { |
716 | case 0: | 716 | case 0: |
717 | filer = f; | 717 | filer = f; |
718 | break; | 718 | break; |
719 | case 1: | 719 | case 1: |
720 | DocLnk sf(f); | 720 | DocLnk sf(f); |
721 | filer = sf.file(); | 721 | filer = sf.file(); |
722 | break; | 722 | break; |
723 | } | 723 | } |
724 | } else if(fi.baseName().left(1) == "") { | 724 | } else if(fi.baseName().left(1) == "") { |
725 | currentFileName=f; | 725 | currentFileName=f; |
726 | openDotFile(currentFileName); | 726 | openDotFile(currentFileName); |
727 | } else { | 727 | } else { |
728 | DocLnk sf(f); | 728 | DocLnk sf(f); |
729 | filer = sf.file(); | 729 | filer = sf.file(); |
730 | if(filer.right(1) == "/") | 730 | if(filer.right(1) == "/") |
731 | filer = f; | 731 | filer = f; |
732 | } | 732 | } |
733 | 733 | ||
734 | DocLnk nf; | 734 | DocLnk nf; |
735 | nf.setType("text/plain"); | 735 | nf.setType("text/plain"); |
736 | nf.setFile(filer); | 736 | nf.setFile(filer); |
737 | currentFileName=filer; | 737 | currentFileName=filer; |
738 | 738 | ||
739 | nf.setName(fi.baseName()); | 739 | nf.setName(fi.baseName()); |
740 | openFile(nf); | 740 | openFile(nf); |
741 | 741 | ||
742 | qDebug("openFile string "+currentFileName); | 742 | qDebug("openFile string "+currentFileName); |
743 | 743 | ||
744 | showEditTools(); | 744 | showEditTools(); |
745 | // Show filename in caption | 745 | // Show filename in caption |
746 | QString name = filer; | 746 | QString name = filer; |
747 | int sep = name.findRev( '/' ); | 747 | int sep = name.findRev( '/' ); |
748 | if ( sep > 0 ) | 748 | if ( sep > 0 ) |
749 | name = name.mid( sep+1 ); | 749 | name = name.mid( sep+1 ); |
750 | updateCaption( name ); | 750 | updateCaption( name ); |
751 | } | 751 | } |
752 | 752 | ||
753 | void TextEdit::openFile( const DocLnk &f ) { | 753 | void TextEdit::openFile( const DocLnk &f ) { |
754 | // clear(); | 754 | // clear(); |
755 | // bFromDocView = true; | 755 | // bFromDocView = true; |
756 | FileManager fm; | 756 | FileManager fm; |
757 | QString txt; | 757 | QString txt; |
758 | currentFileName=f.file(); | 758 | currentFileName=f.file(); |
759 | qDebug("openFile doclnk " + currentFileName); | 759 | qDebug("openFile doclnk " + currentFileName); |
760 | if ( !fm.loadFile( f, txt ) ) { | 760 | if ( !fm.loadFile( f, txt ) ) { |
761 | // ####### could be a new file | 761 | // ####### could be a new file |
762 | qDebug( "Cannot open file" ); | 762 | qDebug( "Cannot open file" ); |
763 | } | 763 | } |
764 | // fileNew(); | 764 | // fileNew(); |
765 | if ( doc ) | 765 | if ( doc ) |
766 | delete doc; | 766 | delete doc; |
767 | doc = new DocLnk(f); | 767 | doc = new DocLnk(f); |
768 | editor->setText(txt); | 768 | editor->setText(txt); |
769 | editor->setEdited( false); | 769 | editor->setEdited( false); |
770 | edited1=false; | 770 | edited1=false; |
771 | edited=false; | 771 | edited=false; |
772 | 772 | ||
773 | doc->setName(currentFileName); | 773 | doc->setName(currentFileName); |
774 | updateCaption(); | 774 | updateCaption(); |
775 | } | 775 | } |
776 | 776 | ||
777 | void TextEdit::showEditTools() { | 777 | void TextEdit::showEditTools() { |
778 | menu->show(); | 778 | menu->show(); |
779 | editBar->show(); | 779 | editBar->show(); |
780 | if(!useSearchBar) | 780 | if(!useSearchBar) |
781 | searchBar->hide(); | 781 | searchBar->hide(); |
782 | else | 782 | else |
783 | searchBar->show(); | 783 | searchBar->show(); |
784 | setWState (WState_Reserved1 ); | 784 | setWState (WState_Reserved1 ); |
785 | } | 785 | } |
786 | 786 | ||
787 | /*! | 787 | /*! |
788 | unprompted save */ | 788 | unprompted save */ |
789 | bool TextEdit::save() { | 789 | bool TextEdit::save() { |
790 | QString file = doc->file(); | 790 | qDebug("saveAsFile " + currentFileName); |
791 | if(currentFileName.isEmpty()) { | ||
792 | saveAs(); | ||
793 | return; | ||
794 | } | ||
795 | QString file = doc->file(); | ||
791 | qDebug("saver file "+file); | 796 | qDebug("saver file "+file); |
792 | QString name= doc->name(); | 797 | QString name= doc->name(); |
793 | qDebug("File named "+name); | 798 | qDebug("File named "+name); |
794 | QString rt = editor->text(); | 799 | QString rt = editor->text(); |
795 | if( !rt.isEmpty() ) { | 800 | if( !rt.isEmpty() ) { |
796 | if(name.isEmpty()) { | 801 | if(name.isEmpty()) { |
797 | saveAs(); | 802 | saveAs(); |
798 | } else { | 803 | } else { |
799 | currentFileName= name ; | 804 | currentFileName= name ; |
800 | qDebug("saveFile "+currentFileName); | 805 | qDebug("saveFile "+currentFileName); |
801 | 806 | ||
802 | struct stat buf; | 807 | struct stat buf; |
803 | mode_t mode; | 808 | mode_t mode; |
804 | stat(file.latin1(), &buf); | 809 | stat(file.latin1(), &buf); |
805 | mode = buf.st_mode; | 810 | mode = buf.st_mode; |
806 | 811 | ||
807 | if(!fileIs) { | 812 | if(!fileIs) { |
808 | doc->setName( name); | 813 | doc->setName( name); |
809 | FileManager fm; | 814 | FileManager fm; |
810 | if ( !fm.saveFile( *doc, rt ) ) { | 815 | if ( !fm.saveFile( *doc, rt ) ) { |
811 | return false; | 816 | return false; |
812 | } | 817 | } |
813 | } else { | 818 | } else { |
814 | qDebug("regular save file"); | 819 | qDebug("regular save file"); |
815 | QFile f(file); | 820 | QFile f(file); |
816 | if( f.open(IO_WriteOnly)) { | 821 | if( f.open(IO_WriteOnly)) { |
817 | QCString crt = rt.utf8(); | 822 | QCString crt = rt.utf8(); |
818 | f.writeBlock(crt,crt.length()); | 823 | f.writeBlock(crt,crt.length()); |
819 | } else { | 824 | } else { |
820 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); | 825 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); |
821 | return false; | 826 | return false; |
822 | } | 827 | } |
823 | 828 | ||
824 | } | 829 | } |
825 | editor->setEdited( false); | 830 | editor->setEdited( false); |
826 | edited1=false; | 831 | edited1=false; |
827 | edited=false; | 832 | edited=false; |
828 | if(caption().left(1)=="*") | 833 | if(caption().left(1)=="*") |
829 | setCaption(caption().right(caption().length()-1)); | 834 | setCaption(caption().right(caption().length()-1)); |
830 | 835 | ||
831 | 836 | ||
832 | chmod( file.latin1(), mode); | 837 | chmod( file.latin1(), mode); |
833 | } | 838 | } |
834 | return true; | 839 | return true; |
835 | } | 840 | } |
836 | return false; | 841 | return false; |
837 | } | 842 | } |
838 | 843 | ||
839 | /*! | 844 | /*! |
840 | prompted save */ | 845 | prompted save */ |
841 | bool TextEdit::saveAs() { | 846 | bool TextEdit::saveAs() { |
842 | if(caption() == tr("Text Editor")) | 847 | if(caption() == tr("Text Editor")) |
843 | return false; | 848 | return false; |
844 | qDebug("saveAsFile " + currentFileName); | 849 | qDebug("saveAsFile " + currentFileName); |
845 | // case of nothing to save... | 850 | // case of nothing to save... |
846 | // if ( !doc && !currentFileName.isEmpty()) { | 851 | // if ( !doc && !currentFileName.isEmpty()) { |
847 | // //|| !bFromDocView) | 852 | // //|| !bFromDocView) |
848 | // qDebug("no doc"); | 853 | // qDebug("no doc"); |
849 | // return true; | 854 | // return true; |
850 | // } | 855 | // } |
851 | // if ( !editor->edited() ) { | 856 | // if ( !editor->edited() ) { |
852 | // delete doc; | 857 | // delete doc; |
853 | // doc = 0; | 858 | // doc = 0; |
854 | // return true; | 859 | // return true; |
855 | // } | 860 | // } |
856 | 861 | ||
857 | QString rt = editor->text(); | 862 | QString rt = editor->text(); |
858 | qDebug(currentFileName); | 863 | qDebug(currentFileName); |
859 | 864 | ||
860 | if( currentFileName.isEmpty() | 865 | if( currentFileName.isEmpty() |
861 | || currentFileName == tr("Unnamed") | 866 | || currentFileName == tr("Unnamed") |
862 | || currentFileName == tr("Text Editor")) { | 867 | || currentFileName == tr("Text Editor")) { |
863 | qDebug("do silly TT filename thing"); | 868 | qDebug("do silly TT filename thing"); |
864 | // if ( doc && doc->name().isEmpty() ) { | 869 | // if ( doc && doc->name().isEmpty() ) { |
865 | QString pt = rt.simplifyWhiteSpace(); | 870 | QString pt = rt.simplifyWhiteSpace(); |
866 | int i = pt.find( ' ' ); | 871 | int i = pt.find( ' ' ); |
867 | QString docname = pt; | 872 | QString docname = pt; |
868 | if ( i > 0 ) | 873 | if ( i > 0 ) |
869 | docname = pt.left( i ); | 874 | docname = pt.left( i ); |
870 | // remove "." at the beginning | 875 | // remove "." at the beginning |
871 | while( docname.startsWith( "." ) ) | 876 | while( docname.startsWith( "." ) ) |
872 | docname = docname.mid( 1 ); | 877 | docname = docname.mid( 1 ); |
873 | docname.replace( QRegExp("/"), "_" ); | 878 | docname.replace( QRegExp("/"), "_" ); |
874 | // cut the length. filenames longer than that | 879 | // cut the length. filenames longer than that |
875 | //don't make sense and something goes wrong when they get too long. | 880 | //don't make sense and something goes wrong when they get too long. |
876 | if ( docname.length() > 40 ) | 881 | if ( docname.length() > 40 ) |
877 | docname = docname.left(40); | 882 | docname = docname.left(40); |
878 | if ( docname.isEmpty() ) | 883 | if ( docname.isEmpty() ) |
879 | docname = tr("Unnamed"); | 884 | docname = tr("Unnamed"); |
880 | if(doc) doc->setName(docname); | 885 | if(doc) doc->setName(docname); |
881 | currentFileName=docname; | 886 | currentFileName=docname; |
882 | // } | 887 | // } |
883 | // else | 888 | // else |
884 | // qDebug("hmmmmmm"); | 889 | // qDebug("hmmmmmm"); |
885 | } | 890 | } |
886 | 891 | ||
887 | 892 | ||
888 | QMap<QString, QStringList> map; | 893 | QMap<QString, QStringList> map; |
889 | map.insert(tr("All"), QStringList() ); | 894 | map.insert(tr("All"), QStringList() ); |
890 | QStringList text; | 895 | QStringList text; |
891 | text << "text/*"; | 896 | text << "text/*"; |
892 | map.insert(tr("Text"), text ); | 897 | map.insert(tr("Text"), text ); |
893 | text << "*"; | 898 | text << "*"; |
894 | map.insert(tr("All"), text ); | 899 | map.insert(tr("All"), text ); |
895 | 900 | ||
896 | QFileInfo cuFi( currentFileName); | 901 | QFileInfo cuFi( currentFileName); |
897 | QString filee = cuFi.fileName(); | 902 | QString filee = cuFi.fileName(); |
898 | QString dire = cuFi.dirPath(); | 903 | QString dire = cuFi.dirPath(); |
899 | if(dire==".") | 904 | if(dire==".") |
900 | dire = QPEApplication::documentDir(); | 905 | dire = QPEApplication::documentDir(); |
901 | QString str = OFileDialog::getSaveFileName( 2, | 906 | QString str = OFileDialog::getSaveFileName( 2, |
902 | dire, | 907 | dire, |
903 | filee, map); | 908 | filee, map); |
904 | 909 | ||
905 | if(!str.isEmpty()) { | 910 | if(!str.isEmpty()) { |
906 | QString fileNm=str; | 911 | QString fileNm=str; |
907 | 912 | ||
908 | qDebug("saving filename "+fileNm); | 913 | qDebug("saving filename "+fileNm); |
909 | QFileInfo fi(fileNm); | 914 | QFileInfo fi(fileNm); |
910 | currentFileName=fi.fileName(); | 915 | currentFileName=fi.fileName(); |
911 | if(doc) | 916 | if(doc) |
912 | // QString file = doc->file(); | 917 | // QString file = doc->file(); |
913 | // doc->removeFiles(); | 918 | // doc->removeFiles(); |
914 | delete doc; | 919 | delete doc; |
915 | DocLnk nf; | 920 | DocLnk nf; |
916 | nf.setType("text/plain"); | 921 | nf.setType("text/plain"); |
917 | nf.setFile( fileNm); | 922 | nf.setFile( fileNm); |
918 | doc = new DocLnk(nf); | 923 | doc = new DocLnk(nf); |