-rw-r--r-- | core/apps/textedit/textedit.cpp | 281 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 4 |
2 files changed, 137 insertions, 148 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 464671a..1c3b393 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp @@ -196,3 +196,3 @@ void QpeEditor::find ( const QString &txt, bool caseSensitive, { - static bool wrap = FALSE; + static bool wrap = false; int line, col; @@ -201,3 +201,3 @@ void QpeEditor::find ( const QString &txt, bool caseSensitive, line = col = 0; - wrap = FALSE; + wrap = false; // emit searchWrapped(); @@ -210,3 +210,3 @@ void QpeEditor::find ( const QString &txt, bool caseSensitive, if ( line >= numLines() ) { - wrap = TRUE; + wrap = true; //emit notFound(); @@ -216,7 +216,7 @@ void QpeEditor::find ( const QString &txt, bool caseSensitive, if ( findCol >= 0 ) { - setCursorPosition( line, findCol, FALSE ); + setCursorPosition( line, findCol, false ); col = findCol + txt.length(); - setCursorPosition( line, col, TRUE ); + setCursorPosition( line, col, true ); - //found = TRUE; + //found = true; break; @@ -241,8 +241,8 @@ static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) - : QMainWindow( parent, name, f ), bFromDocView( FALSE ) + : QMainWindow( parent, name, f ), bFromDocView( false ) { doc = 0; - edited=FALSE; - edited1=FALSE; - setToolBarsMovable( FALSE ); + edited=false; + edited1=false; + setToolBarsMovable( false ); connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); @@ -256,3 +256,3 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) QPEToolBar *bar = new QPEToolBar( this ); - bar->setHorizontalStretchable( TRUE ); + bar->setHorizontalStretchable( true ); menu = bar; @@ -334,3 +334,3 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); - wa->setToggleAction(TRUE); + wa->setToggleAction(true); wa->addTo( advancedMenu); @@ -339,3 +339,3 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); - nStart->setToggleAction(TRUE); + nStart->setToggleAction(true); nStart->addTo( advancedMenu ); @@ -344,3 +344,3 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) connect( nAdvanced, SIGNAL( toggled(bool) ), this, SLOT( doPrompt(bool) ) ); - nAdvanced->setToggleAction(TRUE); + nAdvanced->setToggleAction(true); nAdvanced->addTo( advancedMenu ); @@ -349,3 +349,3 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) connect( desktopAction, SIGNAL( toggled(bool) ), this, SLOT( doDesktop(bool) ) ); - desktopAction->setToggleAction(TRUE); + desktopAction->setToggleAction(true); desktopAction->addTo( advancedMenu); @@ -354,3 +354,3 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) connect( filePermAction, SIGNAL( toggled(bool) ), this, SLOT( doFilePerms(bool) ) ); - filePermAction->setToggleAction(TRUE); + filePermAction->setToggleAction(true); filePermAction->addTo( advancedMenu); @@ -359,3 +359,3 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) connect( searchBarAction, SIGNAL( toggled(bool) ), this, SLOT( setSearchBar(bool) ) ); - searchBarAction->setToggleAction(TRUE); + searchBarAction->setToggleAction(true); searchBarAction->addTo( advancedMenu); @@ -372,5 +372,5 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) searchBar = new QPEToolBar(this); - addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); + addToolBar( searchBar, "Search", QMainWindow::Top, true ); - searchBar->setHorizontalStretchable( TRUE ); + searchBar->setHorizontalStretchable( true ); @@ -424,10 +424,9 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); - - if(useSearchBar) { - searchBarAction->setOn(true); - } else{ - } - if(promptExit ) nAdvanced->setOn ( true ); - if(openDesktop) desktopAction->setOn ( true ); - if(filePerms) filePermAction->setOn ( true ); + startWithNew = cfg.readBoolEntry ( "startNew", true); + + if(useSearchBar) searchBarAction->setOn(true); + if(promptExit ) nAdvanced->setOn( true ); + if(openDesktop) desktopAction->setOn( true ); + if(filePerms) filePermAction->setOn( true ); + if(startWithNew) nStart->setOn( true ); @@ -437,22 +436,20 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) - if( qApp->argc() > 0) { - currentFileName=qApp->argv()[1]; -// qDebug("<<<<<<<<<<<<<<<<<<<<<<<< "+currentFileName); - QFileInfo fi(currentFileName); - - if(fi.baseName().left(1) == "") { - openDotFile(currentFileName); - } else { - - nStart->setOn(TRUE); - openFile(currentFileName); - } - } else - if(cfg.readEntry("startNew","TRUE") == "TRUE") { + if( qApp->argc() > 1) { + currentFileName=qApp->argv()[1]; +// qDebug("<<<<<<<<<<<<<<<<<<<<<<<< "+currentFileName+" %d",qApp->argc()); + QFileInfo fi(currentFileName); - nStart->setOn(TRUE); - fileNew(); + if(fi.baseName().left(1) == "") { + openDotFile(currentFileName); + } else { + openFile(currentFileName); + } } else { - - fileOpen(); +// qDebug("Do other thing"); + if(startWithNew) { + openDotFile(""); +// fileNew(); + } else { + fileOpen(); + } } @@ -463,4 +460,10 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) TextEdit::~TextEdit() { - if( edited1 & promptExit ) - saveAs(); +// qDebug("destr"); +} + +void TextEdit::closeEvent(QCloseEvent *) { +// qDebug("closing here"); + if( edited1 && promptExit) + saveAs(); + qApp->quit(); } @@ -468,3 +471,3 @@ TextEdit::~TextEdit() { void TextEdit::cleanUp() { - qDebug("cleanUp");// save(); +// qDebug("cleanUp");// save(); @@ -479,3 +482,3 @@ void TextEdit::cleanUp() { cfg.setGroup ( "View" ); - cfg.writeEntry ( "Wrap", editor-> wordWrap ( ) == QMultiLineEdit::WidgetWidth ); + cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); cfg.writeEntry ( "FileView", viewSelection ); @@ -486,2 +489,4 @@ void TextEdit::cleanUp() { cfg.writeEntry ( "SearchBar", useSearchBar ); + cfg.writeEntry ( "startNew", startWithNew ); + } @@ -490,5 +495,6 @@ void TextEdit::cleanUp() { void TextEdit::accept() { - if( edited1) - saveAs(); - exit(0); +// qDebug("accept"); + if( edited1) + saveAs(); + qApp->quit(); } @@ -496,3 +502,3 @@ void TextEdit::accept() { void TextEdit::zoomIn() { - setFontSize(editor->font().pointSize()+1,FALSE); + setFontSize(editor->font().pointSize()+1,false); } @@ -500,3 +506,3 @@ void TextEdit::zoomIn() { void TextEdit::zoomOut() { - setFontSize(editor->font().pointSize()-1,TRUE); + setFontSize(editor->font().pointSize()-1,true); } @@ -568,6 +574,2 @@ void TextEdit::fileNew() { void TextEdit::fileOpen() { - Config cfg("TextEdit"); - cfg.setGroup("View"); - // bool b=FALSE; - QMap<QString, QStringList> map; @@ -579,6 +581,9 @@ void TextEdit::fileOpen() { map.insert(tr("All"), text ); - QString str = OFileDialog::getOpenFileName( 2, QPEApplication::documentDir(), QString::null, map); + QString str = OFileDialog::getOpenFileName( 2, + QPEApplication::documentDir(), + QString::null, map); if(!str.isEmpty() ) openFile( str ); - + else + updateCaption(); } @@ -636,8 +641,3 @@ void TextEdit::editFind() { searchBar->show(); - searchVisible = TRUE; searchEdit->setFocus(); -// Config cfg("TextEdit"); -// cfg.setGroup("View"); -// cfg.writeEntry("SearchBar","Opened"); - } @@ -645,3 +645,3 @@ void TextEdit::editFind() { void TextEdit::findNext() { - editor->find( searchEdit->text(), FALSE, FALSE ); + editor->find( searchEdit->text(), false, false ); @@ -650,8 +650,3 @@ void TextEdit::findNext() { void TextEdit::findClose() { - searchVisible = FALSE; searchBar->hide(); -// Config cfg("TextEdit"); -// cfg.setGroup("View"); -// cfg.writeEntry("SearchBar","Closed"); -// cfg.write(); } @@ -659,3 +654,3 @@ void TextEdit::findClose() { void TextEdit::search() { - editor->find( searchEdit->text(), FALSE, FALSE ); + editor->find( searchEdit->text(), false, false ); } @@ -672,3 +667,3 @@ void TextEdit::newFile( const DocLnk &f ) { updateCaption( currentFileName); -// editor->setEdited( FALSE); +// editor->setEdited( false); } @@ -688,5 +683,5 @@ void TextEdit::openDotFile( const QString &f ) { editor->setText(txt); - editor->setEdited( FALSE); - edited1=FALSE; - edited=FALSE; + editor->setEdited( false); + edited1=false; + edited=false; @@ -701,4 +696,4 @@ void TextEdit::openFile( const QString &f ) { QFileInfo fi( f); -// bFromDocView = TRUE; - if(f.find(".desktop",0,TRUE) != -1 && !openDesktop) { +// bFromDocView = true; + if(f.find(".desktop",0,true) != -1 && !openDesktop) { switch ( QMessageBox::warning(this,tr("Text Editor"), @@ -746,3 +741,3 @@ void TextEdit::openFile( const DocLnk &f ) { // clear(); -// bFromDocView = TRUE; +// bFromDocView = true; FileManager fm; @@ -760,5 +755,5 @@ void TextEdit::openFile( const DocLnk &f ) { editor->setText(txt); - editor->setEdited( FALSE); - edited1=FALSE; - edited=FALSE; + editor->setEdited( false); + edited1=false; + edited=false; @@ -769,10 +764,8 @@ void TextEdit::openFile( const DocLnk &f ) { void TextEdit::showEditTools() { -// if ( !doc ) -// close(); -// clear(); menu->show(); editBar->show(); - if ( searchVisible ) + if(!useSearchBar) + searchBar->hide(); + else searchBar->show(); -// updateCaption(); setWState (WState_Reserved1 ); @@ -818,5 +811,5 @@ bool TextEdit::save() { } - editor->setEdited( FALSE); - edited1=FALSE; - edited=FALSE; + editor->setEdited( false); + edited1=false; + edited=false; if(caption().left(1)=="*") @@ -837,12 +830,12 @@ bool TextEdit::saveAs() { // case of nothing to save... - if ( !doc ) { -//|| !bFromDocView) - qDebug("no doc"); - return true; - } - if ( !editor->edited() ) { - delete doc; - doc = 0; - return true; - } +// if ( !doc && !currentFileName.isEmpty()) { +// //|| !bFromDocView) +// qDebug("no doc"); +// return true; +// } +// if ( !editor->edited() ) { +// delete doc; +// doc = 0; +// return true; +// } @@ -854,24 +847,27 @@ bool TextEdit::saveAs() { || currentFileName == tr("Text Editor")) { -// qDebug("do silly TT filename thing"); - 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 = tr("Unnamed"); - doc->setName(docname); - currentFileName=docname; - } + qDebug("do silly TT filename thing"); +// 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 ) + docname = docname.left(40); + if ( docname.isEmpty() ) + docname = tr("Unnamed"); + if(doc) doc->setName(docname); + currentFileName=docname; +// } +// else +// qDebug("hmmmmmm"); } + QMap<QString, QStringList> map; @@ -883,8 +879,13 @@ bool TextEdit::saveAs() { map.insert(tr("All"), text ); -// if(currentFileName + + QFileInfo cuFi( currentFileName); + QString filee = cuFi.fileName(); + QString dire = cuFi.dirPath(); + if(dire==".") + dire = QPEApplication::documentDir(); QString str = OFileDialog::getSaveFileName( 2, - QPEApplication::documentDir(), - currentFileName, map); + dire, + filee, map); - if(!str.isEmpty() ) { + if(!str.isEmpty()) { QString fileNm=str; @@ -894,3 +895,3 @@ bool TextEdit::saveAs() { currentFileName=fi.fileName(); - if(doc) { + if(doc) // QString file = doc->file(); @@ -903,3 +904,3 @@ bool TextEdit::saveAs() { // editor->setText(rt); -// qDebug("openFile doclnk "+currentFileName); + qDebug("Saving file as "+currentFileName); doc->setName( currentFileName); @@ -923,3 +924,3 @@ bool TextEdit::saveAs() { } - } +// } editor->setEdited( false); @@ -970,7 +971,7 @@ void TextEdit::setDocument(const QString& fileref) { qDebug("setDoc open"); - bFromDocView = TRUE; + bFromDocView = true; openFile(fileref); - editor->setEdited(TRUE); - edited1=FALSE; - edited=TRUE; + editor->setEdited(true); + edited1=false; + edited=true; @@ -982,7 +983,2 @@ void TextEdit::setDocument(const QString& fileref) { -void TextEdit::closeEvent( QCloseEvent *e ) { - bFromDocView = FALSE; - e->accept(); -} - void TextEdit::changeFont() { @@ -1018,11 +1014,6 @@ void TextEdit::editDelete() { void TextEdit::changeStartConfig( bool b ) { - + startWithNew=b; Config cfg("TextEdit"); cfg.setGroup("View"); - if(b) { - qDebug("bool"); - cfg.writeEntry("startNew","TRUE"); - } else { - cfg.writeEntry("startNew","FALSE"); - } + cfg.writeEntry("startNew",b); update(); @@ -1033,5 +1024,5 @@ void TextEdit::editorChanged() { setCaption( "*"+caption()); - edited1=TRUE; + edited1=true; } - edited=TRUE; + edited=true; } diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h index a95e742..bb7d693 100644 --- a/core/apps/textedit/textedit.h +++ b/core/apps/textedit/textedit.h @@ -67,3 +67,2 @@ void receive(const QCString&, const QByteArray&); protected: - bool fileIs, useAdvancedFeatures, promptExit, openDesktop, filePerms, useSearchBar; void closeEvent( QCloseEvent *e ); @@ -116,3 +115,2 @@ private: void setFontSize(int sz, bool round_down_not_up); - private: @@ -125,3 +123,3 @@ private: DocLnk *doc; - bool searchVisible; + bool fileIs, useAdvancedFeatures, promptExit, openDesktop, filePerms, useSearchBar, startWithNew; bool bFromDocView; |