summaryrefslogtreecommitdiff
path: root/noncore
Side-by-side diff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/mainwindow/tinykate.cpp136
-rw-r--r--noncore/apps/tinykate/mainwindow/tinykate.h5
2 files changed, 116 insertions, 25 deletions
diff --git a/noncore/apps/tinykate/mainwindow/tinykate.cpp b/noncore/apps/tinykate/mainwindow/tinykate.cpp
index b1b88e9..e87464e 100644
--- a/noncore/apps/tinykate/mainwindow/tinykate.cpp
+++ b/noncore/apps/tinykate/mainwindow/tinykate.cpp
@@ -138,204 +138,290 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) :
mb->insertItem(tr("Edit"),popup);
//VIEW ACITONS
popup = new QPopupMenu( this );
viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 );
viewIncFontSizes->addTo( popup );
viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 );
viewDecFontSizes->addTo( popup );
mb->insertItem(tr("View"),popup);
popup = new QPopupMenu( this );
mb->insertItem(tr("Utils"),popup);
mb->insertItem( editCut );
mb->insertItem( editCopy );
mb->insertItem( editPaste );
mb->insertItem( editUndo );
mb->insertItem( editRedo );
//Highlight management
hlmenu=new QPopupMenu(this);
HlManager *hlm=HlManager::self();
for (int i=0;i<hlm->highlights();i++)
{
hlmenu->insertItem(hlm->hlName(i),i);
}
popup->insertItem(tr("Highlighting"),hlmenu);
utilSettings = new QAction( tr( "Settings" ),
Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ),
QString::null, 0, this, 0 );
utilSettings->addTo( popup);
if( qApp->argc() > 1) open(qApp->argv()[1]);
else slotNew();
}
TinyKate::~TinyKate( )
{
owarn << "TinyKate destructor\n" << oendl;
- shutDown=true;
- while (currentView!=0)
- {
- slotClose();
- }
-
if( KGlobal::config() != 0 )
{
owarn << "deleting KateConfig object..\n" << oendl;
delete KGlobal::config();
}
}
void TinyKate::slotOpen( )
{
QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
QString::null);
if (!filename.isEmpty())
{
open(filename);
}
}
void TinyKate::open(const QString & filename)
{
KateDocument *kd= new KateDocument(false, false, this,0,this);
KTextEditor::View *kv;
QString realFileName;
//check if filename is a .desktop file
if ( filename.find( ".desktop", 0, true ) != -1 ) {
switch ( QMessageBox::warning( this, tr( "TinyKATE" ),
tr("TinyKATE has detected<BR>you selected a <B>.desktop</B> file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?" ),
tr(".desktop File"),
tr("Linked Document"), 0, 1, 1 ) )
{
case 0: //desktop
realFileName = filename;
break;
case 1: //linked
DocLnk docLnk( filename );
realFileName = docLnk.file();
break;
};
} else {
realFileName = filename;
}
QFileInfo fileInfo( realFileName );
QString filenamed = fileInfo.fileName();
tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed );
odebug << realFileName << oendl;
kd->setDocName( filenamed);
kd->open( realFileName );
viewCount++;
}
void TinyKate::setDocument(const QString& fileref)
{
open( fileref );
}
void TinyKate::slotCurrentChanged( QWidget * view)
{
if (currentView)
{
disconnect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy()));
disconnect(editCut,SIGNAL(clicked()),currentView,SLOT(cut()));
disconnect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste()));
disconnect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo()));
disconnect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo()));
disconnect(editFind,SIGNAL(activated()),currentView,SLOT(find()));
disconnect(editReplace,SIGNAL(activated()),currentView,SLOT(replace()));
disconnect(editGotoLine,SIGNAL(activated()),currentView,SLOT(gotoLine()));
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;
connect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy()));
connect(editCut,SIGNAL(clicked()),currentView,SLOT(cut()));
connect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste()));
connect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo()));
connect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo()));
connect(editFind,SIGNAL(activated()),currentView,SLOT(find()));
connect(editReplace,SIGNAL(activated()),currentView,SLOT(replace()));
connect(editGotoLine,SIGNAL(activated()),currentView,SLOT(gotoLine()));
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;
+
+ kd->setDocName(tr("Unnamed %1").arg(nextUnnamed++));
+ kd->setNewDoc(true);
tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"),
"tinykate/tinykate",
- tr("Unnamed %1").arg(nextUnnamed++));
+ kd->docName());
viewCount++;
}
-void TinyKate::slotClose( )
+bool TinyKate::checkSave() {
+ if (currentView==0) return true;
+
+ KateView *kv = (KateView*) currentView;
+ if(kv->isModified()) {
+ KateDocument *kd = (KateDocument*) kv->document();
+ switch( QMessageBox::information( 0, (tr("TinyKATE")),
+ (tr("Do you want to save\n"
+ "changes to the document\n"
+ "%1?\n").arg(kd->docName())),
+ (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) )
+ {
+ case 0:
+ {
+ return saveDocument();
+ }
+ break;
+
+ case 1:
+ {
+ return true;
+ }
+ break;
+
+ default:
+ {
+ return false;
+ }
+ break;
+ };
+ }
+ else {
+ return true;
+ }
+}
+
+bool TinyKate::closeDocument()
{
- if (currentView==0) return;
+ if (currentView==0) return true;
KTextEditor::View *dv=currentView;
- currentView=0;
- tabwidget->removePage(dv);
- delete dv->document();
- viewCount--;
- if ((!viewCount) && (!shutDown)) slotNew();
+ if(checkSave()) {
+ currentView=0;
+ tabwidget->removePage(dv);
+ delete dv->document();
+ viewCount--;
+ if ((!viewCount) && (!shutDown)) slotNew();
+ return true;
+ }
+ else
+ return false;
}
-void TinyKate::slotSave()
+void TinyKate::slotClose( )
+{
+ closeDocument();
+}
+
+bool TinyKate::saveDocument()
{
// feel free to make this how you want
- if (currentView==0) return;
+ if (currentView==0) return false;
// KateView *kv = (KateView*) currentView;
KateDocument *kd = (KateDocument*) currentView->document();
// odebug << "saving file "+kd->docName() << oendl;
- if( kd->docName().isEmpty())
- slotSaveAs();
+ if( kd->isNewDoc()) {
+ return saveDocumentAs();
+ }
else
- kd->saveFile();
+ return kd->saveFile();
+ // FIXME check result of saveFile and show message if failed?
// kv->save();
// kd->saveFile();
}
-void TinyKate::slotSaveAs()
+bool TinyKate::saveDocumentAs()
{
- if (currentView==0) return;
+ if (currentView==0) return false;
+
+ bool result = false;
KateDocument *kd = (KateDocument*) currentView->document();
QString filename= OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL,
QString::null);
if (!filename.isEmpty())
{
odebug << "saving file "+filename << oendl;
QFileInfo fi(filename);
+ if(fi.exists()) {
+ if ( QMessageBox::warning(this,tr("TinyKATE"),
+ tr("The file %1\n"
+ "already exists.\n\n"
+ "Are you sure you want to\n"
+ "overwrite it?")
+ .arg(fi.fileName()),
+ tr("Yes"),tr("No"),0,0,1) != 0) {
+ return false;
+ }
+ }
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
+ kd->setNewDoc(false);
+ result = kd->saveFile();
+ // FIXME check result of saveFile and show message if failed?
+ tabwidget->changeTab( tabwidget->currentWidget(), "tinykate/tinykate", filenamed );
+ }
+ return result;
+}
+
+void TinyKate::slotSave()
+{
+ saveDocument();
+}
+
+void TinyKate::slotSaveAs()
+{
+ saveDocumentAs();
+}
+
+void TinyKate::closeEvent(QCloseEvent *e) {
+ // Close all documents
+ shutDown = true;
+ while (currentView!=0)
+ {
+ if(!closeDocument()) {
+ // User cancelled
+ shutDown=false;
+ break;
+ }
}
+ if(shutDown)
+ e->accept();
+ else
+ e->ignore();
}
diff --git a/noncore/apps/tinykate/mainwindow/tinykate.h b/noncore/apps/tinykate/mainwindow/tinykate.h
index 6e95d87..7d0c588 100644
--- a/noncore/apps/tinykate/mainwindow/tinykate.h
+++ b/noncore/apps/tinykate/mainwindow/tinykate.h
@@ -3,64 +3,69 @@
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 *
* *
***************************************************************************/
#ifndef __TINYKATE_H__
#define __TINYKATE_H__
#include <qmainwindow.h>
#include <opie2/otabwidget.h>
#include <ktexteditor.h>
class QToolButton;
class QAction;
class QPopupMenu;
class TinyKate : public QMainWindow
{
Q_OBJECT
public:
TinyKate( QWidget *parent=0, const char *name=0, WFlags f = 0);
~TinyKate( );
static QString appName() { return QString::fromLatin1( "tinykate" ); };
public slots:
void slotNew();
void setDocument(const QString& fileref);
protected slots:
void slotOpen();
void slotClose();
void slotCurrentChanged(QWidget *);
void slotSave();
void slotSaveAs();
protected:
void open(const QString&);
+ bool closeDocument();
+ bool checkSave();
+ bool saveDocument();
+ bool saveDocumentAs();
+ void closeEvent(QCloseEvent *e);
private:
QString currentFileName;
Opie::Ui::OTabWidget *tabwidget;
KTextEditor::View *currentView;
bool shutDown;
QToolButton *editCopy, *editCut, *editPaste, *editUndo, *editRedo;
QAction *viewIncFontSizes, *viewDecFontSizes, *utilSettings, *editFind, *editReplace, *editGotoLine;
QPopupMenu *hlmenu;
uint nextUnnamed;
uint viewCount;
};
#endif // __TINYKATE_H__