-rw-r--r-- | core/apps/textedit/textedit.cpp | 23 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 2 |
2 files changed, 23 insertions, 2 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 429c195..834971a 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp @@ -246,64 +246,68 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) menu = bar; QPEMenuBar *mb = new QPEMenuBar( bar ); QPopupMenu *file = new QPopupMenu( this ); QPopupMenu *edit = new QPopupMenu( this ); QPopupMenu *font = new QPopupMenu( this ); bar = new QPEToolBar( this ); editBar = bar; QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); a->addTo( bar ); a->addTo( file ); a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); // a->addTo( bar ); a->addTo( file ); a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); a->addTo( bar ); a->addTo( file ); // a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); // a->addTo( bar ); file->insertSeparator(); a->addTo( file ); + a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); + a->addTo( file ); + a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); a->addTo( editBar ); a->addTo( edit ); a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); a->addTo( editBar ); a->addTo( edit ); a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); a->addTo( editBar ); a->addTo( edit ); a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); edit->insertSeparator(); a->addTo( bar ); a->addTo( edit ); int defsize; bool defb, defi, wrap; Config cfg("TextEdit"); cfg.setGroup("View"); defsize = cfg.readNumEntry("FontSize",10); defb = cfg.readBoolEntry("Bold",FALSE); defi = cfg.readBoolEntry("Italic",FALSE); wrap = cfg.readBoolEntry("Wrap",TRUE); zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); @@ -385,65 +389,65 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) resize( 200, 300 ); // setFontSize(defsize,TRUE); FontDatabase fdb; QFont defaultFont=editor->font(); QFontInfo fontInfo(defaultFont); cfg.setGroup("Font"); QString family = cfg.readEntry("Family", fontInfo.family()); QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); defaultFont = fdb.font(family,style,i_size,charSet); editor->setFont( defaultFont); wa->setOn(wrap); updateCaption(); if( qApp->argc() > 1 ) { for (int i=1;i< qApp->argc();i++) { QString tmp; currentFileName = tmp.sprintf("%s",qApp->argv()[i]); qDebug(currentFileName); setDocument( currentFileName ); } } else fileNew(); } TextEdit::~TextEdit() { - save(); + saveAs(); Config cfg("TextEdit"); cfg.setGroup("View"); QFont f = editor->font(); cfg.writeEntry("FontSize",f.pointSize()); cfg.writeEntry("Bold",f.bold()); cfg.writeEntry("Italic",f.italic()); cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); } void TextEdit::zoomIn() { setFontSize(editor->font().pointSize()+1,FALSE); } void TextEdit::zoomOut() { setFontSize(editor->font().pointSize()-1,TRUE); } 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 { @@ -457,65 +461,65 @@ void TextEdit::setFontSize(int sz, bool round_down_not_up) 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() { if( !bFromDocView ) { - save(); + saveAs(); } 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(currentFileName); } void TextEdit::newFileOpen() { @@ -651,64 +655,79 @@ void TextEdit::openFile( const DocLnk &f ) // ####### 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(currentFileName); } void TextEdit::showEditTools() { // if ( !doc ) // close(); // clear(); fileSelector->hide(); menu->show(); editBar->show(); if ( searchVisible ) searchBar->show(); // updateCaption(); editorStack->raiseWidget( editor ); setWState (WState_Reserved1 ); } bool TextEdit::save() { + QString rt = editor->text(); + doc->setName( currentFileName); + FileManager fm; + if ( !fm.saveFile( *doc, rt ) ) { + return false; + } + delete doc; + doc = 0; + editor->setEdited( false ); + return true; + +} + +bool TextEdit::saveAs() +{ // case of nothing to save... if ( !doc || !bFromDocView) return true; if ( !editor->edited() ) { delete doc; doc = 0; return true; } QString rt = editor->text(); 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; } diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h index 4bfb260..f9eb241 100644 --- a/core/apps/textedit/textedit.h +++ b/core/apps/textedit/textedit.h @@ -32,64 +32,66 @@ #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 fileNew(); void fileRevert(); void fileOpen(); void newFileOpen(); bool save(); + bool saveAs(); + 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; |