Fix broken tree book selection in paged dialogs.
This only affected the tree controls that only parented sub-pages. Do not use the dialog ctor to select the initial page. Queuing a page changed event to fire after the dialog is shown is the proper solution.
This commit is contained in:
parent
b0bf780b80
commit
7b1b96c933
|
@ -106,7 +106,7 @@ PAGED_DIALOG::PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, bool aSho
|
||||||
m_resetButton->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::OnResetButton, this );
|
m_resetButton->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::OnResetButton, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_treebook->Bind( wxEVT_TREEBOOK_PAGE_CHANGED, &PAGED_DIALOG::OnPageChange, this );
|
m_treebook->Bind( wxEVT_TREEBOOK_PAGE_CHANGED, &PAGED_DIALOG::OnPageChanged, this );
|
||||||
m_treebook->Bind( wxEVT_TREEBOOK_PAGE_CHANGING, &PAGED_DIALOG::OnPageChanging, this );
|
m_treebook->Bind( wxEVT_TREEBOOK_PAGE_CHANGING, &PAGED_DIALOG::OnPageChanging, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ PAGED_DIALOG::~PAGED_DIALOG()
|
||||||
m_resetButton->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::OnResetButton, this );
|
m_resetButton->Unbind( wxEVT_COMMAND_BUTTON_CLICKED, &PAGED_DIALOG::OnResetButton, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_treebook->Unbind( wxEVT_TREEBOOK_PAGE_CHANGED, &PAGED_DIALOG::OnPageChange, this );
|
m_treebook->Unbind( wxEVT_TREEBOOK_PAGE_CHANGED, &PAGED_DIALOG::OnPageChanged, this );
|
||||||
m_treebook->Unbind( wxEVT_TREEBOOK_PAGE_CHANGING, &PAGED_DIALOG::OnPageChanging, this );
|
m_treebook->Unbind( wxEVT_TREEBOOK_PAGE_CHANGING, &PAGED_DIALOG::OnPageChanging, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,19 +304,19 @@ void PAGED_DIALOG::SetError( const wxString& aMessage, wxWindow* aPage, wxWindow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PAGED_DIALOG::OnPageChange( wxBookCtrlEvent& event )
|
void PAGED_DIALOG::OnPageChanged( wxBookCtrlEvent& event )
|
||||||
{
|
{
|
||||||
|
int page = event.GetSelection();
|
||||||
|
|
||||||
// Use the first sub-page when a tree level node is selected.
|
// Use the first sub-page when a tree level node is selected.
|
||||||
if( m_treebook->GetCurrentPage()->GetChildren().IsEmpty() )
|
if( m_treebook->GetPageParent( page ) == wxNOT_FOUND )
|
||||||
{
|
{
|
||||||
unsigned next = m_treebook->GetSelection() + 1;
|
unsigned next = page + 1;
|
||||||
|
|
||||||
if( next < m_treebook->GetPageCount() )
|
if( next < m_treebook->GetPageCount() )
|
||||||
m_treebook->ChangeSelection( next );
|
m_treebook->ChangeSelection( next );
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t page = event.GetSelection();
|
|
||||||
|
|
||||||
// NB: dynamic_cast doesn't work over Kiway.
|
// NB: dynamic_cast doesn't work over Kiway.
|
||||||
wxWindow* panel = m_treebook->GetPage( page );
|
wxWindow* panel = m_treebook->GetPage( page );
|
||||||
|
|
||||||
|
@ -343,9 +343,9 @@ void PAGED_DIALOG::OnPageChange( wxBookCtrlEvent& event )
|
||||||
m_resetButton->GetParent()->Layout();
|
m_resetButton->GetParent()->Layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSizeEvent evt( panel->GetSize() );
|
wxSizeEvent evt( wxDefaultSize );
|
||||||
|
|
||||||
panel->ProcessWindowEvent( evt );
|
wxQueueEvent( m_treebook, evt.Clone() );
|
||||||
|
|
||||||
// @todo Test to see if this macOS hack is still necessary now that a psuedo size event is
|
// @todo Test to see if this macOS hack is still necessary now that a psuedo size event is
|
||||||
// processed above.
|
// processed above.
|
||||||
|
|
|
@ -85,11 +85,6 @@ DIALOG_SCHEMATIC_SETUP::DIALOG_SCHEMATIC_SETUP( SCH_EDIT_FRAME* aFrame ) :
|
||||||
m_macHack.push_back( true );
|
m_macHack.push_back( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect Events
|
|
||||||
m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED,
|
|
||||||
wxBookCtrlEventHandler( DIALOG_SCHEMATIC_SETUP::OnPageChange ), nullptr,
|
|
||||||
this );
|
|
||||||
|
|
||||||
finishDialogSettings();
|
finishDialogSettings();
|
||||||
|
|
||||||
if( Prj().IsReadOnly() )
|
if( Prj().IsReadOnly() )
|
||||||
|
@ -97,58 +92,29 @@ DIALOG_SCHEMATIC_SETUP::DIALOG_SCHEMATIC_SETUP( SCH_EDIT_FRAME* aFrame ) :
|
||||||
m_infoBar->ShowMessage( _( "Project is missing or read-only. Settings will not be "
|
m_infoBar->ShowMessage( _( "Project is missing or read-only. Settings will not be "
|
||||||
"editable." ), wxICON_WARNING );
|
"editable." ), wxICON_WARNING );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxBookCtrlEvent evt( wxEVT_TREEBOOK_PAGE_CHANGED, wxID_ANY, 0 );
|
||||||
|
|
||||||
|
wxQueueEvent( m_treebook, evt.Clone() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DIALOG_SCHEMATIC_SETUP::~DIALOG_SCHEMATIC_SETUP()
|
DIALOG_SCHEMATIC_SETUP::~DIALOG_SCHEMATIC_SETUP()
|
||||||
{
|
{
|
||||||
m_treebook->Disconnect( wxEVT_TREEBOOK_PAGE_CHANGED,
|
|
||||||
wxBookCtrlEventHandler( DIALOG_SCHEMATIC_SETUP::OnPageChange ), nullptr,
|
|
||||||
this );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DIALOG_SCHEMATIC_SETUP::OnPageChange( wxBookCtrlEvent& event )
|
void DIALOG_SCHEMATIC_SETUP::OnPageChanged( wxBookCtrlEvent& event )
|
||||||
{
|
{
|
||||||
|
PAGED_DIALOG::OnPageChanged( event );
|
||||||
|
|
||||||
int page = event.GetSelection();
|
int page = event.GetSelection();
|
||||||
|
|
||||||
if( Prj().IsReadOnly() )
|
if( Prj().IsReadOnly() )
|
||||||
KIUI::Disable( m_treebook->GetPage( page ) );
|
KIUI::Disable( m_treebook->GetPage( page ) );
|
||||||
|
|
||||||
// Enable the reset button only if the page is resettable
|
|
||||||
if( m_resetButton )
|
|
||||||
{
|
|
||||||
if( auto panel = dynamic_cast<RESETTABLE_PANEL*>( m_treebook->GetPage( page ) ) )
|
|
||||||
{
|
|
||||||
m_resetButton->SetToolTip( panel->GetResetTooltip() );
|
|
||||||
m_resetButton->Enable( true );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_resetButton->SetToolTip( wxString() );
|
|
||||||
m_resetButton->Enable( false );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Work around an OSX bug where the wxGrid children don't get placed correctly until
|
|
||||||
// the first resize event
|
|
||||||
#ifdef __WXMAC__
|
|
||||||
if( m_macHack[ page ] )
|
|
||||||
{
|
|
||||||
wxSize pageSize = m_treebook->GetPage( page )->GetSize();
|
|
||||||
pageSize.x -= 1;
|
|
||||||
pageSize.y += 2;
|
|
||||||
|
|
||||||
m_treebook->GetPage( page )->SetSize( pageSize );
|
|
||||||
m_macHack[ page ] = false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Layout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Run Import Settings... action
|
|
||||||
void DIALOG_SCHEMATIC_SETUP::OnAuxiliaryAction( wxCommandEvent& event )
|
void DIALOG_SCHEMATIC_SETUP::OnAuxiliaryAction( wxCommandEvent& event )
|
||||||
{
|
{
|
||||||
DIALOG_SCH_IMPORT_SETTINGS importDlg( this, m_frame );
|
DIALOG_SCH_IMPORT_SETTINGS importDlg( this, m_frame );
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
* Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License as published by the
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
@ -40,7 +40,9 @@ public:
|
||||||
~DIALOG_SCHEMATIC_SETUP();
|
~DIALOG_SCHEMATIC_SETUP();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void OnAuxiliaryAction( wxCommandEvent& event ) override;
|
// event handlers
|
||||||
|
void OnPageChanged( wxBookCtrlEvent& aEvent ) override;
|
||||||
|
void OnAuxiliaryAction( wxCommandEvent& aEvent ) override;
|
||||||
|
|
||||||
SCH_EDIT_FRAME* m_frame;
|
SCH_EDIT_FRAME* m_frame;
|
||||||
|
|
||||||
|
@ -53,9 +55,6 @@ protected:
|
||||||
std::shared_ptr<ERC_ITEM> m_pinToPinError;
|
std::shared_ptr<ERC_ITEM> m_pinToPinError;
|
||||||
|
|
||||||
std::vector<bool> m_macHack;
|
std::vector<bool> m_macHack;
|
||||||
|
|
||||||
// event handlers
|
|
||||||
void OnPageChange( wxBookCtrlEvent& event );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -56,8 +56,8 @@ protected:
|
||||||
void OnCancel( wxCommandEvent& event );
|
void OnCancel( wxCommandEvent& event );
|
||||||
virtual void OnAuxiliaryAction( wxCommandEvent& event ) { event.Skip(); }
|
virtual void OnAuxiliaryAction( wxCommandEvent& event ) { event.Skip(); }
|
||||||
void OnResetButton( wxCommandEvent& aEvent );
|
void OnResetButton( wxCommandEvent& aEvent );
|
||||||
void OnPageChange( wxBookCtrlEvent& event );
|
virtual void OnPageChanged( wxBookCtrlEvent& event );
|
||||||
void OnPageChanging( wxBookCtrlEvent& aEvent );
|
virtual void OnPageChanging( wxBookCtrlEvent& aEvent );
|
||||||
|
|
||||||
wxTreebook* m_treebook;
|
wxTreebook* m_treebook;
|
||||||
wxButton* m_auxiliaryButton;
|
wxButton* m_auxiliaryButton;
|
||||||
|
|
|
@ -92,6 +92,7 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) :
|
||||||
m_layerSetupPage = 1;
|
m_layerSetupPage = 1;
|
||||||
|
|
||||||
m_treebook->AddSubPage( m_physicalStackup, _( "Physical Stackup" ) );
|
m_treebook->AddSubPage( m_physicalStackup, _( "Physical Stackup" ) );
|
||||||
|
|
||||||
// Change this value if m_physicalStackup is not the page 2 of m_treebook
|
// Change this value if m_physicalStackup is not the page 2 of m_treebook
|
||||||
m_physicalStackupPage = 2; // The page number (from 0) to select the m_physicalStackup panel
|
m_physicalStackupPage = 2; // The page number (from 0) to select the m_physicalStackup panel
|
||||||
|
|
||||||
|
@ -118,11 +119,6 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) :
|
||||||
|
|
||||||
m_treebook->SetMinSize( wxSize( -1, 480 ) );
|
m_treebook->SetMinSize( wxSize( -1, 480 ) );
|
||||||
|
|
||||||
// Connect Events
|
|
||||||
m_treebook->Connect( wxEVT_TREEBOOK_PAGE_CHANGED,
|
|
||||||
wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), nullptr,
|
|
||||||
this );
|
|
||||||
|
|
||||||
finishDialogSettings();
|
finishDialogSettings();
|
||||||
|
|
||||||
if( Prj().IsReadOnly() )
|
if( Prj().IsReadOnly() )
|
||||||
|
@ -130,20 +126,23 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) :
|
||||||
m_infoBar->ShowMessage( _( "Project is missing or read-only. Some settings will not "
|
m_infoBar->ShowMessage( _( "Project is missing or read-only. Some settings will not "
|
||||||
"be editable." ), wxICON_WARNING );
|
"be editable." ), wxICON_WARNING );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxBookCtrlEvent evt( wxEVT_TREEBOOK_PAGE_CHANGED, wxID_ANY, 0 );
|
||||||
|
|
||||||
|
wxQueueEvent( m_treebook, evt.Clone() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DIALOG_BOARD_SETUP::~DIALOG_BOARD_SETUP()
|
DIALOG_BOARD_SETUP::~DIALOG_BOARD_SETUP()
|
||||||
{
|
{
|
||||||
m_treebook->Disconnect( wxEVT_TREEBOOK_PAGE_CHANGED,
|
|
||||||
wxBookCtrlEventHandler( DIALOG_BOARD_SETUP::OnPageChange ), nullptr,
|
|
||||||
this );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DIALOG_BOARD_SETUP::OnPageChange( wxBookCtrlEvent& event )
|
void DIALOG_BOARD_SETUP::OnPageChanged( wxBookCtrlEvent& aEvent )
|
||||||
{
|
{
|
||||||
int page = event.GetSelection();
|
PAGED_DIALOG::OnPageChanged( aEvent );
|
||||||
|
|
||||||
|
int page = aEvent.GetSelection();
|
||||||
|
|
||||||
// Ensure layer page always gets updated even if we aren't moving towards it
|
// Ensure layer page always gets updated even if we aren't moving towards it
|
||||||
if( m_currentPage == m_physicalStackupPage )
|
if( m_currentPage == m_physicalStackupPage )
|
||||||
|
@ -155,24 +154,10 @@ void DIALOG_BOARD_SETUP::OnPageChange( wxBookCtrlEvent& event )
|
||||||
KIUI::Disable( m_treebook->GetPage( page ) );
|
KIUI::Disable( m_treebook->GetPage( page ) );
|
||||||
|
|
||||||
m_currentPage = page;
|
m_currentPage = page;
|
||||||
|
|
||||||
#ifdef __WXMAC__
|
|
||||||
// Work around an OSX bug where the wxGrid children don't get placed correctly until
|
|
||||||
// the first resize event
|
|
||||||
if( m_macHack[ page ] )
|
|
||||||
{
|
|
||||||
wxSize pageSize = m_treebook->GetPage( page )->GetSize();
|
|
||||||
pageSize.x -= 1;
|
|
||||||
pageSize.y += 2;
|
|
||||||
|
|
||||||
m_treebook->GetPage( page )->SetSize( pageSize );
|
|
||||||
m_macHack[ page ] = false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DIALOG_BOARD_SETUP::OnAuxiliaryAction( wxCommandEvent& event )
|
void DIALOG_BOARD_SETUP::OnAuxiliaryAction( wxCommandEvent& aEvent )
|
||||||
{
|
{
|
||||||
DIALOG_IMPORT_SETTINGS importDlg( this, m_frame );
|
DIALOG_IMPORT_SETTINGS importDlg( this, m_frame );
|
||||||
|
|
||||||
|
@ -244,7 +229,6 @@ void DIALOG_BOARD_SETUP::OnAuxiliaryAction( wxCommandEvent& event )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( okToProceed )
|
if( okToProceed )
|
||||||
{
|
{
|
||||||
otherBoard->SetProject( otherPrj );
|
otherBoard->SetProject( otherPrj );
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2017-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
* Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License as published by the
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
@ -45,7 +45,9 @@ public:
|
||||||
~DIALOG_BOARD_SETUP();
|
~DIALOG_BOARD_SETUP();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void OnAuxiliaryAction( wxCommandEvent& event ) override;
|
// event handlers
|
||||||
|
void OnPageChanged( wxBookCtrlEvent& aEvent ) override;
|
||||||
|
void OnAuxiliaryAction( wxCommandEvent& aEvent ) override;
|
||||||
|
|
||||||
PCB_EDIT_FRAME* m_frame;
|
PCB_EDIT_FRAME* m_frame;
|
||||||
|
|
||||||
|
@ -64,9 +66,6 @@ protected:
|
||||||
|
|
||||||
std::vector<bool> m_macHack;
|
std::vector<bool> m_macHack;
|
||||||
|
|
||||||
// event handlers
|
|
||||||
void OnPageChange( wxBookCtrlEvent& event );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_currentPage; // the current page index
|
int m_currentPage; // the current page index
|
||||||
int m_physicalStackupPage; // the page index of the PANEL_SETUP_BOARD_STACKUP page
|
int m_physicalStackupPage; // the page index of the PANEL_SETUP_BOARD_STACKUP page
|
||||||
|
|
Loading…
Reference in New Issue