forked from teamnwah/openmw-tes3coop
Final changes to implement save-on-close features
This commit is contained in:
parent
9193ddc9d3
commit
bf6c855e6d
2 changed files with 27 additions and 23 deletions
|
@ -18,14 +18,10 @@
|
||||||
#include "operations.hpp"
|
#include "operations.hpp"
|
||||||
#include "subview.hpp"
|
#include "subview.hpp"
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
void CSVDoc::View::closeEvent (QCloseEvent *event)
|
void CSVDoc::View::closeEvent (QCloseEvent *event)
|
||||||
{
|
{
|
||||||
if (!mViewManager.closeRequest (this))
|
if (!mViewManager.closeRequest (this))
|
||||||
{
|
|
||||||
qDebug() << "ignoring event";
|
|
||||||
event->ignore();
|
event->ignore();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVDoc::View::setupFileMenu()
|
void CSVDoc::View::setupFileMenu()
|
||||||
|
@ -43,6 +39,11 @@ void CSVDoc::View::setupFileMenu()
|
||||||
mSave = new QAction (tr ("&Save"), this);
|
mSave = new QAction (tr ("&Save"), this);
|
||||||
connect (mSave, SIGNAL (triggered()), this, SLOT (save()));
|
connect (mSave, SIGNAL (triggered()), this, SLOT (save()));
|
||||||
file->addAction (mSave);
|
file->addAction (mSave);
|
||||||
|
|
||||||
|
QAction *exit = new QAction (tr ("&Exit"), this);
|
||||||
|
connect (exit, SIGNAL (triggered()), this, SLOT (close()));
|
||||||
|
file->addAction(exit);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVDoc::View::setupEditMenu()
|
void CSVDoc::View::setupEditMenu()
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
|
|
||||||
#include "view.hpp"
|
#include "view.hpp"
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,15 +104,13 @@ bool CSVDoc::ViewManager::closeRequest (View *view)
|
||||||
|
|
||||||
CSMDoc::Document *document = view->getDocument();
|
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
|
//notify user of saving in progress
|
||||||
if ( document->getState() & CSMDoc::State_Saving )
|
if ( document->getState() & CSMDoc::State_Saving )
|
||||||
continueWithClose = showSaveInProgressMessageBox (view);
|
continueWithClose = showSaveInProgressMessageBox (view);
|
||||||
|
else
|
||||||
qDebug() << "Continue with close? " << continueWithClose;
|
//notify user of unsaved changes and process response
|
||||||
|
if ( document->getState() & CSMDoc::State_Modified)
|
||||||
|
continueWithClose = showModifiedDocumentMessageBox (view);
|
||||||
|
|
||||||
if (continueWithClose)
|
if (continueWithClose)
|
||||||
{
|
{
|
||||||
|
@ -144,8 +141,13 @@ bool CSVDoc::ViewManager::showModifiedDocumentMessageBox (View* view)
|
||||||
{
|
{
|
||||||
case QMessageBox::Save:
|
case QMessageBox::Save:
|
||||||
view->getDocument()->save();
|
view->getDocument()->save();
|
||||||
mCloseMeOnSaveStateChange = view;
|
|
||||||
retVal = false;
|
retVal = !(view->getDocument()->getState() & CSMDoc::State_Saving);
|
||||||
|
|
||||||
|
if (!retVal)
|
||||||
|
mCloseMeOnSaveStateChange = view;
|
||||||
|
else
|
||||||
|
mCloseMeOnSaveStateChange = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QMessageBox::Discard:
|
case QMessageBox::Discard:
|
||||||
|
@ -181,8 +183,16 @@ bool CSVDoc::ViewManager::showSaveInProgressMessageBox (View* view)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QMessageBox::No: //shutdown after save completes
|
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;
|
mCloseMeOnSaveStateChange = view;
|
||||||
retVal = false;
|
else
|
||||||
|
mCloseMeOnSaveStateChange = 0;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QMessageBox::Cancel: //abort shutdown, allow save to complete
|
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)
|
if ((*iter)->getDocument()==document)
|
||||||
(*iter)->updateDocumentState();
|
(*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
|
//mechanism to shutdown main window after saving operation completes
|
||||||
if (mCloseMeOnSaveStateChange && (mPreviousDocumentState & CSMDoc::State_Saving))
|
if (mCloseMeOnSaveStateChange && (mPreviousDocumentState & CSMDoc::State_Saving))
|
||||||
{
|
if (mCloseMeOnSaveStateChange->close())
|
||||||
mCloseMeOnSaveStateChange->close();
|
mCloseMeOnSaveStateChange = 0;
|
||||||
mCloseMeOnSaveStateChange = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
mPreviousDocumentState = state;
|
mPreviousDocumentState = state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue