Default a library item selection if there is none.

Fixes https://gitlab.com/kicad/code/kicad/issues/13261
This commit is contained in:
Jeff Young 2022-12-26 14:10:15 +00:00
parent 78e2f0fd4d
commit 340a8fb154
1 changed files with 26 additions and 0 deletions

View File

@ -629,6 +629,32 @@ void LIB_TREE::onItemContextMenu( wxDataViewEvent& aEvent )
if( TOOL_INTERACTIVE* tool = m_adapter->GetContextMenuTool() )
{
if( !GetCurrentTreeNode() )
{
wxPoint pos = m_tree_ctrl->ScreenToClient( wxGetMousePosition() );
// What we actually want is the height of the column header, but wxWidgets gives us
// no way to get that, so we use the height of the search ctrl as a proxy. And it's
// not even a very good proxy on Mac....
int headerHeight = m_tree_ctrl->GetPosition().y;
#ifdef __WXMAC__
headerHeight += 5;
#endif
pos.y -= headerHeight;
wxDataViewItem item;
wxDataViewColumn* col;
m_tree_ctrl->HitTest( pos, item, col );
if( item.IsOk() )
{
m_tree_ctrl->SetFocus();
m_tree_ctrl->Select( item );
wxSafeYield();
}
}
tool->Activate();
tool->GetManager()->VetoContextMenuMouseWarp();
tool->GetToolMenu().ShowContextMenu();