|
|
|
@ -12,6 +12,11 @@
|
|
|
|
|
|
|
|
|
|
#include "view.hpp"
|
|
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QtGui/QApplication>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
void CSVDoc::ViewManager::updateIndices()
|
|
|
|
|
{
|
|
|
|
|
std::map<CSMDoc::Document *, std::pair<int, int> > documents;
|
|
|
|
@ -31,7 +36,7 @@ void CSVDoc::ViewManager::updateIndices()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
|
|
|
|
|
: mDocumentManager (documentManager)
|
|
|
|
|
: mDocumentManager (documentManager), mExitOnSaveStateChange(false), mUserWarned(false)
|
|
|
|
|
{
|
|
|
|
|
mDelegateFactories = new CSVWorld::CommandDelegateFactoryCollection;
|
|
|
|
|
|
|
|
|
@ -40,7 +45,6 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
|
|
|
|
|
|
|
|
|
|
mDelegateFactories->add (CSMWorld::ColumnBase::Display_GlobalVarType,
|
|
|
|
|
new CSVWorld::VarTypeDelegateFactory (ESM::VT_Short, ESM::VT_Long, ESM::VT_Float));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSVDoc::ViewManager::~ViewManager()
|
|
|
|
@ -63,9 +67,8 @@ CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document)
|
|
|
|
|
this, SLOT (progress (int, int, int, int, CSMDoc::Document *)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMainWindow *mainWindow = new QMainWindow;
|
|
|
|
|
View *view = new View (*this, document, countViews (document)+1);
|
|
|
|
|
|
|
|
|
|
View *view = new View (*this, document, countViews (document)+1, mainWindow);
|
|
|
|
|
|
|
|
|
|
mViews.push_back (view);
|
|
|
|
|
|
|
|
|
@ -94,6 +97,8 @@ bool CSVDoc::ViewManager::closeRequest (View *view)
|
|
|
|
|
{
|
|
|
|
|
std::vector<View *>::iterator iter = std::find (mViews.begin(), mViews.end(), view);
|
|
|
|
|
|
|
|
|
|
bool continueWithClose = true;
|
|
|
|
|
|
|
|
|
|
if (iter!=mViews.end())
|
|
|
|
|
{
|
|
|
|
|
bool last = countViews (view->getDocument())<=1;
|
|
|
|
@ -101,16 +106,139 @@ bool CSVDoc::ViewManager::closeRequest (View *view)
|
|
|
|
|
/// \todo check if save is in progress -> warn user about possible data loss
|
|
|
|
|
/// \todo check if document has not been saved -> return false and start close dialogue
|
|
|
|
|
|
|
|
|
|
mViews.erase (iter);
|
|
|
|
|
view->deleteLater();
|
|
|
|
|
CSMDoc::Document *document = view->getDocument();
|
|
|
|
|
|
|
|
|
|
if (last)
|
|
|
|
|
mDocumentManager.removeDocument (view->getDocument());
|
|
|
|
|
continueWithClose = notifySaveOnClose (view);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
(*iter)->deleteLater();
|
|
|
|
|
mViews.erase (iter);
|
|
|
|
|
|
|
|
|
|
updateIndices();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return continueWithClose;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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?");
|
|
|
|
|
messageBox.setStandardButtons (QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
|
|
|
|
|
messageBox.setDefaultButton (QMessageBox::Save);
|
|
|
|
|
|
|
|
|
|
bool retVal = true;
|
|
|
|
|
|
|
|
|
|
connect (this, SIGNAL (closeMessageBox()), &messageBox, SLOT (close()));
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
|
|
document->save();
|
|
|
|
|
mExitOnSaveStateChange = true;
|
|
|
|
|
retVal = false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case QMessageBox::Discard:
|
|
|
|
|
|
|
|
|
|
disconnect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case QMessageBox::Cancel:
|
|
|
|
|
|
|
|
|
|
//disconnect to prevent unintended view closures
|
|
|
|
|
disconnect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
|
|
|
|
retVal = false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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?");
|
|
|
|
|
|
|
|
|
|
QPushButton* waitButton = messageBox.addButton (tr("Wait"), QMessageBox::YesRole);
|
|
|
|
|
QPushButton* closeButton = messageBox.addButton (tr("Close Now"), QMessageBox::RejectRole);
|
|
|
|
|
QPushButton* cancelButton = messageBox.addButton (tr("Cancel"), QMessageBox::NoRole);
|
|
|
|
|
|
|
|
|
|
messageBox.setDefaultButton (waitButton);
|
|
|
|
|
|
|
|
|
|
bool retVal = true;
|
|
|
|
|
|
|
|
|
|
//Connections shut down message box if operation ends before user makes a decision.
|
|
|
|
|
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
|
|
|
|
|
mExitOnSaveStateChange = true;
|
|
|
|
|
retVal = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (messageBox.clickedButton() == closeButton)
|
|
|
|
|
{
|
|
|
|
|
//disconnect to avoid segmentation fault
|
|
|
|
|
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
|
|
|
|
|
mExitOnSaveStateChange = false;
|
|
|
|
|
disconnect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
|
|
|
|
retVal = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVDoc::ViewManager::documentStateChanged (int state, CSMDoc::Document *document)
|
|
|
|
@ -126,3 +254,25 @@ void CSVDoc::ViewManager::progress (int current, int max, int type, int threads,
|
|
|
|
|
if ((*iter)->getDocument()==document)
|
|
|
|
|
(*iter)->updateProgress (current, max, type, threads);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVDoc::ViewManager::onExitWarningHandler (int state, CSMDoc::Document *document)
|
|
|
|
|
{
|
|
|
|
|
if ( !(state & CSMDoc::State_Saving) )
|
|
|
|
|
{
|
|
|
|
|
//if the user is being warned (message box is active), shut down the message box,
|
|
|
|
|
//as there is no save operation currently running
|
|
|
|
|
if ( mUserWarned )
|
|
|
|
|
emit closeMessageBox();
|
|
|
|
|
|
|
|
|
|
//otherwise, the user has closed the message box before the save operation ended.
|
|
|
|
|
//exit the application
|
|
|
|
|
else if (mExitOnSaveStateChange)
|
|
|
|
|
QApplication::instance()->exit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVDoc::ViewManager::exitApplication (CSVDoc::View *view)
|
|
|
|
|
{
|
|
|
|
|
if (notifySaveOnClose (view))
|
|
|
|
|
QApplication::instance()->exit();
|
|
|
|
|
}
|
|
|
|
|