Skip to content

Commit d98e41a

Browse files
committed
Define and use ShuttleGui::Disable; remove EnableCtrl
1 parent c72dbf5 commit d98e41a

12 files changed

+85
-81
lines changed

src/BatchCommandDialog.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@ void MacroCommandDialog::PopulateOrExchange(ShuttleGui &S)
8989
S.SetStretchyCol(1);
9090
mCommand = S.AddTextBox(_("&Command"), wxT(""), 20);
9191
mCommand->SetEditable(false);
92-
mEditParams = S.Id(EditParamsButtonID).AddButton(_("&Edit Parameters"));
93-
mEditParams->Enable(false); // disable button as box is empty
94-
mUsePreset = S.Id(UsePresetButtonID).AddButton(_("&Use Preset"));
95-
mUsePreset->Enable(false); // disable button as box is empty
92+
mEditParams = S.Id(EditParamsButtonID)
93+
.Disable() // disable button as box is empty
94+
.AddButton(_("&Edit Parameters"));
95+
mUsePreset = S.Id(UsePresetButtonID)
96+
.Disable() // disable button as box is empty
97+
.AddButton(_("&Use Preset"));
9698
}
9799
S.EndMultiColumn();
98100

src/BatchProcessDialog.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,12 @@ void MacrosWindow::PopulateOrExchange(ShuttleGui & S)
632632
mRestore = S.Id(RestoreButtonID).AddButton(_("Re&store"));
633633
// Not yet ready for prime time.
634634
#if 0
635-
S.Id(ImportButtonID).AddButton(_("I&mport..."))->Enable( false);
636-
S.Id(ExportButtonID).AddButton(_("E&xport..."))->Enable( false);
635+
S.Id(ImportButtonID)
636+
.Disable()
637+
.AddButton(_("I&mport..."));
638+
S.Id(ExportButtonID)
639+
.Disable()
640+
.AddButton(_("E&xport..."));
637641
#endif
638642
}
639643
S.EndVerticalLay();

src/Dependencies.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,10 @@ void DependencyDialog::PopulateOrExchange(ShuttleGui& S)
365365
mCopySelectedFilesButton =
366366
S.Id(CopySelectedFilesButtonID)
367367
.Focus()
368+
.Disable(mFileListCtrl->GetSelectedItemCount() <= 0)
368369
.AddButton(
369370
_("Copy Selected Files"),
370371
wxALIGN_LEFT, true);
371-
mCopySelectedFilesButton->Enable(
372-
mFileListCtrl->GetSelectedItemCount() > 0);
373372
}
374373
S.EndStatic();
375374

@@ -383,11 +382,12 @@ void DependencyDialog::PopulateOrExchange(ShuttleGui& S)
383382
S.Id(wxID_NO).AddButton(_("Do Not Copy"));
384383

385384
mCopyAllFilesButton =
386-
S.Id(wxID_YES).AddButton(_("Copy All Files (Safer)"));
385+
S.Id(wxID_YES)
386+
// Enabling mCopyAllFilesButton is also done in PopulateList,
387+
// but at its call above, mCopyAllFilesButton does not yet exist.
388+
.Disable(mHasMissingFiles)
389+
.AddButton(_("Copy All Files (Safer)"));
387390

388-
// Enabling mCopyAllFilesButton is also done in PopulateList,
389-
// but at its call above, mCopyAllFilesButton does not yet exist.
390-
mCopyAllFilesButton->Enable(!mHasMissingFiles);
391391
}
392392
S.EndHorizontalLay();
393393

src/ShuttleGui.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,6 @@ void ShuttleGuiBase::ResetId()
184184
miIdNext = 3000;
185185
}
186186

187-
void ShuttleGuiBase::EnableCtrl( bool bEnable )
188-
{
189-
if( mShuttleMode != eIsCreating )
190-
return;
191-
mpLastWind->Enable( bEnable );
192-
}
193-
194187
/// Used to modify an already placed Window.
195188
void ShuttleGuiBase::SetSizeHints( int minX, int minY )
196189
{
@@ -2087,6 +2080,9 @@ void ShuttleGuiBase::UpdateSizersCore(bool bPrepend, int Flags, bool prompt)
20872080
if (mItem.mFocused)
20882081
mpWind->SetFocus();
20892082

2083+
if (mItem.mDisabled)
2084+
mpWind->Enable( false );
2085+
20902086
// Reset to defaults
20912087
mItem = {};
20922088
}

src/ShuttleGui.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ struct Item {
174174
return std::move( *this );
175175
}
176176

177+
Item&& Disable( bool disabled = true ) &&
178+
{
179+
mDisabled = disabled;
180+
return std::move( *this );
181+
}
182+
177183
std::function< void(wxWindow*) > mValidatorSetter;
178184
TranslatableString mToolTip;
179185
TranslatableString mName;
@@ -182,6 +188,7 @@ struct Item {
182188
long miStyle{};
183189

184190
bool mFocused { false };
191+
bool mDisabled { false };
185192
};
186193

187194
}
@@ -387,7 +394,6 @@ class AUDACITY_DLL_API ShuttleGuiBase /* not final */
387394
const int max,
388395
const int min);
389396
//-- End of variants.
390-
void EnableCtrl( bool bEnable );
391397
void SetSizeHints( int minX, int minY );
392398
void SetBorder( int Border ) {miBorder = Border;};
393399
void SetSizerProportion( int iProp ) {miSizerProp = iProp;};
@@ -545,6 +551,12 @@ class AUDACITY_DLL_API ShuttleGui /* not final */ : public ShuttleGuiBase
545551
return *this;
546552
}
547553

554+
ShuttleGui &Disable( bool disabled = true )
555+
{
556+
std::move( mItem ).Disable( disabled );
557+
return *this;
558+
}
559+
548560
ShuttleGui & ToolTip( const TranslatableString &tip )
549561
{
550562
std::move( mItem ).ToolTip( tip );

src/effects/Amplify.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,8 @@ void EffectAmplify::PopulateOrExchange(ShuttleGui & S)
271271
// Clipping
272272
S.StartHorizontalLay(wxCENTER);
273273
{
274-
mClip = S.Id(ID_Clip).AddCheckBox(_("Allow clipping"), false);
275-
if (IsBatchProcessing())
276-
{
277-
mClip->Enable(false);
278-
mCanClip = true;
279-
}
274+
mClip = S.Id(ID_Clip).Disable( mCanClip = IsBatchProcessing() )
275+
.AddCheckBox(_("Allow clipping"), false);
280276
}
281277
S.EndHorizontalLay();
282278
}

src/effects/ChangeTempo.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ void EffectChangeTempo::PopulateOrExchange(ShuttleGui & S)
285285
S.StartHorizontalLay(wxALIGN_CENTER);
286286
{
287287
m_pTextCtrl_FromLength = S.Id(ID_FromLength)
288+
.Disable() // Disable because the value comes from the
289+
// user selection.
288290
.Validator<FloatingPointValidator<double>>(
289291
precision, &m_FromLength,
290292
NumValidatorStyle::TWO_TRAILING_ZEROES)
291293
/* i18n-hint: changing a quantity "from" one value "to" another */
292294
.AddTextBox(_("from"), wxT(""), 12);
293-
m_pTextCtrl_FromLength->Enable(false); // Disable because the value comes from the user selection.
294-
295295
m_pTextCtrl_ToLength = S.Id(ID_ToLength)
296296
.Validator<FloatingPointValidator<double>>(
297297
2, &m_ToLength, NumValidatorStyle::TWO_TRAILING_ZEROES,

src/effects/Equalization.cpp

+6-12
Original file line numberDiff line numberDiff line change
@@ -1069,29 +1069,23 @@ void EffectEqualization::PopulateOrExchange(ShuttleGui & S)
10691069
.AddRadioButton(_("D&efault"),
10701070
0, value);
10711071
mMathProcessingType[1] = S.Id(ID_SSE)
1072+
.Disable(!EffectEqualization48x::GetMathCaps()->SSE)
10721073
.AddRadioButtonToGroup(_("&SSE"),
10731074
1, value);
10741075
mMathProcessingType[2] = S.Id(ID_SSEThreaded)
1076+
.Disable(!EffectEqualization48x::GetMathCaps()->SSE)
10751077
.AddRadioButtonToGroup(_("SSE &Threaded"),
10761078
2, value);
10771079
mMathProcessingType[3] = S.Id(ID_AVX)
1080+
// not implemented
1081+
.Disable(true /* !EffectEqualization48x::GetMathCaps()->AVX */)
10781082
.AddRadioButtonToGroup(_("A&VX"),
10791083
3, value);
10801084
mMathProcessingType[4] = S.Id(ID_AVXThreaded)
1085+
// not implemented
1086+
.Disable(true /* !EffectEqualization48x::GetMathCaps()->AVX */)
10811087
.AddRadioButtonToGroup(_("AV&X Threaded"),
10821088
4, value);
1083-
1084-
if (!EffectEqualization48x::GetMathCaps()->SSE)
1085-
{
1086-
mMathProcessingType[1]->Disable();
1087-
mMathProcessingType[2]->Disable();
1088-
}
1089-
if (true) //!EffectEqualization48x::GetMathCaps()->AVX) { not implemented
1090-
{
1091-
mMathProcessingType[3]->Disable();
1092-
mMathProcessingType[4]->Disable();
1093-
}
1094-
10951089
S.Id(ID_Bench).AddButton(_("&Bench"));
10961090
}
10971091
S.EndHorizontalLay();

src/export/ExportMP3.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -392,21 +392,21 @@ void ExportMP3Options::PopulateOrExchange(ShuttleGui & S)
392392
codes
393393
);
394394

395-
mMode = S.TieNumberAsChoice(
396-
_("Variable Speed:"),
397-
{ wxT("/FileFormats/MP3VarMode"), ROUTINE_FAST },
398-
varModeNames );
399-
mMode->Enable(enable);
395+
mMode = S.Disable(!enable)
396+
.TieNumberAsChoice(
397+
_("Variable Speed:"),
398+
{ wxT("/FileFormats/MP3VarMode"), ROUTINE_FAST },
399+
varModeNames );
400400

401401
S.AddPrompt(_("Channel Mode:"));
402402
S.StartMultiColumn(3, wxEXPAND);
403403
{
404404
S.StartRadioButtonGroup(MP3ChannelModeSetting);
405405
{
406-
mJoint = S.TieRadioButton();
407-
mStereo = S.TieRadioButton();
408-
mJoint->Enable(!mono);
409-
mStereo->Enable(!mono);
406+
mJoint = S.Disable(mono)
407+
.TieRadioButton();
408+
mStereo = S.Disable(mono)
409+
.TieRadioButton();
410410
}
411411
S.EndRadioButtonGroup();
412412

src/prefs/LibraryPrefs.cpp

+26-25
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,23 @@ void LibraryPrefs::PopulateOrExchange(ShuttleGui & S)
113113
S.AddVariableText(_("LAME MP3 Library:"),
114114
true,
115115
wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL);
116-
wxButton *locate_button = S.Id(ID_MP3_FIND_BUTTON).AddButton(_("&Locate..."),
117-
wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL);
116+
S.Id(ID_MP3_FIND_BUTTON)
117+
#ifdef DISABLE_DYNAMIC_LOADING_LAME
118+
.Disable()
119+
#endif
120+
.AddButton(_("&Locate..."),
121+
wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL);
118122
S.AddVariableText(_("LAME MP3 Library:"),
119123
true,
120124
wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL);
121-
wxButton *download_button = S.Id(ID_MP3_DOWN_BUTTON).AddButton(_("&Download"),
122-
wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL);
123-
125+
S.Id(ID_MP3_DOWN_BUTTON)
124126
#ifdef DISABLE_DYNAMIC_LOADING_LAME
125-
locate_button->Enable(FALSE);
126-
download_button->Enable(FALSE);
127-
#else
128-
(void)locate_button;
129-
(void)download_button;
130-
#endif // DISABLE_DYNAMIC_LOADING_LAME
127+
.Disable()
131128
#endif
129+
.AddButton(_("&Download"),
130+
wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL);
132131

132+
#endif
133133
}
134134
S.EndTwoColumn();
135135
}
@@ -155,31 +155,32 @@ void LibraryPrefs::PopulateOrExchange(ShuttleGui & S)
155155
true,
156156
wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL);
157157
S.Id(ID_FFMPEG_FIND_BUTTON);
158-
wxButton *bfnd = S.AddButton(_("Loca&te..."),
159-
wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL);
158+
S
159+
#if !defined(USE_FFMPEG) || defined(DISABLE_DYNAMIC_LOADING_FFMPEG)
160+
.Disable()
161+
#endif
162+
.AddButton(_("Loca&te..."),
163+
wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL);
160164
S.AddVariableText(_("FFmpeg Library:"),
161165
true,
162166
wxALL | wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL);
163167
S.Id(ID_FFMPEG_DOWN_BUTTON);
164-
wxButton *bdwn = S.AddButton(_("Dow&nload"),
165-
wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL);
168+
S
166169
#if !defined(USE_FFMPEG) || defined(DISABLE_DYNAMIC_LOADING_FFMPEG)
167-
bdwn->Enable(FALSE);
168-
bfnd->Enable(FALSE);
169-
#else
170-
// fix compilation warnings about unused variables
171-
wxUnusedVar(bfnd);
172-
wxUnusedVar(bdwn);
170+
.Disable()
173171
#endif
172+
.AddButton(_("Dow&nload"),
173+
wxALL | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL);
174174
}
175175
S.EndTwoColumn();
176176
#ifdef EXPERIMENTAL_OD_FFMPEG
177-
wxCheckBox* checkbox = S.TieCheckBox(_("Allow &background on-demand loading"),
178-
wxT("/Library/FFmpegOnDemand"),
179-
false);
177+
S
180178
#if !defined(USE_FFMPEG)
181-
if( checkbox ) checkbox->Enable(FALSE);
179+
.Disable()
182180
#endif
181+
.TieCheckBox(_("Allow &background on-demand loading"),
182+
wxT("/Library/FFmpegOnDemand"),
183+
false);
183184
#endif
184185
}
185186
S.EndStatic();

src/prefs/RecordingPrefs.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,11 @@ void RecordingPrefs::PopulateOrExchange(ShuttleGui & S)
159159

160160
mToggleCustomName = S
161161
.Name(XO("Custom name text"))
162+
.Disable(!mUseCustomTrackName)
162163
.TieTextBox( {},
163164
{wxT("/GUI/TrackNames/RecodingTrackName"),
164165
_("Recorded_Audio")},
165-
30);
166-
if ( mToggleCustomName )
167-
mToggleCustomName->Enable(mUseCustomTrackName);
166+
30);
168167
}
169168
S.EndMultiColumn();
170169

src/widgets/HelpSystem.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,18 @@ void HelpSystem::ShowHtmlText(wxWindow *pParent,
166166
{
167167
S.StartHorizontalLay( wxEXPAND, false );
168168
{
169-
wxButton * pWndBackwards = S.Id( wxID_BACKWARD )
169+
S.Id( wxID_BACKWARD )
170+
.Disable()
170171
#if wxUSE_TOOLTIPS
171172
.ToolTip( XO("Backwards" ) )
172173
#endif
173174
.AddButton( _("<") );
174-
wxButton * pWndForwards = S.Id( wxID_FORWARD )
175+
S.Id( wxID_FORWARD )
176+
.Disable()
175177
#if wxUSE_TOOLTIPS
176178
.ToolTip( XO("Forwards" ) )
177179
#endif
178180
.AddButton( _(">") );
179-
pWndForwards->Enable( false );
180-
pWndBackwards->Enable( false );
181181
}
182182
S.EndHorizontalLay();
183183

0 commit comments

Comments
 (0)