1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-01 21:45:38 +00:00

Final changes to implement save-on-close features

This commit is contained in:
graffy76 2013-03-02 12:49:26 -06:00
parent 9193ddc9d3
commit bf6c855e6d
2 changed files with 27 additions and 23 deletions

View file

@ -18,14 +18,10 @@
#include "operations.hpp"
#include "subview.hpp"
#include <QDebug>
void CSVDoc::View::closeEvent (QCloseEvent *event)
{
if (!mViewManager.closeRequest (this))
{
qDebug() << "ignoring event";
event->ignore();
}
}
void CSVDoc::View::setupFileMenu()
@ -43,6 +39,11 @@ void CSVDoc::View::setupFileMenu()
mSave = new QAction (tr ("&Save"), this);
connect (mSave, SIGNAL (triggered()), this, SLOT (save()));
file->addAction (mSave);
QAction *exit = new QAction (tr ("&Exit"), this);
connect (exit, SIGNAL (triggered()), this, SLOT (close()));
file->addAction(exit);
}
void CSVDoc::View::setupEditMenu()

View file

@ -12,7 +12,6 @@
#include "view.hpp"
#include <QDebug>
#include <QMessageBox>
@ -105,15 +104,13 @@ bool CSVDoc::ViewManager::closeRequest (View *view)
CSMDoc::Document *document = view->getDocument();
//notify user of unsaved changes and process response
if ( document->getState() & CSMDoc::State_Modified)
continueWithClose = showModifiedDocumentMessageBox (view);
//notify user of saving in progress
if ( document->getState() & CSMDoc::State_Saving )
continueWithClose = showSaveInProgressMessageBox (view);
qDebug() << "Continue with close? " << continueWithClose;
else
//notify user of unsaved changes and process response
if ( document->getState() & CSMDoc::State_Modified)
continueWithClose = showModifiedDocumentMessageBox (view);
if (continueWithClose)
{
@ -144,8 +141,13 @@ bool CSVDoc::ViewManager::showModifiedDocumentMessageBox (View* view)
{
case QMessageBox::Save:
view->getDocument()->save();
mCloseMeOnSaveStateChange = view;
retVal = false;
retVal = !(view->getDocument()->getState() & CSMDoc::State_Saving);
if (!retVal)
mCloseMeOnSaveStateChange = view;
else
mCloseMeOnSaveStateChange = 0;
break;
case QMessageBox::Discard:
@ -181,8 +183,16 @@ bool CSVDoc::ViewManager::showSaveInProgressMessageBox (View* view)
break;
case QMessageBox::No: //shutdown after save completes
//return true (continue with close) if the save operation ended before the
//user clicked "No"
retVal = !(view->getDocument()->getState() & CSMDoc::State_Saving);
if (!retVal)
mCloseMeOnSaveStateChange = view;
retVal = false;
else
mCloseMeOnSaveStateChange = 0;
break;
case QMessageBox::Cancel: //abort shutdown, allow save to complete
@ -203,17 +213,10 @@ void CSVDoc::ViewManager::documentStateChanged (int state, CSMDoc::Document *doc
if ((*iter)->getDocument()==document)
(*iter)->updateDocumentState();
if (mPreviousDocumentState & CSMDoc::State_Saving)
qDebug() << "Last state was saving";
else
qDebug() << "Last state was something else";
//mechanism to shutdown main window after saving operation completes
if (mCloseMeOnSaveStateChange && (mPreviousDocumentState & CSMDoc::State_Saving))
{
mCloseMeOnSaveStateChange->close();
mCloseMeOnSaveStateChange = 0;
}
if (mCloseMeOnSaveStateChange->close())
mCloseMeOnSaveStateChange = 0;
mPreviousDocumentState = state;
}