From 9faff782589fc19d56bd7aab01255ae59745789b Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 14 Jul 2022 14:18:04 -0700 Subject: [PATCH] Keep the reset text correct Ensures that after setting the initial dialog page, we also set the proper text in the reset button as the event does not get fired Fixes https://gitlab.com/kicad/code/kicad/issues/11856 --- common/widgets/paged_dialog.cpp | 41 +++++++++++++++++++-------------- include/widgets/paged_dialog.h | 2 ++ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/common/widgets/paged_dialog.cpp b/common/widgets/paged_dialog.cpp index c156459398..1ab001ee6d 100644 --- a/common/widgets/paged_dialog.cpp +++ b/common/widgets/paged_dialog.cpp @@ -219,7 +219,9 @@ bool PAGED_DIALOG::TransferDataToWindow() } } - m_treebook->ChangeSelection( (unsigned) std::max( 0, lastPageIndex ) ); + lastPageIndex = std::max( 0, lastPageIndex ); + m_treebook->ChangeSelection( lastPageIndex ); + UpdateResetButton( lastPageIndex ); return true; } @@ -301,31 +303,19 @@ void PAGED_DIALOG::SetError( const wxString& aMessage, wxWindow* aPage, wxWindow } -void PAGED_DIALOG::OnPageChanged( wxBookCtrlEvent& event ) +void PAGED_DIALOG::UpdateResetButton( int aPage ) { - int page = event.GetSelection(); - - // Use the first sub-page when a tree level node is selected. - if( m_treebook->GetCurrentPage()->GetChildren().IsEmpty() ) - { - unsigned next = page + 1; - - if( next < m_treebook->GetPageCount() ) - m_treebook->ChangeSelection( next ); - } - - // NB: dynamic_cast doesn't work over Kiway. - wxWindow* panel = m_treebook->GetPage( page ); + wxWindow* panel = m_treebook->GetPage( aPage ); wxCHECK( panel, /* void */ ); // Enable the reset button only if the page is re-settable if( m_resetButton ) { - if( panel && panel->GetWindowStyle() & wxRESETTABLE ) + if( panel && ( panel->GetWindowStyle() & wxRESETTABLE ) ) { m_resetButton->SetLabel( wxString::Format( _( "Reset %s to Defaults" ), - m_treebook->GetPageText( page ) ) ); + m_treebook->GetPageText( aPage ) ) ); m_resetButton->SetToolTip( panel->GetHelpTextAtPoint( wxPoint( -INT_MAX, INT_MAX ), wxHelpEvent::Origin_Unknown ) ); m_resetButton->Enable( true ); @@ -339,6 +329,23 @@ void PAGED_DIALOG::OnPageChanged( wxBookCtrlEvent& event ) m_resetButton->GetParent()->Layout(); } +} + + +void PAGED_DIALOG::OnPageChanged( wxBookCtrlEvent& event ) +{ + int page = event.GetSelection(); + + // Use the first sub-page when a tree level node is selected. + if( m_treebook->GetCurrentPage()->GetChildren().IsEmpty() ) + { + unsigned next = page + 1; + + if( next < m_treebook->GetPageCount() ) + m_treebook->ChangeSelection( next ); + } + + UpdateResetButton( page ); wxSizeEvent evt( wxDefaultSize ); diff --git a/include/widgets/paged_dialog.h b/include/widgets/paged_dialog.h index 693465f1e9..0cd7590748 100644 --- a/include/widgets/paged_dialog.h +++ b/include/widgets/paged_dialog.h @@ -46,6 +46,8 @@ public: void SetError( const wxString& aMessage, wxWindow* aPage, wxWindow* aCtrl, int aRow = -1, int aCol = -1 ); + void UpdateResetButton( int aPage ); + protected: void finishInitialization();