diff --git a/src/ShuttleGui.cpp b/src/ShuttleGui.cpp index 1c265bfa8..522bc5102 100644 --- a/src/ShuttleGui.cpp +++ b/src/ShuttleGui.cpp @@ -1874,30 +1874,11 @@ wxChoice *ShuttleGuiBase::TieChoice( choiceSetting.Read(); const auto &symbols = choiceSetting.GetSymbols(); + const auto &SettingName = choiceSetting.Key(); + const auto &Default = choiceSetting.Default().Internal(); + const auto &Choices = symbols.GetTranslations(); + const auto &InternalChoices = symbols.GetInternals(); - return TieChoice( - Prompt, - choiceSetting.Key(), - choiceSetting.Default().Internal(), - symbols.GetTranslations(), - symbols.GetInternals() - ); -} - -/// Variant of the standard TieChoice which does the two step exchange -/// between gui and stack variable and stack variable and shuttle. -/// @param Prompt The prompt shown beside the control. -/// @param SettingName The setting name as stored in gPrefs -/// @param Default The default internal string value for this control -/// @param Choices An array of choices that appear on screen. -/// @param InternalChoices The corresponding values (as a string array) -wxChoice * ShuttleGuiBase::TieChoice( - const wxString &Prompt, - const wxString &SettingName, - const wxString &Default, - const wxArrayStringEx & Choices, - const wxArrayStringEx & InternalChoices) -{ wxChoice * pChoice=(wxChoice*)NULL; int TempIndex=0; @@ -1935,6 +1916,7 @@ wxChoice * ShuttleGuiBase::TieNumberAsChoice( const std::vector * pInternalChoices) { auto fn = [](int arg){ return wxString::Format( "%d", arg ); }; + wxArrayStringEx InternalChoices; if ( pInternalChoices ) InternalChoices = @@ -1943,13 +1925,25 @@ wxChoice * ShuttleGuiBase::TieNumberAsChoice( for ( int ii = 0; ii < Choices.size(); ++ii ) InternalChoices.push_back( fn( ii ) ); - return ShuttleGuiBase::TieChoice( - Prompt, + long defaultIndex; + if ( pInternalChoices ) + defaultIndex = make_iterator_range( *pInternalChoices ).index( Default ); + else + defaultIndex = Default; + if ( defaultIndex < 0 || defaultIndex >= Choices.size() ) + defaultIndex = -1; + + ChoiceSetting Setting{ SettingName, - fn( Default ), - Choices, - InternalChoices - ); + { + ByColumns, + Choices, + InternalChoices, + }, + defaultIndex + }; + + return ShuttleGuiBase::TieChoice( Prompt, Setting ); } //------------------------------------------------------------------// diff --git a/src/ShuttleGui.h b/src/ShuttleGui.h index 8153ffcc2..7d67ff049 100644 --- a/src/ShuttleGui.h +++ b/src/ShuttleGui.h @@ -232,18 +232,10 @@ public: const wxString &SettingName, const bool bDefault); - // This one is defined in terms of the next and not virtual virtual wxChoice *TieChoice( const wxString &Prompt, const ChoiceSetting &choiceSetting ); - virtual wxChoice * TieChoice( - const wxString &Prompt, - const wxString &SettingName, - const wxString &Default, - const wxArrayStringEx &Choices, - const wxArrayStringEx & InternalChoices ); - // This overload presents what is really a numerical setting as a choice among // commonly used values, but the choice is not necessarily exhaustive. // This behaves just like the previous for building dialogs, but the diff --git a/src/commands/GetInfoCommand.cpp b/src/commands/GetInfoCommand.cpp index 4a6f8b815..3c7d5c471 100644 --- a/src/commands/GetInfoCommand.cpp +++ b/src/commands/GetInfoCommand.cpp @@ -206,12 +206,6 @@ public: const wxString &Prompt, const wxString &SettingName, const bool bDefault) override; - wxChoice * TieChoice( - const wxString &Prompt, - const wxString &SettingName, - const wxString &Default, - const wxArrayStringEx &Choices, - const wxArrayStringEx & InternalChoices ) override; wxChoice * TieNumberAsChoice( const wxString &Prompt, @@ -281,27 +275,6 @@ wxCheckBox * ShuttleGuiGetDefinition::TieCheckBoxOnRight( EndStruct(); return ShuttleGui::TieCheckBoxOnRight( Prompt, SettingName, bDefault ); } -wxChoice * ShuttleGuiGetDefinition::TieChoice( - const wxString &Prompt, - const wxString &SettingName, - const wxString &Default, - const wxArrayStringEx &Choices, - const wxArrayStringEx & InternalChoices ) -{ - StartStruct(); - AddItem( SettingName, "id" ); - AddItem( Prompt, "prompt" ); - AddItem( "enum", "type" ); - AddItem( Default, "default" ); - StartField( "enum" ); - StartArray(); - for( size_t i=0;iSetMinSize(c->GetBestSize()); S.TieNumericTextBox(_("&Maximum effects per group (0 to disable):"), diff --git a/src/prefs/GUIPrefs.cpp b/src/prefs/GUIPrefs.cpp index fb7c8c159..e494b1e67 100644 --- a/src/prefs/GUIPrefs.cpp +++ b/src/prefs/GUIPrefs.cpp @@ -69,7 +69,8 @@ wxString GUIPrefs::HelpPageName() void GUIPrefs::GetRangeChoices( wxArrayStringEx *pChoicesUntranslated, wxArrayStringEx *pChoicesTranslated, - wxArrayStringEx *pCodes + wxArrayStringEx *pCodes, + int *pDefaultRangeIndex ) { static const auto sCodes = { @@ -102,6 +103,9 @@ void GUIPrefs::GetRangeChoices( if (pChoicesTranslated) *pChoicesTranslated = transform_container( sChoices, GetCustomTranslation ); + + if (pDefaultRangeIndex) + *pDefaultRangeIndex = 2; // 60 == ENV_DB_RANGE } void GUIPrefs::Populate() @@ -109,43 +113,7 @@ void GUIPrefs::Populate() // First any pre-processing for constructing the GUI. GetLanguages(mLangCodes, mLangNames); - mHtmlHelpCodes.clear(); - auto values = { - wxT("Local") , - wxT("FromInternet") , - }; - mHtmlHelpCodes.insert( mHtmlHelpCodes.end(), values ); - - mHtmlHelpChoices.clear(); - auto values2 = { - XO("Local") , - XO("From Internet") , - }; - mHtmlHelpChoices.insert( mHtmlHelpChoices.end(), values2 ); - - mThemeCodes.clear(); - mThemeCodes.insert( mThemeCodes.end(), { - wxT("classic") , - wxT("light") , - wxT("dark") , - wxT("high-contrast") , - wxT("custom") , - } ); - - mThemeChoices.clear(); - mThemeChoices.insert( mThemeChoices.end(), { - /* i18n-hint: describing the "classic" or traditional appearance of older versions of Audacity */ - XO("Classic") , - /* i18n-hint: Light meaning opposite of dark */ - XO("Light") , - XO("Dark") , - /* i18n-hint: greater difference between foreground and background colors */ - XO("High Contrast") , - /* i18n-hint: user defined */ - XO("Custom") , - } ); - - GetRangeChoices(&mRangeChoices, nullptr, &mRangeCodes); + GetRangeChoices(&mRangeChoices, nullptr, &mRangeCodes, &mDefaultRangeIndex); #if 0 mLangCodes.insert( mLangCodes.end(), { @@ -169,6 +137,52 @@ void GUIPrefs::Populate() // ----------------------- End of main section -------------- } +ChoiceSetting GUIManualLocation{ + wxT("/GUI/Help"), + { + ByColumns, + { XO("Local") , XO("From Internet") , }, + { wxT("Local") , wxT("FromInternet") , } + }, + 0 // "Local" +}; + +constexpr int defaultTheme = +#ifdef EXPERIMENTAL_DA + 2 // "dark" +#else + 1 // "light" +#endif +; + +ChoiceSetting GUITheme{ + wxT("/GUI/Theme"), + { + ByColumns, + { + /* i18n-hint: describing the "classic" or traditional + appearance of older versions of Audacity */ + XO("Classic") , + /* i18n-hint: Light meaning opposite of dark */ + XO("Light") , + XO("Dark") , + /* i18n-hint: greater difference between foreground and + background colors */ + XO("High Contrast") , + /* i18n-hint: user defined */ + XO("Custom") , + }, + { + wxT("classic") , + wxT("light") , + wxT("dark") , + wxT("high-contrast") , + wxT("custom") , + } + }, + defaultTheme +}; + void GUIPrefs::PopulateOrExchange(ShuttleGui & S) { S.SetBorder(2); @@ -179,36 +193,24 @@ void GUIPrefs::PopulateOrExchange(ShuttleGui & S) S.StartMultiColumn(2); { -#ifdef EXPERIMENTAL_DA - const wxString defaultTheme = wxT("dark"); -#else - const wxString defaultTheme = wxT("light"); -#endif - const wxString defaultRange = wxString::Format(wxT("%d"), ENV_DB_RANGE); + S.TieChoice( _("&Language:"), + { + wxT("/Locale/Language"), + { ByColumns, mLangNames, mLangCodes } + } + ); - S.TieChoice(_("&Language:"), - wxT("/Locale/Language"), - wxT(""), - mLangNames, - mLangCodes); + S.TieChoice( _("Location of &Manual:"), GUIManualLocation); - S.TieChoice(_("Location of &Manual:"), - wxT("/GUI/Help"), - wxT("Local"), - mHtmlHelpChoices, - mHtmlHelpCodes); + S.TieChoice( _("Th&eme:"), GUITheme); - S.TieChoice(_("Th&eme:"), - wxT("/GUI/Theme"), - defaultTheme, - mThemeChoices, - mThemeCodes); - - S.TieChoice(_("Meter dB &range:"), - ENV_DB_KEY, - defaultRange, - mRangeChoices, - mRangeCodes); + S.TieChoice( _("Meter dB &range:"), + { + ENV_DB_KEY, + { ByColumns, mRangeChoices, mRangeCodes }, + mDefaultRangeIndex + } + ); } S.EndMultiColumn(); // S.AddSpace(10); diff --git a/src/prefs/GUIPrefs.h b/src/prefs/GUIPrefs.h index 4157b225e..0606c9f4e 100644 --- a/src/prefs/GUIPrefs.h +++ b/src/prefs/GUIPrefs.h @@ -37,7 +37,9 @@ class GUIPrefs final : public PrefsPanel static void GetRangeChoices( wxArrayStringEx *pChoicesUntranslated, wxArrayStringEx *pChoicesTranslated, - wxArrayStringEx *pCodes); + wxArrayStringEx *pCodes, + int *pDefaultRangeIndex = nullptr + ); // If no input language given, defaults first to choice in preferences, then // to system language. @@ -57,14 +59,9 @@ class GUIPrefs final : public PrefsPanel wxArrayStringEx mLangCodes; wxArrayStringEx mLangNames; - wxArrayStringEx mHtmlHelpCodes; - wxArrayStringEx mHtmlHelpChoices; - - wxArrayStringEx mThemeCodes; - wxArrayStringEx mThemeChoices; - wxArrayStringEx mRangeCodes; wxArrayStringEx mRangeChoices; + int mDefaultRangeIndex; }; /// A PrefsPanel::Factory that creates one GUIPrefs panel. diff --git a/src/prefs/MidiIOPrefs.cpp b/src/prefs/MidiIOPrefs.cpp index 7cb4bd7f9..512c60cb2 100644 --- a/src/prefs/MidiIOPrefs.cpp +++ b/src/prefs/MidiIOPrefs.cpp @@ -138,11 +138,12 @@ void MidiIOPrefs::PopulateOrExchange( ShuttleGui & S ) { { S.Id(HostID); /* i18n-hint: (noun) */ - mHost = S.TieChoice(_("&Host:"), - wxT("/MidiIO/Host"), - wxT(""), - mHostNames, - mHostLabels); + mHost = S.TieChoice( _("&Host:"), + { + wxT("/MidiIO/Host"), + { ByColumns, mHostNames, mHostLabels } + } + ); S.AddPrompt(_("Using: PortMidi")); } diff --git a/src/prefs/TracksBehaviorsPrefs.cpp b/src/prefs/TracksBehaviorsPrefs.cpp index eadad7463..6b6a41845 100644 --- a/src/prefs/TracksBehaviorsPrefs.cpp +++ b/src/prefs/TracksBehaviorsPrefs.cpp @@ -56,14 +56,6 @@ const wxChar *TracksBehaviorsPrefs::ScrollingPreferenceKey() void TracksBehaviorsPrefs::Populate() { - mSoloCodes.push_back(wxT("Simple")); - mSoloCodes.push_back(wxT("Multi")); - mSoloCodes.push_back(wxT("None")); - - mSoloChoices.push_back(XO("Simple")); - mSoloChoices.push_back(XO("Multi-track")); - mSoloChoices.push_back(XO("None")); - //------------------------- Main section -------------------- // Now construct the GUI itself. ShuttleGui S(this, eIsCreatingFromPrefs); @@ -71,6 +63,16 @@ void TracksBehaviorsPrefs::Populate() // ----------------------- End of main section -------------- } +ChoiceSetting TracksBehaviorsSolo{ + wxT("/GUI/Solo"), + { + ByColumns, + { XO("Simple"), XO("Multi-track"), XO("None") }, + { wxT("Simple"), wxT("Multi"), wxT("None") } + }, + 0, // "Simple" +}; + void TracksBehaviorsPrefs::PopulateOrExchange(ShuttleGui & S) { S.SetBorder(2); @@ -113,11 +115,7 @@ void TracksBehaviorsPrefs::PopulateOrExchange(ShuttleGui & S) S.StartMultiColumn(2); { - S.TieChoice(_("Solo &Button:"), - wxT("/GUI/Solo"), - wxT("Standard"), - mSoloChoices, - mSoloCodes); + S.TieChoice( _("Solo &Button:"), TracksBehaviorsSolo); } S.EndMultiColumn(); } diff --git a/src/prefs/TracksBehaviorsPrefs.h b/src/prefs/TracksBehaviorsPrefs.h index 7d62e3f5a..0d6027f79 100644 --- a/src/prefs/TracksBehaviorsPrefs.h +++ b/src/prefs/TracksBehaviorsPrefs.h @@ -38,9 +38,6 @@ class TracksBehaviorsPrefs final : public PrefsPanel private: void Populate(); void PopulateOrExchange(ShuttleGui & S) override; - - wxArrayStringEx mSoloCodes; - wxArrayStringEx mSoloChoices; }; /// A PrefsPanel::Factory that creates one TracksBehaviorsPrefs panel.