diff --git a/src/BatchCommandDialog.cpp b/src/BatchCommandDialog.cpp index 108c3490b..147154dc6 100644 --- a/src/BatchCommandDialog.cpp +++ b/src/BatchCommandDialog.cpp @@ -89,10 +89,12 @@ void MacroCommandDialog::PopulateOrExchange(ShuttleGui &S) S.SetStretchyCol(1); mCommand = S.AddTextBox(_("&Command"), wxT(""), 20); mCommand->SetEditable(false); - mEditParams = S.Id(EditParamsButtonID).AddButton(_("&Edit Parameters")); - mEditParams->Enable(false); // disable button as box is empty - mUsePreset = S.Id(UsePresetButtonID).AddButton(_("&Use Preset")); - mUsePreset->Enable(false); // disable button as box is empty + mEditParams = S.Id(EditParamsButtonID) + .Disable() // disable button as box is empty + .AddButton(_("&Edit Parameters")); + mUsePreset = S.Id(UsePresetButtonID) + .Disable() // disable button as box is empty + .AddButton(_("&Use Preset")); } S.EndMultiColumn(); diff --git a/src/BatchProcessDialog.cpp b/src/BatchProcessDialog.cpp index babc70203..07f045c5d 100644 --- a/src/BatchProcessDialog.cpp +++ b/src/BatchProcessDialog.cpp @@ -632,8 +632,12 @@ void MacrosWindow::PopulateOrExchange(ShuttleGui & S) mRestore = S.Id(RestoreButtonID).AddButton(_("Re&store")); // Not yet ready for prime time. #if 0 - S.Id(ImportButtonID).AddButton(_("I&mport..."))->Enable( false); - S.Id(ExportButtonID).AddButton(_("E&xport..."))->Enable( false); + S.Id(ImportButtonID) + .Disable() + .AddButton(_("I&mport...")); + S.Id(ExportButtonID) + .Disable() + .AddButton(_("E&xport...")); #endif } S.EndVerticalLay(); diff --git a/src/Dependencies.cpp b/src/Dependencies.cpp index 85c876d94..6c723c1fd 100644 --- a/src/Dependencies.cpp +++ b/src/Dependencies.cpp @@ -365,11 +365,10 @@ void DependencyDialog::PopulateOrExchange(ShuttleGui& S) mCopySelectedFilesButton = S.Id(CopySelectedFilesButtonID) .Focus() + .Disable(mFileListCtrl->GetSelectedItemCount() <= 0) .AddButton( _("Copy Selected Files"), wxALIGN_LEFT, true); - mCopySelectedFilesButton->Enable( - mFileListCtrl->GetSelectedItemCount() > 0); } S.EndStatic(); @@ -383,11 +382,12 @@ void DependencyDialog::PopulateOrExchange(ShuttleGui& S) S.Id(wxID_NO).AddButton(_("Do Not Copy")); mCopyAllFilesButton = - S.Id(wxID_YES).AddButton(_("Copy All Files (Safer)")); + S.Id(wxID_YES) + // Enabling mCopyAllFilesButton is also done in PopulateList, + // but at its call above, mCopyAllFilesButton does not yet exist. + .Disable(mHasMissingFiles) + .AddButton(_("Copy All Files (Safer)")); - // Enabling mCopyAllFilesButton is also done in PopulateList, - // but at its call above, mCopyAllFilesButton does not yet exist. - mCopyAllFilesButton->Enable(!mHasMissingFiles); } S.EndHorizontalLay(); diff --git a/src/ShuttleGui.cpp b/src/ShuttleGui.cpp index f5161512d..835bdab42 100644 --- a/src/ShuttleGui.cpp +++ b/src/ShuttleGui.cpp @@ -184,13 +184,6 @@ void ShuttleGuiBase::ResetId() miIdNext = 3000; } -void ShuttleGuiBase::EnableCtrl( bool bEnable ) -{ - if( mShuttleMode != eIsCreating ) - return; - mpLastWind->Enable( bEnable ); -} - /// Used to modify an already placed Window. void ShuttleGuiBase::SetSizeHints( int minX, int minY ) { @@ -2087,6 +2080,9 @@ void ShuttleGuiBase::UpdateSizersCore(bool bPrepend, int Flags, bool prompt) if (mItem.mFocused) mpWind->SetFocus(); + if (mItem.mDisabled) + mpWind->Enable( false ); + // Reset to defaults mItem = {}; } diff --git a/src/ShuttleGui.h b/src/ShuttleGui.h index ae1be8477..9c84c1013 100644 --- a/src/ShuttleGui.h +++ b/src/ShuttleGui.h @@ -174,6 +174,12 @@ struct Item { return std::move( *this ); } + Item&& Disable( bool disabled = true ) && + { + mDisabled = disabled; + return std::move( *this ); + } + std::function< void(wxWindow*) > mValidatorSetter; TranslatableString mToolTip; TranslatableString mName; @@ -182,6 +188,7 @@ struct Item { long miStyle{}; bool mFocused { false }; + bool mDisabled { false }; }; } @@ -387,7 +394,6 @@ public: const int max, const int min); //-- End of variants. - void EnableCtrl( bool bEnable ); void SetSizeHints( int minX, int minY ); void SetBorder( int Border ) {miBorder = Border;}; void SetSizerProportion( int iProp ) {miSizerProp = iProp;}; @@ -545,6 +551,12 @@ public: return *this; } + ShuttleGui &Disable( bool disabled = true ) + { + std::move( mItem ).Disable( disabled ); + return *this; + } + ShuttleGui & ToolTip( const TranslatableString &tip ) { std::move( mItem ).ToolTip( tip ); diff --git a/src/effects/Amplify.cpp b/src/effects/Amplify.cpp index b65107e9a..59de3812e 100644 --- a/src/effects/Amplify.cpp +++ b/src/effects/Amplify.cpp @@ -271,12 +271,8 @@ void EffectAmplify::PopulateOrExchange(ShuttleGui & S) // Clipping S.StartHorizontalLay(wxCENTER); { - mClip = S.Id(ID_Clip).AddCheckBox(_("Allow clipping"), false); - if (IsBatchProcessing()) - { - mClip->Enable(false); - mCanClip = true; - } + mClip = S.Id(ID_Clip).Disable( mCanClip = IsBatchProcessing() ) + .AddCheckBox(_("Allow clipping"), false); } S.EndHorizontalLay(); } diff --git a/src/effects/ChangeTempo.cpp b/src/effects/ChangeTempo.cpp index 2e93908c6..eae5907b0 100644 --- a/src/effects/ChangeTempo.cpp +++ b/src/effects/ChangeTempo.cpp @@ -285,13 +285,13 @@ void EffectChangeTempo::PopulateOrExchange(ShuttleGui & S) S.StartHorizontalLay(wxALIGN_CENTER); { m_pTextCtrl_FromLength = S.Id(ID_FromLength) + .Disable() // Disable because the value comes from the + // user selection. .Validator>( precision, &m_FromLength, NumValidatorStyle::TWO_TRAILING_ZEROES) /* i18n-hint: changing a quantity "from" one value "to" another */ .AddTextBox(_("from"), wxT(""), 12); - m_pTextCtrl_FromLength->Enable(false); // Disable because the value comes from the user selection. - m_pTextCtrl_ToLength = S.Id(ID_ToLength) .Validator>( 2, &m_ToLength, NumValidatorStyle::TWO_TRAILING_ZEROES, diff --git a/src/effects/Equalization.cpp b/src/effects/Equalization.cpp index bf5121076..746e6e20d 100644 --- a/src/effects/Equalization.cpp +++ b/src/effects/Equalization.cpp @@ -1069,29 +1069,23 @@ void EffectEqualization::PopulateOrExchange(ShuttleGui & S) .AddRadioButton(_("D&efault"), 0, value); mMathProcessingType[1] = S.Id(ID_SSE) + .Disable(!EffectEqualization48x::GetMathCaps()->SSE) .AddRadioButtonToGroup(_("&SSE"), 1, value); mMathProcessingType[2] = S.Id(ID_SSEThreaded) + .Disable(!EffectEqualization48x::GetMathCaps()->SSE) .AddRadioButtonToGroup(_("SSE &Threaded"), 2, value); mMathProcessingType[3] = S.Id(ID_AVX) + // not implemented + .Disable(true /* !EffectEqualization48x::GetMathCaps()->AVX */) .AddRadioButtonToGroup(_("A&VX"), 3, value); mMathProcessingType[4] = S.Id(ID_AVXThreaded) + // not implemented + .Disable(true /* !EffectEqualization48x::GetMathCaps()->AVX */) .AddRadioButtonToGroup(_("AV&X Threaded"), 4, value); - - if (!EffectEqualization48x::GetMathCaps()->SSE) - { - mMathProcessingType[1]->Disable(); - mMathProcessingType[2]->Disable(); - } - if (true) //!EffectEqualization48x::GetMathCaps()->AVX) { not implemented - { - mMathProcessingType[3]->Disable(); - mMathProcessingType[4]->Disable(); - } - S.Id(ID_Bench).AddButton(_("&Bench")); } S.EndHorizontalLay(); diff --git a/src/export/ExportMP3.cpp b/src/export/ExportMP3.cpp index 56d67e58d..7d05816e5 100644 --- a/src/export/ExportMP3.cpp +++ b/src/export/ExportMP3.cpp @@ -392,21 +392,21 @@ void ExportMP3Options::PopulateOrExchange(ShuttleGui & S) codes ); - mMode = S.TieNumberAsChoice( - _("Variable Speed:"), - { wxT("/FileFormats/MP3VarMode"), ROUTINE_FAST }, - varModeNames ); - mMode->Enable(enable); + mMode = S.Disable(!enable) + .TieNumberAsChoice( + _("Variable Speed:"), + { wxT("/FileFormats/MP3VarMode"), ROUTINE_FAST }, + varModeNames ); S.AddPrompt(_("Channel Mode:")); S.StartMultiColumn(3, wxEXPAND); { S.StartRadioButtonGroup(MP3ChannelModeSetting); { - mJoint = S.TieRadioButton(); - mStereo = S.TieRadioButton(); - mJoint->Enable(!mono); - mStereo->Enable(!mono); + mJoint = S.Disable(mono) + .TieRadioButton(); + mStereo = S.Disable(mono) + .TieRadioButton(); } S.EndRadioButtonGroup(); diff --git a/src/prefs/LibraryPrefs.cpp b/src/prefs/LibraryPrefs.cpp index 681893aae..66de1ea01 100644 --- a/src/prefs/LibraryPrefs.cpp +++ b/src/prefs/LibraryPrefs.cpp @@ -113,23 +113,23 @@ void LibraryPrefs::PopulateOrExchange(ShuttleGui & S) S.AddVariableText(_("LAME MP3 Library:"), true, wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL); - wxButton *locate_button = S.Id(ID_MP3_FIND_BUTTON).AddButton(_("&Locate..."), - wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL); + S.Id(ID_MP3_FIND_BUTTON) +#ifdef DISABLE_DYNAMIC_LOADING_LAME + .Disable() +#endif + .AddButton(_("&Locate..."), + wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL); S.AddVariableText(_("LAME MP3 Library:"), true, wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL); - wxButton *download_button = S.Id(ID_MP3_DOWN_BUTTON).AddButton(_("&Download"), - wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL); - + S.Id(ID_MP3_DOWN_BUTTON) #ifdef DISABLE_DYNAMIC_LOADING_LAME - locate_button->Enable(FALSE); - download_button->Enable(FALSE); -#else - (void)locate_button; - (void)download_button; -#endif // DISABLE_DYNAMIC_LOADING_LAME + .Disable() #endif + .AddButton(_("&Download"), + wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL); +#endif } S.EndTwoColumn(); } @@ -155,31 +155,32 @@ void LibraryPrefs::PopulateOrExchange(ShuttleGui & S) true, wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL); S.Id(ID_FFMPEG_FIND_BUTTON); - wxButton *bfnd = S.AddButton(_("Loca&te..."), - wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL); + S +#if !defined(USE_FFMPEG) || defined(DISABLE_DYNAMIC_LOADING_FFMPEG) + .Disable() +#endif + .AddButton(_("Loca&te..."), + wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL); S.AddVariableText(_("FFmpeg Library:"), true, wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL); S.Id(ID_FFMPEG_DOWN_BUTTON); - wxButton *bdwn = S.AddButton(_("Dow&nload"), - wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL); + S #if !defined(USE_FFMPEG) || defined(DISABLE_DYNAMIC_LOADING_FFMPEG) - bdwn->Enable(FALSE); - bfnd->Enable(FALSE); -#else - // fix compilation warnings about unused variables - wxUnusedVar(bfnd); - wxUnusedVar(bdwn); + .Disable() #endif + .AddButton(_("Dow&nload"), + wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL); } S.EndTwoColumn(); #ifdef EXPERIMENTAL_OD_FFMPEG - wxCheckBox* checkbox = S.TieCheckBox(_("Allow &background on-demand loading"), + S +#if !defined(USE_FFMPEG) + .Disable() +#endif + .TieCheckBox(_("Allow &background on-demand loading"), wxT("/Library/FFmpegOnDemand"), false); -#if !defined(USE_FFMPEG) - if( checkbox ) checkbox->Enable(FALSE); -#endif #endif } S.EndStatic(); diff --git a/src/prefs/RecordingPrefs.cpp b/src/prefs/RecordingPrefs.cpp index b9d90e832..bd4c1a167 100644 --- a/src/prefs/RecordingPrefs.cpp +++ b/src/prefs/RecordingPrefs.cpp @@ -159,12 +159,11 @@ void RecordingPrefs::PopulateOrExchange(ShuttleGui & S) mToggleCustomName = S .Name(XO("Custom name text")) + .Disable(!mUseCustomTrackName) .TieTextBox( {}, {wxT("/GUI/TrackNames/RecodingTrackName"), _("Recorded_Audio")}, - 30); - if ( mToggleCustomName ) - mToggleCustomName->Enable(mUseCustomTrackName); + 30); } S.EndMultiColumn(); diff --git a/src/widgets/HelpSystem.cpp b/src/widgets/HelpSystem.cpp index 1e2fafb60..f60e1a49b 100644 --- a/src/widgets/HelpSystem.cpp +++ b/src/widgets/HelpSystem.cpp @@ -166,18 +166,18 @@ void HelpSystem::ShowHtmlText(wxWindow *pParent, { S.StartHorizontalLay( wxEXPAND, false ); { - wxButton * pWndBackwards = S.Id( wxID_BACKWARD ) + S.Id( wxID_BACKWARD ) + .Disable() #if wxUSE_TOOLTIPS .ToolTip( XO("Backwards" ) ) #endif .AddButton( _("<") ); - wxButton * pWndForwards = S.Id( wxID_FORWARD ) + S.Id( wxID_FORWARD ) + .Disable() #if wxUSE_TOOLTIPS .ToolTip( XO("Forwards" ) ) #endif .AddButton( _(">") ); - pWndForwards->Enable( false ); - pWndBackwards->Enable( false ); } S.EndHorizontalLay();