From aee4a33d6ba0801834e0b64bee745314618f041e Mon Sep 17 00:00:00 2001 From: James Crook Date: Fri, 9 Oct 2015 23:53:49 +0100 Subject: [PATCH] Bug 1221 - Chain asserts (Linux) or causes switch away from Audacity (Windows) on completion. New fix. It appears to be a bug in wx3. Hiding a Modal window (under linux) can stop it being modal. So rather than EndModal() we send an event to close the window which works whether wxWidgets thinks the window is modal or not. Additionally we set the focus back to the parent window, becuase of a side bug under windows, and we new the status dialog rather than allocate it on the stack, because the status dialog is NOT run with ShowModal() which is the only time we can safely use an on stack dialog. --- src/BatchProcessDialog.cpp | 44 ++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/BatchProcessDialog.cpp b/src/BatchProcessDialog.cpp index 59ccf68fb..d22013025 100644 --- a/src/BatchProcessDialog.cpp +++ b/src/BatchProcessDialog.cpp @@ -174,7 +174,7 @@ void BatchProcessDialog::OnApplyToProject(wxCommandEvent & WXUNUSED(event)) pD->Move(-1, 0); pD->Show(); - Hide(); + Hide();// Caused Bug #1221 gPrefs->Write(wxT("/Batch/ActiveChain"), name); gPrefs->Flush(); @@ -192,9 +192,14 @@ void BatchProcessDialog::OnApplyToProject(wxCommandEvent & WXUNUSED(event)) return; } // pD->Destroy(); + + wxWindow * pWnd = this->GetParent(); + // Under Linux an EndModal() here is the cause of Bug #1221. + // But sending a close message instead is OK. wxCloseEvent Evt; Evt.SetEventObject( this); ProcessWindowEvent( Evt ); + pWnd->SetFocus(); } void BatchProcessDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event)) @@ -277,9 +282,9 @@ void BatchProcessDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event)) files.Sort(); - wxDialog d(this, wxID_ANY, GetTitle()); - d.SetName(d.GetTitle()); - ShuttleGui S(&d, eIsCreating); + wxDialog * pD = new wxDialog(this, wxID_ANY, GetTitle()); + pD->SetName(pD->GetTitle()); + ShuttleGui S(pD, eIsCreating); S.StartVerticalLay(false); { @@ -320,17 +325,17 @@ void BatchProcessDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event)) mList->SetInitialSize(sz); } - d.Layout(); - d.Fit(); - d.SetSizeHints(d.GetSize()); - d.CenterOnScreen(); - d.Move(-1, 0); - d.Show(); + pD->Layout(); + pD->Fit(); + pD->SetSizeHints(pD->GetSize()); + pD->CenterOnScreen(); + pD->Move(-1, 0); + pD->Show(); Hide(); mBatchCommands.ReadChain(name); for (i = 0; i < (int)files.GetCount(); i++) { - wxWindowDisabler wd(&d); + wxWindowDisabler wd(pD); if (i > 0) { //Clear the arrow in previous item. mList->SetItemImage(i - 1, 0, 0); @@ -344,7 +349,7 @@ void BatchProcessDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event)) break; } - if (!d.IsShown() || mAbort) { + if (!pD->IsShown() || mAbort) { break; } UndoManager *um = project->GetUndoManager(); @@ -354,12 +359,23 @@ void BatchProcessDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event)) } project->OnRemoveTracks(); - EndModal(wxID_OK); + wxWindow * pWnd = this->GetParent(); + // Under Linux an EndModal() here is the cause of Bug #1221. + // But sending a close message instead is OK. + wxCloseEvent Evt; + Evt.SetEventObject( this); + ProcessWindowEvent( Evt ); + pWnd->SetFocus(); } void BatchProcessDialog::OnCancel(wxCommandEvent & WXUNUSED(event)) { - EndModal(wxID_CANCEL); + // Under Linux an EndModal() here is the cause of Bug #1221. + // But sending a close message instead is OK. + wxCloseEvent Evt; + Evt.SetEventObject( this); + ProcessWindowEvent( Evt ); + //EndModal(wxID_CANCEL); } /////////////////////////////////////////////////////////////////////