author | llornkcor <llornkcor> | 2002-02-18 14:52:54 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-02-18 14:52:54 (UTC) |
commit | 00f89d28e669140eb50f1f220c389f88fba1105c (patch) (side-by-side diff) | |
tree | deb87bb87d855bbacddc79d8a0a79edfb1cf1cd8 | |
parent | 9741205aa0b0892b870d2b7df7c5dd7e25b0bb18 (diff) | |
download | opie-00f89d28e669140eb50f1f220c389f88fba1105c.zip opie-00f89d28e669140eb50f1f220c389f88fba1105c.tar.gz opie-00f89d28e669140eb50f1f220c389f88fba1105c.tar.bz2 |
fixed filesave and fileopen cancel
-rw-r--r-- | core/apps/textedit/fileSaver.cpp | 16 | ||||
-rw-r--r-- | core/apps/textedit/textedit.cpp | 52 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 2 |
3 files changed, 42 insertions, 28 deletions
diff --git a/core/apps/textedit/fileSaver.cpp b/core/apps/textedit/fileSaver.cpp index d01daee..88608cc 100644 --- a/core/apps/textedit/fileSaver.cpp +++ b/core/apps/textedit/fileSaver.cpp @@ -1,104 +1,111 @@ /**************************************************************************** ** copyright 2001 ljp ljp@llornkcor.com ** Created: Fri Dec 14 08:16:46 2001 fileSaver.cpp ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ****************************************************************************/ #include "fileSaver.h" #include <qpe/config.h> #include <qpe/qpeapplication.h> #include <qlistview.h> #include <qpushbutton.h> #include <qfile.h> #include <qmessagebox.h> #include <unistd.h> #include <qlineedit.h> fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl , const QString currentFileName ) : QDialog( parent, name, modal, fl ) { if ( !name ) setName( "fileSaver" ); resize( 236, 280 ); setCaption(tr( "Save file" ) ); -// filterStr=currentFileName; + QFileInfo fi(currentFileName); + QString tmpFileName=fi.fileName(); +// qDebug( tmpFileName); dirLabel = new QLabel(this, "DirLabel"); dirLabel->setText(currentDir.canonicalPath()); dirLabel->setGeometry(10,4,230,30); ListView = new QListView( this, "ListView" ); ListView->addColumn( tr( "Name" ) ); ListView->setColumnWidth(0,140); ListView->setSorting( 2, FALSE); ListView->addColumn( tr( "Size" ) ); ListView->setColumnWidth(1,59); // ListView->setMultiSelection(true); // ListView->setSelectionMode(QListView::Extended); ListView->setAllColumnsShowFocus( TRUE ); ListView->setGeometry( QRect( 10, 35, 220, 160 ) ); fileEdit= new QLineEdit(this); fileEdit->setGeometry( QRect( 10, 230, 200, 25)); - fileEdit->setText(currentFileName); - // signals and slots connections + + fileEdit->setText( tmpFileName); + + // signals and slots connections connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); - currentDir.setPath(QDir::currentDirPath() ); + +// tmpFileName=fi.FilePath(); +// qDebug( tmpFileName); + currentDir.setPath( QDir::currentDirPath() ); populateList(); } fileSaver::~fileSaver() { } void fileSaver::populateList() { ListView->clear(); currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden ); currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); currentDir.setMatchAllDirs(TRUE); currentDir.setNameFilter("*"); QString fileL, fileS; const QFileInfoList *list = currentDir.entryInfoList(QDir::All /*, QDir::SortByMask*/); QFileInfoListIterator it(*list); QFileInfo *fi; while ( (fi=it.current()) ) { if (fi->isSymLink() ){ QString symLink=fi->readLink(); // qDebug("Symlink detected "+symLink); QFileInfo sym( symLink); fileS.sprintf( "%10li", sym.size() ); fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); } else { // // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); fileS.sprintf( "%10li", fi->size() ); fileL.sprintf( "%s",fi->fileName().data() ); if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { fileL+="/"; // qDebug(currentDir.canonicalPath()+fileL); } } item= new QListViewItem( ListView,fileL,fileS ); ++it; } ListView->setSorting( 2, FALSE); dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); } void fileSaver::upDir() @@ -115,50 +122,51 @@ void fileSaver::listClicked(QListViewItem *selectedItem) QString strItem=selectedItem->text(0); QString strSize=selectedItem->text(1); // qDebug("strItem is "+strItem); strSize.stripWhiteSpace(); // qDebug(strSize); if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); // qDebug("strItem symlink is "+strItem2); if(QDir(strItem2).exists() ) { currentDir.cd(strItem2, TRUE); populateList(); } } else { // not a symlink if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); currentDir.cd(strItem,FALSE); // qDebug("Path is "+strItem); populateList(); } else { currentDir.cdUp(); populateList(); } if(QDir(strItem).exists()){ currentDir.cd(strItem, TRUE); populateList(); } } // else // if( QFile::exists(strItem ) ) { // qDebug("We found our files!!"); // OnOK(); } //end not symlink chdir(strItem.latin1()); } void fileSaver::OnOK() { // reject(); } void fileSaver::accept() { selectedFileName = fileEdit->text(); selectedFileName = currentDir.canonicalPath()+ selectedFileName; + qDebug("goint to save "+selectedFileName); reject(); } diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 14bc496..429c195 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp @@ -440,327 +440,333 @@ void TextEdit::setFontSize(int sz, bool round_down_not_up) { int s=10; for (int i=0; i<nfontsizes; i++) { if ( fontsize[i] == sz ) { s = sz; break; } else if ( round_down_not_up ) { if ( fontsize[i] < sz ) s = fontsize[i]; } else { if ( fontsize[i] > sz ) { s = fontsize[i]; break; } } } QFont f = editor->font(); f.setPointSize(s); editor->setFont(f); zin->setEnabled(s != fontsize[nfontsizes-1]); zout->setEnabled(s != fontsize[0]); } void TextEdit::setBold(bool y) { QFont f = editor->font(); f.setBold(y); editor->setFont(f); } void TextEdit::setItalic(bool y) { QFont f = editor->font(); f.setItalic(y); editor->setFont(f); } void TextEdit::setWordWrap(bool y) { bool state = editor->edited(); editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); editor->setEdited( state ); } void TextEdit::fileNew() { - save(); + if( !bFromDocView ) { + save(); + } newFile(DocLnk()); } void TextEdit::fileOpen() { // if ( !save() ) { // if ( QMessageBox::critical( this, tr( "Out of space" ), // tr( "Text Editor was unable to\n" // "save your changes.\n" // "Free some space and try again.\n" // "\nContinue anyway?" ), // QMessageBox::Yes|QMessageBox::Escape, // QMessageBox::No|QMessageBox::Default ) // != QMessageBox::Yes ) // return; // else { // delete doc; // doc = 0; // } // } menu->hide(); editBar->hide(); searchBar->hide(); clearWState (WState_Reserved1 ); editorStack->raiseWidget( fileSelector ); fileSelector->reread(); - updateCaption(); + updateCaption(currentFileName); } void TextEdit::newFileOpen() { fileBrowser *browseForFiles; browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*"); - browseForFiles->exec(); - QString selFile= browseForFiles->selectedFileName; - QStringList fileList=browseForFiles->fileList; - qDebug(selFile); - QStringList::ConstIterator f; - QString fileTemp; - for ( f = fileList.begin(); f != fileList.end(); f++ ) { - fileTemp = *f; - fileTemp.right( fileTemp.length()-5); - QString fileName = fileTemp; - if( fileName != "Unnamed" || fileName != "Empty Text" ) { - currentFileName = fileName; - qDebug("please open "+currentFileName); - openFile(fileName ); + if( browseForFiles->exec()!= 0 ) { + QString selFile= browseForFiles->selectedFileName; + QStringList fileList=browseForFiles->fileList; + qDebug(selFile); + QStringList::ConstIterator f; + QString fileTemp; + for ( f = fileList.begin(); f != fileList.end(); f++ ) { + fileTemp = *f; + fileTemp.right( fileTemp.length()-5); + QString fileName = fileTemp; + if( fileName != "Unnamed" || fileName != "Empty Text" ) { + currentFileName = fileName; +// qDebug("please open "+currentFileName); + openFile(fileName ); + } } } delete browseForFiles; } #if 0 void TextEdit::slotFind() { FindDialog frmFind( "Text Editor", this ); connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), editor, SLOT(slotDoFind( const QString&,bool,bool))); //case sensitive, backwards, [category] connect( editor, SIGNAL(notFound()), &frmFind, SLOT(slotNotFound()) ); connect( editor, SIGNAL(searchWrapped()), &frmFind, SLOT(slotWrapAround()) ); frmFind.exec(); } #endif void TextEdit::fileRevert() { clear(); fileOpen(); } void TextEdit::editCut() { #ifndef QT_NO_CLIPBOARD editor->cut(); #endif } void TextEdit::editCopy() { #ifndef QT_NO_CLIPBOARD editor->copy(); #endif } void TextEdit::editPaste() { #ifndef QT_NO_CLIPBOARD editor->paste(); #endif } void TextEdit::editFind() { searchBar->show(); searchVisible = TRUE; searchEdit->setFocus(); } void TextEdit::findNext() { editor->find( searchEdit->text(), FALSE, FALSE ); } void TextEdit::findClose() { searchVisible = FALSE; searchBar->hide(); } void TextEdit::search() { editor->find( searchEdit->text(), FALSE, FALSE ); } void TextEdit::newFile( const DocLnk &f ) { DocLnk nf = f; nf.setType("text/plain"); clear(); editorStack->raiseWidget( editor ); setWState (WState_Reserved1 ); editor->setFocus(); doc = new DocLnk(nf); - updateCaption(); +// updateCaption(); } void TextEdit::openFile( const QString &f ) { bFromDocView = TRUE; DocLnk nf; nf.setType("text/plain"); nf.setFile(f); openFile(nf); showEditTools(); // Show filename in caption QString name = f; 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; if ( !fm.loadFile( f, txt ) ) { // ####### could be a new file qDebug( "Cannot open file" ); //return; } fileNew(); if ( doc ) delete doc; doc = new DocLnk(f); editor->setText(txt); editor->setEdited(FALSE); - updateCaption(); + updateCaption(currentFileName); } void TextEdit::showEditTools() { // if ( !doc ) // close(); // clear(); fileSelector->hide(); menu->show(); editBar->show(); if ( searchVisible ) searchBar->show(); - updateCaption(); +// updateCaption(); editorStack->raiseWidget( editor ); setWState (WState_Reserved1 ); } bool TextEdit::save() { // case of nothing to save... if ( !doc || !bFromDocView) return true; if ( !editor->edited() ) { delete doc; doc = 0; return true; } QString rt = editor->text(); - - if(currentFileName.isEmpty() || currentFileName == "Unnamed") { + qDebug(currentFileName); + + if( currentFileName.isEmpty() || currentFileName == "Unnamed") { if ( 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 ) docname = docname.left(40); if ( docname.isEmpty() ) docname = "Empty Text"; doc->setName(docname); currentFileName=docname; } } fileSaver *fileSaveDlg; fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName); - fileSaveDlg->exec(); + if( fileSaveDlg->exec() != 0 ) { QString fileNm=fileSaveDlg->selectedFileName; qDebug("save filename "+fileNm); doc->setName(fileNm); - updateCaption(); + updateCaption(fileNm); + } delete fileSaveDlg; FileManager fm; if ( !fm.saveFile( *doc, rt ) ) { return false; } delete doc; doc = 0; editor->setEdited( false ); return true; } void TextEdit::clear() { delete doc; doc = 0; editor->clear(); } void TextEdit::updateCaption( const QString &name ) { if ( !doc ) setCaption( tr("Text Editor") ); else { QString s = name; if ( s.isNull() ) s = doc->name(); if ( s.isEmpty() ) { s = tr( "Unnamed" ); currentFileName=s; } setCaption( s + " - " + tr("Text Editor") ); } } void TextEdit::setDocument(const QString& fileref) { bFromDocView = TRUE; openFile(DocLnk(fileref)); // showEditTools(); } void TextEdit::closeEvent( QCloseEvent *e ) { if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { e->ignore(); repaint(); // fileRevert(); diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h index 4e469cc..4bfb260 100644 --- a/core/apps/textedit/textedit.h +++ b/core/apps/textedit/textedit.h @@ -10,96 +10,96 @@ ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ // additions made by L.J. Potter Sun 02-17-2002 22:27:46 #ifndef TEXTEDIT_H #define TEXTEDIT_H #define QTEXTEDIT_OPEN_API #include <qpe/filemanager.h> #include <qmainwindow.h> #include <qmultilineedit.h> #include <qlist.h> #include <qmap.h> class QWidgetStack; class QToolButton; class QPopupMenu; class QToolBar; class QLineEdit; class QAction; class FileSelector; class QpeEditor; class TextEdit : public QMainWindow { Q_OBJECT public: TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); ~TextEdit(); void openFile( const QString & ); protected: void closeEvent( QCloseEvent *e ); private slots: void setDocument(const QString&); - void changeFont(); + void changeFont(); void fileNew(); void fileRevert(); void fileOpen(); void newFileOpen(); bool save(); void editCut(); void editCopy(); void editPaste(); void editFind(); void findNext(); void findClose(); void search(); void accept(); void newFile( const DocLnk & ); void openFile( const DocLnk & ); void showEditTools(); void zoomIn(); void zoomOut(); void setBold(bool y); void setItalic(bool y); void setWordWrap(bool y); private: void colorChanged( const QColor &c ); void clear(); void updateCaption( const QString &name=QString::null ); void setFontSize(int sz, bool round_down_not_up); private: QWidgetStack *editorStack; FileSelector *fileSelector; QpeEditor* editor; QToolBar *menu, *editBar, *searchBar; QLineEdit *searchEdit; DocLnk *doc; bool searchVisible; bool bFromDocView; QAction *zin, *zout; QString currentFileName; }; #endif |