Move showing of save result dialog out of Song
Move the showing of save result dialogs, e.g. "The project XYZ is now saved.", from the class Song into the class MainWindow. Implementation details: Add three new methods guiSaveProject, guiSaveProjectAs and handleSaveResult to MainWindow. The first two correspond to the methods with the same name in Song which don't do anything GUI related anymore. The GUI related actions are instead implemented in the two new methods in MainWindow. The method handleSaveResult shows the dialogs for successful and failed saves, updates the list of recent files and the title bar of the main window. This commit also fixes a problem in Song::guiSaveProject where a failed saved without a GUI would still have returned true, i.e. success.
This commit is contained in:
@@ -197,6 +197,9 @@ private:
|
||||
void refocus();
|
||||
|
||||
void exportProject(bool multiExport = false);
|
||||
void handleSaveResult(QString const & filename, bool songSavedSuccessfully);
|
||||
bool guiSaveProject();
|
||||
bool guiSaveProjectAs( const QString & filename );
|
||||
|
||||
QMdiArea * m_workspace;
|
||||
|
||||
|
||||
@@ -51,7 +51,6 @@
|
||||
#include "ProjectJournal.h"
|
||||
#include "ProjectNotes.h"
|
||||
#include "SongEditor.h"
|
||||
#include "TextFloat.h"
|
||||
#include "TimeLineWidget.h"
|
||||
#include "PeakController.h"
|
||||
|
||||
@@ -1186,50 +1185,43 @@ bool Song::saveProjectFile( const QString & filename )
|
||||
|
||||
|
||||
|
||||
// save current song and update the gui
|
||||
// Save the current song
|
||||
bool Song::guiSaveProject()
|
||||
{
|
||||
DataFile dataFile( DataFile::SongProject );
|
||||
m_fileName = dataFile.nameWithExtension( m_fileName );
|
||||
if( saveProjectFile( m_fileName ) && gui != nullptr )
|
||||
|
||||
bool const saveResult = saveProjectFile( m_fileName );
|
||||
|
||||
if( saveResult )
|
||||
{
|
||||
TextFloat::displayMessage( tr( "Project saved" ),
|
||||
tr( "The project %1 is now saved."
|
||||
).arg( m_fileName ),
|
||||
embed::getIconPixmap( "project_save", 24, 24 ),
|
||||
2000 );
|
||||
ConfigManager::inst()->addRecentlyOpenedProject( m_fileName );
|
||||
m_modified = false;
|
||||
gui->mainWindow()->resetWindowTitle();
|
||||
}
|
||||
else if( gui != nullptr )
|
||||
{
|
||||
TextFloat::displayMessage( tr( "Project NOT saved." ),
|
||||
tr( "The project %1 was not saved!" ).arg(
|
||||
m_fileName ),
|
||||
embed::getIconPixmap( "error" ), 4000 );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return saveResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// save current song in given filename
|
||||
// Save the current song with the given filename
|
||||
bool Song::guiSaveProjectAs( const QString & _file_name )
|
||||
{
|
||||
QString o = m_oldFileName;
|
||||
m_oldFileName = m_fileName;
|
||||
m_fileName = _file_name;
|
||||
if( guiSaveProject() == false )
|
||||
|
||||
if(!guiSaveProject())
|
||||
{
|
||||
// Saving failed. Restore old filenames.
|
||||
m_fileName = m_oldFileName;
|
||||
m_oldFileName = o;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
m_oldFileName = m_fileName;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
#include "SetupDialog.h"
|
||||
#include "SideBar.h"
|
||||
#include "SongEditor.h"
|
||||
#include "TextFloat.h"
|
||||
#include "ToolButton.h"
|
||||
#include "ToolPlugin.h"
|
||||
#include "VersionedSaveDialog.h"
|
||||
@@ -948,7 +949,7 @@ bool MainWindow::saveProject()
|
||||
}
|
||||
else
|
||||
{
|
||||
Engine::getSong()->guiSaveProject();
|
||||
this->guiSaveProject();
|
||||
if( getSession() == Recover )
|
||||
{
|
||||
sessionCleanup();
|
||||
@@ -1000,7 +1001,7 @@ bool MainWindow::saveProjectAs()
|
||||
}
|
||||
}
|
||||
}
|
||||
Engine::getSong()->guiSaveProjectAs( fname );
|
||||
this->guiSaveProjectAs( fname );
|
||||
if( getSession() == Recover )
|
||||
{
|
||||
sessionCleanup();
|
||||
@@ -1025,7 +1026,7 @@ bool MainWindow::saveProjectAsNewVersion()
|
||||
do VersionedSaveDialog::changeFileNameVersion( fileName, true );
|
||||
while ( QFile( fileName ).exists() );
|
||||
|
||||
Engine::getSong()->guiSaveProjectAs( fileName );
|
||||
this->guiSaveProjectAs( fileName );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1695,6 +1696,40 @@ void MainWindow::exportProject(bool multiExport)
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::handleSaveResult(QString const & filename, bool songSavedSuccessfully)
|
||||
{
|
||||
if (songSavedSuccessfully)
|
||||
{
|
||||
TextFloat::displayMessage( tr( "Project saved" ), tr( "The project %1 is now saved.").arg( filename ),
|
||||
embed::getIconPixmap( "project_save", 24, 24 ), 2000 );
|
||||
ConfigManager::inst()->addRecentlyOpenedProject(filename);
|
||||
resetWindowTitle();
|
||||
}
|
||||
else
|
||||
{
|
||||
TextFloat::displayMessage( tr( "Project NOT saved." ), tr( "The project %1 was not saved!" ).arg(filename),
|
||||
embed::getIconPixmap( "error" ), 4000 );
|
||||
}
|
||||
}
|
||||
|
||||
bool MainWindow::guiSaveProject()
|
||||
{
|
||||
Song * song = Engine::getSong();
|
||||
bool const songSaveResult = song->guiSaveProject();
|
||||
handleSaveResult(song->projectFileName(), songSaveResult);
|
||||
|
||||
return songSaveResult;
|
||||
}
|
||||
|
||||
bool MainWindow::guiSaveProjectAs( const QString & filename )
|
||||
{
|
||||
Song * song = Engine::getSong();
|
||||
bool const songSaveResult = song->guiSaveProjectAs(filename);
|
||||
handleSaveResult(filename, songSaveResult);
|
||||
|
||||
return songSaveResult;
|
||||
}
|
||||
|
||||
void MainWindow::onExportProject()
|
||||
{
|
||||
this->exportProject();
|
||||
|
||||
Reference in New Issue
Block a user