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() ...@@ -743,10 +743,28 @@ MainWindow::saveSettings()
void void
MainWindow::closeEvent( QCloseEvent* e ) MainWindow::closeEvent( QCloseEvent* e )
{ {
if ( saveSettings() ) if ( Core::getInstance()->currentProject()->isClean() == false )
e->accept(); {
else QMessageBox msgBox;
e->ignore(); 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 void
......
...@@ -51,26 +51,3 @@ GUIProjectManager::getProjectFileDestination( const QString &defaultPath ) ...@@ -51,26 +51,3 @@ GUIProjectManager::getProjectFileDestination( const QString &defaultPath )
defaultPath, QObject::tr( "VLMC project file(*.vlmc)" ) ); 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: ...@@ -31,7 +31,6 @@ public:
virtual bool shouldLoadBackupFile(); virtual bool shouldLoadBackupFile();
virtual bool shouldDeleteOutdatedBackupFile(); virtual bool shouldDeleteOutdatedBackupFile();
virtual QString getProjectFileDestination( const QString &defaultPath ); virtual QString getProjectFileDestination( const QString &defaultPath );
virtual SaveMode shouldSaveBeforeClose();
}; };
#endif // GUIPROJECTMANAGER_H #endif // GUIPROJECTMANAGER_H
...@@ -62,7 +62,7 @@ Project::Project( QFile* projectFile ) ...@@ -62,7 +62,7 @@ Project::Project( QFile* projectFile )
m_workflowRenderer = new WorkflowRenderer( Backend::getBackend(), m_workflow ); m_workflowRenderer = new WorkflowRenderer( Backend::getBackend(), m_workflow );
initSettings(); initSettings();
connectComponents(); connectComponents();
loadProject(); load();
} }
Project::Project( const QString& projectName, const QString& projectPath ) Project::Project( const QString& projectName, const QString& projectPath )
...@@ -86,7 +86,8 @@ Project::Project( const QString& projectName, const QString& projectPath ) ...@@ -86,7 +86,8 @@ Project::Project( const QString& projectName, const QString& projectPath )
Project::~Project() Project::~Project()
{ {
closeProject(); Q_ASSERT( m_projectFile != NULL );
delete m_projectFile; delete m_projectFile;
delete m_library; delete m_library;
delete m_workflow; delete m_workflow;
...@@ -127,7 +128,7 @@ Project::settings() ...@@ -127,7 +128,7 @@ Project::settings()
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
bool bool
Project::loadProject() Project::load()
{ {
Q_ASSERT( m_projectFile != NULL ); Q_ASSERT( m_projectFile != NULL );
...@@ -178,29 +179,6 @@ Project::connectComponents() ...@@ -178,29 +179,6 @@ Project::connectComponents()
registerLoadSave( m_workflowRenderer ); 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 void
Project::save() Project::save()
{ {
...@@ -339,6 +317,12 @@ Project::registerLoadSave( ILoadSave* loadSave ) ...@@ -339,6 +317,12 @@ Project::registerLoadSave( ILoadSave* loadSave )
return true; return true;
} }
bool
Project::isClean() const
{
return m_isClean;
}
QFile* Project::emergencyBackupFile() QFile* Project::emergencyBackupFile()
{ {
const QString lastProject = Core::getInstance()->settings()->value( "private/EmergencyBackup" )->get().toString(); const QString lastProject = Core::getInstance()->settings()->value( "private/EmergencyBackup" )->get().toString();
......
...@@ -61,6 +61,7 @@ class Project : public QObject ...@@ -61,6 +61,7 @@ class Project : public QObject
void saveAs(); void saveAs();
void emergencyBackup(); void emergencyBackup();
bool registerLoadSave( ILoadSave* loadSave ); bool registerLoadSave( ILoadSave* loadSave );
bool isClean() const;
public: public:
static QFile* emergencyBackupFile(); static QFile* emergencyBackupFile();
...@@ -74,7 +75,7 @@ class Project : public QObject ...@@ -74,7 +75,7 @@ class Project : public QObject
* if an outdated project backup is found, the used is asked if she wants to delete * if an outdated project backup is found, the used is asked if she wants to delete
* it. * it.
*/ */
bool loadProject(); bool load();
/** /**
* @brief connectComponents Connects project specific components' signals & slots * @brief connectComponents Connects project specific components' signals & slots
*/ */
...@@ -87,7 +88,6 @@ class Project : public QObject ...@@ -87,7 +88,6 @@ class Project : public QObject
QString checkBackupFile( const QString& projectFile ); QString checkBackupFile( const QString& projectFile );
void initSettings(); void initSettings();
QString name(); QString name();
bool closeProject();
void saveProject( const QString& filename ); void saveProject( const QString& filename );
void newProject( const QString& projectName, const QString& projectPath ); void newProject( const QString& projectName, const QString& projectPath );
......
...@@ -37,13 +37,6 @@ public: ...@@ -37,13 +37,6 @@ public:
virtual ~IProjectUiCb() {} 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 * @brief getProjectFile Ask the user where to save a new project
* @param defaultPath A default project location, if any. * @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