2012-11-22 13:30:02 +01:00
|
|
|
#include "viewmanager.hpp"
|
|
|
|
|
2015-06-03 12:01:13 +03:00
|
|
|
#include <vector>
|
2012-11-22 15:09:04 +01:00
|
|
|
#include <map>
|
|
|
|
|
2013-05-07 20:33:42 -05:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QDesktopWidget>
|
2015-06-12 15:10:12 +02:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QPushButton>
|
2013-05-07 20:33:42 -05:00
|
|
|
|
2012-11-22 14:10:23 +01:00
|
|
|
#include "../../model/doc/documentmanager.hpp"
|
2012-11-22 23:42:17 +01:00
|
|
|
#include "../../model/doc/document.hpp"
|
2013-09-02 11:58:05 +02:00
|
|
|
#include "../../model/world/columns.hpp"
|
2014-09-23 17:01:08 +10:00
|
|
|
#include "../../model/world/universalid.hpp"
|
2015-06-03 12:01:13 +03:00
|
|
|
#include "../../model/world/idcompletionmanager.hpp"
|
2012-11-22 14:10:23 +01:00
|
|
|
|
2015-12-15 10:40:00 +01:00
|
|
|
#include "../../model/prefs/state.hpp"
|
|
|
|
|
2013-02-10 17:21:25 +01:00
|
|
|
#include "../world/util.hpp"
|
2013-02-17 17:27:25 +01:00
|
|
|
#include "../world/enumdelegate.hpp"
|
|
|
|
#include "../world/vartypedelegate.hpp"
|
2013-05-29 06:38:35 -05:00
|
|
|
#include "../world/recordstatusdelegate.hpp"
|
2013-09-22 13:39:44 +02:00
|
|
|
#include "../world/idtypedelegate.hpp"
|
2015-05-30 18:37:13 +03:00
|
|
|
#include "../world/idcompletiondelegate.hpp"
|
2015-06-12 23:09:31 +03:00
|
|
|
#include "../world/colordelegate.hpp"
|
2014-04-22 22:19:53 -05:00
|
|
|
|
2012-11-22 13:30:02 +01:00
|
|
|
#include "view.hpp"
|
|
|
|
|
2012-11-22 15:09:04 +01:00
|
|
|
void CSVDoc::ViewManager::updateIndices()
|
|
|
|
{
|
|
|
|
std::map<CSMDoc::Document *, std::pair<int, int> > documents;
|
|
|
|
|
|
|
|
for (std::vector<View *>::const_iterator iter (mViews.begin()); iter!=mViews.end(); ++iter)
|
|
|
|
{
|
|
|
|
std::map<CSMDoc::Document *, std::pair<int, int> >::iterator document = documents.find ((*iter)->getDocument());
|
|
|
|
|
|
|
|
if (document==documents.end())
|
|
|
|
document =
|
|
|
|
documents.insert (
|
|
|
|
std::make_pair ((*iter)->getDocument(), std::make_pair (0, countViews ((*iter)->getDocument())))).
|
|
|
|
first;
|
|
|
|
|
|
|
|
(*iter)->setIndex (document->second.first++, document->second.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-22 14:10:23 +01:00
|
|
|
CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
|
2013-03-12 06:28:13 -05:00
|
|
|
: mDocumentManager (documentManager), mExitOnSaveStateChange(false), mUserWarned(false)
|
2012-11-22 13:30:02 +01:00
|
|
|
{
|
2013-02-10 17:21:25 +01:00
|
|
|
mDelegateFactories = new CSVWorld::CommandDelegateFactoryCollection;
|
2013-02-17 17:27:25 +01:00
|
|
|
|
2013-03-05 11:37:13 +01:00
|
|
|
mDelegateFactories->add (CSMWorld::ColumnBase::Display_GmstVarType,
|
2013-02-17 17:27:25 +01:00
|
|
|
new CSVWorld::VarTypeDelegateFactory (ESM::VT_None, ESM::VT_String, ESM::VT_Int, ESM::VT_Float));
|
2013-03-05 11:37:13 +01:00
|
|
|
|
|
|
|
mDelegateFactories->add (CSMWorld::ColumnBase::Display_GlobalVarType,
|
|
|
|
new CSVWorld::VarTypeDelegateFactory (ESM::VT_Short, ESM::VT_Long, ESM::VT_Float));
|
2013-03-23 13:13:53 +01:00
|
|
|
|
2013-09-02 11:58:05 +02:00
|
|
|
mDelegateFactories->add (CSMWorld::ColumnBase::Display_RecordState,
|
|
|
|
new CSVWorld::RecordStatusDelegateFactory());
|
2013-05-16 16:27:33 +02:00
|
|
|
|
2013-09-02 11:58:05 +02:00
|
|
|
mDelegateFactories->add (CSMWorld::ColumnBase::Display_RefRecordType,
|
2013-09-22 13:39:44 +02:00
|
|
|
new CSVWorld::IdTypeDelegateFactory());
|
2013-05-19 14:44:41 +02:00
|
|
|
|
2015-06-08 21:33:23 +03:00
|
|
|
mDelegateFactories->add (CSMWorld::ColumnBase::Display_Colour,
|
2015-06-12 23:09:31 +03:00
|
|
|
new CSVWorld::ColorDelegateFactory());
|
2015-06-08 21:33:23 +03:00
|
|
|
|
2015-06-03 12:01:13 +03:00
|
|
|
std::vector<CSMWorld::ColumnBase::Display> idCompletionColumns = CSMWorld::IdCompletionManager::getDisplayTypes();
|
|
|
|
for (std::vector<CSMWorld::ColumnBase::Display>::const_iterator current = idCompletionColumns.begin();
|
|
|
|
current != idCompletionColumns.end();
|
|
|
|
++current)
|
2015-05-30 18:37:13 +03:00
|
|
|
{
|
2015-06-03 12:01:13 +03:00
|
|
|
mDelegateFactories->add(*current, new CSVWorld::IdCompletionDelegateFactory());
|
2015-05-30 18:37:13 +03:00
|
|
|
}
|
|
|
|
|
2013-09-02 11:58:05 +02:00
|
|
|
struct Mapping
|
|
|
|
{
|
|
|
|
CSMWorld::ColumnBase::Display mDisplay;
|
|
|
|
CSMWorld::Columns::ColumnId mColumnId;
|
|
|
|
bool mAllowNone;
|
|
|
|
};
|
2013-05-29 06:38:35 -05:00
|
|
|
|
2013-09-02 11:58:05 +02:00
|
|
|
static const Mapping sMapping[] =
|
|
|
|
{
|
|
|
|
{ CSMWorld::ColumnBase::Display_Specialisation, CSMWorld::Columns::ColumnId_Specialisation, false },
|
|
|
|
{ CSMWorld::ColumnBase::Display_Attribute, CSMWorld::Columns::ColumnId_Attribute, true },
|
|
|
|
{ CSMWorld::ColumnBase::Display_SpellType, CSMWorld::Columns::ColumnId_SpellType, false },
|
|
|
|
{ CSMWorld::ColumnBase::Display_ApparatusType, CSMWorld::Columns::ColumnId_ApparatusType, false },
|
|
|
|
{ CSMWorld::ColumnBase::Display_ArmorType, CSMWorld::Columns::ColumnId_ArmorType, false },
|
|
|
|
{ CSMWorld::ColumnBase::Display_ClothingType, CSMWorld::Columns::ColumnId_ClothingType, false },
|
|
|
|
{ CSMWorld::ColumnBase::Display_CreatureType, CSMWorld::Columns::ColumnId_CreatureType, false },
|
2013-10-20 17:26:09 +02:00
|
|
|
{ CSMWorld::ColumnBase::Display_WeaponType, CSMWorld::Columns::ColumnId_WeaponType, false },
|
2013-10-31 12:54:55 +01:00
|
|
|
{ CSMWorld::ColumnBase::Display_DialogueType, CSMWorld::Columns::ColumnId_DialogueType, false },
|
2013-11-05 11:41:48 +01:00
|
|
|
{ CSMWorld::ColumnBase::Display_QuestStatusType, CSMWorld::Columns::ColumnId_QuestStatusType, false },
|
2014-07-01 09:42:56 +02:00
|
|
|
{ CSMWorld::ColumnBase::Display_EnchantmentType, CSMWorld::Columns::ColumnId_EnchantmentType, false },
|
2014-07-01 14:28:12 +02:00
|
|
|
{ CSMWorld::ColumnBase::Display_BodyPartType, CSMWorld::Columns::ColumnId_BodyPartType, false },
|
|
|
|
{ CSMWorld::ColumnBase::Display_MeshType, CSMWorld::Columns::ColumnId_MeshType, false },
|
2014-09-25 11:40:45 +02:00
|
|
|
{ CSMWorld::ColumnBase::Display_Gender, CSMWorld::Columns::ColumnId_Gender, true },
|
2014-09-30 12:33:48 +02:00
|
|
|
{ CSMWorld::ColumnBase::Display_SoundGeneratorType, CSMWorld::Columns::ColumnId_SoundGeneratorType, false },
|
2015-08-04 16:19:00 +03:00
|
|
|
{ CSMWorld::ColumnBase::Display_School, CSMWorld::Columns::ColumnId_School, false },
|
2015-10-08 12:35:09 +11:00
|
|
|
{ CSMWorld::ColumnBase::Display_SkillId, CSMWorld::Columns::ColumnId_Skill, true },
|
2015-04-18 08:09:14 +10:00
|
|
|
{ CSMWorld::ColumnBase::Display_EffectRange, CSMWorld::Columns::ColumnId_EffectRange, false },
|
2015-04-18 08:31:08 +10:00
|
|
|
{ CSMWorld::ColumnBase::Display_EffectId, CSMWorld::Columns::ColumnId_EffectId, false },
|
2015-04-18 09:37:19 +10:00
|
|
|
{ CSMWorld::ColumnBase::Display_PartRefType, CSMWorld::Columns::ColumnId_PartRefType, false },
|
|
|
|
{ CSMWorld::ColumnBase::Display_AiPackageType, CSMWorld::Columns::ColumnId_AiPackageType, false },
|
2015-05-09 21:21:16 +10:00
|
|
|
{ CSMWorld::ColumnBase::Display_InfoCondFunc, CSMWorld::Columns::ColumnId_InfoCondFunc, false },
|
2015-05-19 06:56:38 +10:00
|
|
|
{ CSMWorld::ColumnBase::Display_InfoCondComp, CSMWorld::Columns::ColumnId_InfoCondComp, false },
|
2015-10-28 11:49:24 +11:00
|
|
|
{ CSMWorld::ColumnBase::Display_IngredEffectId, CSMWorld::Columns::ColumnId_EffectId, true },
|
|
|
|
{ CSMWorld::ColumnBase::Display_EffectSkill, CSMWorld::Columns::ColumnId_Skill, false },
|
|
|
|
{ CSMWorld::ColumnBase::Display_EffectAttribute, CSMWorld::Columns::ColumnId_Attribute, false },
|
2013-09-02 11:58:05 +02:00
|
|
|
};
|
2013-06-15 06:40:18 -05:00
|
|
|
|
2013-09-02 11:58:05 +02:00
|
|
|
for (std::size_t i=0; i<sizeof (sMapping)/sizeof (Mapping); ++i)
|
|
|
|
mDelegateFactories->add (sMapping[i].mDisplay, new CSVWorld::EnumDelegateFactory (
|
|
|
|
CSMWorld::Columns::getEnums (sMapping[i].mColumnId), sMapping[i].mAllowNone));
|
2013-06-29 08:11:09 -05:00
|
|
|
|
2014-04-29 14:27:44 +02:00
|
|
|
connect (&mDocumentManager, SIGNAL (loadRequest (CSMDoc::Document *)),
|
|
|
|
&mLoader, SLOT (add (CSMDoc::Document *)));
|
2014-04-29 14:17:25 +02:00
|
|
|
|
|
|
|
connect (
|
|
|
|
&mDocumentManager, SIGNAL (loadingStopped (CSMDoc::Document *, bool, const std::string&)),
|
|
|
|
&mLoader, SLOT (loadingStopped (CSMDoc::Document *, bool, const std::string&)));
|
2014-05-03 13:01:29 +02:00
|
|
|
|
|
|
|
connect (
|
2014-05-03 15:33:35 +02:00
|
|
|
&mDocumentManager, SIGNAL (nextStage (CSMDoc::Document *, const std::string&, int)),
|
|
|
|
&mLoader, SLOT (nextStage (CSMDoc::Document *, const std::string&, int)));
|
|
|
|
|
|
|
|
connect (
|
2014-06-26 11:41:21 +02:00
|
|
|
&mDocumentManager, SIGNAL (nextRecord (CSMDoc::Document *, int)),
|
|
|
|
&mLoader, SLOT (nextRecord (CSMDoc::Document *, int)));
|
2014-05-03 16:44:50 +02:00
|
|
|
|
2014-05-10 13:18:40 +02:00
|
|
|
connect (
|
|
|
|
&mDocumentManager, SIGNAL (loadMessage (CSMDoc::Document *, const std::string&)),
|
|
|
|
&mLoader, SLOT (loadMessage (CSMDoc::Document *, const std::string&)));
|
|
|
|
|
2014-05-03 16:44:50 +02:00
|
|
|
connect (
|
|
|
|
&mLoader, SIGNAL (cancel (CSMDoc::Document *)),
|
|
|
|
&mDocumentManager, SIGNAL (cancelLoading (CSMDoc::Document *)));
|
2014-05-06 09:39:39 +02:00
|
|
|
|
|
|
|
connect (
|
|
|
|
&mLoader, SIGNAL (close (CSMDoc::Document *)),
|
|
|
|
&mDocumentManager, SLOT (removeDocument (CSMDoc::Document *)));
|
2012-11-22 13:30:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CSVDoc::ViewManager::~ViewManager()
|
|
|
|
{
|
2013-02-10 17:21:25 +01:00
|
|
|
delete mDelegateFactories;
|
|
|
|
|
2012-11-22 13:30:02 +01:00
|
|
|
for (std::vector<View *>::iterator iter (mViews.begin()); iter!=mViews.end(); ++iter)
|
|
|
|
delete *iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document)
|
|
|
|
{
|
2012-11-22 23:42:17 +01:00
|
|
|
if (countViews (document)==0)
|
|
|
|
{
|
|
|
|
// new document
|
|
|
|
connect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)),
|
|
|
|
this, SLOT (documentStateChanged (int, CSMDoc::Document *)));
|
2012-11-23 10:25:34 +01:00
|
|
|
|
2012-11-23 12:20:35 +01:00
|
|
|
connect (document, SIGNAL (progress (int, int, int, int, CSMDoc::Document *)),
|
|
|
|
this, SLOT (progress (int, int, int, int, CSMDoc::Document *)));
|
2012-11-22 23:42:17 +01:00
|
|
|
}
|
|
|
|
|
2013-03-02 21:34:55 -06:00
|
|
|
View *view = new View (*this, document, countViews (document)+1);
|
2012-11-22 13:30:02 +01:00
|
|
|
|
|
|
|
mViews.push_back (view);
|
|
|
|
|
2015-12-15 10:40:00 +01:00
|
|
|
view->toggleStatusBar (CSMPrefs::get()["Windows"]["show-statusbar"].isTrue());
|
2012-11-22 13:30:02 +01:00
|
|
|
view->show();
|
|
|
|
|
2013-09-08 12:06:28 +02:00
|
|
|
connect (view, SIGNAL (newGameRequest ()), this, SIGNAL (newGameRequest()));
|
|
|
|
connect (view, SIGNAL (newAddonRequest ()), this, SIGNAL (newAddonRequest()));
|
2013-02-02 16:14:58 +01:00
|
|
|
connect (view, SIGNAL (loadDocumentRequest ()), this, SIGNAL (loadDocumentRequest()));
|
2013-09-08 09:33:45 +02:00
|
|
|
connect (view, SIGNAL (editSettingsRequest()), this, SIGNAL (editSettingsRequest()));
|
2015-08-06 12:52:10 +02:00
|
|
|
connect (view, SIGNAL (mergeDocument (CSMDoc::Document *)), this, SIGNAL (mergeDocument (CSMDoc::Document *)));
|
2012-11-23 14:05:49 +01:00
|
|
|
|
2012-11-22 15:09:04 +01:00
|
|
|
updateIndices();
|
|
|
|
|
2012-11-22 13:30:02 +01:00
|
|
|
return view;
|
2012-11-22 14:10:23 +01:00
|
|
|
}
|
|
|
|
|
2014-09-23 17:01:08 +10:00
|
|
|
CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document, const CSMWorld::UniversalId& id, const std::string& hint)
|
|
|
|
{
|
|
|
|
View* view = addView(document);
|
|
|
|
view->addSubView(id, hint);
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2012-11-22 14:10:23 +01:00
|
|
|
int CSVDoc::ViewManager::countViews (const CSMDoc::Document *document) const
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for (std::vector<View *>::const_iterator iter (mViews.begin()); iter!=mViews.end(); ++iter)
|
|
|
|
if ((*iter)->getDocument()==document)
|
|
|
|
++count;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CSVDoc::ViewManager::closeRequest (View *view)
|
|
|
|
{
|
|
|
|
std::vector<View *>::iterator iter = std::find (mViews.begin(), mViews.end(), view);
|
|
|
|
|
2014-09-09 21:09:37 +10:00
|
|
|
bool continueWithClose = false;
|
2013-03-02 07:57:41 -06:00
|
|
|
|
2014-09-07 18:37:33 +10:00
|
|
|
if (iter!=mViews.end())
|
2012-11-22 14:10:23 +01:00
|
|
|
{
|
|
|
|
bool last = countViews (view->getDocument())<=1;
|
|
|
|
|
2014-09-07 18:37:33 +10:00
|
|
|
if (last)
|
2013-03-12 06:28:13 -05:00
|
|
|
continueWithClose = notifySaveOnClose (view);
|
|
|
|
else
|
2013-03-02 07:57:41 -06:00
|
|
|
{
|
2014-09-07 18:37:33 +10:00
|
|
|
(*iter)->deleteLater();
|
2013-03-06 06:41:33 -06:00
|
|
|
mViews.erase (iter);
|
|
|
|
|
2013-03-12 06:28:13 -05:00
|
|
|
updateIndices();
|
2013-03-02 07:57:41 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return continueWithClose;
|
|
|
|
}
|
|
|
|
|
2014-09-09 21:09:37 +10:00
|
|
|
// NOTE: This method assumes that it is called only if the last document
|
|
|
|
void CSVDoc::ViewManager::removeDocAndView (CSMDoc::Document *document)
|
2014-09-09 13:04:48 +10:00
|
|
|
{
|
2014-09-09 21:24:54 +10:00
|
|
|
for (std::vector<View *>::iterator iter (mViews.begin()); iter!=mViews.end(); ++iter)
|
2014-09-09 21:09:37 +10:00
|
|
|
{
|
|
|
|
// the first match should also be the only match
|
|
|
|
if((*iter)->getDocument() == document)
|
|
|
|
{
|
|
|
|
mDocumentManager.removeDocument(document);
|
|
|
|
(*iter)->deleteLater();
|
|
|
|
mViews.erase (iter);
|
|
|
|
|
|
|
|
updateIndices();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-09-09 13:04:48 +10:00
|
|
|
}
|
|
|
|
|
2013-03-12 06:28:13 -05:00
|
|
|
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)
|
2013-03-02 07:57:41 -06:00
|
|
|
{
|
2014-09-10 14:03:25 +10:00
|
|
|
emit closeMessageBox();
|
|
|
|
|
|
|
|
QMessageBox messageBox(view);
|
2013-03-12 06:28:13 -05:00
|
|
|
CSMDoc::Document *document = view->getDocument();
|
2013-03-02 07:57:41 -06:00
|
|
|
|
2015-03-16 15:45:41 +01:00
|
|
|
messageBox.setWindowTitle (QString::fromUtf8(document->getSavePath().filename().string().c_str()));
|
2013-03-02 07:57:41 -06:00
|
|
|
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);
|
2014-09-10 14:03:25 +10:00
|
|
|
messageBox.setWindowModality (Qt::NonModal);
|
|
|
|
messageBox.hide();
|
|
|
|
messageBox.show();
|
2013-03-02 07:57:41 -06:00
|
|
|
|
|
|
|
bool retVal = true;
|
|
|
|
|
2013-03-06 06:41:33 -06:00
|
|
|
connect (this, SIGNAL (closeMessageBox()), &messageBox, SLOT (close()));
|
|
|
|
|
2013-03-12 06:28:13 -05:00
|
|
|
connect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
2013-03-06 06:41:33 -06:00
|
|
|
|
2013-03-12 06:28:13 -05:00
|
|
|
mUserWarned = true;
|
|
|
|
int response = messageBox.exec();
|
2013-03-06 06:41:33 -06:00
|
|
|
mUserWarned = false;
|
|
|
|
|
|
|
|
switch (response)
|
2013-03-02 07:57:41 -06:00
|
|
|
{
|
|
|
|
case QMessageBox::Save:
|
2013-03-02 12:49:26 -06:00
|
|
|
|
2013-03-12 06:28:13 -05:00
|
|
|
document->save();
|
|
|
|
mExitOnSaveStateChange = true;
|
2013-03-06 06:41:33 -06:00
|
|
|
retVal = false;
|
2013-03-02 07:57:41 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QMessageBox::Discard:
|
2013-03-06 06:41:33 -06:00
|
|
|
|
2013-03-12 06:28:13 -05:00
|
|
|
disconnect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
2013-03-02 07:57:41 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QMessageBox::Cancel:
|
2013-03-06 06:41:33 -06:00
|
|
|
|
|
|
|
//disconnect to prevent unintended view closures
|
2013-03-12 06:28:13 -05:00
|
|
|
disconnect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
2013-03-02 07:57:41 -06:00
|
|
|
retVal = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
2012-11-22 14:10:23 +01:00
|
|
|
|
2013-03-12 06:28:13 -05:00
|
|
|
bool CSVDoc::ViewManager::showSaveInProgressMessageBox (CSVDoc::View *view)
|
2013-03-02 07:57:41 -06:00
|
|
|
{
|
|
|
|
QMessageBox messageBox;
|
2013-03-12 06:28:13 -05:00
|
|
|
CSMDoc::Document *document = view->getDocument();
|
2013-03-02 07:57:41 -06:00
|
|
|
|
|
|
|
messageBox.setText ("The document is currently being saved.");
|
2013-03-06 06:41:33 -06:00
|
|
|
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);
|
2013-03-02 07:57:41 -06:00
|
|
|
|
2013-03-02 09:22:44 -06:00
|
|
|
bool retVal = true;
|
2013-03-02 07:57:41 -06:00
|
|
|
|
2013-03-06 06:41:33 -06:00
|
|
|
//Connections shut down message box if operation ends before user makes a decision.
|
2013-03-12 06:28:13 -05:00
|
|
|
connect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
2013-03-06 06:41:33 -06:00
|
|
|
connect (this, SIGNAL (closeMessageBox()), &messageBox, SLOT (close()));
|
2013-03-02 07:57:41 -06:00
|
|
|
|
2013-03-06 06:41:33 -06:00
|
|
|
//set / clear the user warned flag to indicate whether or not the message box is currently active.
|
|
|
|
mUserWarned = true;
|
|
|
|
messageBox.exec();
|
|
|
|
mUserWarned = false;
|
2013-03-02 12:49:26 -06:00
|
|
|
|
2013-03-06 06:41:33 -06:00
|
|
|
//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
|
2013-03-12 06:28:13 -05:00
|
|
|
mExitOnSaveStateChange = true;
|
2013-03-06 06:41:33 -06:00
|
|
|
retVal = false;
|
|
|
|
}
|
2013-03-02 07:57:41 -06:00
|
|
|
|
2013-03-06 06:41:33 -06:00
|
|
|
else if (messageBox.clickedButton() == closeButton)
|
|
|
|
{
|
|
|
|
//disconnect to avoid segmentation fault
|
2013-03-12 06:28:13 -05:00
|
|
|
disconnect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
|
|
|
|
|
|
|
view->abortOperation(CSMDoc::State_Saving);
|
|
|
|
mExitOnSaveStateChange = true;
|
2013-03-06 06:41:33 -06:00
|
|
|
}
|
2013-03-02 07:57:41 -06:00
|
|
|
|
2013-03-06 06:41:33 -06:00
|
|
|
else if (messageBox.clickedButton() == cancelButton)
|
|
|
|
{
|
|
|
|
//abort shutdown, allow save to complete
|
|
|
|
//disconnection to prevent unintended view closures
|
2013-03-12 06:28:13 -05:00
|
|
|
mExitOnSaveStateChange = false;
|
|
|
|
disconnect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (onExitWarningHandler(int, CSMDoc::Document *)));
|
2013-03-06 06:41:33 -06:00
|
|
|
retVal = false;
|
2012-11-22 14:10:23 +01:00
|
|
|
}
|
|
|
|
|
2013-03-02 07:57:41 -06:00
|
|
|
return retVal;
|
2012-11-22 23:42:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSVDoc::ViewManager::documentStateChanged (int state, CSMDoc::Document *document)
|
|
|
|
{
|
|
|
|
for (std::vector<View *>::const_iterator iter (mViews.begin()); iter!=mViews.end(); ++iter)
|
|
|
|
if ((*iter)->getDocument()==document)
|
|
|
|
(*iter)->updateDocumentState();
|
2012-11-23 00:36:01 +01:00
|
|
|
}
|
2012-11-23 10:25:34 +01:00
|
|
|
|
2012-11-23 12:20:35 +01:00
|
|
|
void CSVDoc::ViewManager::progress (int current, int max, int type, int threads, CSMDoc::Document *document)
|
2012-11-23 10:25:34 +01:00
|
|
|
{
|
|
|
|
for (std::vector<View *>::const_iterator iter (mViews.begin()); iter!=mViews.end(); ++iter)
|
|
|
|
if ((*iter)->getDocument()==document)
|
2012-11-23 12:20:35 +01:00
|
|
|
(*iter)->updateProgress (current, max, type, threads);
|
2013-02-22 21:53:32 -06:00
|
|
|
}
|
2013-03-06 06:41:33 -06:00
|
|
|
|
2013-03-11 06:38:27 -05:00
|
|
|
void CSVDoc::ViewManager::onExitWarningHandler (int state, CSMDoc::Document *document)
|
2013-03-06 06:41:33 -06:00
|
|
|
{
|
|
|
|
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.
|
2013-03-11 06:38:27 -05:00
|
|
|
//exit the application
|
2013-03-12 06:28:13 -05:00
|
|
|
else if (mExitOnSaveStateChange)
|
|
|
|
QApplication::instance()->exit();
|
2013-03-06 06:41:33 -06:00
|
|
|
}
|
|
|
|
}
|
2013-03-12 06:28:13 -05:00
|
|
|
|
2014-09-10 14:40:41 +10:00
|
|
|
bool CSVDoc::ViewManager::removeDocument (CSVDoc::View *view)
|
2013-03-12 06:28:13 -05:00
|
|
|
{
|
2014-09-09 10:05:06 +10:00
|
|
|
if(!notifySaveOnClose(view))
|
2014-09-10 14:40:41 +10:00
|
|
|
return false;
|
2014-09-07 18:35:50 +10:00
|
|
|
else
|
|
|
|
{
|
2014-09-09 21:09:37 +10:00
|
|
|
// don't bother closing views or updating indicies, but remove from mViews
|
2014-09-09 10:05:06 +10:00
|
|
|
CSMDoc::Document * document = view->getDocument();
|
2014-09-09 21:09:37 +10:00
|
|
|
std::vector<View *> remainingViews;
|
2014-09-10 14:40:41 +10:00
|
|
|
std::vector<View *>::const_iterator iter = mViews.begin();
|
|
|
|
for (; iter!=mViews.end(); ++iter)
|
2014-09-09 21:09:37 +10:00
|
|
|
{
|
|
|
|
if(document == (*iter)->getDocument())
|
|
|
|
(*iter)->setVisible(false);
|
|
|
|
else
|
|
|
|
remainingViews.push_back(*iter);
|
|
|
|
}
|
|
|
|
mDocumentManager.removeDocument(document);
|
|
|
|
mViews = remainingViews;
|
2014-09-10 14:40:41 +10:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-07 18:35:50 +10:00
|
|
|
|
2014-09-10 14:40:41 +10:00
|
|
|
void CSVDoc::ViewManager::exitApplication (CSVDoc::View *view)
|
|
|
|
{
|
|
|
|
if(!removeDocument(view)) // close the current document first
|
|
|
|
return;
|
|
|
|
|
|
|
|
while(!mViews.empty()) // attempt to close all other documents
|
|
|
|
{
|
|
|
|
mViews.back()->activateWindow();
|
|
|
|
mViews.back()->raise(); // raise the window to alert the user
|
|
|
|
if(!removeDocument(mViews.back()))
|
|
|
|
return;
|
2014-09-07 18:35:50 +10:00
|
|
|
}
|
2014-09-09 10:05:06 +10:00
|
|
|
// Editor exits (via a signal) when the last document is deleted
|
2013-03-12 06:28:13 -05:00
|
|
|
}
|