Commit 5433c79b authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Ask the users if they want to save the project from the MainWindow

This removes the UI interaction from closeProject, and actually removes
closeProject, since we now delete the current project when closing it.
parent 13503890
......@@ -743,10 +743,28 @@ MainWindow::saveSettings()
void
MainWindow::closeEvent( QCloseEvent* e )
{
if ( saveSettings() )
e->accept();
else
e->ignore();
if ( Core::getInstance()->currentProject()->isClean() == false )
{
QMessageBox msgBox;
msgBox.setText( QObject::tr( "The project has been modified." ) );
msgBox.setInformativeText( QObject::tr( "Do you want to save it?" ) );
msgBox.setStandardButtons( QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel );
msgBox.setDefaultButton( QMessageBox::Save );
int ret = msgBox.exec();
switch ( ret )
{
case QMessageBox::Save:
Core::getInstance()->currentProject()->save();
break;
case QMessageBox::Discard:
break;
case QMessageBox::Cancel:
e->ignore();
return;
}
}
saveSettings();
e->accept();
}
void
......
......@@ -51,26 +51,3 @@ GUIProjectManager::getProjectFileDestination( const QString &defaultPath )
defaultPath, QObject::tr( "VLMC project file(*.vlmc)" ) );
}
IProjectUiCb::SaveMode
GUIProjectManager::shouldSaveBeforeClose()
{
QMessageBox msgBox;
msgBox.setText( QObject::tr( "The project has been modified." ) );
msgBox.setInformativeText( QObject::tr( "Do you want to save it?" ) );
msgBox.setStandardButtons( QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel );
msgBox.setDefaultButton( QMessageBox::Save );
int ret = msgBox.exec();
switch ( ret )
{
case QMessageBox::Save:
return Save;
case QMessageBox::Discard:
return Discard;
case QMessageBox::Cancel:
default:
return Cancel;
}
}
......@@ -31,7 +31,6 @@ public:
virtual bool shouldLoadBackupFile();
virtual bool shouldDeleteOutdatedBackupFile();
virtual QString getProjectFileDestination( const QString &defaultPath );
virtual SaveMode shouldSaveBeforeClose();
};
#endif // GUIPROJECTMANAGER_H
......@@ -62,7 +62,7 @@ Project::Project( QFile* projectFile )
m_workflowRenderer = new WorkflowRenderer( Backend::getBackend(), m_workflow );
initSettings();
connectComponents();
loadProject();
load();
}
Project::Project( const QString& projectName, const QString& projectPath )
......@@ -86,7 +86,8 @@ Project::Project( const QString& projectName, const QString& projectPath )
Project::~Project()
{
closeProject();
Q_ASSERT( m_projectFile != NULL );
delete m_projectFile;
delete m_library;
delete m_workflow;
......@@ -127,7 +128,7 @@ Project::settings()
//////////////////////////////////////////////////////////////////////////////////////////
bool
Project::loadProject()
Project::load()
{
Q_ASSERT( m_projectFile != NULL );
......@@ -178,29 +179,6 @@ Project::connectComponents()
registerLoadSave( m_workflowRenderer );
}
bool
Project::closeProject()
{
Q_ASSERT( m_projectFile != NULL );
//FIXME: This is now called from the destructor, so we can't stop the project closing.
if ( m_projectManagerUi != NULL )
{
IProjectUiCb::SaveMode mode = m_projectManagerUi->shouldSaveBeforeClose();
if ( mode == IProjectUiCb::Cancel )
return false;
if ( mode == IProjectUiCb::Save )
save();
}
delete m_projectFile;
m_projectFile = NULL;
m_isClean = true;
m_projectName = QString();
Core::getInstance()->currentProject()->undoStack()->clear();
emit projectUpdated( name() );
return true;
}
void
Project::save()
{
......@@ -339,6 +317,12 @@ Project::registerLoadSave( ILoadSave* loadSave )
return true;
}
bool
Project::isClean() const
{
return m_isClean;
}
QFile* Project::emergencyBackupFile()
{
const QString lastProject = Core::getInstance()->settings()->value( "private/EmergencyBackup" )->get().toString();
......
......@@ -61,6 +61,7 @@ class Project : public QObject
void saveAs();
void emergencyBackup();
bool registerLoadSave( ILoadSave* loadSave );
bool isClean() const;
public:
static QFile* emergencyBackupFile();
......@@ -74,7 +75,7 @@ class Project : public QObject
* if an outdated project backup is found, the used is asked if she wants to delete
* it.
*/
bool loadProject();
bool load();
/**
* @brief connectComponents Connects project specific components' signals & slots
*/
......@@ -87,7 +88,6 @@ class Project : public QObject
QString checkBackupFile( const QString& projectFile );
void initSettings();
QString name();
bool closeProject();
void saveProject( const QString& filename );
void newProject( const QString& projectName, const QString& projectPath );
......
......@@ -37,13 +37,6 @@ public:
virtual ~IProjectUiCb() {}
/**
* @brief shouldSaveBeforeClose Ask the user if she wants to save the project in case
* it's about to be closed
* @return True if the project should be saved. False if changes are to be discarded.
*/
virtual SaveMode shouldSaveBeforeClose() = 0;
/**
* @brief getProjectFile Ask the user where to save a new project
* @param defaultPath A default project location, if any.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment