Commit b119862e authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Asking for confirmation when closing the project

Refactored confirmation when closing the app.
parent e545ea25
......@@ -421,31 +421,10 @@ void MainWindow::on_actionProject_Preferences_triggered()
void MainWindow::closeEvent( QCloseEvent* e )
{
if ( ProjectManager::getInstance()->needSave() == true )
{
QMessageBox msgBox;
msgBox.setText( tr( "The project has been modified." ) );
msgBox.setInformativeText( 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:
ProjectManager::getInstance()->saveProject();
break ;
case QMessageBox::Discard:
break ;
case QMessageBox::Cancel:
default:
e->ignore();
return ;
e->accept();
}
}
else
if ( ProjectManager::getInstance()->askForSaveIfModified() )
e->accept();
else
e->ignore();
}
void MainWindow::projectChanged( const QString& projectName, bool savedStatus )
......
......@@ -23,6 +23,7 @@
#include <QFileDialog>
#include <QtDebug>
#include <QSettings>
#include <QMessageBox>
#include "ProjectManager.h"
#include "Library.h"
......@@ -167,6 +168,8 @@ void ProjectManager::saveProject( bool saveAs /*= true*/ )
void ProjectManager::closeProject()
{
if ( askForSaveIfModified() == false )
return ;
if ( m_projectFile != NULL )
{
delete m_projectFile;
......@@ -174,3 +177,29 @@ void ProjectManager::closeProject()
}
emit projectClosed();
}
bool ProjectManager::askForSaveIfModified()
{
if ( m_needSave == true )
{
QMessageBox msgBox;
msgBox.setText( tr( "The project has been modified." ) );
msgBox.setInformativeText( 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:
saveProject();
break ;
case QMessageBox::Discard:
break ;
case QMessageBox::Cancel:
default:
return false ;
}
}
return true;
}
......@@ -41,6 +41,7 @@ public:
bool needSave() const;
QStringList recentsProjects() const;
void closeProject();
bool askForSaveIfModified();
private:
ProjectManager();
......
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