forked from teamnwah/openmw-tes3coop
Fix to allow application closing from multiple views and a single view.
This commit is contained in:
parent
96b62940b3
commit
50abb22162
7 changed files with 76 additions and 52 deletions
|
@ -2,7 +2,7 @@
|
|||
#include "document.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <QDebug>
|
||||
void CSMDoc::Document::load (const std::vector<boost::filesystem::path>::const_iterator& begin,
|
||||
const std::vector<boost::filesystem::path>::const_iterator& end, bool lastAsModified)
|
||||
{
|
||||
|
@ -237,6 +237,11 @@ CSMDoc::Document::Document (const std::vector<boost::filesystem::path>& files, b
|
|||
connect (&mSaveTimer, SIGNAL(timeout()), this, SLOT (saving()));
|
||||
}
|
||||
|
||||
CSMDoc::Document::~Document()
|
||||
{
|
||||
qDebug() << "document destroyed";
|
||||
}
|
||||
|
||||
QUndoStack& CSMDoc::Document::getUndoStack()
|
||||
{
|
||||
return mUndoStack;
|
||||
|
|
|
@ -63,6 +63,7 @@ namespace CSMDoc
|
|||
public:
|
||||
|
||||
Document (const std::vector<boost::filesystem::path>& files, bool new_);
|
||||
~Document();
|
||||
|
||||
QUndoStack& getUndoStack();
|
||||
|
||||
|
@ -105,4 +106,4 @@ namespace CSMDoc
|
|||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -46,7 +46,8 @@ void CSVDoc::View::setupFileMenu()
|
|||
file->addAction(close);
|
||||
|
||||
QAction *exit = new QAction (tr ("&Exit"), this);
|
||||
connect (exit, SIGNAL (triggered()), QApplication::instance(), SLOT (closeAllWindows()));
|
||||
connect (exit, SIGNAL (triggered()), this, SLOT (exit()));
|
||||
connect (this, SIGNAL(exitApplicationRequest(CSVDoc::View *)), &mViewManager, SLOT(exitApplication(CSVDoc::View *)));
|
||||
|
||||
file->addAction(exit);
|
||||
}
|
||||
|
@ -131,8 +132,6 @@ CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int to
|
|||
: mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1),
|
||||
mViewTotal (totalViews)
|
||||
{
|
||||
// setDockOptions (QMainWindow::AllowNestedDocks);
|
||||
|
||||
resize (300, 300); /// \todo get default size from settings and set reasonable minimal size
|
||||
|
||||
mSubViewWindow.setDockOptions (QMainWindow::AllowNestedDocks);
|
||||
|
@ -255,3 +254,8 @@ CSVDoc::Operations *CSVDoc::View::getOperations() const
|
|||
{
|
||||
return mOperations;
|
||||
}
|
||||
|
||||
void CSVDoc::View::exit()
|
||||
{
|
||||
emit exitApplicationRequest (this);
|
||||
}
|
||||
|
|
|
@ -66,6 +66,8 @@ namespace CSVDoc
|
|||
|
||||
void updateActions();
|
||||
|
||||
void exitApplication();
|
||||
|
||||
public:
|
||||
|
||||
View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews);
|
||||
|
@ -92,7 +94,7 @@ namespace CSVDoc
|
|||
|
||||
void loadDocumentRequest();
|
||||
|
||||
void closeAllViews (View *);
|
||||
void exitApplicationRequest (CSVDoc::View *view);
|
||||
|
||||
public slots:
|
||||
|
||||
|
@ -106,6 +108,8 @@ namespace CSVDoc
|
|||
|
||||
void save();
|
||||
|
||||
void exit();
|
||||
|
||||
void verify();
|
||||
|
||||
void addGlobalsSubView();
|
||||
|
|
|
@ -36,7 +36,7 @@ void CSVDoc::ViewManager::updateIndices()
|
|||
}
|
||||
|
||||
CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
|
||||
: mDocumentManager (documentManager), mCloseMeOnSaveStateChange(0), mUserWarned(false)
|
||||
: mDocumentManager (documentManager), mExitOnSaveStateChange(false), mUserWarned(false)
|
||||
{
|
||||
mDelegateFactories = new CSVWorld::CommandDelegateFactoryCollection;
|
||||
|
||||
|
@ -45,16 +45,12 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
|
|||
|
||||
mDelegateFactories->add (CSMWorld::ColumnBase::Display_GlobalVarType,
|
||||
new CSVWorld::VarTypeDelegateFactory (ESM::VT_Short, ESM::VT_Long, ESM::VT_Float));
|
||||
|
||||
connect (this, SIGNAL (exitApplication()), QApplication::instance(), SLOT (closeAllWindows()));
|
||||
|
||||
}
|
||||
|
||||
CSVDoc::ViewManager::~ViewManager()
|
||||
{
|
||||
delete mDelegateFactories;
|
||||
|
||||
//not needed due to deletion in ViewManager::closeRequest?
|
||||
for (std::vector<View *>::iterator iter (mViews.begin()); iter!=mViews.end(); ++iter)
|
||||
delete *iter;
|
||||
}
|
||||
|
@ -112,32 +108,40 @@ bool CSVDoc::ViewManager::closeRequest (View *view)
|
|||
|
||||
CSMDoc::Document *document = view->getDocument();
|
||||
|
||||
//notify user of saving in progress
|
||||
if ( (document->getState() & CSMDoc::State_Saving) )
|
||||
continueWithClose = showSaveInProgressMessageBox (iter);
|
||||
|
||||
//notify user of unsaved changes and process response
|
||||
else if ( document->getState() & CSMDoc::State_Modified)
|
||||
continueWithClose = showModifiedDocumentMessageBox (iter);
|
||||
|
||||
if (continueWithClose)
|
||||
if (last)
|
||||
continueWithClose = notifySaveOnClose (view);
|
||||
else
|
||||
{
|
||||
(*iter)->deleteLater();
|
||||
mViews.erase (iter);
|
||||
|
||||
if (last)
|
||||
mDocumentManager.removeDocument (document);
|
||||
else
|
||||
updateIndices();
|
||||
updateIndices();
|
||||
}
|
||||
}
|
||||
|
||||
return continueWithClose;
|
||||
}
|
||||
|
||||
bool CSVDoc::ViewManager::showModifiedDocumentMessageBox (std::vector<View *>::iterator viewIter)
|
||||
bool CSVDoc::ViewManager::notifySaveOnClose (CSVDoc::View *view)
|
||||
{
|
||||
bool result = true;
|
||||
CSMDoc::Document *document = view->getDocument();
|
||||
|
||||
//notify user of saving in progress
|
||||
if ( (document->getState() & CSMDoc::State_Saving) )
|
||||
result = showSaveInProgressMessageBox (view);
|
||||
|
||||
//notify user of unsaved changes and process response
|
||||
else if ( document->getState() & CSMDoc::State_Modified)
|
||||
result = showModifiedDocumentMessageBox (view);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CSVDoc::ViewManager::showModifiedDocumentMessageBox (CSVDoc::View *view)
|
||||
{
|
||||
QMessageBox messageBox;
|
||||
CSMDoc::Document *document = view->getDocument();
|
||||
|
||||
messageBox.setText ("The document has been modified.");
|
||||
messageBox.setInformativeText ("Do you want to save your changes?");
|
||||
|
@ -147,31 +151,31 @@ bool CSVDoc::ViewManager::showModifiedDocumentMessageBox (std::vector<View *>::i
|
|||
bool retVal = true;
|
||||
|
||||
connect (this, SIGNAL (closeMessageBox()), &messageBox, SLOT (close()));
|
||||
connect ((*viewIter)->getDocument(), SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
||||
|
||||
connect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
||||
|
||||
mUserWarned = true;
|
||||
|
||||
int response = messageBox.exec();
|
||||
|
||||
mUserWarned = false;
|
||||
|
||||
switch (response)
|
||||
{
|
||||
case QMessageBox::Save:
|
||||
|
||||
(*viewIter)->getDocument()->save();
|
||||
mCloseMeOnSaveStateChange = viewIter;
|
||||
document->save();
|
||||
mExitOnSaveStateChange = true;
|
||||
retVal = false;
|
||||
break;
|
||||
|
||||
case QMessageBox::Discard:
|
||||
|
||||
disconnect ((*viewIter)->getDocument(), SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
||||
disconnect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
||||
break;
|
||||
|
||||
case QMessageBox::Cancel:
|
||||
|
||||
//disconnect to prevent unintended view closures
|
||||
disconnect ((*viewIter)->getDocument(), SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
||||
disconnect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
||||
retVal = false;
|
||||
break;
|
||||
|
||||
|
@ -183,9 +187,10 @@ bool CSVDoc::ViewManager::showModifiedDocumentMessageBox (std::vector<View *>::i
|
|||
return retVal;
|
||||
}
|
||||
|
||||
bool CSVDoc::ViewManager::showSaveInProgressMessageBox (std::vector<View *>::iterator viewIter)
|
||||
bool CSVDoc::ViewManager::showSaveInProgressMessageBox (CSVDoc::View *view)
|
||||
{
|
||||
QMessageBox messageBox;
|
||||
CSMDoc::Document *document = view->getDocument();
|
||||
|
||||
messageBox.setText ("The document is currently being saved.");
|
||||
messageBox.setInformativeText("Do you want to close now and abort saving, or wait until saving has completed?");
|
||||
|
@ -199,38 +204,37 @@ bool CSVDoc::ViewManager::showSaveInProgressMessageBox (std::vector<View *>::ite
|
|||
bool retVal = true;
|
||||
|
||||
//Connections shut down message box if operation ends before user makes a decision.
|
||||
connect ((*viewIter)->getDocument(), SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
||||
connect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
||||
connect (this, SIGNAL (closeMessageBox()), &messageBox, SLOT (close()));
|
||||
|
||||
//set / clear the user warned flag to indicate whether or not the message box is currently active.
|
||||
mUserWarned = true;
|
||||
|
||||
messageBox.exec();
|
||||
|
||||
mUserWarned = false;
|
||||
|
||||
//if closed by the warning handler, defaults to the RejectRole button (closeButton)
|
||||
if (messageBox.clickedButton() == waitButton)
|
||||
{
|
||||
//save the View iterator for shutdown after the save operation ends
|
||||
mCloseMeOnSaveStateChange = viewIter;
|
||||
mExitOnSaveStateChange = true;
|
||||
retVal = false;
|
||||
}
|
||||
|
||||
else if (messageBox.clickedButton() == closeButton)
|
||||
{
|
||||
//disconnect to avoid segmentation fault
|
||||
disconnect ((*viewIter)->getDocument(), SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
||||
(*viewIter)->abortOperation(CSMDoc::State_Saving);
|
||||
mCloseMeOnSaveStateChange = mViews.end();
|
||||
disconnect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
||||
|
||||
view->abortOperation(CSMDoc::State_Saving);
|
||||
mExitOnSaveStateChange = true;
|
||||
}
|
||||
|
||||
else if (messageBox.clickedButton() == cancelButton)
|
||||
{
|
||||
//abort shutdown, allow save to complete
|
||||
//disconnection to prevent unintended view closures
|
||||
mCloseMeOnSaveStateChange = mViews.end();
|
||||
disconnect ((*viewIter)->getDocument(), SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
||||
mExitOnSaveStateChange = false;
|
||||
disconnect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
||||
retVal = false;
|
||||
}
|
||||
|
||||
|
@ -262,10 +266,13 @@ void CSVDoc::ViewManager::onExitWarningHandler (int state, CSMDoc::Document *doc
|
|||
|
||||
//otherwise, the user has closed the message box before the save operation ended.
|
||||
//exit the application
|
||||
else if (mCloseMeOnSaveStateChange!=mViews.end())
|
||||
{
|
||||
emit exitApplication();
|
||||
mCloseMeOnSaveStateChange = mViews.end();
|
||||
}
|
||||
else if (mExitOnSaveStateChange)
|
||||
QApplication::instance()->exit();
|
||||
}
|
||||
}
|
||||
|
||||
void CSVDoc::ViewManager::exitApplication (CSVDoc::View *view)
|
||||
{
|
||||
if (notifySaveOnClose (view))
|
||||
QApplication::instance()->exit();
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace CSVDoc
|
|||
CSMDoc::DocumentManager& mDocumentManager;
|
||||
std::vector<View *> mViews;
|
||||
CSVWorld::CommandDelegateFactoryCollection *mDelegateFactories;
|
||||
std::vector<View *>::iterator mCloseMeOnSaveStateChange;
|
||||
bool mExitOnSaveStateChange;
|
||||
bool mUserWarned;
|
||||
|
||||
// not implemented
|
||||
|
@ -35,8 +35,9 @@ namespace CSVDoc
|
|||
ViewManager& operator= (const ViewManager&);
|
||||
|
||||
void updateIndices();
|
||||
bool showModifiedDocumentMessageBox (std::vector<View*>::iterator view);
|
||||
bool showSaveInProgressMessageBox (std::vector<View*>::iterator view);
|
||||
bool notifySaveOnClose (View *view = 0);
|
||||
bool showModifiedDocumentMessageBox (View *view);
|
||||
bool showSaveInProgressMessageBox (View *view);
|
||||
|
||||
public:
|
||||
|
||||
|
@ -60,7 +61,9 @@ namespace CSVDoc
|
|||
|
||||
void closeMessageBox();
|
||||
|
||||
void exitApplication();
|
||||
public slots:
|
||||
|
||||
void exitApplication (CSVDoc::View *view);
|
||||
|
||||
private slots:
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
|
|
Loading…
Reference in a new issue