|
|
|
@ -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 *)));
|
|
|
|
|
mUserWarned = true;
|
|
|
|
|
|
|
|
|
|
int response = messageBox.exec();
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|