[vlmc-devel] Ask the users if they want to save the project from the MainWindow
Hugo Beauzée-Luyssen
git at videolan.org
Mon Feb 29 01:06:29 CET 2016
vlmc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Thu Feb 25 22:40:34 2016 +0100| [5433c79b7360a91f4f9618e502218a7a59a6f274] | committer: 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.
> https://code.videolan.org/videolan/vlmc/commit/5433c79b7360a91f4f9618e502218a7a59a6f274
---
src/Gui/MainWindow.cpp | 26 +++++++++++++++++++++----
src/Gui/project/GuiProjectManager.cpp | 23 ----------------------
src/Gui/project/GuiProjectManager.h | 1 -
src/Project/Project.cpp | 36 ++++++++++-------------------------
src/Project/Project.h | 4 ++--
src/Project/ProjectCallbacks.h | 7 -------
6 files changed, 34 insertions(+), 63 deletions(-)
diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp
index 80109ff..d3b11f7 100644
--- a/src/Gui/MainWindow.cpp
+++ b/src/Gui/MainWindow.cpp
@@ -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
diff --git a/src/Gui/project/GuiProjectManager.cpp b/src/Gui/project/GuiProjectManager.cpp
index 4f293f6..0faa144 100644
--- a/src/Gui/project/GuiProjectManager.cpp
+++ b/src/Gui/project/GuiProjectManager.cpp
@@ -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;
- }
-}
-
diff --git a/src/Gui/project/GuiProjectManager.h b/src/Gui/project/GuiProjectManager.h
index 694f534..ab7e177 100644
--- a/src/Gui/project/GuiProjectManager.h
+++ b/src/Gui/project/GuiProjectManager.h
@@ -31,7 +31,6 @@ public:
virtual bool shouldLoadBackupFile();
virtual bool shouldDeleteOutdatedBackupFile();
virtual QString getProjectFileDestination( const QString &defaultPath );
- virtual SaveMode shouldSaveBeforeClose();
};
#endif // GUIPROJECTMANAGER_H
diff --git a/src/Project/Project.cpp b/src/Project/Project.cpp
index c407f42..a4ac81b 100644
--- a/src/Project/Project.cpp
+++ b/src/Project/Project.cpp
@@ -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();
diff --git a/src/Project/Project.h b/src/Project/Project.h
index de27979..c8ef16e 100644
--- a/src/Project/Project.h
+++ b/src/Project/Project.h
@@ -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 );
diff --git a/src/Project/ProjectCallbacks.h b/src/Project/ProjectCallbacks.h
index 2fc8d25..629d52d 100644
--- a/src/Project/ProjectCallbacks.h
+++ b/src/Project/ProjectCallbacks.h
@@ -38,13 +38,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.
* @return The selected project file
More information about the Vlmc-devel
mailing list