diff --git a/src/AboutDialog.cpp b/src/AboutDialog.cpp index 69176b8b6..f5d9dbcd4 100644 --- a/src/AboutDialog.cpp +++ b/src/AboutDialog.cpp @@ -393,11 +393,10 @@ visit our [[https://forum.audacityteam.org/|forum]]."); wxDefaultPosition, wxSize(ABOUT_DIALOG_WIDTH, 359), wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER); - html->SetFocus(); html->SetPage(creditStr); /* locate the html renderer where it fits in the dialogue */ - S.Prop(1).AddWindow( html, wxEXPAND ); + S.Prop(1).Focus().AddWindow( html, wxEXPAND ); S.EndVerticalLay(); S.EndNotebookPage(); diff --git a/src/Dependencies.cpp b/src/Dependencies.cpp index 3cf0417b3..85c876d94 100644 --- a/src/Dependencies.cpp +++ b/src/Dependencies.cpp @@ -364,12 +364,12 @@ void DependencyDialog::PopulateOrExchange(ShuttleGui& S) mCopySelectedFilesButton = S.Id(CopySelectedFilesButtonID) + .Focus() .AddButton( _("Copy Selected Files"), wxALIGN_LEFT, true); mCopySelectedFilesButton->Enable( mFileListCtrl->GetSelectedItemCount() > 0); - mCopySelectedFilesButton->SetFocus(); } S.EndStatic(); diff --git a/src/FreqWindow.cpp b/src/FreqWindow.cpp index 6d4955ea8..daa8201e7 100644 --- a/src/FreqWindow.cpp +++ b/src/FreqWindow.cpp @@ -447,7 +447,7 @@ FreqWindow::FreqWindow(wxWindow * parent, wxWindowID id, S.AddSpace(5); - mAlgChoice = S.Id(FreqAlgChoiceID) + mAlgChoice = S.Id(FreqAlgChoiceID).Focus() .AddChoice(_("&Algorithm:"), algChoices, mAlg); S.SetSizeHints(wxDefaultCoord, wxDefaultCoord); @@ -514,7 +514,6 @@ FreqWindow::FreqWindow(wxWindow * parent, wxWindowID id, mCloseButton = static_cast(FindWindowById( wxID_CANCEL )); mCloseButton->SetDefault(); - mCloseButton->SetFocus(); Layout(); Fit(); @@ -522,7 +521,6 @@ FreqWindow::FreqWindow(wxWindow * parent, wxWindowID id, Center(); SetMinSize(GetSize()); - mAlgChoice->SetFocus(); #if defined(__WXGTK__) // This should be rechecked with wx3. diff --git a/src/ShuttleGui.cpp b/src/ShuttleGui.cpp index 824ef7b2f..f5161512d 100644 --- a/src/ShuttleGui.cpp +++ b/src/ShuttleGui.cpp @@ -2084,6 +2084,9 @@ void ShuttleGuiBase::UpdateSizersCore(bool bPrepend, int Flags, bool prompt) mpWind->SetName( mpWind->GetName() + mItem.mNameSuffix.Translation() ); + if (mItem.mFocused) + mpWind->SetFocus(); + // Reset to defaults mItem = {}; } diff --git a/src/ShuttleGui.h b/src/ShuttleGui.h index 76c8b4be8..ae1be8477 100644 --- a/src/ShuttleGui.h +++ b/src/ShuttleGui.h @@ -167,12 +167,21 @@ struct Item { return std::move( *this ); } + // Only the last item specified as focused (if more than one) will be + Item&& Focus( bool focused = true ) && + { + mFocused = focused; + return std::move( *this ); + } + std::function< void(wxWindow*) > mValidatorSetter; TranslatableString mToolTip; TranslatableString mName; TranslatableString mNameSuffix; long miStyle{}; + + bool mFocused { false }; }; } @@ -529,6 +538,13 @@ public: ShuttleGui & Optional( bool & bVar ); ShuttleGui & Id(int id ); + // Only the last item specified as focused (if more than one) will be + ShuttleGui & Focus( bool focused = true ) + { + std::move( mItem ).Focus( focused ); + return *this; + } + ShuttleGui & ToolTip( const TranslatableString &tip ) { std::move( mItem ).ToolTip( tip ); diff --git a/src/effects/ScienFilter.cpp b/src/effects/ScienFilter.cpp index 8749aa0c8..04b8e11f9 100644 --- a/src/effects/ScienFilter.cpp +++ b/src/effects/ScienFilter.cpp @@ -458,6 +458,7 @@ void EffectScienFilter::PopulateOrExchange(ShuttleGui & S) wxASSERT(nTypes == WXSIZEOF(kTypeStrings)); mFilterTypeCtl = S.Id(ID_Type) + .Focus() .Validator(&mFilterType) .AddChoice(_("&Filter Type:"), LocalizedStrings(kTypeStrings, nTypes) @@ -516,8 +517,6 @@ void EffectScienFilter::PopulateOrExchange(ShuttleGui & S) } S.EndMultiColumn(); - mFilterTypeCtl->SetFocus(); - return; } diff --git a/src/effects/nyquist/Nyquist.cpp b/src/effects/nyquist/Nyquist.cpp index 82dc0387c..07ea13865 100644 --- a/src/effects/nyquist/Nyquist.cpp +++ b/src/effects/nyquist/Nyquist.cpp @@ -2587,7 +2587,7 @@ void NyquistEffect::BuildPromptWindow(ShuttleGui & S) S.StartHorizontalLay(wxEXPAND, 1); { - mCommandText = S.AddTextWindow(wxT("")); + mCommandText = S.Focus().AddTextWindow(wxT("")); mCommandText->SetMinSize(wxSize(500, 200)); } S.EndHorizontalLay(); @@ -2600,8 +2600,6 @@ void NyquistEffect::BuildPromptWindow(ShuttleGui & S) S.EndHorizontalLay(); } S.EndVerticalLay(); - - mCommandText->SetFocus(); } void NyquistEffect::BuildEffectWindow(ShuttleGui & S) diff --git a/src/widgets/HelpSystem.cpp b/src/widgets/HelpSystem.cpp index 4cbe9125d..1e2fafb60 100644 --- a/src/widgets/HelpSystem.cpp +++ b/src/widgets/HelpSystem.cpp @@ -192,7 +192,7 @@ void HelpSystem::ShowHtmlText(wxWindow *pParent, else html->SetPage( HtmlText); - S.Prop(1).AddWindow( html, wxEXPAND ); + S.Prop(1).Focus().AddWindow( html, wxEXPAND ); S.Id( wxID_CANCEL ).AddButton( _("Close"), wxALIGN_CENTER, true ); } @@ -228,7 +228,6 @@ void HelpSystem::ShowHtmlText(wxWindow *pParent, } html->SetRelatedStatusBar( 0 ); - html->SetFocus(); return; }