1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 16:10:06 +02:00

ShuttleGui::AddChoice takes int to specify selection, with a default...

... This makes things brief and where non-default avoids some repetition of
literal strings
This commit is contained in:
Paul Licameli 2019-02-12 16:30:22 -05:00
parent fbf324f52e
commit dcd82b8ef5
25 changed files with 78 additions and 87 deletions

View File

@ -397,7 +397,9 @@ void DependencyDialog::PopulateOrExchange(ShuttleGui& S)
mFutureActionChoice =
S.Id(FutureActionChoiceID).AddChoice(
_("Whenever a project depends on other files:"),
_("Ask me"), &choices);
&choices,
0 // "Ask me"
);
}
S.EndHorizontalLay();
} else

View File

@ -443,14 +443,14 @@ FreqWindow::FreqWindow(wxWindow * parent, wxWindowID id,
S.AddSpace(5);
mAlgChoice = S.Id(FreqAlgChoiceID).AddChoice(_("&Algorithm:"), wxT(""), &algChoices);
mAlgChoice->SetSelection(mAlg);
mAlgChoice = S.Id(FreqAlgChoiceID)
.AddChoice(_("&Algorithm:"), &algChoices, mAlg);
S.SetSizeHints(wxDefaultCoord, wxDefaultCoord);
S.AddSpace(5);
mSizeChoice = S.Id(FreqSizeChoiceID).AddChoice(_("&Size:"), wxT(""), &sizeChoices);
mSizeChoice->SetSelection(mSize);
mSizeChoice = S.Id(FreqSizeChoiceID)
.AddChoice(_("&Size:"), &sizeChoices, mSize);
S.SetSizeHints(wxDefaultCoord, wxDefaultCoord);
S.AddSpace(5);
@ -466,15 +466,15 @@ FreqWindow::FreqWindow(wxWindow * parent, wxWindowID id,
S.AddSpace(5);
mFuncChoice = S.Id(FreqFuncChoiceID).AddChoice(_("&Function:"), wxT(""), &funcChoices);
mFuncChoice->SetSelection(mFunc);
mFuncChoice = S.Id(FreqFuncChoiceID)
.AddChoice(_("&Function:"), &funcChoices, mFunc);
S.SetSizeHints(wxDefaultCoord, wxDefaultCoord);
mFuncChoice->MoveAfterInTabOrder(mSizeChoice);
S.AddSpace(5);
mAxisChoice = S.Id(FreqAxisChoiceID).AddChoice(_("&Axis:"), wxT(""), &axisChoices);
mAxisChoice->SetSelection(mAxis);
mAxisChoice = S.Id(FreqAxisChoiceID)
.AddChoice(_("&Axis:"), &axisChoices, mAxis);
S.SetSizeHints(wxDefaultCoord, wxDefaultCoord);
mAxisChoice->MoveAfterInTabOrder(mFuncChoice);

View File

@ -77,12 +77,8 @@ LangChoiceDialog::LangChoiceDialog(wxWindow * parent,
{
SetName(GetTitle());
GetLanguages(mLangCodes, mLangNames);
int ndx = make_iterator_range( mLangCodes ).index( GetSystemLanguageCode() );
wxString lang;
if (ndx != wxNOT_FOUND) {
lang = mLangNames[ndx];
}
int lang =
make_iterator_range( mLangCodes ).index( GetSystemLanguageCode() );
ShuttleGui S(this, eIsCreating);
@ -92,8 +88,8 @@ LangChoiceDialog::LangChoiceDialog(wxWindow * parent,
{
S.SetBorder(15);
mChoice = S.AddChoice(_("Choose Language for Audacity to use:"),
lang,
&mLangNames);
&mLangNames,
lang);
}
S.EndVerticalLay();

View File

@ -376,7 +376,8 @@ wxBitmapButton * ShuttleGuiBase::AddBitmapButton(const wxBitmap &Bitmap, int Pos
return pBtn;
}
wxChoice * ShuttleGuiBase::AddChoice( const wxString &Prompt, const wxString &Selected, const wxArrayString * pChoices )
wxChoice * ShuttleGuiBase::AddChoice( const wxString &Prompt,
const wxArrayString * pChoices, int Selected )
{
HandleOptionality( Prompt );
AddPrompt( Prompt );
@ -396,7 +397,8 @@ wxChoice * ShuttleGuiBase::AddChoice( const wxString &Prompt, const wxString &Se
pChoice->SetSizeHints( 180,-1);// Use -1 for 'default size' - Platform specific.
pChoice->SetName(wxStripMenuCodes(Prompt));
pChoice->SetStringSelection( Selected );
if ( Selected >= 0 && Selected < pChoices->size() )
pChoice->SetSelection( Selected );
UpdateSizers();
return pChoice;
@ -1374,17 +1376,12 @@ wxChoice * ShuttleGuiBase::TieChoice(
{
case eIsCreating:
{
if( WrappedRef.IsString() )
pChoice = AddChoice( Prompt, WrappedRef.ReadAsString(), pChoices );
else
{
wxString Temp;
if( pChoices && ( WrappedRef.ReadAsInt() < (int)pChoices->size() ) )
{
Temp = (*pChoices)[WrappedRef.ReadAsInt()];
}
pChoice = AddChoice( Prompt, Temp, pChoices );
if( WrappedRef.IsString() ) {
auto Selected = pChoices->Index( WrappedRef.ReadAsString() );
pChoice = AddChoice( Prompt, pChoices, Selected );
}
else
pChoice = AddChoice( Prompt, pChoices, WrappedRef.ReadAsInt() );
}
break;
// IF setting internal storage from the controls.

View File

@ -110,7 +110,7 @@ public:
wxCheckBox * AddCheckBox( const wxString &Prompt, const wxString &Selected);
wxCheckBox * AddCheckBoxOnRight( const wxString &Prompt, const wxString &Selected);
wxComboBox * AddCombo( const wxString &Prompt, const wxString &Selected,const wxArrayString * pChoices, long style = 0 );
wxChoice * AddChoice( const wxString &Prompt, const wxString &Selected, const wxArrayString * pChoices );
wxChoice * AddChoice( const wxString &Prompt, const wxArrayString * pChoices, int Selected = -1 );
wxMenuBar * AddMenuBar( );
wxMenu * AddMenu( const wxString & Title );
void AddIcon( wxBitmap * pBmp);

View File

@ -941,11 +941,10 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
m_sTimerAfterCompleteOptionsArray.push_back(arrayOptions[2]);
m_sTimerAfterCompleteOptionsArray.push_back(arrayOptions[3]);
#endif
m_sTimerAfterCompleteOption = arrayOptions[iPostTimerRecordAction];
m_pTimerAfterCompleteChoiceCtrl = S.AddChoice(_("After Recording completes:"),
m_sTimerAfterCompleteOption,
&m_sTimerAfterCompleteOptionsArray);
&m_sTimerAfterCompleteOptionsArray,
iPostTimerRecordAction);
}
S.EndMultiColumn();
}

View File

@ -145,7 +145,6 @@ private:
bool m_bProjectAlreadySaved;
// Variables for After Timer Recording Option
wxString m_sTimerAfterCompleteOption;
wxArrayString m_sTimerAfterCompleteOptionsArray;
DECLARE_EVENT_TABLE()

View File

@ -270,7 +270,7 @@ void EffectChangePitch::PopulateOrExchange(ShuttleGui & S)
{
S.StartMultiColumn(6, wxALIGN_CENTER); // 6 controls, because each AddChoice adds a wxStaticText and a wxChoice.
{
m_pChoice_FromPitch = S.Id(ID_FromPitch).AddChoice(_("from"), wxT(""), &pitch);
m_pChoice_FromPitch = S.Id(ID_FromPitch).AddChoice(_("from"), &pitch);
m_pChoice_FromPitch->SetName(_("from"));
m_pChoice_FromPitch->SetSizeHints(80, -1);
@ -278,7 +278,7 @@ void EffectChangePitch::PopulateOrExchange(ShuttleGui & S)
m_pSpin_FromOctave->SetName(_("from Octave"));
m_pSpin_FromOctave->SetSizeHints(50, -1);
m_pChoice_ToPitch = S.Id(ID_ToPitch).AddChoice(_("to"), wxT(""), &pitch);
m_pChoice_ToPitch = S.Id(ID_ToPitch).AddChoice(_("to"), &pitch);
m_pChoice_ToPitch->SetName(_("to"));
m_pChoice_ToPitch->SetSizeHints(80, -1);

View File

@ -350,12 +350,12 @@ void EffectChangeSpeed::PopulateOrExchange(ShuttleGui & S)
}
mpChoice_FromVinyl =
S.Id(ID_FromVinyl).AddChoice(_("from"), wxT(""), &vinylChoices);
S.Id(ID_FromVinyl).AddChoice(_("from"), &vinylChoices);
mpChoice_FromVinyl->SetName(_("From rpm"));
mpChoice_FromVinyl->SetSizeHints(100, -1);
mpChoice_ToVinyl =
S.Id(ID_ToVinyl).AddChoice(_("to"), wxT(""), &vinylChoices);
S.Id(ID_ToVinyl).AddChoice(_("to"), &vinylChoices);
mpChoice_ToVinyl->SetName(_("To rpm"));
mpChoice_ToVinyl->SetSizeHints(100, -1);
}

View File

@ -367,7 +367,7 @@ void EffectDistortion::PopulateOrExchange(ShuttleGui & S)
S.StartMultiColumn(4, wxCENTER);
{
auto tableTypes = LocalizedStrings(kTableTypeStrings, nTableTypes);
mTypeChoiceCtrl = S.Id(ID_Type).AddChoice(_("Distortion type:"), wxT(""), &tableTypes);
mTypeChoiceCtrl = S.Id(ID_Type).AddChoice(_("Distortion type:"), &tableTypes);
mTypeChoiceCtrl->SetValidator(wxGenericValidator(&mParams.mTableChoiceIndx));
S.SetSizeHints(-1, -1);

View File

@ -3920,8 +3920,7 @@ EffectPresetsDialog::EffectPresetsDialog(wxWindow *parent, Effect *effect)
wxArrayString empty;
S.AddPrompt(_("Type:"));
mType = S.Id(ID_Type).AddChoice( {}, wxT(""), &empty);
mType->SetSelection(0);
mType = S.Id(ID_Type).AddChoice( {}, &empty, 0 );
S.AddPrompt(_("&Preset:"));
mPresets = S.AddListBox(&empty, wxLB_SINGLE | wxLB_NEEDED_SB );

View File

@ -762,9 +762,8 @@ void EffectEqualization::PopulateOrExchange(ShuttleGui & S)
auto interpolations =
LocalizedStrings(kInterpStrings, nInterpolations);
mInterpChoice = S.Id(ID_Interp).AddChoice( {}, wxT(""), &interpolations);
mInterpChoice = S.Id(ID_Interp).AddChoice( {}, &interpolations, 0 );
mInterpChoice->SetName(_("Interpolation type"));
mInterpChoice->SetSelection(0);
}
S.EndHorizontalLay();
@ -836,7 +835,7 @@ void EffectEqualization::PopulateOrExchange(ShuttleGui & S)
curves.push_back(mCurves[ i ].Name);
}
mCurve = S.Id(ID_Curve).AddChoice( {}, wxT(""), &curves);
mCurve = S.Id(ID_Curve).AddChoice( {}, &curves );
mCurve->SetName(_("Select Curve"));
}
S.EndHorizontalLay();

View File

@ -224,7 +224,8 @@ void EffectNoise::PopulateOrExchange(ShuttleGui & S)
S.StartMultiColumn(2, wxCENTER);
{
auto typeChoices = LocalizedStrings(kTypeStrings, nTypes);
S.AddChoice(_("Noise type:"), wxT(""), &typeChoices)->SetValidator(wxGenericValidator(&mType));
S.AddChoice(_("Noise type:"), &typeChoices)
->SetValidator(wxGenericValidator(&mType));
FloatingPointValidator<double> vldAmp(6, &mAmp, NumValidatorStyle::NO_TRAILING_ZEROES);
vldAmp.SetRange(MIN_Amp, MAX_Amp);

View File

@ -462,7 +462,8 @@ void EffectScienFilter::PopulateOrExchange(ShuttleGui & S)
wxASSERT(nTypes == WXSIZEOF(kTypeStrings));
auto typeChoices = LocalizedStrings(kTypeStrings, nTypes);
mFilterTypeCtl = S.Id(ID_Type).AddChoice(_("&Filter Type:"), wxT(""), &typeChoices);
mFilterTypeCtl = S.Id(ID_Type)
.AddChoice(_("&Filter Type:"), &typeChoices);
mFilterTypeCtl->SetValidator(wxGenericValidator(&mFilterType));
S.SetSizeHints(-1, -1);
@ -472,7 +473,7 @@ void EffectScienFilter::PopulateOrExchange(ShuttleGui & S)
orders.push_back(wxString::Format(wxT("%d"), i));
}
/*i18n-hint: 'Order' means the complexity of the filter, and is a number between 1 and 10.*/
mFilterOrderCtl = S.Id(ID_Order).AddChoice(_("O&rder:"), wxT(""), &orders);
mFilterOrderCtl = S.Id(ID_Order).AddChoice(_("O&rder:"), &orders);
mFilterOrderCtl->SetValidator(wxGenericValidator(&mOrderIndex));
S.SetSizeHints(-1, -1);
S.AddSpace(1, 1);
@ -489,7 +490,8 @@ void EffectScienFilter::PopulateOrExchange(ShuttleGui & S)
wxASSERT(nSubTypes == WXSIZEOF(kSubTypeStrings));
auto subTypeChoices = LocalizedStrings(kSubTypeStrings, nSubTypes);
mFilterSubTypeCtl = S.Id(ID_SubType).AddChoice(_("&Subtype:"), wxT(""), &subTypeChoices);
mFilterSubTypeCtl = S.Id(ID_SubType)
.AddChoice(_("&Subtype:"), &subTypeChoices);
mFilterSubTypeCtl->SetValidator(wxGenericValidator(&mFilterSubtype));
S.SetSizeHints(-1, -1);

View File

@ -334,7 +334,7 @@ void EffectToneGen::PopulateOrExchange(ShuttleGui & S)
S.StartMultiColumn(2, wxCENTER);
{
auto waveforms = LocalizedStrings(kWaveStrings, nWaveforms);
wxChoice *c = S.AddChoice(_("Waveform:"), wxT(""), &waveforms);
wxChoice *c = S.AddChoice(_("Waveform:"), &waveforms);
c->SetValidator(wxGenericValidator(&mWaveform));
if (mChirp)
@ -407,7 +407,7 @@ void EffectToneGen::PopulateOrExchange(ShuttleGui & S)
S.EndHorizontalLay();
auto interpolations = LocalizedStrings(kInterStrings, nInterpolations);
c = S.AddChoice(_("Interpolation:"), wxT(""), &interpolations);
c = S.AddChoice(_("Interpolation:"), &interpolations);
c->SetValidator(wxGenericValidator(&mInterpolation));
}
else

View File

@ -775,7 +775,7 @@ void EffectTruncSilence::PopulateOrExchange(ShuttleGui & S)
{
// Action choices
auto actionChoices = LocalizedStrings(kActionStrings, nActions);
mActionChoice = S.AddChoice( {}, wxT(""), &actionChoices);
mActionChoice = S.AddChoice( {}, &actionChoices );
mActionChoice->SetValidator(wxGenericValidator(&mActionIndex));
S.SetSizeHints(-1, -1);
}

View File

@ -2609,7 +2609,7 @@ void NyquistEffect::BuildEffectWindow(ShuttleGui & S)
auto choices =
LocalizedStrings(ctrl.choices.data(), ctrl.choices.size());
S.Id(ID_Choice + i).AddChoice( {}, wxT(""), &choices);
S.Id(ID_Choice + i).AddChoice( {}, &choices );
}
else if (ctrl.type == NYQ_CTRL_TIME)
{

View File

@ -567,7 +567,11 @@ void VampEffect::PopulateOrExchange(ShuttleGui & S)
S.AddPrompt(_("Program"));
S.Id(ID_Program);
mProgram = S.AddChoice( {}, currentProgram, &choices);
mProgram = S.AddChoice(
{},
&choices,
choices.Index( currentProgram )
);
mProgram->SetName(_("Program"));
mProgram->SetSizeHints(-1, -1);
wxSizer *s = mProgram->GetContainingSizer();
@ -624,20 +628,20 @@ void VampEffect::PopulateOrExchange(ShuttleGui & S)
!mParameters[p].valueNames.empty())
{
wxArrayString choices;
wxString selected;
int selected = -1;
for (size_t i = 0, cnt = mParameters[p].valueNames.size(); i < cnt; i++)
{
wxString choice = wxString::FromUTF8(mParameters[p].valueNames[i].c_str());
if (size_t(value - mParameters[p].minValue + 0.5) == i)
{
selected = choice;
selected = i;
}
choices.push_back(choice);
}
S.Id(ID_Choices + p);
mChoices[p] = S.AddChoice( {}, selected, &choices);
mChoices[p] = S.AddChoice( {}, &choices, selected );
mChoices[p]->SetName(labelText);
mChoices[p]->SetSizeHints(-1, -1);
if (!tip.empty())

View File

@ -1020,7 +1020,7 @@ int ExportFFmpeg::AskResample(int bitrate, int rate, int lowrate, int highrate,
S.EndHorizontalLay();
wxArrayString choices;
wxString selected = wxT("");
int selected = -1;
for (int i = 0; sampRates[i] > 0; i++)
{
int label = sampRates[i];
@ -1030,21 +1030,19 @@ int ExportFFmpeg::AskResample(int bitrate, int rate, int lowrate, int highrate,
choices.push_back(name);
if (label <= rate)
{
selected = name;
selected = i;
}
}
}
if (selected.empty())
{
selected = choices[0];
}
if (selected == -1)
selected = 0;
S.StartHorizontalLay(wxALIGN_CENTER, false);
{
choice = S.AddChoice(_("Sample Rates"),
selected,
&choices);
&choices,
selected);
}
S.EndHorizontalLay();
}

View File

@ -2002,26 +2002,26 @@ int ExportMP3::AskResample(int bitrate, int rate, int lowrate, int highrate)
S.EndHorizontalLay();
wxArrayString choices;
wxString selected;
int selected = -1;
for (size_t i = 0; i < WXSIZEOF(sampRates); i++) {
int label = sampRates[i].label;
if (label >= lowrate && label <= highrate) {
choices.push_back(sampRates[i].name);
if (label <= rate) {
selected = sampRates[i].name;
selected = i;
}
}
}
if (selected.empty()) {
selected = choices[0];
if (selected == -1) {
selected = 0;
}
S.StartHorizontalLay(wxALIGN_CENTER, false);
{
choice = S.AddChoice(_("Sample Rates"),
selected,
&choices);
&choices,
selected);
}
S.EndHorizontalLay();
}

View File

@ -191,12 +191,12 @@ void ExportPCMOptions::PopulateOrExchange(ShuttleGui & S)
S.SetStretchyCol(1);
mHeaderChoice = S.Id(ID_HEADER_CHOICE)
.AddChoice(_("Header:"),
mHeaderNames[mHeaderFromChoice],
&mHeaderNames);
&mHeaderNames,
mHeaderFromChoice);
mEncodingChoice = S.Id(ID_ENCODING_CHOICE)
.AddChoice(_("Encoding:"),
mEncodingNames[mEncodingFromChoice],
&mEncodingNames);
&mEncodingNames,
mEncodingFromChoice);
}
S.EndMultiColumn();
}

View File

@ -398,14 +398,14 @@ ImportRawDialog::ImportRawDialog(wxWindow * parent,
S.StartTwoColumn();
{
mEncodingChoice = S.Id(ChoiceID).AddChoice(_("Encoding:"),
encodings[selection],
&encodings);
&encodings,
selection);
mEndianChoice = S.Id(ChoiceID).AddChoice(_("Byte order:"),
endians[endian],
&endians);
&endians,
endian);
mChannelChoice = S.Id(ChoiceID).AddChoice(_("Channels:"),
chans[mChannels-1],
&chans);
&chans,
mChannels - 1);
}
S.EndTwoColumn();

View File

@ -137,7 +137,6 @@ void DevicePrefs::PopulateOrExchange(ShuttleGui & S)
{
S.Id(PlayID);
mPlay = S.AddChoice(_("&Device:"),
wxEmptyString,
&empty);
}
S.EndMultiColumn();
@ -150,12 +149,10 @@ void DevicePrefs::PopulateOrExchange(ShuttleGui & S)
{
S.Id(RecordID);
mRecord = S.AddChoice(_("De&vice:"),
wxEmptyString,
&empty);
S.Id(ChannelsID);
mChannels = S.AddChoice(_("Cha&nnels:"),
wxEmptyString,
&empty);
}
S.EndMultiColumn();

View File

@ -141,7 +141,6 @@ void MidiIOPrefs::PopulateOrExchange( ShuttleGui & S ) {
{
S.Id(PlayID);
mPlay = S.AddChoice(_("&Device:"),
wxEmptyString,
&empty);
int latency = gPrefs->Read(wxT("/MidiIO/OutputLatency"),
DEFAULT_SYNTH_LATENCY);
@ -159,7 +158,6 @@ void MidiIOPrefs::PopulateOrExchange( ShuttleGui & S ) {
{
S.Id(RecordID);
mRecord = S.AddChoice(_("De&vice:"),
wxEmptyString,
&empty);
S.Id(ChannelsID);

View File

@ -822,8 +822,8 @@ void DeviceToolBar::ShowComboDialog(wxChoice *combo, const wxString &title)
S.StartHorizontalLay(wxCENTER, false);
{
c = S.AddChoice(combo->GetName(),
combo->GetStringSelection(),
&inputSources);
&inputSources,
combo->GetSelection());
}
S.EndHorizontalLay();
}