mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 20:53:50 +00:00
80% complete save-on-close feature
This commit is contained in:
parent
6f89d453a5
commit
f85be6a744
5 changed files with 129 additions and 16 deletions
|
@ -54,7 +54,7 @@ void CSVDoc::Operations::quitOperation (int type)
|
|||
|
||||
mLayout->removeItem ((*iter)->getLayout());
|
||||
|
||||
delete *iter;
|
||||
(*iter)->deleteLater();
|
||||
mOperations.erase (iter);
|
||||
|
||||
if (oldCount > 1)
|
||||
|
|
|
@ -18,10 +18,14 @@
|
|||
#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()
|
||||
|
@ -117,9 +121,11 @@ void CSVDoc::View::updateActions()
|
|||
mVerify->setEnabled (!(mDocument->getState() & CSMDoc::State_Verifying));
|
||||
}
|
||||
|
||||
CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews, QMainWindow *viewParent)
|
||||
: mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1), mViewTotal (totalViews), QMainWindow (viewParent)
|
||||
CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews) //, QMainWindow *viewParent)
|
||||
: mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1),
|
||||
mViewTotal (totalViews) //, QMainWindow (viewParent)
|
||||
{
|
||||
setAttribute (Qt::WA_DeleteOnClose, true);
|
||||
setDockOptions (QMainWindow::AllowNestedDocks);
|
||||
|
||||
resize (300, 300); /// \todo get default size from settings and set reasonable minimal size
|
||||
|
|
|
@ -67,7 +67,7 @@ namespace CSVDoc
|
|||
|
||||
public:
|
||||
|
||||
View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews, QMainWindow *viewParent);
|
||||
View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews); //, QMainWindow *viewParent);
|
||||
///< The ownership of \a document is not transferred to *this.
|
||||
|
||||
virtual ~View();
|
||||
|
@ -94,6 +94,8 @@ namespace CSVDoc
|
|||
|
||||
void addSubView (const CSMWorld::UniversalId& id);
|
||||
|
||||
void abortOperation (int type);
|
||||
|
||||
private slots:
|
||||
|
||||
void newView();
|
||||
|
@ -106,7 +108,6 @@ namespace CSVDoc
|
|||
|
||||
void addGmstsSubView();
|
||||
|
||||
void abortOperation (int type);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
|
||||
#include "view.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMessageBox>
|
||||
|
||||
|
||||
void CSVDoc::ViewManager::updateIndices()
|
||||
{
|
||||
std::map<CSMDoc::Document *, std::pair<int, int> > documents;
|
||||
|
@ -31,7 +35,7 @@ void CSVDoc::ViewManager::updateIndices()
|
|||
}
|
||||
|
||||
CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
|
||||
: mDocumentManager (documentManager)
|
||||
: mDocumentManager (documentManager), mCloseMeOnSaveStateChange(0)
|
||||
{
|
||||
mDelegateFactories = new CSVWorld::CommandDelegateFactoryCollection;
|
||||
|
||||
|
@ -59,9 +63,9 @@ CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document)
|
|||
this, SLOT (progress (int, int, int, int, CSMDoc::Document *)));
|
||||
}
|
||||
|
||||
QMainWindow *mainWindow = new QMainWindow;
|
||||
// QMainWindow *mainWindow = new QMainWindow;
|
||||
|
||||
View *view = new View (*this, document, countViews (document)+1, mainWindow);
|
||||
View *view = new View (*this, document, countViews (document)+1); //, mainWindow);
|
||||
|
||||
mViews.push_back (view);
|
||||
|
||||
|
@ -90,6 +94,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;
|
||||
|
@ -97,16 +103,98 @@ 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());
|
||||
else
|
||||
updateIndices();
|
||||
//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;
|
||||
|
||||
if (continueWithClose)
|
||||
{
|
||||
mViews.erase (iter);
|
||||
|
||||
if (last)
|
||||
mDocumentManager.removeDocument (document);
|
||||
else
|
||||
updateIndices();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return continueWithClose;
|
||||
}
|
||||
|
||||
bool CSVDoc::ViewManager::showModifiedDocumentMessageBox (View* view)
|
||||
{
|
||||
QMessageBox messageBox;
|
||||
|
||||
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;
|
||||
|
||||
switch (messageBox.exec())
|
||||
{
|
||||
case QMessageBox::Save:
|
||||
view->getDocument()->save();
|
||||
mCloseMeOnSaveStateChange = view;
|
||||
retVal = false;
|
||||
break;
|
||||
|
||||
case QMessageBox::Discard:
|
||||
break;
|
||||
|
||||
case QMessageBox::Cancel:
|
||||
retVal = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool CSVDoc::ViewManager::showSaveInProgressMessageBox (View* view)
|
||||
{
|
||||
QMessageBox messageBox;
|
||||
|
||||
messageBox.setText ("The document is currently being saved.");
|
||||
messageBox.setInformativeText("Do you want to abort the save?");
|
||||
messageBox.setStandardButtons (QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
|
||||
|
||||
bool retVal = false;
|
||||
|
||||
switch (messageBox.exec())
|
||||
{
|
||||
case QMessageBox::Yes:
|
||||
view->abortOperation(CSMDoc::State_Saving);
|
||||
// mCloseMeOnSaveStateChange = view;
|
||||
retVal = false;
|
||||
break;
|
||||
|
||||
case QMessageBox::No:
|
||||
//mCloseMeOnSaveStateChange = view;
|
||||
retVal = false;
|
||||
break;
|
||||
|
||||
case QMessageBox::Cancel:
|
||||
retVal = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void CSVDoc::ViewManager::documentStateChanged (int state, CSMDoc::Document *document)
|
||||
|
@ -114,6 +202,19 @@ void CSVDoc::ViewManager::documentStateChanged (int state, CSMDoc::Document *doc
|
|||
for (std::vector<View *>::const_iterator iter (mViews.begin()); iter!=mViews.end(); ++iter)
|
||||
if ((*iter)->getDocument()==document)
|
||||
(*iter)->updateDocumentState();
|
||||
|
||||
if (mPreviousDocumentState & CSMDoc::State_Saving)
|
||||
qDebug() << "Last state was saving";
|
||||
else
|
||||
qDebug() << "Last state was something else";
|
||||
/*
|
||||
if (mCloseMeOnSaveStateChange && (mPreviousDocumentState & CSMDoc::State_Saving))
|
||||
{
|
||||
mCloseMeOnSaveStateChange->close();
|
||||
mCloseMeOnSaveStateChange = 0;
|
||||
}
|
||||
*/
|
||||
mPreviousDocumentState = state;
|
||||
}
|
||||
|
||||
void CSVDoc::ViewManager::progress (int current, int max, int type, int threads, CSMDoc::Document *document)
|
||||
|
|
|
@ -27,12 +27,17 @@ namespace CSVDoc
|
|||
CSMDoc::DocumentManager& mDocumentManager;
|
||||
std::vector<View *> mViews;
|
||||
CSVWorld::CommandDelegateFactoryCollection *mDelegateFactories;
|
||||
View *mCloseMeOnSaveStateChange;
|
||||
int mPreviousDocumentState;
|
||||
|
||||
// not implemented
|
||||
ViewManager (const ViewManager&);
|
||||
ViewManager& operator= (const ViewManager&);
|
||||
|
||||
void updateIndices();
|
||||
bool showModifiedDocumentMessageBox (View* view);
|
||||
bool showSaveInProgressMessageBox (View* view);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
@ -63,4 +68,4 @@ namespace CSVDoc
|
|||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue