-rw-r--r-- | core/apps/textedit/textedit.cpp | 36 |
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 @@ -730,143 +730,149 @@ void TextEdit::openFile( const QString &f ) { showEditTools(); // Show filename in caption QString name = filer; int sep = name.findRev( '/' ); if ( sep > 0 ) name = name.mid( sep+1 ); updateCaption( name ); } void TextEdit::openFile( const DocLnk &f ) { // clear(); // bFromDocView = true; FileManager fm; QString txt; currentFileName=f.file(); odebug << "openFile doclnk " + currentFileName << oendl; if ( !fm.loadFile( f, txt ) ) { // ####### could be a new file odebug << "Cannot open file" << oendl; } // fileNew(); if ( doc ) delete doc; doc = new DocLnk(f); editor->setText(txt); editor->setEdited( false); edited1=false; edited=false; doc->setName(currentFileName); updateCaption(); setTimer(); } void TextEdit::showEditTools() { menu->show(); editBar->show(); if(!useSearchBar) searchBar->hide(); else searchBar->show(); setWState (WState_Reserved1 ); } /*! unprompted save */ bool TextEdit::save() { + QString name, file; odebug << "saveAsFile " + currentFileName << oendl; if(currentFileName.isEmpty()) { saveAs(); return false; } - - QString file = doc->file(); - odebug << "saver file "+file << oendl; - QString name= doc->name(); - odebug << "File named "+name << oendl; + name = currentFileName; + if(doc) { + file = doc->file(); + odebug << "saver file "+file << oendl; + name = doc->name(); + odebug << "File named "+name << oendl; + } else { + name = file = currentFileName; + } + QString rt = editor->text(); if( !rt.isEmpty() ) { if(name.isEmpty()) { saveAs(); } else { - currentFileName= name ; + currentFileName = name; odebug << "saveFile "+currentFileName << oendl; struct stat buf; mode_t mode; stat(file.latin1(), &buf); mode = buf.st_mode; if(!fileIs) { doc->setName( name); FileManager fm; if ( !fm.saveFile( *doc, rt ) ) { - QMessageBox::message(tr("Text Edit"),tr("Save Failed")); + QMessageBox::message(tr("Text Edit"),tr("Save Failed")); return false; } } else { odebug << "regular save file" << oendl; QFile f(file); - if( f.open(IO_WriteOnly)) { - QCString crt = rt.utf8(); - f.writeBlock(crt,crt.length()); - } else { - QMessageBox::message(tr("Text Edit"),tr("Write Failed")); - return false; - } + if( f.open(IO_WriteOnly)) { + QCString crt = rt.utf8(); + f.writeBlock(crt,crt.length()); + } else { + QMessageBox::message(tr("Text Edit"),tr("Write Failed")); + return false; + } } editor->setEdited( false); edited1=false; edited=false; if(caption().left(1)=="*") - setCaption(caption().right(caption().length()-1)); + setCaption(caption().right(caption().length()-1)); chmod( file.latin1(), mode); } return true; } return false; } /*! prompted save */ bool TextEdit::saveAs() { if(caption() == tr("Text Editor")) return false; odebug << "saveAsFile " + currentFileName << oendl; // case of nothing to save... // if ( !doc && !currentFileName.isEmpty()) { // //|| !bFromDocView) // odebug << "no doc" << oendl; // return true; // } // if ( !editor->edited() ) { // delete doc; // doc = 0; // return true; // } QString rt = editor->text(); odebug << currentFileName << oendl; if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { odebug << "do silly TT filename thing" << oendl; // if ( doc && doc->name().isEmpty() ) { QString pt = rt.simplifyWhiteSpace(); int i = pt.find( ' ' ); QString docname = pt; if ( i > 0 ) docname = pt.left( i ); // remove "." at the beginning while( docname.startsWith( "." ) ) docname = docname.mid( 1 ); docname.replace( QRegExp("/"), "_" ); // cut the length. filenames longer than that //don't make sense and something goes wrong when they get too long. if ( docname.length() > 40 ) |