-rw-r--r-- | core/apps/textedit/textedit.cpp | 40 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 5 |
2 files changed, 37 insertions, 8 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 03f3a1e..78c4d8a 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp @@ -144,52 +144,52 @@ static char * filesave_xpm[] = { " 90ab=c;dd;e1fg ", " [ahij((kbl0mn$ ", " op^q^^7r&]s/$+ ", "@btu;vbwxy]zAB ", "CzDEvEv;;DssF$ ", "G.H{E{E{IxsJ$+ ", " +...vEKxzLM ", " +...z]n$ ", " +... "}; #if QT_VERSION < 300 class QpeEditor : public QMultiLineEdit { // Q_OBJECT public: QpeEditor( QWidget *parent, const char * name = 0 ) : QMultiLineEdit( parent, name ) { clearTableFlags(); setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); } - //public slots: void find( const QString &txt, bool caseSensitive, bool backwards ); - /* +//public slots: + /* signals: void notFound(); void searchWrapped(); */ private: }; void QpeEditor::find ( const QString &txt, bool caseSensitive, bool backwards ) { static bool wrap = FALSE; int line, col; if ( wrap ) { if ( !backwards ) line = col = 0; wrap = FALSE; // emit searchWrapped(); } else { getCursorPosition( &line, &col ); } //ignore backwards for now.... @@ -219,49 +219,50 @@ void QpeEditor::find ( const QString &txt, bool caseSensitive, #else #error "Must make a QpeEditor that inherits QTextEdit" #endif static int u_id = 1; static int get_unique_id() { return u_id++; } static const int nfontsizes = 6; 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 ) { doc = 0; - + edited=FALSE; + edited1=FALSE; 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 ); 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 ); @@ -379,48 +380,49 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); a->addTo( searchBar ); edit->insertSeparator(); a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); a->addTo( edit ); searchBar->hide(); editorStack = new QWidgetStack( this ); setCentralWidget( editorStack ); searchVisible = FALSE; fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); // fileOpen(); editor = new QpeEditor( editorStack ); editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); editorStack->addWidget( editor, get_unique_id() ); + connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); 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(); cfg.setGroup("View"); if(cfg.readEntry("startNew","TRUE") == "TRUE") { nStart->setOn(TRUE); fileNew(); @@ -535,49 +537,52 @@ void TextEdit::fileOpen() updateCaption(); } void TextEdit::newFileOpen() { browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "*"); if( browseForFiles->exec() != -1 ) { 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; - editor->setEdited( true ); + editor->setEdited( FALSE); + edited1=FALSE; + edited=FALSE; + setCaption(caption().right(caption().length()-1)); } #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() { @@ -663,96 +668,104 @@ void TextEdit::openFile( const QString &f ) name = name.mid( sep+1 ); updateCaption( name ); } void TextEdit::openFile( const DocLnk &f ) { // clear(); bFromDocView = TRUE; FileManager fm; QString txt; currentFileName=f.name(); qDebug("openFile doclnk " + currentFileName); 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); + editor->setEdited( FALSE); + edited1=FALSE; + edited=FALSE; + setCaption(caption().right(caption().length()-1)); + qDebug("openFile doclnk "+currentFileName); doc->setName(currentFileName); updateCaption(); } void TextEdit::showEditTools() { // if ( !doc ) // close(); // clear(); fileSelector->hide(); menu->show(); editBar->show(); 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 ); + editor->setEdited( FALSE); + edited1=FALSE; + edited=FALSE; + setCaption(caption().right(caption().length()-1)); + 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; // } if ( !editor->edited() ) { delete doc; doc = 0; return true; @@ -792,54 +805,59 @@ bool TextEdit::saveAs() qDebug("saving filename "+fileNm); QFileInfo fi(fileNm); currentFileName=fi.fileName(); if(doc) { // 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); 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 ); + if( filePerm) delete filePerm; } } } + editor->setEdited( FALSE); + edited1=FALSE; + edited=FALSE; + if(caption().left(1)=="*") + setCaption(caption().right(caption().length()-1)); if(fileSaveDlg) delete fileSaveDlg; 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; @@ -917,24 +935,32 @@ void TextEdit::editDelete() 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(); } + +void TextEdit::editorChanged() { + if(editor->edited() && edited && !edited1) { + setCaption( "*"+caption()); + edited1=TRUE; + } + edited=TRUE; +} diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h index fb58738..e7e20e3 100644 --- a/core/apps/textedit/textedit.h +++ b/core/apps/textedit/textedit.h @@ -33,50 +33,53 @@ #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; + bool edited, edited1; void openFile( const QString & ); - +public slots: + void editorChanged(); + 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(); |