1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-02 17:09:26 +02:00

More use of ShuttleGui for dialogs in import and export

This commit is contained in:
Paul Licameli 2019-12-18 11:23:48 -05:00
commit 2c7e08eeec
12 changed files with 123 additions and 119 deletions

View File

@ -220,12 +220,8 @@ bool ExportPlugin::DisplayOptions(wxWindow * WXUNUSED(parent), int WXUNUSED(form
return false; return false;
} }
wxWindow *ExportPlugin::OptionsCreate(wxWindow *parent, int WXUNUSED(format)) void ExportPlugin::OptionsCreate(ShuttleGui &S, int WXUNUSED(format))
{ {
wxASSERT(parent); // To justify safenew
wxPanel *p = safenew wxPanelWrapper(parent, wxID_ANY);
ShuttleGui S(p, eIsCreatingFromPrefs);
S.StartHorizontalLay(wxCENTER); S.StartHorizontalLay(wxCENTER);
{ {
S.StartHorizontalLay(wxCENTER, 0); S.StartHorizontalLay(wxCENTER, 0);
@ -235,8 +231,6 @@ wxWindow *ExportPlugin::OptionsCreate(wxWindow *parent, int WXUNUSED(format))
S.EndHorizontalLay(); S.EndHorizontalLay();
} }
S.EndHorizontalLay(); S.EndHorizontalLay();
return p;
} }
//Create a mixer by computing the time warp factor //Create a mixer by computing the time warp factor
@ -994,17 +988,21 @@ void Exporter::CreateUserPane(wxWindow *parent)
{ {
S.StartStatic(_("Format Options"), 1); S.StartStatic(_("Format Options"), 1);
{ {
mBook = safenew wxSimplebook(S.GetParent()); mBook = S.Position(wxEXPAND)
S.Position(wxEXPAND) .StartSimplebook();
.AddWindow(mBook);
for (const auto &pPlugin : mPlugins) for (const auto &pPlugin : mPlugins)
{ {
for (int j = 0; j < pPlugin->GetFormatCount(); j++) for (int j = 0; j < pPlugin->GetFormatCount(); j++)
{ {
mBook->AddPage(pPlugin->OptionsCreate(mBook, j), wxEmptyString); // Name of simple book page is not displayed
S.StartNotebookPage( wxEmptyString );
pPlugin->OptionsCreate(S, j);
S.EndNotebookPage();
} }
} }
S.EndSimplebook();
} }
S.EndStatic(); S.EndStatic();
} }
@ -1411,42 +1409,45 @@ ExportMixerDialog::ExportMixerDialog( const TrackList *tracks, bool selectedOnly
mMixerSpec = std::make_unique<MixerSpec>(numTracks, maxNumChannels); mMixerSpec = std::make_unique<MixerSpec>(numTracks, maxNumChannels);
wxBoxSizer *vertSizer; auto label = XO("Output Channels: %2d")
.Format( mMixerSpec->GetNumChannels() );
ShuttleGui S{ this, eIsCreating };
{ {
auto uVertSizer = std::make_unique<wxBoxSizer>(wxVERTICAL); S.SetBorder( 5 );
vertSizer = uVertSizer.get();
wxWindow *mixerPanel = safenew ExportMixerPanel(this, ID_MIXERPANEL, auto mixerPanel = safenew ExportMixerPanel(
mMixerSpec.get(), mTrackNames, S.GetParent(), ID_MIXERPANEL, mMixerSpec.get(),
wxDefaultPosition, wxSize(400, -1)); mTrackNames, wxDefaultPosition, wxSize(400, -1));
mixerPanel->SetName(_("Mixer Panel")); S.Prop(1)
vertSizer->Add(mixerPanel, 1, wxEXPAND | wxALL, 5); .Name(XO("Mixer Panel"))
.Position(wxEXPAND | wxALL)
.AddWindow(mixerPanel);
S.StartHorizontalLay(wxALIGN_CENTRE | wxALL, 0);
{ {
auto horSizer = std::make_unique<wxBoxSizer>(wxHORIZONTAL); mChannelsText = S.AddVariableText(
label.Translation(),
false, wxALIGN_LEFT | wxALL );
wxString label; S
label.Printf(_("Output Channels: %2d"), mMixerSpec->GetNumChannels()); .Id(ID_SLIDER_CHANNEL)
mChannelsText = safenew wxStaticText(this, -1, label); .Name(label)
horSizer->Add(mChannelsText, 0, wxALIGN_LEFT | wxALL, 5); .Size({300, -1})
.Style(wxSL_HORIZONTAL)
wxSlider *channels = safenew wxSliderWrapper(this, ID_SLIDER_CHANNEL, .Position(wxEXPAND | wxALL)
mMixerSpec->GetNumChannels(), 1, mMixerSpec->GetMaxNumChannels(), .AddSlider( {},
wxDefaultPosition, wxSize(300, -1)); mMixerSpec->GetNumChannels(),
channels->SetName(label); mMixerSpec->GetMaxNumChannels(), 1 );
horSizer->Add(channels, 0, wxEXPAND | wxALL, 5);
vertSizer->Add(horSizer.release(), 0, wxALIGN_CENTRE | wxALL, 5);
} }
S.EndHorizontalLay();
vertSizer->Add(CreateStdButtonSizer(this, eCancelButton | eOkButton | eHelpButton).release(), 0, wxEXPAND); S.AddStandardButtons( eCancelButton | eOkButton | eHelpButton );
}
SetAutoLayout(true); SetAutoLayout(true);
SetSizer(uVertSizer.release()); GetSizer()->Fit( this );
} GetSizer()->SetSizeHints( this );
vertSizer->Fit( this );
vertSizer->SetSizeHints( this );
SetSizeHints( 640, 480, 20000, 20000 ); SetSizeHints( 640, 480, 20000, 20000 );

View File

@ -31,6 +31,7 @@ class Tags;
class TrackList; class TrackList;
class MixerSpec; class MixerSpec;
class ProgressDialog; class ProgressDialog;
class ShuttleGui;
class Mixer; class Mixer;
using WaveTrackConstArray = std::vector < std::shared_ptr < const WaveTrack > >; using WaveTrackConstArray = std::vector < std::shared_ptr < const WaveTrack > >;
enum class ProgressResult : unsigned; enum class ProgressResult : unsigned;
@ -92,8 +93,7 @@ public:
virtual bool DisplayOptions(wxWindow *parent, int format = 0); virtual bool DisplayOptions(wxWindow *parent, int format = 0);
// Precondition: parent != NULL virtual void OptionsCreate(ShuttleGui &S, int format) = 0;
virtual wxWindow *OptionsCreate(wxWindow *parent, int format) = 0;
virtual bool CheckFileName(wxFileName &filename, int format = 0); virtual bool CheckFileName(wxFileName &filename, int format = 0);
/** @brief Exporter plug-ins may override this to specify the number /** @brief Exporter plug-ins may override this to specify the number

View File

@ -289,7 +289,7 @@ public:
ExportCL(); ExportCL();
// Required // Required
wxWindow *OptionsCreate(wxWindow *parent, int format) override; void OptionsCreate(ShuttleGui &S, int format) override;
ProgressResult Export(AudacityProject *project, ProgressResult Export(AudacityProject *project,
std::unique_ptr<ProgressDialog> &pDialog, std::unique_ptr<ProgressDialog> &pDialog,
@ -552,10 +552,9 @@ ProgressResult ExportCL::Export(AudacityProject *project,
return updateResult; return updateResult;
} }
wxWindow *ExportCL::OptionsCreate(wxWindow *parent, int format) void ExportCL::OptionsCreate(ShuttleGui &S, int format)
{ {
wxASSERT(parent); // to justify safenew S.AddWindow( safenew ExportCLOptions{ S.GetParent(), format } );
return safenew ExportCLOptions(parent, format);
} }
static Exporter::RegisteredExportPlugin static Exporter::RegisteredExportPlugin

View File

@ -122,7 +122,7 @@ public:
/// Creates options panel /// Creates options panel
///\param format - index of export type ///\param format - index of export type
wxWindow *OptionsCreate(wxWindow *parent, int format) override; void OptionsCreate(ShuttleGui &S, int format) override;
/// Check whether or not current project sample rate is compatible with the export codec /// Check whether or not current project sample rate is compatible with the export codec
bool CheckSampleRate(int rate, int lowrate, int highrate, const int *sampRates); bool CheckSampleRate(int rate, int lowrate, int highrate, const int *sampRates);
@ -1067,33 +1067,42 @@ int ExportFFmpeg::AskResample(int bitrate, int rate, int lowrate, int highrate,
return wxAtoi(choice->GetStringSelection()); return wxAtoi(choice->GetStringSelection());
} }
wxWindow *ExportFFmpeg::OptionsCreate(wxWindow *parent, int format) void ExportFFmpeg::OptionsCreate(ShuttleGui &S, int format)
{ {
wxASSERT(parent); // to justify safenew
// subformat index may not correspond directly to fmts[] index, convert it // subformat index may not correspond directly to fmts[] index, convert it
mSubFormat = AdjustFormatIndex(format); mSubFormat = AdjustFormatIndex(format);
if (mSubFormat == FMT_M4A) if (mSubFormat == FMT_M4A)
{ {
return safenew ExportFFmpegAACOptions(parent, format); S.AddWindow(
safenew ExportFFmpegAACOptions{ S.GetParent(), format } );
return;
} }
else if (mSubFormat == FMT_AC3) else if (mSubFormat == FMT_AC3)
{ {
return safenew ExportFFmpegAC3Options(parent, format); S.AddWindow(
safenew ExportFFmpegAC3Options{ S.GetParent(), format } );
return;
} }
else if (mSubFormat == FMT_AMRNB) else if (mSubFormat == FMT_AMRNB)
{ {
return safenew ExportFFmpegAMRNBOptions(parent, format); S.AddWindow(
safenew ExportFFmpegAMRNBOptions{ S.GetParent(), format } );
return;
} }
else if (mSubFormat == FMT_WMA2) else if (mSubFormat == FMT_WMA2)
{ {
return safenew ExportFFmpegWMAOptions(parent, format); S.AddWindow(
safenew ExportFFmpegWMAOptions{ S.GetParent(), format } );
return;
} }
else if (mSubFormat == FMT_OTHER) else if (mSubFormat == FMT_OTHER)
{ {
return safenew ExportFFmpegCustomOptions(parent, format); S.AddWindow(
safenew ExportFFmpegCustomOptions{ S.GetParent(), format } );
return;
} }
return ExportPlugin::OptionsCreate(parent, format); ExportPlugin::OptionsCreate(S, format);
} }
static Exporter::RegisteredExportPlugin static Exporter::RegisteredExportPlugin

View File

@ -212,7 +212,7 @@ public:
// Required // Required
wxWindow *OptionsCreate(wxWindow *parent, int format) override; void OptionsCreate(ShuttleGui &S, int format) override;
ProgressResult Export(AudacityProject *project, ProgressResult Export(AudacityProject *project,
std::unique_ptr<ProgressDialog> &pDialog, std::unique_ptr<ProgressDialog> &pDialog,
unsigned channels, unsigned channels,
@ -435,10 +435,9 @@ ProgressResult ExportFLAC::Export(AudacityProject *project,
return updateResult; return updateResult;
} }
wxWindow *ExportFLAC::OptionsCreate(wxWindow *parent, int format) void ExportFLAC::OptionsCreate(ShuttleGui &S, int format)
{ {
wxASSERT(parent); // to justify safenew S.AddWindow( safenew ExportFLACOptions{ S.GetParent(), format } );
return safenew ExportFLACOptions(parent, format);
} }
// LL: There's a bug in libflac++ 1.1.2 that prevents us from using // LL: There's a bug in libflac++ 1.1.2 that prevents us from using

View File

@ -205,7 +205,7 @@ public:
// Required // Required
wxWindow *OptionsCreate(wxWindow *parent, int format) override; void OptionsCreate(ShuttleGui &S, int format) override;
ProgressResult Export(AudacityProject *project, ProgressResult Export(AudacityProject *project,
std::unique_ptr<ProgressDialog> &pDialog, std::unique_ptr<ProgressDialog> &pDialog,
unsigned channels, unsigned channels,
@ -377,10 +377,9 @@ ProgressResult ExportMP2::Export(AudacityProject *project,
return updateResult; return updateResult;
} }
wxWindow *ExportMP2::OptionsCreate(wxWindow *parent, int format) void ExportMP2::OptionsCreate(ShuttleGui &S, int format)
{ {
wxASSERT(parent); // to justify safenew S.AddWindow( safenew ExportMP2Options{ S.GetParent(), format } );
return safenew ExportMP2Options(parent, format);
} }

View File

@ -1654,7 +1654,7 @@ public:
// Required // Required
wxWindow *OptionsCreate(wxWindow *parent, int format) override; void OptionsCreate(ShuttleGui &S, int format) override;
ProgressResult Export(AudacityProject *project, ProgressResult Export(AudacityProject *project,
std::unique_ptr<ProgressDialog> &pDialog, std::unique_ptr<ProgressDialog> &pDialog,
unsigned channels, unsigned channels,
@ -1992,10 +1992,9 @@ ProgressResult ExportMP3::Export(AudacityProject *project,
return updateResult; return updateResult;
} }
wxWindow *ExportMP3::OptionsCreate(wxWindow *parent, int format) void ExportMP3::OptionsCreate(ShuttleGui &S, int format)
{ {
wxASSERT(parent); // to justify safenew S.AddWindow( safenew ExportMP3Options{ S.GetParent(), format } );
return safenew ExportMP3Options(parent, format);
} }
int ExportMP3::AskResample(int bitrate, int rate, int lowrate, int highrate) int ExportMP3::AskResample(int bitrate, int rate, int lowrate, int highrate)

View File

@ -294,19 +294,25 @@ void ExportMultipleDialog::PopulateOrExchange(ShuttleGui& S)
S.AddVariableText( {}, false); S.AddVariableText( {}, false);
S.AddPrompt(_("Options:")); S.AddPrompt(_("Options:"));
if (!mBook)
mBook = S.Id(OptionsID)
.Style(wxBORDER_STATIC)
.StartSimplebook();
if (S.GetMode() == eIsCreating)
{ {
mBook = safenew wxSimplebook(S.GetParent(), OptionsID, wxDefaultPosition, wxDefaultSize, wxBORDER_STATIC);
for (const auto &pPlugin : mPlugins) for (const auto &pPlugin : mPlugins)
{ {
for (int j = 0; j < pPlugin->GetFormatCount(); j++) for (int j = 0; j < pPlugin->GetFormatCount(); j++)
{ {
mBook->AddPage(pPlugin->OptionsCreate(mBook, j), wxEmptyString); // Name of simple book page is not displayed
S.StartNotebookPage( wxEmptyString );
pPlugin->OptionsCreate(S, j);
S.EndNotebookPage();
} }
} }
mBook->ChangeSelection(mFormat->GetSelection()); mBook->ChangeSelection(mFormat->GetSelection());
} }
S.AddWindow(mBook); S.EndSimplebook();
S.AddVariableText( {}, false); S.AddVariableText( {}, false);
S.AddVariableText( {}, false); S.AddVariableText( {}, false);
} }

View File

@ -129,7 +129,7 @@ public:
ExportOGG(); ExportOGG();
// Required // Required
wxWindow *OptionsCreate(wxWindow *parent, int format) override; void OptionsCreate(ShuttleGui &S, int format) override;
ProgressResult Export(AudacityProject *project, ProgressResult Export(AudacityProject *project,
std::unique_ptr<ProgressDialog> &pDialog, std::unique_ptr<ProgressDialog> &pDialog,
@ -369,10 +369,9 @@ ProgressResult ExportOGG::Export(AudacityProject *project,
return updateResult; return updateResult;
} }
wxWindow *ExportOGG::OptionsCreate(wxWindow *parent, int format) void ExportOGG::OptionsCreate(ShuttleGui &S, int format)
{ {
wxASSERT(parent); // to justify safenew S.AddWindow( safenew ExportOGGOptions{ S.GetParent(), format } );
return safenew ExportOGGOptions(parent, format);
} }
bool ExportOGG::FillComment(AudacityProject *project, vorbis_comment *comment, const Tags *metadata) bool ExportOGG::FillComment(AudacityProject *project, vorbis_comment *comment, const Tags *metadata)

View File

@ -327,7 +327,7 @@ public:
// Required // Required
wxWindow *OptionsCreate(wxWindow *parent, int format) override; void OptionsCreate(ShuttleGui &S, int format) override;
ProgressResult Export(AudacityProject *project, ProgressResult Export(AudacityProject *project,
std::unique_ptr<ProgressDialog> &pDialog, std::unique_ptr<ProgressDialog> &pDialog,
unsigned channels, unsigned channels,
@ -929,16 +929,16 @@ bool ExportPCM::AddID3Chunk(
return true; return true;
} }
wxWindow *ExportPCM::OptionsCreate(wxWindow *parent, int format) void ExportPCM::OptionsCreate(ShuttleGui &S, int format)
{ {
wxASSERT(parent); // to justify safenew
// default, full user control // default, full user control
if (format < 0 || static_cast<unsigned int>(format) >= WXSIZEOF(kFormats)) if (format < 0 || static_cast<unsigned int>(format) >= WXSIZEOF(kFormats))
{ {
return safenew ExportPCMOptions(parent, format); S.AddWindow( safenew ExportPCMOptions{ S.GetParent(), format } );
return;
} }
return ExportPlugin::OptionsCreate(parent, format); ExportPlugin::OptionsCreate(S, format);
} }
FileExtension ExportPCM::GetExtension(int index) FileExtension ExportPCM::GetExtension(int index)

View File

@ -752,26 +752,25 @@ wxDialogWrapper( parent, id, title, position, size, style | wxRESIZE_BORDER )
for (wxInt32 i = 0; i < scount; i++) for (wxInt32 i = 0; i < scount; i++)
mFile->SetStreamUsage(i, FALSE); mFile->SetStreamUsage(i, FALSE);
wxBoxSizer *vertSizer; ShuttleGui S{ this, eIsCreating };
{ {
auto uVertSizer = std::make_unique<wxBoxSizer>(wxVERTICAL); S.SetBorder( 5 );
vertSizer = uVertSizer.get();
const auto choices = transform_container<wxArrayStringEx>( StreamList = S
.Style(wxLB_EXTENDED | wxLB_ALWAYS_SB)
.AddListBox(
transform_container<wxArrayStringEx>(
mFile->GetStreamInfo(), mFile->GetStreamInfo(),
std::mem_fn( &TranslatableString::Translation ) ); std::mem_fn( &TranslatableString::Translation ) ) );
StreamList = safenew wxListBox(this, -1, wxDefaultPosition, wxDefaultSize, choices, wxLB_EXTENDED | wxLB_ALWAYS_SB);
vertSizer->Add(StreamList, 1, wxEXPAND | wxALIGN_LEFT | wxALL, 5); S.Prop(1)
.Position(wxEXPAND | wxALIGN_LEFT | wxALL)
vertSizer->Add(CreateStdButtonSizer(this, eCancelButton | eOkButton).release(), 0, wxEXPAND); .AddWindow(StreamList);
S.AddStandardButtons();
SetAutoLayout(true);
SetSizer(uVertSizer.release());
} }
vertSizer->Fit( this ); SetAutoLayout(true);
GetSizer()->Fit( this );
SetSize( 400, 200 ); SetSize( 400, 200 );
} }

View File

@ -37,6 +37,8 @@
#include "sndfile.h" #include "sndfile.h"
#include "../WaveClip.h" #include "../WaveClip.h"
#include "../ShuttleGui.h"
#include "../ondemand/ODManager.h" #include "../ondemand/ODManager.h"
#include "../ondemand/ODComputeSummaryTask.h" #include "../ondemand/ODComputeSummaryTask.h"
#include "../blockfile/ODPCMAliasBlockFile.h" #include "../blockfile/ODPCMAliasBlockFile.h"
@ -318,9 +320,6 @@ static wxString AskCopyOrEdit()
wxDialogWrapper dialog( nullptr, -1, XO("Warning") ); wxDialogWrapper dialog( nullptr, -1, XO("Warning") );
dialog.SetName(); dialog.SetName();
wxBoxSizer *vbox;
dialog.SetSizer(vbox = safenew wxBoxSizer(wxVERTICAL));
wxString clause1 = _( wxString clause1 = _(
"When importing uncompressed audio files you can either copy them into the project," "When importing uncompressed audio files you can either copy them into the project,"
" or read them directly from their current location (without copying).\n\n" " or read them directly from their current location (without copying).\n\n"
@ -340,36 +339,31 @@ static wxString AskCopyOrEdit()
"How do you want to import the current file(s)?" "How do you want to import the current file(s)?"
); );
wxStaticText *message = ShuttleGui S{ &dialog, eIsCreating };
safenew wxStaticText(&dialog, -1, clause1 + clause2 + clause3); S.SetBorder(10);
S
message->Wrap(500); .Position( wxALL | wxEXPAND )
message->SetName(message->GetLabel()); .AddUnits( clause1 + clause2 + clause3, 500);
vbox->Add(message, 1, wxALL | wxEXPAND, 10);
wxStaticBox *box = safenew wxStaticBoxWrapper(&dialog, -1, _("Choose an import method"));
box->SetName(box->GetLabel());
wxRadioButton *aliasRadio; wxRadioButton *aliasRadio;
wxRadioButton *copyRadio; wxRadioButton *copyRadio;
wxCheckBox *dontAskNextTimeBox; wxCheckBox *dontAskNextTimeBox;
S.StartStatic(_("Choose an import method"));
{ {
auto boxsizer = std::make_unique<wxStaticBoxSizer>(box, wxVERTICAL); S.SetBorder(0);
copyRadio = safenew wxRadioButton(&dialog, -1, _("Make a &copy of the files before editing (safer)"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP); copyRadio = S.AddRadioButton(
boxsizer->Add(copyRadio, 0, wxALL); _("Make a &copy of the files before editing (safer)") );
copyRadio->SetName(wxStripMenuCodes(copyRadio->GetLabel()));
aliasRadio = safenew wxRadioButton(&dialog, -1, _("Read the files &directly from the original (faster)")); aliasRadio = S.AddRadioButtonToGroup(
boxsizer->Add(aliasRadio, 0, wxALL); _("Read the files &directly from the original (faster)") );
aliasRadio->SetName(wxStripMenuCodes(aliasRadio->GetLabel()));
dontAskNextTimeBox = safenew wxCheckBox(&dialog, -1, _("Don't &warn again and always use my choice above")); dontAskNextTimeBox = S.AddCheckBox(
boxsizer->Add(dontAskNextTimeBox, 0, wxALL); _("Don't &warn again and always use my choice above"),
vbox->Add(boxsizer.release(), 0, wxALL, 10); wxT("false"));
} }
S.EndStatic();
dontAskNextTimeBox->SetName(wxStripMenuCodes(dontAskNextTimeBox->GetLabel())); dontAskNextTimeBox->SetName(wxStripMenuCodes(dontAskNextTimeBox->GetLabel()));
@ -377,8 +371,8 @@ static wxString AskCopyOrEdit()
wxRadioButton *prefsRadio = oldCopyPref == wxT("copy") ? copyRadio : aliasRadio; wxRadioButton *prefsRadio = oldCopyPref == wxT("copy") ? copyRadio : aliasRadio;
prefsRadio->SetValue(true); prefsRadio->SetValue(true);
wxSizer *buttonSizer = dialog.CreateButtonSizer(wxOK | wxCANCEL); S.SetBorder( 10 );
vbox->Add(buttonSizer, 0, wxALL | wxEXPAND, 10); S.AddStandardButtons( eOkButton | eCancelButton );
dialog.SetSize(dialog.GetBestSize()); dialog.SetSize(dialog.GetBestSize());
dialog.Layout(); dialog.Layout();