Skip to content

Commit

Permalink
Added 'bool stopPlayback' parameter to MainWindow::mayChangeProject()…
Browse files Browse the repository at this point in the history
… to preserve old behavior outside of 'Open project dialog' case; fixes LMMS#1384
  • Loading branch information
csimons committed Mar 10, 2015
1 parent 393eaca commit 95c7d72
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
4 changes: 3 additions & 1 deletion include/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ class MainWindow : public QMainWindow
/// 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();
Expand Down
4 changes: 2 additions & 2 deletions src/gui/FileBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
Expand Down Expand Up @@ -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;
}
Expand Down
15 changes: 9 additions & 6 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -731,7 +734,7 @@ void MainWindow::enterWhatsThisMode()

void MainWindow::createNewProject()
{
if( mayChangeProject() )
if( mayChangeProject(true) )
{
Engine::getSong()->createNewProject();
}
Expand All @@ -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 ?
Expand All @@ -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)" ) );

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/gui/TrackContainerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down

0 comments on commit 95c7d72

Please sign in to comment.