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

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.
This commit is contained in:
Paul Licameli 2019-04-02 18:15:06 -04:00
parent c5e21ead18
commit e008a44022
9 changed files with 108 additions and 52 deletions

View File

@ -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 &not copy any audio") },
{ wxT("ask"), XO("As&k") },
},
2 // ask
};

View File

@ -17,6 +17,7 @@
#include "sndfile.h"
class ChoiceSetting;
class wxString;
//
@ -130,4 +131,7 @@ struct SFFile : public std::unique_ptr<SNDFILE, ::SFFileCloser>
}
};
extern ChoiceSetting FileFormatsCopyOrEditSetting;
extern ChoiceSetting FileFormatsSaveWithDependenciesSetting;
#endif

View File

@ -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;
}
//-----------------------------------------------------------------------//

View File

@ -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<WrappedType> mRadioValue; /// The wrapped value associated with the active radio button.
int mRadioCount; /// The index of this radio item. -1 for none.

View File

@ -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);
}

View File

@ -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();

View File

@ -20,6 +20,7 @@
#include <wx/defs.h>
#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();
}

View File

@ -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

View File

@ -22,6 +22,7 @@ handling.
#include <wx/defs.h>
#include <wx/textctrl.h>
#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 &not copy any audio"),
wxT("never"));
S.TieRadioButton(_("As&k"),
wxT("ask"));
S.TieRadioButton();
S.TieRadioButton();
S.TieRadioButton();
}
S.EndRadioButtonGroup();
}