summaryrefslogtreecommitdiff
Unidiff
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
@@ -180,18 +180,12 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) :
180} 180}
181 181
182TinyKate::~TinyKate( ) 182TinyKate::~TinyKate( )
183{ 183{
184 owarn << "TinyKate destructor\n" << oendl; 184 owarn << "TinyKate destructor\n" << oendl;
185 185
186 shutDown=true;
187 while (currentView!=0)
188 {
189 slotClose();
190 }
191
192 if( KGlobal::config() != 0 ) 186 if( KGlobal::config() != 0 )
193 { 187 {
194 owarn << "deleting KateConfig object..\n" << oendl; 188 owarn << "deleting KateConfig object..\n" << oendl;
195 delete KGlobal::config(); 189 delete KGlobal::config();
196 } 190 }
197} 191}
@@ -282,60 +276,152 @@ void TinyKate::slotCurrentChanged( QWidget * view)
282} 276}
283 277
284void TinyKate::slotNew( ) 278void TinyKate::slotNew( )
285{ 279{
286 KateDocument *kd= new KateDocument(false, false, this,0,this); 280 KateDocument *kd= new KateDocument(false, false, this,0,this);
287 KTextEditor::View *kv; 281 KTextEditor::View *kv;
282
283 kd->setDocName(tr("Unnamed %1").arg(nextUnnamed++));
284 kd->setNewDoc(true);
288 tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), 285 tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"),
289 "tinykate/tinykate", 286 "tinykate/tinykate",
290 tr("Unnamed %1").arg(nextUnnamed++)); 287 kd->docName());
291 viewCount++; 288 viewCount++;
292} 289}
293 290
294void TinyKate::slotClose( ) 291bool TinyKate::checkSave() {
292 if (currentView==0) return true;
293
294 KateView *kv = (KateView*) currentView;
295 if(kv->isModified()) {
296 KateDocument *kd = (KateDocument*) kv->document();
297 switch( QMessageBox::information( 0, (tr("TinyKATE")),
298 (tr("Do you want to save\n"
299 "changes to the document\n"
300 "%1?\n").arg(kd->docName())),
301 (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) )
302 {
303 case 0:
304 {
305 return saveDocument();
306 }
307 break;
308
309 case 1:
310 {
311 return true;
312 }
313 break;
314
315 default:
316 {
317 return false;
318 }
319 break;
320 };
321 }
322 else {
323 return true;
324 }
325}
326
327bool TinyKate::closeDocument()
295{ 328{
296 if (currentView==0) return; 329 if (currentView==0) return true;
297 KTextEditor::View *dv=currentView; 330 KTextEditor::View *dv=currentView;
298 currentView=0; 331 if(checkSave()) {
299 tabwidget->removePage(dv); 332 currentView=0;
300 delete dv->document(); 333 tabwidget->removePage(dv);
301 viewCount--; 334 delete dv->document();
302 if ((!viewCount) && (!shutDown)) slotNew(); 335 viewCount--;
336 if ((!viewCount) && (!shutDown)) slotNew();
337 return true;
338 }
339 else
340 return false;
303} 341}
304 342
305void TinyKate::slotSave() 343void TinyKate::slotClose( )
344{
345 closeDocument();
346}
347
348bool TinyKate::saveDocument()
306{ 349{
307 // feel free to make this how you want 350 // feel free to make this how you want
308 if (currentView==0) return; 351 if (currentView==0) return false;
309 352
310 // KateView *kv = (KateView*) currentView; 353 // KateView *kv = (KateView*) currentView;
311 KateDocument *kd = (KateDocument*) currentView->document(); 354 KateDocument *kd = (KateDocument*) currentView->document();
312 // odebug << "saving file "+kd->docName() << oendl; 355 // odebug << "saving file "+kd->docName() << oendl;
313 if( kd->docName().isEmpty()) 356 if( kd->isNewDoc()) {
314 slotSaveAs(); 357 return saveDocumentAs();
358 }
315 else 359 else
316 kd->saveFile(); 360 return kd->saveFile();
361 // FIXME check result of saveFile and show message if failed?
317 // kv->save(); 362 // kv->save();
318 // kd->saveFile(); 363 // kd->saveFile();
319} 364}
320 365
321void TinyKate::slotSaveAs() 366bool TinyKate::saveDocumentAs()
322{ 367{
323 if (currentView==0) return; 368 if (currentView==0) return false;
369
370 bool result = false;
324 KateDocument *kd = (KateDocument*) currentView->document(); 371 KateDocument *kd = (KateDocument*) currentView->document();
325 372
326 QString filename= OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, 373 QString filename= OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL,
327 QString::null); 374 QString::null);
328 if (!filename.isEmpty()) 375 if (!filename.isEmpty())
329 { 376 {
330 odebug << "saving file "+filename << oendl; 377 odebug << "saving file "+filename << oendl;
331 QFileInfo fi(filename); 378 QFileInfo fi(filename);
379 if(fi.exists()) {
380 if ( QMessageBox::warning(this,tr("TinyKATE"),
381 tr("The file %1\n"
382 "already exists.\n\n"
383 "Are you sure you want to\n"
384 "overwrite it?")
385 .arg(fi.fileName()),
386 tr("Yes"),tr("No"),0,0,1) != 0) {
387 return false;
388 }
389 }
332 QString filenamed = fi.fileName(); 390 QString filenamed = fi.fileName();
333 kd->setDocFile( filename); 391 kd->setDocFile( filename);
334 kd->setDocName( filenamed); 392 kd->setDocName( filenamed);
335 kd->saveFile(); 393 kd->setNewDoc(false);
336 // KTextEditor::View *dv = currentView; 394 result = kd->saveFile();
337 // tabwidget->changeTab( dv, filenamed); 395 // FIXME check result of saveFile and show message if failed?
338 // need to change tab label here 396 tabwidget->changeTab( tabwidget->currentWidget(), "tinykate/tinykate", filenamed );
397 }
398 return result;
399}
400
401void TinyKate::slotSave()
402{
403 saveDocument();
404}
405
406void TinyKate::slotSaveAs()
407{
408 saveDocumentAs();
409}
410
411void TinyKate::closeEvent(QCloseEvent *e) {
412 // Close all documents
413 shutDown = true;
414 while (currentView!=0)
415 {
416 if(!closeDocument()) {
417 // User cancelled
418 shutDown=false;
419 break;
420 }
339 } 421 }
340 422
423 if(shutDown)
424 e->accept();
425 else
426 e->ignore();
341} 427}
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
@@ -45,12 +45,17 @@ protected slots:
45 void slotClose(); 45 void slotClose();
46 void slotCurrentChanged(QWidget *); 46 void slotCurrentChanged(QWidget *);
47 void slotSave(); 47 void slotSave();
48 void slotSaveAs(); 48 void slotSaveAs();
49protected: 49protected:
50 void open(const QString&); 50 void open(const QString&);
51 bool closeDocument();
52 bool checkSave();
53 bool saveDocument();
54 bool saveDocumentAs();
55 void closeEvent(QCloseEvent *e);
51private: 56private:
52 QString currentFileName; 57 QString currentFileName;
53 Opie::Ui::OTabWidget *tabwidget; 58 Opie::Ui::OTabWidget *tabwidget;
54 KTextEditor::View *currentView; 59 KTextEditor::View *currentView;
55 bool shutDown; 60 bool shutDown;
56 61