diff --git a/src/ShuttleGui.cpp b/src/ShuttleGui.cpp index a6dcbf773..9dcbfd67b 100644 --- a/src/ShuttleGui.cpp +++ b/src/ShuttleGui.cpp @@ -95,6 +95,7 @@ for registering for changes. #include "Audacity.h" #include "Experimental.h" +#include "Prefs.h" #include "Shuttle.h" #include "ShuttleGui.h" @@ -106,6 +107,7 @@ for registering for changes. #include #include #include +#include "../include/audacity/IdentInterface.h" #include "Internat.h" #include "WrappedType.h" #include "widgets/wxPanelWrapper.h" @@ -1847,32 +1849,55 @@ wxTextCtrl * ShuttleGuiBase::TieNumericTextBox( return pText; } +/// 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 Setting Encapsulates setting name, internal and visible +/// choice strings, and a designation of one of +/// those as default. +wxChoice *ShuttleGuiBase::TieChoice( + const wxString &Prompt, + EnumSetting &enumSetting ) +{ + // Do this to force any needed migrations first + enumSetting.Read(); + + wxArrayString visibleChoices, internalChoices; + for (const auto &ident : enumSetting) { + visibleChoices.push_back( ident.Translation() ); + internalChoices.push_back( ident.Internal() ); + } + return TieChoice( + Prompt, enumSetting.Key(), enumSetting.Default().Translation(), + visibleChoices, internalChoices ); +} + /// 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 value for this control (translated) /// @param Choices An array of choices that appear on screen. -/// @param TranslatedChoices The corresponding values (as a string array) +/// @param InternalChoices The corresponding values (as a string array) wxChoice * ShuttleGuiBase::TieChoice( const wxString &Prompt, const wxString &SettingName, const wxString &Default, const wxArrayString & Choices, - const wxArrayString & TranslatedChoices) + const wxArrayString & InternalChoices) { wxChoice * pChoice=(wxChoice*)NULL; int TempIndex=0; -// int TempIndex = TranslateToIndex( Default, TranslatedChoices ); +// int TempIndex = TranslateToIndex( Default, InternalChoices ); wxString TempStr = Default; WrappedType WrappedRef( TempStr ); // Get from prefs does 1 and 2. // Put to prefs does 2 and 3. if( DoStep(1) ) DoDataShuttle( SettingName, WrappedRef ); // Get Index from Prefs. - if( DoStep(1) ) TempIndex = TranslateToIndex( TempStr, TranslatedChoices ); // To an index + if( DoStep(1) ) TempIndex = TranslateToIndex( TempStr, InternalChoices ); // To an index if( DoStep(2) ) pChoice = TieChoice( Prompt, TempIndex, &Choices ); // Get/Put index from GUI. - if( DoStep(3) ) TempStr = TranslateFromIndex( TempIndex, TranslatedChoices ); // To a string + if( DoStep(3) ) TempStr = TranslateFromIndex( TempIndex, InternalChoices ); // To a string if( DoStep(3) ) DoDataShuttle( SettingName, WrappedRef ); // Put into Prefs. return pChoice; } @@ -1885,13 +1910,13 @@ wxChoice * ShuttleGuiBase::TieChoice( /// @param SettingName The setting name as stored in gPrefs /// @param Default The default value for this control (translated) /// @param Choices An array of choices that appear on screen. -/// @param TranslatedChoices The correcponding values (as an integer array) +/// @param InternalChoices The corresponding values (as an integer array) wxChoice * ShuttleGuiBase::TieChoice( const wxString &Prompt, const wxString &SettingName, const int Default, const wxArrayString & Choices, - const std::vector & TranslatedChoices) + const std::vector & InternalChoices) { wxChoice * pChoice=(wxChoice*)NULL; @@ -1901,9 +1926,9 @@ wxChoice * ShuttleGuiBase::TieChoice( // Get from prefs does 1 and 2. // Put to prefs does 2 and 3. if( DoStep(1) ) DoDataShuttle( SettingName, WrappedRef ); // Get Int from Prefs. - if( DoStep(1) ) TempIndex = TranslateToIndex( TranslatedInt, TranslatedChoices ); // Int to an index. + if( DoStep(1) ) TempIndex = TranslateToIndex( TranslatedInt, InternalChoices ); // Int to an index. if( DoStep(2) ) pChoice = TieChoice( Prompt, TempIndex, &Choices ); // Get/Put index from GUI. - if( DoStep(3) ) TranslatedInt = TranslateFromIndex( TempIndex, TranslatedChoices ); // Index to int + if( DoStep(3) ) TranslatedInt = TranslateFromIndex( TempIndex, InternalChoices ); // Index to int if( DoStep(3) ) DoDataShuttle( SettingName, WrappedRef ); // Put into Prefs. return pChoice; } @@ -2391,7 +2416,7 @@ wxChoice * ShuttleGuiGetDefinition::TieChoice( const wxString &SettingName, const wxString &Default, const wxArrayString &Choices, - const wxArrayString & TranslatedChoices ) + const wxArrayString & InternalChoices ) { StartStruct(); AddItem( SettingName, "id" ); @@ -2405,14 +2430,14 @@ wxChoice * ShuttleGuiGetDefinition::TieChoice( EndArray(); EndField(); EndStruct(); - return ShuttleGui::TieChoice( Prompt, SettingName, Default, Choices, TranslatedChoices ); + return ShuttleGui::TieChoice( Prompt, SettingName, Default, Choices, InternalChoices ); } wxChoice * ShuttleGuiGetDefinition::TieChoice( const wxString &Prompt, const wxString &SettingName, const int Default, const wxArrayString & Choices, - const std::vector & TranslatedChoices) + const std::vector & InternalChoices) { StartStruct(); AddItem( SettingName, "id" ); @@ -2426,7 +2451,7 @@ wxChoice * ShuttleGuiGetDefinition::TieChoice( EndArray(); EndField(); EndStruct(); - return ShuttleGui::TieChoice( Prompt, SettingName, Default, Choices, TranslatedChoices ); + return ShuttleGui::TieChoice( Prompt, SettingName, Default, Choices, InternalChoices ); } wxTextCtrl * ShuttleGuiGetDefinition::TieTextBox( const wxString &Prompt, diff --git a/src/ShuttleGui.h b/src/ShuttleGui.h index bdd96c7e0..db225c7c4 100644 --- a/src/ShuttleGui.h +++ b/src/ShuttleGui.h @@ -27,6 +27,9 @@ // For ShuttleGuiGetDefinitions. #include "commands/CommandTargets.h" +class EnumSetting; + + const int nMaxNestedSizers = 20; enum teShuttleMode @@ -209,18 +212,24 @@ public: const wxString &Prompt, const wxString &SettingName, const bool bDefault); + + // This one is defined in terms of the next and not virtual + virtual wxChoice *TieChoice( + const wxString &Prompt, + EnumSetting &enumSetting ); + virtual wxChoice * TieChoice( const wxString &Prompt, const wxString &SettingName, const wxString &Default, const wxArrayString &Choices, - const wxArrayString & TranslatedChoices ); + const wxArrayString & InternalChoices ); virtual wxChoice * TieChoice( const wxString &Prompt, const wxString &SettingName, const int Default, const wxArrayString & Choices, - const std::vector & TranslatedChoices); + const std::vector & InternalChoices ); virtual wxTextCtrl * TieTextBox( const wxString &Prompt, const wxString &SettingName, @@ -421,13 +430,13 @@ public: const wxString &SettingName, const wxString &Default, const wxArrayString &Choices, - const wxArrayString & TranslatedChoices ) override; + const wxArrayString & InternalChoices ) override; wxChoice * TieChoice( const wxString &Prompt, const wxString &SettingName, const int Default, const wxArrayString & Choices, - const std::vector & TranslatedChoices) override; + const std::vector & InternalChoices) override; wxTextCtrl * TieTextBox( const wxString &Prompt, const wxString &SettingName,