summaryrefslogtreecommitdiff
authorpaule <paule>2007-01-13 07:34:07 (UTC)
committer paule <paule>2007-01-13 07:34:07 (UTC)
commitb1075202780c1d807c9d9f5286a2ffa7714bae51 (patch) (side-by-side diff)
tree6d37dc6d7f7b45d39f7f379c8654fd085d63e895
parentee43ea083b2abea078507677ee30c7af88d248c4 (diff)
downloadopie-b1075202780c1d807c9d9f5286a2ffa7714bae51.zip
opie-b1075202780c1d807c9d9f5286a2ffa7714bae51.tar.gz
opie-b1075202780c1d807c9d9f5286a2ffa7714bae51.tar.bz2
Prompt user to save on closing a modified file; prompt user on Save As if specified file already exists; change tab to show filename when saving a new file
Diffstat (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
@@ -183,12 +183,6 @@ TinyKate::~TinyKate( )
{
owarn << "TinyKate destructor\n" << oendl;
- shutDown=true;
- while (currentView!=0)
- {
- slotClose();
- }
-
if( KGlobal::config() != 0 )
{
owarn << "deleting KateConfig object..\n" << oendl;
@@ -285,42 +279,95 @@ 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,
@@ -329,13 +376,52 @@ void TinyKate::slotSaveAs()
{
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
@@ -48,6 +48,11 @@ protected slots:
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;