-rw-r--r-- | core/apps/textedit/fileSaver.cpp | 2 | ||||
-rw-r--r-- | core/apps/textedit/textedit.cpp | 52 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 6 |
3 files changed, 51 insertions, 9 deletions
diff --git a/core/apps/textedit/fileSaver.cpp b/core/apps/textedit/fileSaver.cpp index d78f2e8..4e80735 100644 --- a/core/apps/textedit/fileSaver.cpp +++ b/core/apps/textedit/fileSaver.cpp @@ -66,25 +66,25 @@ fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl filePermCheck = new QCheckBox( this, "SetFilePerms" ); filePermCheck->setText("set file permissions"); filePermCheck->setGeometry(10, 178, 150,17); // signals and slots connections connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); // tmpFileName=fi.FilePath(); // qDebug( tmpFileName); currentDir.setPath( QDir::currentDirPath() ); populateList(); move(0,15); - + fileEdit->setFocus(); } 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); diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 0f19da9..03f3a1e 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp @@ -243,25 +243,25 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) setToolBarsMovable( FALSE ); setIcon( Resource::loadPixmap( "TextEditor" ) ); QPEToolBar *bar = new QPEToolBar( this ); bar->setHorizontalStretchable( TRUE ); menu = bar; QPEMenuBar *mb = new QPEMenuBar( bar ); QPopupMenu *file = new QPopupMenu( this ); QPopupMenu *edit = new QPopupMenu( this ); - QPopupMenu *font = new QPopupMenu( this ); + 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 ); @@ -340,24 +340,30 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) font->insertSeparator(); #endif QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); wa->setToggleAction(TRUE); wa->addTo( font ); font->insertSeparator(); font->insertItem("Font", this, SLOT(changeFont()) ); + font->insertSeparator(); + nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); + connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); + nStart->setToggleAction(TRUE); + nStart->addTo( font ); + mb->insertItem( tr( "File" ), file ); mb->insertItem( tr( "Edit" ), edit ); mb->insertItem( tr( "View" ), font ); searchBar = new QPEToolBar(this); addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); searchBar->setHorizontalStretchable( TRUE ); searchEdit = new QLineEdit( searchBar, "searchEdit" ); searchBar->setStretchableWidget( searchEdit ); connect( searchEdit, SIGNAL( textChanged( const QString & ) ), @@ -405,25 +411,32 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) 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(); + cfg.setGroup("View"); + if(cfg.readEntry("startNew","TRUE") == "TRUE") { + nStart->setOn(TRUE); fileNew(); + } else { + fileOpen(); + } + } TextEdit::~TextEdit() { // save(); 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()); @@ -688,45 +701,53 @@ void TextEdit::showEditTools() if ( searchVisible ) searchBar->show(); // updateCaption(); editorStack->raiseWidget( editor ); setWState (WState_Reserved1 ); } /*! unprompted save */ bool TextEdit::save() { QString file = doc->file(); + qDebug(file); QString name= doc->name(); - + qDebug(name); QString rt = editor->text(); + if( !rt.isEmpty() ) { + if(name.isEmpty()) { + saveAs(); + } else { currentFileName= name ; qDebug("saveFile "+currentFileName); struct stat buf; mode_t mode; stat(file.latin1(), &buf); mode = buf.st_mode; doc->setName( name); FileManager fm; if ( !fm.saveFile( *doc, rt ) ) { return false; } editor->setEdited( false ); chmod( file.latin1(), mode); + } return true; } + return false; +} /*! prompted save */ bool TextEdit::saveAs() { // qDebug("saveAsFile "+currentFileName); // case of nothing to save... /// there's always something to save // if ( !doc )//|| !bFromDocView) // { // qDebug("no doc"); // return true; @@ -754,43 +775,42 @@ bool TextEdit::saveAs() 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 = "Unnamed"; doc->setName(docname); currentFileName=docname; } } - fileSaveDlg=new fileSaver(this,"Save File",TRUE, 0, currentFileName); + fileSaveDlg=new fileSaver(this,"Save File As?",TRUE, 0, currentFileName); qDebug("wanna save filename "+currentFileName); fileSaveDlg->exec(); if( fileSaveDlg->result() == 1 ) { QString fileNm=fileSaveDlg->selectedFileName; qDebug("saving filename "+fileNm); QFileInfo fi(fileNm); currentFileName=fi.fileName(); if(doc) { - qDebug("doclnk exists"); // QString file = doc->file(); // doc->removeFiles(); delete doc; DocLnk nf; nf.setType("text/plain"); nf.setFile( fileNm); doc = new DocLnk(nf); // editor->setText(rt); - qDebug("openFile doclnk "+currentFileName); +// qDebug("openFile doclnk "+currentFileName); doc->setName( currentFileName); updateCaption( currentFileName); FileManager fm; if ( !fm.saveFile( *doc, rt ) ) { return false; } if( fileSaveDlg->filePermCheck->isChecked() ) { filePermissions *filePerm; filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm); filePerm->exec(); editor->setEdited( false ); @@ -847,27 +867,32 @@ void TextEdit::closeEvent( QCloseEvent *e ) e->ignore(); repaint(); // fileRevert(); } else { bFromDocView = FALSE; e->accept(); } } void TextEdit::accept() { + QString file = doc->file(); + if (file.find("_.txt",0,TRUE) ==-1) save(); - close(); -// fileOpen(); //godamn thats obnoxious! lemme out!!! + else { + QFile(file).remove(); + } + exit(0); + } void TextEdit::changeFont() { FontDatabase fdb; QFont defaultFont=editor->font(); QFontInfo fontInfo(defaultFont); Config cfg("TextEdit"); 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()) ); @@ -891,12 +916,25 @@ void TextEdit::editDelete() case 0: if(doc) { doc->removeFiles(); clear(); setCaption( tr("Text Editor") ); } break; case 1: // exit break; }; } + +void TextEdit::changeStartConfig( bool b ) { + + Config cfg("TextEdit"); + cfg.setGroup("View"); + if(b) { + qDebug("bool"); + cfg.writeEntry("startNew","TRUE"); + } else { + cfg.writeEntry("startNew","FALSE"); + } + update(); +} diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h index 781061a..fb58738 100644 --- a/core/apps/textedit/textedit.h +++ b/core/apps/textedit/textedit.h @@ -25,53 +25,57 @@ #define QTEXTEDIT_OPEN_API #include "fileBrowser.h" #include "fileSaver.h" #include <qpe/filemanager.h> #include <qmainwindow.h> #include <qmultilineedit.h> #include <qlist.h> #include <qmap.h> +class QAction; class QWidgetStack; class QToolButton; class QPopupMenu; class QToolBar; class QLineEdit; class QAction; class FileSelector; class QpeEditor; +class QPopupMenu; class TextEdit : public QMainWindow { Q_OBJECT public: TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); ~TextEdit(); - + QPopupMenu *font; + QAction *nStart; 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(); + void changeStartConfig(bool); bool save(); bool saveAs(); void editCut(); void editCopy(); void editPaste(); void editFind(); void editDelete(); void findNext(); void findClose(); |