Pass hotkeys from search pane to frame

If the search pane doesn't handle the key, push it through the frame
hotkey handling system

Fixes https://gitlab.com/kicad/code/kicad/-/issues/12474

(cherry picked from commit 322c08d5f0de3b9fc37c93c69db79b3f2a26efdf)
This commit is contained in:
Seth Hillbrand 2025-07-24 13:13:42 -07:00
parent dc0b408eeb
commit 2e5be57499
3 changed files with 118 additions and 21 deletions

View File

@ -21,6 +21,8 @@
#include <memory>
#include <tool/action_menu.h>
#include <tool/tool_dispatcher.h>
#include <tool/tool_manager.h>
#include <settings/app_settings.h>
#include <eda_draw_frame.h>
#include <bitmaps.h>
@ -120,6 +122,7 @@ SEARCH_PANE::SEARCH_PANE( EDA_DRAW_FRAME* aFrame ) :
} );
m_frame->Bind( wxEVT_AUI_PANE_CLOSE, &SEARCH_PANE::OnClosed, this );
Bind( wxEVT_CHAR_HOOK, &SEARCH_PANE::OnCharHook, this );
}
@ -127,6 +130,7 @@ SEARCH_PANE::~SEARCH_PANE()
{
m_frame->Unbind( wxEVT_AUI_PANE_CLOSE, &SEARCH_PANE::OnClosed, this );
m_frame->Unbind( EDA_LANG_CHANGED, &SEARCH_PANE::OnLanguageChange, this );
Unbind( wxEVT_CHAR_HOOK, &SEARCH_PANE::OnCharHook, this );
m_handlers.clear();
@ -216,3 +220,25 @@ SEARCH_PANE_TAB* SEARCH_PANE::GetCurrentTab() const
{
return dynamic_cast<SEARCH_PANE_TAB*>( m_notebook->GetCurrentPage() );
}
void SEARCH_PANE::OnCharHook( wxKeyEvent& aEvent )
{
// Check if the event is from a child window of the search pane
wxWindow* eventObject = dynamic_cast<wxWindow*>( aEvent.GetEventObject() );
if( !eventObject || !IsDescendant( eventObject ) )
{
aEvent.Skip();
return;
}
// Try to let the tool framework handle the event
if( m_frame->GetToolDispatcher() )
{
m_frame->GetToolDispatcher()->DispatchWxEvent( aEvent );
return;
}
aEvent.Skip();
}

View File

@ -150,42 +150,111 @@ void SEARCH_PANE_LISTVIEW::OnColClicked( wxListEvent& aEvent )
void SEARCH_PANE_LISTVIEW::OnChar( wxKeyEvent& aEvent )
{
if( aEvent.GetKeyCode() == WXK_CONTROL_A )
bool handled = false;
switch( aEvent.GetKeyCode() )
{
// Select All
for( int row = 0; row < GetItemCount(); row++ )
SetItemState( row, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
}
else if( aEvent.GetKeyCode() == WXK_CONTROL_C )
{
// Copy to clipboard the selected rows
if( wxTheClipboard->Open() )
case WXK_CONTROL_A:
{
wxString txt;
// Select All
for( int row = 0; row < GetItemCount(); row++ )
SetItemState( row, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
handled = true;
break;
}
case WXK_CONTROL_C:
{
// Copy to clipboard the selected rows
if( wxTheClipboard->Open() )
{
if( GetItemState( row, wxLIST_STATE_SELECTED ) == wxLIST_STATE_SELECTED )
wxString txt;
for( int row = 0; row < GetItemCount(); row++ )
{
for( int col = 0; col < GetColumnCount(); col++ )
if( GetItemState( row, wxLIST_STATE_SELECTED ) == wxLIST_STATE_SELECTED )
{
if( GetColumnWidth( col ) > 0 )
for( int col = 0; col < GetColumnCount(); col++ )
{
txt += GetItemText( row, col );
if( GetColumnWidth( col ) > 0 )
{
txt += GetItemText( row, col );
if( row <= GetItemCount() - 1 )
txt += wxT( "\t" );
if( row <= GetItemCount() - 1 )
txt += wxT( "\t" );
}
}
}
txt += wxT( "\n" );
txt += wxT( "\n" );
}
}
wxTheClipboard->SetData( new wxTextDataObject( txt ) );
wxTheClipboard->Close();
}
wxTheClipboard->SetData( new wxTextDataObject( txt ) );
wxTheClipboard->Close();
handled = true;
break;
}
case WXK_DOWN:
case WXK_NUMPAD_DOWN:
{
// Move selection down
long focused = GetFocusedItem();
if( focused < 0 )
focused = 0;
if( focused < GetItemCount() - 1 )
{
if( !(aEvent.GetModifiers() & wxMOD_SHIFT) )
{
int next = -1;
while( ( next = GetNextSelected( next ) ) != wxNOT_FOUND )
Select( next, false );
}
++focused;
Focus( focused );
Select( focused );
}
handled = true;
break;
}
case WXK_UP:
case WXK_NUMPAD_UP:
{
// Move selection up
long focused = GetFocusedItem();
if( focused < 0 )
focused = 0;
if( focused > 0 )
{
if( !(aEvent.GetModifiers() & wxMOD_SHIFT) )
{
int next = -1;
while( ( next = GetNextSelected( next ) ) != wxNOT_FOUND )
Select( next, false );
}
--focused;
Focus( focused );
Select( focused );
}
handled = true;
break;
}
}
if( !handled )
aEvent.Skip();
}

View File

@ -81,6 +81,8 @@ public:
void FocusSearch();
void ClearAllResults();
void OnCharHook( wxKeyEvent& aEvent );
protected:
void OnLanguageChange( wxCommandEvent& aEvent );
SEARCH_PANE_TAB* GetCurrentTab() const;