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 | |||
@@ -742,97 +742,102 @@ file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), | |||
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 | ||