From 7eda100c0561a792a417e8ca910a65380f1f780c Mon Sep 17 00:00:00 2001 From: ubbo Date: Wed, 5 Jan 2011 20:28:55 +0000 Subject: check all tabs for unsaved changes, show dialog if this is the case git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@434 34ebc366-c3a9-4b3c-9f84-69acf7962910 --- textedit.cpp | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'textedit.cpp') diff --git a/textedit.cpp b/textedit.cpp index 36a895b..f43970f 100644 --- a/textedit.cpp +++ b/textedit.cpp @@ -284,15 +284,44 @@ void TextEdit::selectAll() /*! Checks if there are unsaved documents, returns true if this is the case. - If it returns true, the close event is aborted. - TODO: rename to "hasUnsavedDocuments", + If it returns false, the close event is aborted. + TODO: rename to "okToQuit" or similar, merge code from commented function above */ bool TextEdit::maybeSave() { - EditorPage *page = curPage(); + // if no tab open, closing prog should be fine + //if(tabWidget->count() == 0) { + // return true; + //} + + QHash unsavedDocs; + + for(int i=0; i < tabWidget->count(); i++) { + EditorPage *ep = qobject_cast (tabWidget->widget(i)); + if(ep->getTextPage()->document()->isModified()) { + unsavedDocs.insert(i, tabWidget->tabText(i)); + } + } + + QHashIterator i(unsavedDocs); + while (i.hasNext()) { + i.next(); + qDebug() << "unsaved: " << i.key() << ": " << i.value() << endl; + } - if(tabWidget->count() == 0) { + if(unsavedDocs.size() > 0) { + QMessageBox::StandardButton result; + result = QMessageBox::warning(this, tr("Application"), + tr("There are unsaved Changes"), + QMessageBox::Discard | QMessageBox::Cancel); + + if (result == QMessageBox::Discard) { + return true; + } else { + return false; + } + } else { return true; } @@ -301,6 +330,8 @@ bool TextEdit::maybeSave() return false; }*/ + /* + EditorPage *page = curPage(); QTextDocument *document = page->getTextPage()->document(); if (document->isModified()) @@ -332,7 +363,7 @@ bool TextEdit::maybeSave() return false; } } - return true; + return true;*/ } -- cgit v1.2.3