-rw-r--r-- | noncore/apps/tinykate/tinykate.cpp | 41 | ||||
-rw-r--r-- | noncore/apps/tinykate/tinykate.h | 6 |
2 files changed, 44 insertions, 3 deletions
diff --git a/noncore/apps/tinykate/tinykate.cpp b/noncore/apps/tinykate/tinykate.cpp index a823530..c8c3b31 100644 --- a/noncore/apps/tinykate/tinykate.cpp +++ b/noncore/apps/tinykate/tinykate.cpp @@ -25,24 +25,25 @@ #include <opie/ofiledialog.h> #include "tinykate.h" #include "pics/file-new.xpm" #include "pics/file-open.xpm" #include "pics/file-save.xpm" #include "pics/edit-undo.xpm" #include "pics/edit-redo.xpm" #include <katedocument.h> #include <katehighlight.h> +#include <kateview.h> TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : QMainWindow( parent, name, f ) { nextUnnamed=0; currentView=0; viewCount=0; setCaption(tr("TinyKATE")); setToolBarsMovable(FALSE); QPEToolBar *bar = new QPEToolBar( this ); @@ -62,28 +63,30 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : a->addTo( popup ); connect(a, SIGNAL(activated()), this, SLOT(slotNew())); // Action for opening an exisiting document a = new QAction( tr( "Open" ), QPixmap((const char**)file_open_xpm), QString::null, 0, this, 0 ); a->addTo(popup); connect(a, SIGNAL(activated()), this, SLOT(slotOpen())); // Action for saving document a = new QAction( tr( "Save" ), QPixmap((const char**)file_save_xpm), QString::null, 0, this, 0 ); a->addTo(popup); + connect(a, SIGNAL(activated()), this, SLOT(slotSave())); // Action for saving document to a new name a = new QAction( tr( "Save As" ), QPixmap((const char**)file_save_xpm), QString::null, 0, this, 0 ); a->addTo(popup); + connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs())); // Action for closing the currently active document a = new QAction( tr( "Close" ), QPixmap(), QString::null, 0, this, 0 ); a->addTo(popup); connect(a, SIGNAL(activated()), this, SLOT(slotClose())); mb->insertItem(tr("File"),popup); //EDIT ACTIONS // Action for cutting text @@ -159,24 +162,25 @@ void TinyKate::open(const QString & filename) KateDocument *kd= new KateDocument(false, false, this,0,this); KTextEditor::View *kv; QFileInfo fi(filename); tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate",fi.fileName()); qDebug(filename); kd->open(filename); viewCount++; } void TinyKate::slotCurrentChanged( QWidget * view) { if (currentView) { + disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); } currentView=(KTextEditor::View*)view; @@ -188,27 +192,62 @@ void TinyKate::slotCurrentChanged( QWidget * view) connect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); } void TinyKate::slotNew( ) { KateDocument *kd= new KateDocument(false, false, this,0,this); KTextEditor::View *kv; - tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"),"tinykate/tinykate",tr("Unnamed %1").arg(nextUnnamed++)); + tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), + "tinykate/tinykate", + tr("Unnamed %1").arg(nextUnnamed++)); viewCount++; } void TinyKate::slotClose( ) { if (currentView==0) return; KTextEditor::View *dv=currentView; currentView=0; tabwidget->removePage(dv); delete dv->document(); viewCount--; if (!viewCount) slotNew(); } +void TinyKate::slotSave() { + // feel free to make this how you want + if (currentView==0) return; + + // KateView *kv = (KateView*) currentView; + KateDocument *kd = (KateDocument*) currentView->document(); + // qDebug("saving file "+kd->docName()); + if( kd->docName().isEmpty()) + slotSaveAs(); + else + kd->saveFile(); + // kv->save(); + // kd->saveFile(); +} + +void TinyKate::slotSaveAs() { + if (currentView==0) return; + KateDocument *kd = (KateDocument*) currentView->document(); + + QString filename=OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL); + if (!filename.isEmpty()) { + qDebug("saving file "+filename); + QFileInfo fi(filename); + QString filenamed = fi.fileName(); + kd->setDocFile( filename); + kd->setDocName( filenamed); + kd->saveFile(); +// KTextEditor::View *dv = currentView; +// tabwidget->changeTab( dv, filenamed); + // need to change tab label here + } + +} diff --git a/noncore/apps/tinykate/tinykate.h b/noncore/apps/tinykate/tinykate.h index ef0dcba..7b61bae 100644 --- a/noncore/apps/tinykate/tinykate.h +++ b/noncore/apps/tinykate/tinykate.h @@ -1,15 +1,15 @@ /*************************************************************************** tinykate.h - Tiny KATE mainwindow + Tiny KATE mainwindow ------------------- begin : November 2002 copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation. * * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * * * @@ -24,31 +24,33 @@ #include <ktexteditor.h> class QAction; class QPopupMenu; class TinyKate : public QMainWindow { Q_OBJECT public: TinyKate( QWidget *parent=0, const char *name=0, WFlags f = 0); public slots: + QString currentFileName; void slotNew(); protected slots: void slotOpen(); void slotClose(); void slotCurrentChanged(QWidget *); - + void slotSave(); + void slotSaveAs(); protected: void open(const QString&); private: OTabWidget *tabwidget; KTextEditor::View *currentView; QAction *editCopy; QAction *editCut; QAction *editPaste; QAction *editUndo; QAction *editRedo; QAction *editFindReplace; |