From 8ab69ae5c3ce60313f37e68a122c595083dfad46 Mon Sep 17 00:00:00 2001 From: James Crook Date: Sat, 3 Mar 2018 18:01:40 +0000 Subject: [PATCH] Update tools menu on Mac too. This entailed making the Edit Chains and Apply Chain dialogs modeless. That is good for other reasons too. --- src/BatchProcessDialog.cpp | 185 +++++++++++++++---------------------- src/BatchProcessDialog.h | 20 ++-- src/Menus.cpp | 57 +++++++----- src/Project.h | 2 + 4 files changed, 118 insertions(+), 146 deletions(-) diff --git a/src/BatchProcessDialog.cpp b/src/BatchProcessDialog.cpp index a2aca38e3..582e6206c 100644 --- a/src/BatchProcessDialog.cpp +++ b/src/BatchProcessDialog.cpp @@ -92,6 +92,19 @@ void BatchProcessDialog::Populate() ShuttleGui S(this, eIsCreating); PopulateOrExchange(S); // ----------------------- End of main section -------------- + // Get and validate the currently active chain + mActiveChain = gPrefs->Read(wxT("/Batch/ActiveChain"), wxT("")); + // Go populate the chains list. + PopulateChains(); + + Layout(); + Fit(); + SetSizeHints(GetSize()); + Center(); + + // Set the column size for the chains list. + wxSize sz = mChains->GetClientSize(); + mChains->SetColumnWidth(0, sz.x); } /// Defines the dialog and does data exchange with it. @@ -122,34 +135,32 @@ void BatchProcessDialog::PopulateOrExchange(ShuttleGui &S) S.EndHorizontalLay(); } S.EndVerticalLay(); +} +/// This clears and updates the contents of mChains, the list of chains. +void BatchProcessDialog::PopulateChains() +{ wxArrayString names = mBatchCommands.GetNames(); - for (int i = 0; i < (int)names.GetCount(); i++) { + int i; + + mChains->DeleteAllItems(); + for (i = 0; i < (int)names.GetCount(); i++) { mChains->InsertItem(i, names[i]); } - // Get and validate the currently active chain - wxString name = gPrefs->Read(wxT("/Batch/ActiveChain"), wxT("")); - - int item = mChains->FindItem(-1, name); + int item = mChains->FindItem(-1, mActiveChain); if (item == -1) { item = 0; - name = mChains->GetItemText(0); + mActiveChain = mChains->GetItemText(0); } // Select the name in the list...this will fire an event. mChains->SetItemState(item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); - - Layout(); - Fit(); - SetSizeHints(GetSize()); - Center(); - - // Set the column size for the chains list. - wxSize sz = mChains->GetClientSize(); - mChains->SetColumnWidth(0, sz.x); } + + + void BatchProcessDialog::OnHelp(wxCommandEvent & WXUNUSED(event)) { wxString page = GetHelpPageName(); @@ -166,6 +177,7 @@ void BatchProcessDialog::OnApplyToProject(wxCommandEvent & WXUNUSED(event)) AudacityMessageBox(_("No chain selected")); return; } + ApplyChainToProject( item ); } void BatchProcessDialog::ApplyChainToProject( int iChain, bool bHasGui ) @@ -174,9 +186,9 @@ void BatchProcessDialog::ApplyChainToProject( int iChain, bool bHasGui ) if( name.IsEmpty() ) return; - wxDialog * pD = safenew wxDialogWrapper(this, wxID_ANY, GetTitle()); - pD->SetName(pD->GetTitle()); - ShuttleGui S(pD, eIsCreating); + wxDialogWrapper activityWin( this, wxID_ANY, GetTitle()); + activityWin.SetName(activityWin.GetTitle()); + ShuttleGui S(&activityWin, eIsCreating); S.StartHorizontalLay(wxCENTER, false); { @@ -190,14 +202,14 @@ void BatchProcessDialog::ApplyChainToProject( int iChain, bool bHasGui ) } S.EndHorizontalLay(); - pD->Layout(); - pD->Fit(); - pD->CenterOnScreen(); + activityWin.Layout(); + activityWin.Fit(); + activityWin.CenterOnScreen(); // Avoid overlap with progress. int x,y; - pD->GetPosition( &x, &y ); - pD->Move(wxMax(0,x-300), 0); - pD->Show(); + activityWin.GetPosition( &x, &y ); + activityWin.Move(wxMax(0,x-300), 0); + activityWin.Show(); // Without this the newly created dialog may not show completely. wxYield(); @@ -219,7 +231,7 @@ void BatchProcessDialog::ApplyChainToProject( int iChain, bool bHasGui ) // the menus on OSX will remain disabled. bool success; { - wxWindowDisabler wd(pD); + wxWindowDisabler wd(&activityWin); success = GuardedCall< bool >( [this]{ return mBatchCommands.ApplyChain(); } ); } @@ -232,20 +244,7 @@ void BatchProcessDialog::ApplyChainToProject( int iChain, bool bHasGui ) Show(); return; } - -#if !defined(__WXMAC__) - // Under Linux an EndModal() here crashes (Bug #1221). - // But sending a close message instead is OK. - wxCloseEvent Evt; - Evt.SetId( wxID_OK ); - Evt.SetEventObject( this); - ProcessWindowEvent( Evt ); -#else - EndModal(wxID_OK); -#endif - - // Raise myself again, and the parent window with me - Show(); + Hide(); } void BatchProcessDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event)) @@ -327,9 +326,9 @@ void BatchProcessDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event)) files.Sort(); - wxDialog * pD = safenew wxDialogWrapper(this, wxID_ANY, GetTitle()); - pD->SetName(pD->GetTitle()); - ShuttleGui S(pD, eIsCreating); + wxDialogWrapper activityWin(this, wxID_ANY, GetTitle()); + activityWin.SetName(activityWin.GetTitle()); + ShuttleGui S(&activityWin, eIsCreating); S.StartVerticalLay(false); { @@ -371,22 +370,22 @@ void BatchProcessDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event)) mList->SetInitialSize(sz); } - pD->Layout(); - pD->Fit(); - pD->SetSizeHints(pD->GetSize()); - pD->CenterOnScreen(); + activityWin.Layout(); + activityWin.Fit(); + activityWin.CenterOnScreen(); // Avoid overlap with progress. int x,y; - pD->GetPosition( &x, &y ); - pD->Move(wxMax(0,x-300), 0); - pD->Show(); - // Give dialog a chance to actually show. + activityWin.GetPosition( &x, &y ); + activityWin.Move(wxMax(0,x-300), 0); + activityWin.Show(); + + // Without this the newly created dialog may not show completely. wxYield(); Hide(); mBatchCommands.ReadChain(name); for (i = 0; i < (int)files.GetCount(); i++) { - wxWindowDisabler wd(pD); + wxWindowDisabler wd(&activityWin); if (i > 0) { //Clear the arrow in previous item. mList->SetItemImage(i - 1, 0, 0); @@ -401,7 +400,7 @@ void BatchProcessDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event)) if (!mBatchCommands.ApplyChain()) return false; - if (!pD->IsShown() || mAbort) + if (!activityWin.IsShown() || mAbort) return false; return true; @@ -416,38 +415,12 @@ void BatchProcessDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event)) project->OnRemoveTracks(*project); } project->OnRemoveTracks(*project); - - // Under Linux an EndModal() here crashes (Bug #1221). - // But sending a close message instead is OK. -#if !defined(__WXMAC__) - wxCloseEvent Evt; - Evt.SetId( wxID_OK ); - Evt.SetEventObject( this); - ProcessWindowEvent( Evt ); -#else - EndModal(wxID_OK); -#endif - - // Raise myself again, and the parent window with me - Show(); + Hide(); } void BatchProcessDialog::OnCancel(wxCommandEvent & WXUNUSED(event)) { -#if !defined(__WXMAC__) - // It is possible that we could just do EndModal() - // here even on Linux. However, we know the alternative way of - // closing works, if we are hidden, so we hide and then do that. Hide(); - // Under Linux an EndModal() here potentially crashes (Bug #1221). - // But sending a close message instead is OK. - wxCloseEvent Evt; - Evt.SetId( wxID_CANCEL ); - Evt.SetEventObject( this); - ProcessWindowEvent( Evt ); -#else - EndModal(wxID_CANCEL); -#endif } ///////////////////////////////////////////////////////////////////// @@ -505,9 +478,10 @@ enum { }; /// Constructor -EditChainsDialog::EditChainsDialog(wxWindow * parent): +EditChainsDialog::EditChainsDialog(wxWindow * parent, bool bExpanded): BatchProcessDialog(parent, true) { + mbExpanded = bExpanded; SetLabel(_("Edit Chains")); // Provide visual label SetName(_("Edit Chains")); // Provide audible label SetTitle(_("Edit Chains")); @@ -515,7 +489,10 @@ EditChainsDialog::EditChainsDialog(wxWindow * parent): mChanged = false; mSelectedCommand = 0; - Populate(); + if( mbExpanded ) + Populate(); + else + BatchProcessDialog::Populate(); } EditChainsDialog::~EditChainsDialog() @@ -534,7 +511,6 @@ void EditChainsDialog::Populate() // Get and validate the currently active chain mActiveChain = gPrefs->Read(wxT("/Batch/ActiveChain"), wxT("")); - // Go populate the chains list. PopulateChains(); @@ -642,28 +618,7 @@ void EditChainsDialog::PopulateOrExchange(ShuttleGui & S) return; } -/// This clears and updates the contents of mChains -void EditChainsDialog::PopulateChains() -{ - wxArrayString names = mBatchCommands.GetNames(); - int i; - - mChains->DeleteAllItems(); - for (i = 0; i < (int)names.GetCount(); i++) { - mChains->InsertItem(i, names[i]); - } - - int item = mChains->FindItem(-1, mActiveChain); - if (item == -1) { - item = 0; - mActiveChain = mChains->GetItemText(0); - } - - // Select the name in the list...this will fire an event. - mChains->SetItemState(item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); -} - -/// This clears and updates the contents of mList +/// This clears and updates the contents of mList, the commands for the current chain. void EditChainsDialog::PopulateList() { mList->DeleteAllItems(); @@ -704,10 +659,14 @@ void EditChainsDialog::AddItem(const wxString &Action, const wxString &Params) void EditChainsDialog::UpdateMenus() { -// Mac won't tolerate a menus update during a modal dialog. -#ifndef __WXMAC__ + // OK even on mac, as dialog is modal. GetActiveProject()->RebuildMenuBar(); -#endif +} + +void EditChainsDialog::UpdateDisplay( bool WXUNUSED(bExpanded) ) +{ + //if(IsShown()) + // DoUpdate(); } bool EditChainsDialog::ChangeOK() @@ -748,7 +707,9 @@ void EditChainsDialog::OnChainSelected(wxListEvent & event) mActiveChain = mChains->GetItemText(item); mBatchCommands.ReadChain(mActiveChain); - + if( !mbExpanded ) + return; + if (mBatchCommands.IsFixed(mActiveChain)) { mRemove->Disable(); mRename->Disable(); @@ -774,6 +735,8 @@ void EditChainsDialog::OnSize(wxSizeEvent & WXUNUSED(event)) { // Refrsh the layout and re-fit the columns. Layout(); + if( !mbExpanded ) + return; FitColumns(); } @@ -1116,7 +1079,8 @@ void EditChainsDialog::OnOK(wxCommandEvent & WXUNUSED(event)) { if( !SaveChanges() ) return; - EndModal(true); + Hide(); + //EndModal(true); } /// @@ -1125,8 +1089,7 @@ void EditChainsDialog::OnCancel(wxCommandEvent & event) if (!ChangeOK()) { return; } - BatchProcessDialog::OnCancel( event ); - //EndModal(false); + Hide(); } /// diff --git a/src/BatchProcessDialog.h b/src/BatchProcessDialog.h index 44871c242..2cd7973cd 100644 --- a/src/BatchProcessDialog.h +++ b/src/BatchProcessDialog.h @@ -45,8 +45,9 @@ class BatchProcessDialog : public wxDialogWrapper { BatchProcessDialog(wxWindow * parent, bool bInherited=false); virtual ~BatchProcessDialog(); public: - virtual void Populate(); - virtual void PopulateOrExchange( ShuttleGui & S ); + // Populate methods NOT virtual. + void Populate(); + void PopulateOrExchange( ShuttleGui & S ); virtual void OnApplyToProject(wxCommandEvent & event); virtual void OnApplyToFiles(wxCommandEvent & event); virtual void OnCancel(wxCommandEvent & event); @@ -54,7 +55,7 @@ class BatchProcessDialog : public wxDialogWrapper { virtual wxString GetHelpPageName() {return "Tools_Menu#chains_compact_dialog";}; - + void PopulateChains(); void ApplyChainToProject( int iChain, bool bHasGui=true ); @@ -67,6 +68,7 @@ class BatchProcessDialog : public wxDialogWrapper { wxButton *mCancel; wxTextCtrl *mResults; bool mAbort; + wxString mActiveChain; DECLARE_EVENT_TABLE() }; @@ -74,19 +76,19 @@ class BatchProcessDialog : public wxDialogWrapper { class EditChainsDialog final : public BatchProcessDialog { public: - EditChainsDialog(wxWindow * parent); + EditChainsDialog(wxWindow * parent, bool bExpanded=true); ~EditChainsDialog(); + void UpdateDisplay( bool bExpanded ); private: - void Populate() override; - void PopulateOrExchange(ShuttleGui &S) override; + void Populate(); + void PopulateOrExchange(ShuttleGui &S); void OnApplyToProject(wxCommandEvent & event) override; void OnApplyToFiles(wxCommandEvent & event) override; void OnCancel(wxCommandEvent &event) override; virtual wxString GetHelpPageName() override {return "Tools_Menu#chains_full_dialog";}; - void PopulateChains(); void PopulateList(); void AddItem(const wxString &command, wxString const ¶ms); bool ChangeOK(); @@ -129,11 +131,9 @@ private: wxButton *mRename; wxButton *mDefaults; - - wxString mActiveChain; - int mSelectedCommand; bool mChanged; + bool mbExpanded; using CommandName = std::tuple; using CommandNameVector = std::vector; diff --git a/src/Menus.cpp b/src/Menus.cpp index c50677336..7a46bcca9 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -6854,6 +6854,38 @@ void AudacityProject::OnShowExtraMenus(const CommandContext &WXUNUSED(context) ) RebuildAllMenuBars(); } +void AudacityProject::OnApplyChainDirectly(const CommandContext &context ) +{ + //wxLogDebug( "Chain was: %s", context.parameter); + BatchProcessDialog dlg(this); + wxString Name = context.parameter; + long item=0; + // Take last three letters (of e.g. Chain007) and convert to a number. + Name.Mid( Name.Length() - 3 ).ToLong( &item, 10 ); + dlg.ApplyChainToProject( item, false ); + ModifyUndoMenuItems(); +} + +void AudacityProject::OnApplyChain(const CommandContext &WXUNUSED(context) ) +{ + const bool bExpanded = false; + if (!mChainsWindow) + mChainsWindow = safenew EditChainsDialog(this, bExpanded); + mChainsWindow->Show(); + mChainsWindow->Raise(); + mChainsWindow->UpdateDisplay( bExpanded); +} + +void AudacityProject::OnEditChains(const CommandContext &WXUNUSED(context) ) +{ + const bool bExpanded = true; + if (!mChainsWindow) + mChainsWindow = safenew EditChainsDialog(this, bExpanded); + mChainsWindow->Show(); + mChainsWindow->Raise(); + mChainsWindow->UpdateDisplay( bExpanded); +} + void AudacityProject::OnHistory(const CommandContext &WXUNUSED(context) ) { if (!mHistoryWindow) @@ -6862,7 +6894,6 @@ void AudacityProject::OnHistory(const CommandContext &WXUNUSED(context) ) mHistoryWindow->Raise(); mHistoryWindow->UpdateDisplay(); } - void AudacityProject::OnKaraoke(const CommandContext &WXUNUSED(context) ) { if (!mLyricsWindow) @@ -8472,30 +8503,6 @@ void AudacityProject::OnToggleTypeToCreateLabel(const CommandContext &WXUNUSED(c ModifyAllProjectToolbarMenus(); } -void AudacityProject::OnApplyChain(const CommandContext &WXUNUSED(context) ) -{ - BatchProcessDialog dlg(this); - dlg.ShowModal(); - ModifyUndoMenuItems(); -} - -void AudacityProject::OnApplyChainDirectly(const CommandContext &context ) -{ - //wxLogDebug( "Chain was: %s", context.parameter); - BatchProcessDialog dlg(this); - wxString Name = context.parameter; - long item=0; - // Take last three letters (of e.g. Chain007) and convert to a number. - Name.Mid( Name.Length() - 3 ).ToLong( &item, 10 ); - dlg.ApplyChainToProject( item, false ); - ModifyUndoMenuItems(); -} - -void AudacityProject::OnEditChains(const CommandContext &WXUNUSED(context) ) -{ - EditChainsDialog dlg(this); - dlg.ShowModal(); -} void AudacityProject::OnRemoveTracks(const CommandContext &WXUNUSED(context) ) { diff --git a/src/Project.h b/src/Project.h index f04fa5bdb..14afca1bc 100644 --- a/src/Project.h +++ b/src/Project.h @@ -86,6 +86,7 @@ class TranscriptionToolBar; // windows and frames class AdornedRulerPanel; class HistoryWindow; +class EditChainsDialog; class LyricsWindow; class MixerBoard; class MixerBoardFrame; @@ -679,6 +680,7 @@ private: bool mActive{ true }; bool mIconized; + EditChainsDialog *mChainsWindow{}; HistoryWindow *mHistoryWindow{}; LyricsWindow* mLyricsWindow{}; MixerBoardFrame* mMixerBoardFrame{};