diff --git a/include/MainWindow.h b/include/MainWindow.h index 86ab8adc6..5e1f294ae 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -69,10 +69,12 @@ public: /// opens another file...) must call this before and may only proceed if /// this function returns true. /// + /// \param stopPlayback whether playback should be stopped upon prompting. If set to false, the caller should ensure that Engine::getSong()->stop() is called before unloading/loading a song. + /// /// \return true if the user allows the software to proceed, false if they /// cancel the action. /// - bool mayChangeProject(); + bool mayChangeProject(bool stopPlayback); void clearKeyModifiers(); diff --git a/src/gui/FileBrowser.cpp b/src/gui/FileBrowser.cpp index 942e1f360..6ea9d5134 100644 --- a/src/gui/FileBrowser.cpp +++ b/src/gui/FileBrowser.cpp @@ -583,7 +583,7 @@ void FileBrowserTreeWidget::handleFile(FileItem * f, InstrumentTrack * it ) switch( f->handling() ) { case FileItem::LoadAsProject: - if( gui->mainWindow()->mayChangeProject() ) + if( gui->mainWindow()->mayChangeProject(true) ) { Engine::getSong()->loadProject( f->fullName() ); } @@ -614,7 +614,7 @@ void FileBrowserTreeWidget::handleFile(FileItem * f, InstrumentTrack * it ) case FileItem::ImportAsProject: if( f->type() == FileItem::FlpFile && - !gui->mainWindow()->mayChangeProject() ) + !gui->mainWindow()->mayChangeProject(true) ) { break; } diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 6c052593a..8250163af 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -618,8 +618,11 @@ void MainWindow::resetWindowTitle() -bool MainWindow::mayChangeProject() +bool MainWindow::mayChangeProject(bool stopPlayback) { + if( stopPlayback ) + Engine::getSong()->stop(); + if( !Engine::getSong()->isModified() ) { return( true ); @@ -731,7 +734,7 @@ void MainWindow::enterWhatsThisMode() void MainWindow::createNewProject() { - if( mayChangeProject() ) + if( mayChangeProject(true) ) { Engine::getSong()->createNewProject(); } @@ -742,7 +745,7 @@ void MainWindow::createNewProject() void MainWindow::createNewProjectFromTemplate( QAction * _idx ) { - if( m_templatesMenu != NULL && mayChangeProject() ) + if( m_templatesMenu != NULL && mayChangeProject(true) ) { QString dir_base = m_templatesMenu->actions().indexOf( _idx ) >= m_custom_templates_count ? @@ -758,7 +761,7 @@ void MainWindow::createNewProjectFromTemplate( QAction * _idx ) void MainWindow::openProject() { - if( mayChangeProject() ) + if( mayChangeProject(false) ) { FileDialog ofd( this, tr( "Open Project" ), "", tr( "LMMS (*.mmp *.mmpz)" ) ); @@ -796,7 +799,7 @@ void MainWindow::updateRecentlyOpenedProjectsMenu() void MainWindow::openRecentlyOpenedProject( QAction * _action ) { - if ( mayChangeProject() ) + if ( mayChangeProject(true) ) { const QString & f = _action->text(); setCursor( Qt::WaitCursor ); @@ -1185,7 +1188,7 @@ void MainWindow::redo() void MainWindow::closeEvent( QCloseEvent * _ce ) { - if( mayChangeProject() ) + if( mayChangeProject(true) ) { // delete recovery file QFile::remove(ConfigManager::inst()->recoveryFile()); diff --git a/src/gui/TrackContainerView.cpp b/src/gui/TrackContainerView.cpp index 4513e9edf..f49f75bba 100644 --- a/src/gui/TrackContainerView.cpp +++ b/src/gui/TrackContainerView.cpp @@ -377,7 +377,7 @@ void TrackContainerView::dropEvent( QDropEvent * _de ) else if( type == "projectfile") { - if( gui->mainWindow()->mayChangeProject() ) + if( gui->mainWindow()->mayChangeProject(true) ) { Engine::getSong()->loadProject( value ); }