summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp36
1 files changed, 21 insertions, 15 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 086fdb6..1d0df6a 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -746,111 +746,117 @@ void TextEdit::openFile( const DocLnk &f ) {
746 odebug << "openFile doclnk " + currentFileName << oendl; 746 odebug << "openFile doclnk " + currentFileName << oendl;
747 if ( !fm.loadFile( f, txt ) ) { 747 if ( !fm.loadFile( f, txt ) ) {
748 // ####### could be a new file 748 // ####### could be a new file
749 odebug << "Cannot open file" << oendl; 749 odebug << "Cannot open file" << oendl;
750 } 750 }
751// fileNew(); 751// fileNew();
752 if ( doc ) 752 if ( doc )
753 delete doc; 753 delete doc;
754 doc = new DocLnk(f); 754 doc = new DocLnk(f);
755 editor->setText(txt); 755 editor->setText(txt);
756 editor->setEdited( false); 756 editor->setEdited( false);
757 edited1=false; 757 edited1=false;
758 edited=false; 758 edited=false;
759 759
760 doc->setName(currentFileName); 760 doc->setName(currentFileName);
761 updateCaption(); 761 updateCaption();
762 setTimer(); 762 setTimer();
763} 763}
764 764
765void TextEdit::showEditTools() { 765void TextEdit::showEditTools() {
766 menu->show(); 766 menu->show();
767 editBar->show(); 767 editBar->show();
768 if(!useSearchBar) 768 if(!useSearchBar)
769 searchBar->hide(); 769 searchBar->hide();
770 else 770 else
771 searchBar->show(); 771 searchBar->show();
772 setWState (WState_Reserved1 ); 772 setWState (WState_Reserved1 );
773} 773}
774 774
775/*! 775/*!
776 unprompted save */ 776 unprompted save */
777bool TextEdit::save() { 777bool TextEdit::save() {
778 QString name, file;
778 odebug << "saveAsFile " + currentFileName << oendl; 779 odebug << "saveAsFile " + currentFileName << oendl;
779 if(currentFileName.isEmpty()) { 780 if(currentFileName.isEmpty()) {
780 saveAs(); 781 saveAs();
781 return false; 782 return false;
782 } 783 }
783 784 name = currentFileName;
784 QString file = doc->file(); 785 if(doc) {
785 odebug << "saver file "+file << oendl; 786 file = doc->file();
786 QString name= doc->name(); 787 odebug << "saver file "+file << oendl;
787 odebug << "File named "+name << oendl; 788 name = doc->name();
789 odebug << "File named "+name << oendl;
790 } else {
791 name = file = currentFileName;
792 }
793
788 QString rt = editor->text(); 794 QString rt = editor->text();
789 if( !rt.isEmpty() ) { 795 if( !rt.isEmpty() ) {
790 if(name.isEmpty()) { 796 if(name.isEmpty()) {
791 saveAs(); 797 saveAs();
792 } else { 798 } else {
793 currentFileName= name ; 799 currentFileName = name;
794 odebug << "saveFile "+currentFileName << oendl; 800 odebug << "saveFile "+currentFileName << oendl;
795 801
796 struct stat buf; 802 struct stat buf;
797 mode_t mode; 803 mode_t mode;
798 stat(file.latin1(), &buf); 804 stat(file.latin1(), &buf);
799 mode = buf.st_mode; 805 mode = buf.st_mode;
800 806
801 if(!fileIs) { 807 if(!fileIs) {
802 doc->setName( name); 808 doc->setName( name);
803 FileManager fm; 809 FileManager fm;
804 if ( !fm.saveFile( *doc, rt ) ) { 810 if ( !fm.saveFile( *doc, rt ) ) {
805 QMessageBox::message(tr("Text Edit"),tr("Save Failed")); 811 QMessageBox::message(tr("Text Edit"),tr("Save Failed"));
806 return false; 812 return false;
807 } 813 }
808 } else { 814 } else {
809 odebug << "regular save file" << oendl; 815 odebug << "regular save file" << oendl;
810 QFile f(file); 816 QFile f(file);
811 if( f.open(IO_WriteOnly)) { 817 if( f.open(IO_WriteOnly)) {
812 QCString crt = rt.utf8(); 818 QCString crt = rt.utf8();
813 f.writeBlock(crt,crt.length()); 819 f.writeBlock(crt,crt.length());
814 } else { 820 } else {
815 QMessageBox::message(tr("Text Edit"),tr("Write Failed")); 821 QMessageBox::message(tr("Text Edit"),tr("Write Failed"));
816 return false; 822 return false;
817 } 823 }
818 824
819 } 825 }
820 editor->setEdited( false); 826 editor->setEdited( false);
821 edited1=false; 827 edited1=false;
822 edited=false; 828 edited=false;
823 if(caption().left(1)=="*") 829 if(caption().left(1)=="*")
824 setCaption(caption().right(caption().length()-1)); 830 setCaption(caption().right(caption().length()-1));
825 831
826 832
827 chmod( file.latin1(), mode); 833 chmod( file.latin1(), mode);
828 } 834 }
829 return true; 835 return true;
830 } 836 }
831 return false; 837 return false;
832} 838}
833 839
834/*! 840/*!
835 prompted save */ 841 prompted save */
836bool TextEdit::saveAs() { 842bool TextEdit::saveAs() {
837 843
838 if(caption() == tr("Text Editor")) 844 if(caption() == tr("Text Editor"))
839 return false; 845 return false;
840 odebug << "saveAsFile " + currentFileName << oendl; 846 odebug << "saveAsFile " + currentFileName << oendl;
841 // case of nothing to save... 847 // case of nothing to save...
842// if ( !doc && !currentFileName.isEmpty()) { 848// if ( !doc && !currentFileName.isEmpty()) {
843// //|| !bFromDocView) 849// //|| !bFromDocView)
844// odebug << "no doc" << oendl; 850// odebug << "no doc" << oendl;
845// return true; 851// return true;
846// } 852// }
847// if ( !editor->edited() ) { 853// if ( !editor->edited() ) {
848// delete doc; 854// delete doc;
849// doc = 0; 855// doc = 0;
850// return true; 856// return true;
851// } 857// }
852 858
853 QString rt = editor->text(); 859 QString rt = editor->text();
854 odebug << currentFileName << oendl; 860 odebug << currentFileName << oendl;
855 861
856 if( currentFileName.isEmpty() 862 if( currentFileName.isEmpty()