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]()
|
||||
{
|
||||
EndModal( wxID_OK );
|
||||
},
|
||||
[this]()
|
||||
{
|
||||
EndModal( wxID_CANCEL );
|
||||
} );
|
||||
|
||||
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() );
|
||||
SetupStandardButtons();
|
||||
|
||||
Bind( wxEVT_CHAR_HOOK,
|
||||
[&]( wxKeyEvent& aEvent )
|
||||
{
|
||||
if( aEvent.GetKeyCode() == WXK_ESCAPE )
|
||||
{
|
||||
m_chooserPanel->FinishSetup();
|
||||
}
|
||||
} );
|
||||
|
||||
m_chooserPanel->FinishSetup();
|
||||
Layout();
|
||||
}
|
||||
|
|
|
@ -81,8 +81,13 @@ SYMBOL_CHOOSER_FRAME::SYMBOL_CHOOSER_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
|
|||
{
|
||||
wxCommandEvent dummy;
|
||||
OnOK( dummy );
|
||||
},
|
||||
[this]()
|
||||
{
|
||||
DismissModal( false );
|
||||
} );
|
||||
|
||||
|
||||
sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
|
||||
|
||||
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>& aAlreadyPlaced,
|
||||
bool aAllowFieldEdits, bool aShowFootprints,
|
||||
std::function<void()> aCloseHandler ) :
|
||||
std::function<void()> aAcceptHandler,
|
||||
std::function<void()> aEscapeHandler ) :
|
||||
wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
|
||||
m_symbol_preview( nullptr ),
|
||||
m_hsplitter( nullptr ),
|
||||
|
@ -64,7 +65,8 @@ PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aP
|
|||
m_tree( nullptr ),
|
||||
m_details( nullptr ),
|
||||
m_frame( aFrame ),
|
||||
m_closeHandler( std::move( aCloseHandler ) ),
|
||||
m_acceptHandler( std::move( aAcceptHandler ) ),
|
||||
m_escapeHandler( std::move( aEscapeHandler ) ),
|
||||
m_showPower( false ),
|
||||
m_allow_field_edits( aAllowFieldEdits ),
|
||||
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 ) )
|
||||
{
|
||||
// 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 )
|
||||
{
|
||||
m_details->Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( PANEL_SYMBOL_CHOOSER::OnCharHook ),
|
||||
m_details->Connect( wxEVT_CHAR_HOOK,
|
||||
wxKeyEventHandler( PANEL_SYMBOL_CHOOSER::OnDetailsCharHook ),
|
||||
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 )
|
||||
{
|
||||
m_details->Disconnect( wxEVT_CHAR_HOOK,
|
||||
wxKeyEventHandler( PANEL_SYMBOL_CHOOSER::OnCharHook ), nullptr,
|
||||
this );
|
||||
wxKeyEventHandler( PANEL_SYMBOL_CHOOSER::OnDetailsCharHook ),
|
||||
nullptr, this );
|
||||
}
|
||||
|
||||
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() &&
|
||||
!e.AltDown() && !e.ShiftDown() && !e.MetaDown() )
|
||||
|
@ -459,7 +488,7 @@ void PANEL_SYMBOL_CHOOSER::onCloseTimer( wxTimerEvent& aEvent )
|
|||
}
|
||||
else
|
||||
{
|
||||
m_closeHandler();
|
||||
m_acceptHandler();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,14 +52,16 @@ public:
|
|||
* (currently just footprint selection) will not be available.
|
||||
* @param aShowFootprints if false, all footprint preview and selection features are
|
||||
* 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,
|
||||
const SYMBOL_LIBRARY_FILTER* aFilter,
|
||||
std::vector<PICKED_SYMBOL>& aHistoryList,
|
||||
std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
|
||||
bool aAllowFieldEdits, bool aShowFootprints,
|
||||
std::function<void()> aCloseHandler );
|
||||
std::function<void()> aAcceptHandler,
|
||||
std::function<void()> aEscapeHandler );
|
||||
|
||||
~PANEL_SYMBOL_CHOOSER();
|
||||
|
||||
|
@ -99,7 +101,7 @@ protected:
|
|||
|
||||
wxPanel* constructRightPanel( wxWindow* aParent );
|
||||
|
||||
void OnCharHook( wxKeyEvent& aEvt );
|
||||
void OnDetailsCharHook( wxKeyEvent& aEvt );
|
||||
void onCloseTimer( wxTimerEvent& aEvent );
|
||||
|
||||
void onFootprintSelected( wxCommandEvent& aEvent );
|
||||
|
@ -150,7 +152,8 @@ protected:
|
|||
HTML_WINDOW* m_details;
|
||||
|
||||
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_allow_field_edits;
|
||||
|
|
Loading…
Reference in New Issue