Implement ESC processing for choose symbol dialog.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/16271
This commit is contained in:
parent
057baf306f
commit
518be57516
|
@ -52,6 +52,10 @@ DIALOG_SYMBOL_CHOOSER::DIALOG_SYMBOL_CHOOSER( SCH_BASE_FRAME* aParent, const LIB
|
||||||
[this]()
|
[this]()
|
||||||
{
|
{
|
||||||
EndModal( wxID_OK );
|
EndModal( wxID_OK );
|
||||||
|
},
|
||||||
|
[this]()
|
||||||
|
{
|
||||||
|
EndModal( wxID_CANCEL );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
|
sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
|
||||||
|
@ -98,6 +102,15 @@ DIALOG_SYMBOL_CHOOSER::DIALOG_SYMBOL_CHOOSER( SCH_BASE_FRAME* aParent, const LIB
|
||||||
SetInitialFocus( m_chooserPanel->GetFocusTarget() );
|
SetInitialFocus( m_chooserPanel->GetFocusTarget() );
|
||||||
SetupStandardButtons();
|
SetupStandardButtons();
|
||||||
|
|
||||||
|
Bind( wxEVT_CHAR_HOOK,
|
||||||
|
[&]( wxKeyEvent& aEvent )
|
||||||
|
{
|
||||||
|
if( aEvent.GetKeyCode() == WXK_ESCAPE )
|
||||||
|
{
|
||||||
|
m_chooserPanel->FinishSetup();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
m_chooserPanel->FinishSetup();
|
m_chooserPanel->FinishSetup();
|
||||||
Layout();
|
Layout();
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,8 +81,13 @@ SYMBOL_CHOOSER_FRAME::SYMBOL_CHOOSER_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
|
||||||
{
|
{
|
||||||
wxCommandEvent dummy;
|
wxCommandEvent dummy;
|
||||||
OnOK( dummy );
|
OnOK( dummy );
|
||||||
|
},
|
||||||
|
[this]()
|
||||||
|
{
|
||||||
|
DismissModal( false );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
||||||
sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
|
sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
|
||||||
|
|
||||||
wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
|
wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
|
||||||
|
|
|
@ -54,7 +54,8 @@ PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aP
|
||||||
std::vector<PICKED_SYMBOL>& aHistoryList,
|
std::vector<PICKED_SYMBOL>& aHistoryList,
|
||||||
std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
|
std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
|
||||||
bool aAllowFieldEdits, bool aShowFootprints,
|
bool aAllowFieldEdits, bool aShowFootprints,
|
||||||
std::function<void()> aCloseHandler ) :
|
std::function<void()> aAcceptHandler,
|
||||||
|
std::function<void()> aEscapeHandler ) :
|
||||||
wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
|
wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
|
||||||
m_symbol_preview( nullptr ),
|
m_symbol_preview( nullptr ),
|
||||||
m_hsplitter( nullptr ),
|
m_hsplitter( nullptr ),
|
||||||
|
@ -64,7 +65,8 @@ PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aP
|
||||||
m_tree( nullptr ),
|
m_tree( nullptr ),
|
||||||
m_details( nullptr ),
|
m_details( nullptr ),
|
||||||
m_frame( aFrame ),
|
m_frame( aFrame ),
|
||||||
m_closeHandler( std::move( aCloseHandler ) ),
|
m_acceptHandler( std::move( aAcceptHandler ) ),
|
||||||
|
m_escapeHandler( std::move( aEscapeHandler ) ),
|
||||||
m_showPower( false ),
|
m_showPower( false ),
|
||||||
m_allow_field_edits( aAllowFieldEdits ),
|
m_allow_field_edits( aAllowFieldEdits ),
|
||||||
m_show_footprints( aShowFootprints )
|
m_show_footprints( aShowFootprints )
|
||||||
|
@ -170,7 +172,7 @@ PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aP
|
||||||
if( !adapter->AddLibraries( libNicknames, m_frame ) )
|
if( !adapter->AddLibraries( libNicknames, m_frame ) )
|
||||||
{
|
{
|
||||||
// loading cancelled by user
|
// loading cancelled by user
|
||||||
m_closeHandler();
|
m_acceptHandler();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,9 +262,36 @@ PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aP
|
||||||
|
|
||||||
if( m_details )
|
if( m_details )
|
||||||
{
|
{
|
||||||
m_details->Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( PANEL_SYMBOL_CHOOSER::OnCharHook ),
|
m_details->Connect( wxEVT_CHAR_HOOK,
|
||||||
|
wxKeyEventHandler( PANEL_SYMBOL_CHOOSER::OnDetailsCharHook ),
|
||||||
nullptr, this );
|
nullptr, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bind( wxEVT_CHAR_HOOK,
|
||||||
|
[&]( wxKeyEvent& aEvent )
|
||||||
|
{
|
||||||
|
if( aEvent.GetKeyCode() == WXK_ESCAPE )
|
||||||
|
{
|
||||||
|
wxObject* eventSource = aEvent.GetEventObject();
|
||||||
|
|
||||||
|
if( wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( eventSource ) )
|
||||||
|
{
|
||||||
|
// First escape cancels search string value
|
||||||
|
if( textCtrl->GetValue() == m_tree->GetSearchString()
|
||||||
|
&& !m_tree->GetSearchString().IsEmpty() )
|
||||||
|
{
|
||||||
|
m_tree->SetSearchString( wxEmptyString );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_escapeHandler();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
aEvent.Skip();
|
||||||
|
}
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -290,8 +319,8 @@ PANEL_SYMBOL_CHOOSER::~PANEL_SYMBOL_CHOOSER()
|
||||||
if( m_details )
|
if( m_details )
|
||||||
{
|
{
|
||||||
m_details->Disconnect( wxEVT_CHAR_HOOK,
|
m_details->Disconnect( wxEVT_CHAR_HOOK,
|
||||||
wxKeyEventHandler( PANEL_SYMBOL_CHOOSER::OnCharHook ), nullptr,
|
wxKeyEventHandler( PANEL_SYMBOL_CHOOSER::OnDetailsCharHook ),
|
||||||
this );
|
nullptr, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
|
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
|
||||||
|
@ -410,7 +439,7 @@ void PANEL_SYMBOL_CHOOSER::FinishSetup()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PANEL_SYMBOL_CHOOSER::OnCharHook( wxKeyEvent& e )
|
void PANEL_SYMBOL_CHOOSER::OnDetailsCharHook( wxKeyEvent& e )
|
||||||
{
|
{
|
||||||
if( m_details && e.GetKeyCode() == 'C' && e.ControlDown() &&
|
if( m_details && e.GetKeyCode() == 'C' && e.ControlDown() &&
|
||||||
!e.AltDown() && !e.ShiftDown() && !e.MetaDown() )
|
!e.AltDown() && !e.ShiftDown() && !e.MetaDown() )
|
||||||
|
@ -459,7 +488,7 @@ void PANEL_SYMBOL_CHOOSER::onCloseTimer( wxTimerEvent& aEvent )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_closeHandler();
|
m_acceptHandler();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,14 +52,16 @@ public:
|
||||||
* (currently just footprint selection) will not be available.
|
* (currently just footprint selection) will not be available.
|
||||||
* @param aShowFootprints if false, all footprint preview and selection features are
|
* @param aShowFootprints if false, all footprint preview and selection features are
|
||||||
* disabled. This forces aAllowFieldEdits false too.
|
* disabled. This forces aAllowFieldEdits false too.
|
||||||
* @param aCloseHandler a handler to be called on double-click of a footprint
|
* @param aAcceptHandler a handler to be called on double-click of a footprint
|
||||||
|
* @param aEscapeHandler a handler to be called on <ESC>
|
||||||
*/
|
*/
|
||||||
PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aParent,
|
PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aParent,
|
||||||
const SYMBOL_LIBRARY_FILTER* aFilter,
|
const SYMBOL_LIBRARY_FILTER* aFilter,
|
||||||
std::vector<PICKED_SYMBOL>& aHistoryList,
|
std::vector<PICKED_SYMBOL>& aHistoryList,
|
||||||
std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
|
std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
|
||||||
bool aAllowFieldEdits, bool aShowFootprints,
|
bool aAllowFieldEdits, bool aShowFootprints,
|
||||||
std::function<void()> aCloseHandler );
|
std::function<void()> aAcceptHandler,
|
||||||
|
std::function<void()> aEscapeHandler );
|
||||||
|
|
||||||
~PANEL_SYMBOL_CHOOSER();
|
~PANEL_SYMBOL_CHOOSER();
|
||||||
|
|
||||||
|
@ -99,7 +101,7 @@ protected:
|
||||||
|
|
||||||
wxPanel* constructRightPanel( wxWindow* aParent );
|
wxPanel* constructRightPanel( wxWindow* aParent );
|
||||||
|
|
||||||
void OnCharHook( wxKeyEvent& aEvt );
|
void OnDetailsCharHook( wxKeyEvent& aEvt );
|
||||||
void onCloseTimer( wxTimerEvent& aEvent );
|
void onCloseTimer( wxTimerEvent& aEvent );
|
||||||
|
|
||||||
void onFootprintSelected( wxCommandEvent& aEvent );
|
void onFootprintSelected( wxCommandEvent& aEvent );
|
||||||
|
@ -150,7 +152,8 @@ protected:
|
||||||
HTML_WINDOW* m_details;
|
HTML_WINDOW* m_details;
|
||||||
|
|
||||||
SCH_BASE_FRAME* m_frame;
|
SCH_BASE_FRAME* m_frame;
|
||||||
std::function<void()> m_closeHandler;
|
std::function<void()> m_acceptHandler;
|
||||||
|
std::function<void()> m_escapeHandler;
|
||||||
|
|
||||||
bool m_showPower;
|
bool m_showPower;
|
||||||
bool m_allow_field_edits;
|
bool m_allow_field_edits;
|
||||||
|
|
Loading…
Reference in New Issue