From e008a4402281e41d7b630988e47fbf57d0545e6b Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 2 Apr 2019 18:15:06 -0400 Subject: [PATCH] Pass ChoiceSetting to StartRadioButtonGroup... ... and we don't need to pass strings to TieRadioButton. This removes some repetition of string literals in import/export, which is good too. --- src/FileFormats.cpp | 26 ++++++++++++++++++++++++ src/FileFormats.h | 4 ++++ src/ShuttleGui.cpp | 35 ++++++++++++++++++++++++--------- src/ShuttleGui.h | 7 +++++-- src/export/ExportMP3.cpp | 16 +++++++-------- src/export/ExportMultiple.cpp | 19 +++++++++++------- src/prefs/ImportExportPrefs.cpp | 25 ++++++++++------------- src/prefs/KeyConfigPrefs.cpp | 16 +++++++++++---- src/prefs/ProjectsPrefs.cpp | 12 +++++------ 9 files changed, 108 insertions(+), 52 deletions(-) diff --git a/src/FileFormats.cpp b/src/FileFormats.cpp index 28341da5a..50a699503 100644 --- a/src/FileFormats.cpp +++ b/src/FileFormats.cpp @@ -23,6 +23,7 @@ information. #include "sndfile.h" #include "Internat.h" #include "widgets/AudacityMessageBox.h" +#include "Prefs.h" #ifndef SNDFILE_1 #error Requires libsndfile 1.0 or higher @@ -334,3 +335,28 @@ int SFFileCloser::operator() (SNDFILE *sf) const } return err; } + +ChoiceSetting FileFormatsCopyOrEditSetting{ + wxT("/FileFormats/CopyOrEditUncompressedData"), + { + EnumValueSymbol{ + wxT("copy"), + XO("&Copy uncompressed files into the project (safer)") + }, + EnumValueSymbol{ + wxT("edit"), + XO("&Read uncompressed files from original location (faster)") + }, + }, + 0 // copy +}; + +ChoiceSetting FileFormatsSaveWithDependenciesSetting{ + wxT("/FileFormats/SaveProjectWithDependencies"), + { + { wxT("copy"), XO("&Copy all audio into project (safest)") }, + { wxT("never"), XO("Do ¬ copy any audio") }, + { wxT("ask"), XO("As&k") }, + }, + 2 // ask +}; diff --git a/src/FileFormats.h b/src/FileFormats.h index 9fc346cc5..c5a017672 100644 --- a/src/FileFormats.h +++ b/src/FileFormats.h @@ -17,6 +17,7 @@ #include "sndfile.h" +class ChoiceSetting; class wxString; // @@ -130,4 +131,7 @@ struct SFFile : public std::unique_ptr } }; +extern ChoiceSetting FileFormatsCopyOrEditSetting; +extern ChoiceSetting FileFormatsSaveWithDependenciesSetting; + #endif diff --git a/src/ShuttleGui.cpp b/src/ShuttleGui.cpp index 2464db68c..742a4e1f2 100644 --- a/src/ShuttleGui.cpp +++ b/src/ShuttleGui.cpp @@ -1449,17 +1449,26 @@ wxChoice * ShuttleGuiBase::TieChoice( } /// This function must be within a StartRadioButtonGroup - EndRadioButtonGroup pair. -wxRadioButton * ShuttleGuiBase::TieRadioButton( - const wxString &Prompt, - const wxString &Value) +wxRadioButton * ShuttleGuiBase::TieRadioButton() { + wxASSERT( mRadioCount >= 0); // Did you remember to use StartRadioButtonGroup() ? + + EnumValueSymbol symbol; + if (mpRadioSetting && mRadioCount >= 0) { + const auto &symbols = mpRadioSetting->GetSymbols(); + if ( mRadioCount < symbols.size() ) + symbol = symbols[ mRadioCount ]; + } + // In what follows, WrappedRef is used in read only mode, but we // don't have a 'read-only' version, so we copy to deal with the constness. - wxString Temp = Value; + auto Temp = symbol.Internal(); + wxASSERT( !Temp.empty() ); // More buttons than values? + WrappedType WrappedRef( Temp ); - wxASSERT( mRadioCount >= 0); // Did you remember to use StartRadioButtonGroup() ? mRadioCount++; + UseUpId(); wxRadioButton * pRadioButton = NULL; @@ -1467,6 +1476,8 @@ wxRadioButton * ShuttleGuiBase::TieRadioButton( { case eIsCreating: { + const auto &Prompt = symbol.Translation(); + mpWind = pRadioButton = safenew wxRadioButton(GetParent(), miId, Prompt, wxDefaultPosition, wxDefaultSize, (mRadioCount==1)?wxRB_GROUP:0); @@ -1500,28 +1511,34 @@ wxRadioButton * ShuttleGuiBase::TieRadioButton( } /// Call this before any TieRadioButton calls. -void ShuttleGuiBase::StartRadioButtonGroup( const wxString & SettingName, const wxString & DefaultValue ) +void ShuttleGuiBase::StartRadioButtonGroup( const ChoiceSetting &Setting ) { + mpRadioSetting = &Setting; + // Configure the generic type mechanism to use OUR string. - mRadioValueString = DefaultValue; + mRadioValueString = Setting.Default().Internal(); mRadioValue.create( mRadioValueString ); // Now actually start the radio button group. - mRadioSettingName = SettingName; + mRadioSettingName = Setting.Key(); mRadioCount = 0; if( mShuttleMode == eIsCreating ) - DoDataShuttle( SettingName, *mRadioValue ); + DoDataShuttle( Setting.Key(), *mRadioValue ); } /// Call this after any TieRadioButton calls. /// It's generic too. We don't need type-specific ones. void ShuttleGuiBase::EndRadioButtonGroup() { + // too few buttons? + wxASSERT( mRadioCount == mpRadioSetting->GetSymbols().size() ); + if( mShuttleMode == eIsGettingFromDialog ) DoDataShuttle( mRadioSettingName, *mRadioValue ); mRadioValue.reset();// Clear it out... mRadioSettingName = wxT(""); mRadioCount = -1; // So we detect a problem. + mpRadioSetting = nullptr; } //-----------------------------------------------------------------------// diff --git a/src/ShuttleGui.h b/src/ShuttleGui.h index 62afa39d2..1f32b32c7 100644 --- a/src/ShuttleGui.h +++ b/src/ShuttleGui.h @@ -175,7 +175,7 @@ public: wxPanel * StartInvisiblePanel(); void EndInvisiblePanel(); - void StartRadioButtonGroup( const wxString & SettingName, const wxString &DefaultValue ); + void StartRadioButtonGroup( const ChoiceSetting &Setting ); void EndRadioButtonGroup(); void DoDataShuttle( const wxString &Name, WrappedType & WrappedRef ); @@ -213,7 +213,9 @@ public: wxSlider * TieSlider( const wxString &Prompt, float &pos, const float fMin, const float fMax); wxSlider * TieVSlider( const wxString &Prompt, float &pos, const float fMin, const float fMax); - wxRadioButton * TieRadioButton( const wxString &Prompt, const wxString &Value); + // Must be called between a StartRadioButtonGroup / EndRadioButtonGroup pair, + // and as many times as there are values in the enumeration. + wxRadioButton * TieRadioButton(); wxSpinCtrl * TieSpinCtrl( const wxString &Prompt, WrappedType & WrappedRef, const int max, const int min = 0 ); wxSpinCtrl * TieSpinCtrl( const wxString &Prompt, int &Value, const int max, const int min = 0 ); @@ -363,6 +365,7 @@ protected: wxMenu * mpMenu; private: + const ChoiceSetting *mpRadioSetting = nullptr; wxString mRadioSettingName; /// The setting controlled by a group. Maybe mRadioValue; /// The wrapped value associated with the active radio button. int mRadioCount; /// The index of this radio item. -1 for none. diff --git a/src/export/ExportMP3.cpp b/src/export/ExportMP3.cpp index 6a096e35a..b71e8f651 100644 --- a/src/export/ExportMP3.cpp +++ b/src/export/ExportMP3.cpp @@ -380,12 +380,12 @@ void ExportMP3Options::PopulateOrExchange(ShuttleGui & S) S.AddPrompt(_("Bit Rate Mode:")); S.StartHorizontalLay(); { - S.StartRadioButtonGroup(wxT("/FileFormats/MP3RateModeChoice"), wxT("SET")); + S.StartRadioButtonGroup(MP3RateModeSetting); { - mSET = S.Id(ID_SET).TieRadioButton(_("Preset"), wxT("SET")); - mVBR = S.Id(ID_VBR).TieRadioButton(_("Variable"), wxT("VBR")); - mABR = S.Id(ID_ABR).TieRadioButton(_("Average"), wxT("ABR")); - mCBR = S.Id(ID_CBR).TieRadioButton(_("Constant"), wxT("CBR")); + mSET = S.Id(ID_SET).TieRadioButton(); + mVBR = S.Id(ID_VBR).TieRadioButton(); + mABR = S.Id(ID_ABR).TieRadioButton(); + mCBR = S.Id(ID_CBR).TieRadioButton(); } S.EndRadioButtonGroup(); } @@ -441,10 +441,10 @@ void ExportMP3Options::PopulateOrExchange(ShuttleGui & S) bool mono = false; gPrefs->Read(wxT("/FileFormats/MP3ForceMono"), &mono, 0); - S.StartRadioButtonGroup(wxT("/FileFormats/MP3ChannelModeChoice"), wxT("JOINT")); + S.StartRadioButtonGroup(MP3ChannelModeSetting); { - mJoint = S.TieRadioButton(_("Joint Stereo"), wxT("JOINT")); - mStereo = S.TieRadioButton(_("Stereo"), wxT("STEREO")); + mJoint = S.TieRadioButton(); + mStereo = S.TieRadioButton(); mJoint->Enable(!mono); mStereo->Enable(!mono); } diff --git a/src/export/ExportMultiple.cpp b/src/export/ExportMultiple.cpp index 32c06b663..101a27c3d 100644 --- a/src/export/ExportMultiple.cpp +++ b/src/export/ExportMultiple.cpp @@ -353,16 +353,21 @@ void ExportMultiple::PopulateOrExchange(ShuttleGui& S) S.StartStatic(_("Name files:"), 1); { S.SetBorder(2); - S.StartRadioButtonGroup(wxT("/Export/TrackNameWithOrWithoutNumbers"), wxT("labelTrack")); + S.StartRadioButtonGroup({ + wxT("/Export/TrackNameWithOrWithoutNumbers"), + { + { wxT("labelTrack"), XO("Using Label/Track Name") }, + { wxT("numberBefore"), XO("Numbering before Label/Track Name") }, + { wxT("numberAfter"), XO("Numbering after File name prefix") }, + }, + 0 // labelTrack + }); { - mByName = S.Id(ByNameID) - .TieRadioButton(_("Using Label/Track Name"), wxT("labelTrack")); + mByName = S.Id(ByNameID).TieRadioButton(); - mByNumberAndName = S.Id(ByNameAndNumberID) - .TieRadioButton(_("Numbering before Label/Track Name"), wxT("numberBefore")); + mByNumberAndName = S.Id(ByNameAndNumberID).TieRadioButton(); - mByNumber = S.Id(ByNumberID) - .TieRadioButton(_("Numbering after File name prefix"), wxT("numberAfter")); + mByNumber = S.Id(ByNumberID).TieRadioButton(); } S.EndRadioButtonGroup(); diff --git a/src/prefs/ImportExportPrefs.cpp b/src/prefs/ImportExportPrefs.cpp index e9708b262..92c3c1064 100644 --- a/src/prefs/ImportExportPrefs.cpp +++ b/src/prefs/ImportExportPrefs.cpp @@ -20,6 +20,7 @@ #include +#include "../FileFormats.h" #include "../Prefs.h" #include "../ShuttleGui.h" @@ -98,12 +99,10 @@ void ImportExportPrefs::PopulateOrExchange(ShuttleGui & S) #ifdef EXPERIMENTAL_OD_DATA S.StartStatic(_("When importing audio files")); { - S.StartRadioButtonGroup(wxT("/FileFormats/CopyOrEditUncompressedData"), wxT("copy")); + S.StartRadioButtonGroup(FileFormatsCopyOrEditSetting); { - S.TieRadioButton(_("&Copy uncompressed files into the project (safer)"), - wxT("copy")); - S.TieRadioButton(_("&Read uncompressed files from original location (faster)"), - wxT("edit")); + S.TieRadioButton(); + S.TieRadioButton(); } S.EndRadioButtonGroup(); } @@ -111,12 +110,10 @@ void ImportExportPrefs::PopulateOrExchange(ShuttleGui & S) #endif S.StartStatic(_("When exporting tracks to an audio file")); { - S.StartRadioButtonGroup(wxT("/FileFormats/ExportDownMixChoice"), wxT("MixDown")); + S.StartRadioButtonGroup(ImportExportPrefs::ExportDownMixSetting); { - S.TieRadioButton(_("&Mix down to Stereo or Mono"), - wxT("MixDown")); - S.TieRadioButton(_("&Use Advanced Mixing Options"), - wxT("Custom")); + S.TieRadioButton(); + S.TieRadioButton(); } S.EndRadioButtonGroup(); @@ -132,12 +129,10 @@ void ImportExportPrefs::PopulateOrExchange(ShuttleGui & S) #ifdef USE_MIDI S.StartStatic(_("Exported Allegro (.gro) files save time as:")); { - S.StartRadioButtonGroup(wxT("/FileFormats/AllegroStyleChoice"), wxT("Seconds")); + S.StartRadioButtonGroup(ImportExportPrefs::AllegroStyleSetting); { - S.TieRadioButton(_("&Seconds"), - wxT("Seconds")); - S.TieRadioButton(_("&Beats"), - wxT("Beats")); + S.TieRadioButton(); + S.TieRadioButton(); } S.EndRadioButtonGroup(); } diff --git a/src/prefs/KeyConfigPrefs.cpp b/src/prefs/KeyConfigPrefs.cpp index a975e078b..4a6668943 100644 --- a/src/prefs/KeyConfigPrefs.cpp +++ b/src/prefs/KeyConfigPrefs.cpp @@ -174,13 +174,21 @@ void KeyConfigPrefs::PopulateOrExchange(ShuttleGui & S) S.StartHorizontalLay(wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 0); { S.AddTitle(_("View by:")); - S.StartRadioButtonGroup(wxT("/Prefs/KeyConfig/ViewBy"), wxT("tree")); + S.StartRadioButtonGroup({ + wxT("/Prefs/KeyConfig/ViewBy"), + { + { wxT("tree"), XO("&Tree") }, + { wxT("name"), XO("&Name") }, + { wxT("key"), XO("&Key") }, + }, + 0 // tree + }); { - mViewByTree = S.Id(ViewByTreeID).TieRadioButton(_("&Tree"), wxT("tree")); + mViewByTree = S.Id(ViewByTreeID).TieRadioButton(); if( mViewByTree ) mViewByTree->SetName(_("View by tree")); - mViewByName = S.Id(ViewByNameID).TieRadioButton(_("&Name"), wxT("name")); + mViewByName = S.Id(ViewByNameID).TieRadioButton(); if( mViewByName ) mViewByName->SetName(_("View by name")); - mViewByKey = S.Id(ViewByKeyID).TieRadioButton(_("&Key"), wxT("key")); + mViewByKey = S.Id(ViewByKeyID).TieRadioButton(); if( mViewByKey ) mViewByKey->SetName(_("View by key")); #if wxUSE_ACCESSIBILITY // so that name can be set on a standard control diff --git a/src/prefs/ProjectsPrefs.cpp b/src/prefs/ProjectsPrefs.cpp index 1bc30b815..f1fdfc91e 100644 --- a/src/prefs/ProjectsPrefs.cpp +++ b/src/prefs/ProjectsPrefs.cpp @@ -22,6 +22,7 @@ handling. #include #include +#include "../FileFormats.h" #include "../Prefs.h" #include "../ShuttleGui.h" @@ -73,14 +74,11 @@ void ProjectsPrefs::PopulateOrExchange(ShuttleGui & S) S.StartStatic(_("When saving a project that depends on other audio files")); { - S.StartRadioButtonGroup(wxT("/FileFormats/SaveProjectWithDependencies"), wxT("ask")); + S.StartRadioButtonGroup(FileFormatsSaveWithDependenciesSetting); { - S.TieRadioButton(_("&Copy all audio into project (safest)"), - wxT("copy")); - S.TieRadioButton(_("Do ¬ copy any audio"), - wxT("never")); - S.TieRadioButton(_("As&k"), - wxT("ask")); + S.TieRadioButton(); + S.TieRadioButton(); + S.TieRadioButton(); } S.EndRadioButtonGroup(); }