2019-08-26 10:57:07 +00:00
|
|
|
/*
|
2017-04-10 14:22:41 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
|
2021-06-10 14:10:55 +00:00
|
|
|
* Copyright (C) 2014-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-04-10 14:22:41 +00:00
|
|
|
*
|
|
|
|
* 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 Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2020-12-17 13:12:18 +00:00
|
|
|
#include <widgets/lib_tree.h>
|
2020-04-24 23:44:09 +00:00
|
|
|
#include <macros.h>
|
2017-04-10 14:22:41 +00:00
|
|
|
#include <wxdataviewctrl_helpers.h>
|
|
|
|
#include <wx/artprov.h>
|
|
|
|
#include <wx/sizer.h>
|
2019-06-05 19:15:57 +00:00
|
|
|
#include <tool/tool_interactive.h>
|
|
|
|
#include <tool/tool_manager.h>
|
2021-07-05 01:24:03 +00:00
|
|
|
#include <wx/srchctrl.h>
|
2021-05-01 18:04:11 +00:00
|
|
|
#include <wx/settings.h>
|
|
|
|
#include <wx/statbmp.h>
|
2021-07-05 01:59:51 +00:00
|
|
|
#include <wx/timer.h>
|
2019-08-26 10:57:07 +00:00
|
|
|
|
2017-09-15 14:17:44 +00:00
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable,
|
2021-10-10 12:52:37 +00:00
|
|
|
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter, WIDGETS aWidgets,
|
|
|
|
HTML_WINDOW* aDetails ) :
|
|
|
|
wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxWANTS_CHARS | wxTAB_TRAVERSAL | wxNO_BORDER ),
|
|
|
|
m_lib_table( aLibTable ), m_adapter( aAdapter ), m_query_ctrl( nullptr ),
|
|
|
|
m_details_ctrl( nullptr )
|
2017-04-10 14:22:41 +00:00
|
|
|
{
|
2021-08-03 16:53:30 +00:00
|
|
|
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2017-04-10 14:43:25 +00:00
|
|
|
// Search text control
|
|
|
|
if( aWidgets & SEARCH )
|
|
|
|
{
|
2021-08-03 16:53:30 +00:00
|
|
|
wxBoxSizer* search_sizer = new wxBoxSizer( wxHORIZONTAL );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2021-07-05 01:24:03 +00:00
|
|
|
m_query_ctrl = new wxSearchCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition,
|
2021-07-07 16:00:24 +00:00
|
|
|
wxDefaultSize );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2021-07-05 01:24:03 +00:00
|
|
|
m_query_ctrl->ShowCancelButton( true );
|
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
#ifdef __WXGTK__
|
2021-08-25 03:04:20 +00:00
|
|
|
// wxSearchCtrl vertical height is not calculated correctly on some GTK setups
|
|
|
|
// See https://gitlab.com/kicad/code/kicad/-/issues/9019
|
|
|
|
m_query_ctrl->SetMinSize( wxSize( -1, GetTextExtent( wxT( "qb" ) ).y + 10 ) );
|
2017-04-10 14:22:41 +00:00
|
|
|
#endif
|
2021-08-25 03:04:20 +00:00
|
|
|
|
|
|
|
m_debounceTimer = new wxTimer( this );
|
|
|
|
|
2020-12-20 12:34:48 +00:00
|
|
|
search_sizer->Add( m_query_ctrl, 1, wxEXPAND, 5 );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2017-04-10 14:43:25 +00:00
|
|
|
sizer->Add( search_sizer, 0, wxEXPAND, 5 );
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
m_query_ctrl->Bind( wxEVT_TEXT, &LIB_TREE::onQueryText, this );
|
2021-07-07 19:50:04 +00:00
|
|
|
|
2021-07-07 20:52:21 +00:00
|
|
|
#if wxCHECK_VERSION( 3, 1, 1 )
|
2021-07-07 16:00:24 +00:00
|
|
|
m_query_ctrl->Bind( wxEVT_SEARCH, &LIB_TREE::onQueryEnter, this );
|
2021-07-07 19:50:04 +00:00
|
|
|
#else
|
|
|
|
m_query_ctrl->Bind( wxEVT_TEXT_ENTER, &LIB_TREE::onQueryEnter, this );
|
|
|
|
#endif
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
m_query_ctrl->Bind( wxEVT_CHAR_HOOK, &LIB_TREE::onQueryCharHook, this );
|
2021-07-05 01:59:51 +00:00
|
|
|
|
2021-07-07 16:00:24 +00:00
|
|
|
|
2021-07-05 01:59:51 +00:00
|
|
|
Bind( wxEVT_TIMER, &LIB_TREE::onDebounceTimer, this, m_debounceTimer->GetId() );
|
2017-04-10 14:43:25 +00:00
|
|
|
}
|
|
|
|
|
2018-08-04 11:59:04 +00:00
|
|
|
// Tree control
|
2018-07-25 23:16:34 +00:00
|
|
|
m_tree_ctrl = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
2019-08-26 10:57:07 +00:00
|
|
|
wxDV_SINGLE );
|
2017-04-10 14:43:25 +00:00
|
|
|
m_adapter->AttachTo( m_tree_ctrl );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2018-08-05 13:22:29 +00:00
|
|
|
if( aWidgets & DETAILS )
|
2020-12-20 12:34:48 +00:00
|
|
|
sizer->AddSpacer( 5 );
|
|
|
|
|
|
|
|
sizer->Add( m_tree_ctrl, 5, wxRIGHT | wxBOTTOM | wxEXPAND, 1 );
|
2017-04-10 14:43:25 +00:00
|
|
|
|
|
|
|
// Description panel
|
|
|
|
if( aWidgets & DETAILS )
|
|
|
|
{
|
2018-01-03 02:52:35 +00:00
|
|
|
if( !aDetails )
|
|
|
|
{
|
2020-12-20 12:34:48 +00:00
|
|
|
wxPoint html_size = ConvertDialogToPixels( wxPoint( 80, 80 ) );
|
2018-06-06 06:47:53 +00:00
|
|
|
|
2021-10-14 19:45:38 +00:00
|
|
|
m_details_ctrl = new HTML_WINDOW( this, wxID_ANY, wxDefaultPosition,
|
|
|
|
wxSize( html_size.x, html_size.y ),
|
|
|
|
wxHW_SCROLLBAR_AUTO );
|
2018-01-03 02:52:35 +00:00
|
|
|
|
2020-12-23 18:33:17 +00:00
|
|
|
sizer->Add( m_details_ctrl, 2, wxTOP | wxEXPAND, 5 );
|
2018-01-03 02:52:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_details_ctrl = aDetails;
|
|
|
|
}
|
2018-06-06 06:47:53 +00:00
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
m_details_ctrl->Bind( wxEVT_HTML_LINK_CLICKED, &LIB_TREE::onDetailsLink, this );
|
2017-04-10 14:43:25 +00:00
|
|
|
}
|
2017-04-10 14:22:41 +00:00
|
|
|
|
|
|
|
SetSizer( sizer );
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &LIB_TREE::onTreeActivate, this );
|
|
|
|
m_tree_ctrl->Bind( wxEVT_DATAVIEW_SELECTION_CHANGED, &LIB_TREE::onTreeSelect, this );
|
|
|
|
m_tree_ctrl->Bind( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &LIB_TREE::onContextMenu, this );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
Bind( SYMBOL_PRESELECTED, &LIB_TREE::onPreselect, this );
|
2017-06-25 21:13:39 +00:00
|
|
|
|
2017-08-19 06:39:55 +00:00
|
|
|
// If wxTextCtrl::SetHint() is called before binding wxEVT_TEXT, the event
|
|
|
|
// handler will intermittently fire.
|
|
|
|
if( m_query_ctrl )
|
|
|
|
{
|
2021-07-05 15:31:50 +00:00
|
|
|
m_query_ctrl->SetDescriptiveText( _( "Filter" ) );
|
2017-08-19 06:39:55 +00:00
|
|
|
m_query_ctrl->SetFocus();
|
2020-08-11 23:09:08 +00:00
|
|
|
m_query_ctrl->SetValue( wxEmptyString );
|
|
|
|
|
|
|
|
// Force an update of the adapter with the empty text to ensure preselect is done
|
|
|
|
Regenerate( false );
|
2017-08-19 06:39:55 +00:00
|
|
|
}
|
2021-02-25 20:13:42 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// There may be a part preselected in the model. Make sure it is displayed.
|
|
|
|
// Regenerate does this in the other branch
|
|
|
|
postPreselectEvent();
|
|
|
|
}
|
2017-08-19 06:39:55 +00:00
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
Layout();
|
|
|
|
sizer->Fit( this );
|
2018-06-06 06:47:53 +00:00
|
|
|
|
|
|
|
#ifdef __WXGTK__
|
|
|
|
// Scrollbars must be always enabled to prevent an infinite event loop
|
|
|
|
// more details: http://trac.wxwidgets.org/ticket/18141
|
2018-06-06 14:59:59 +00:00
|
|
|
if( m_details_ctrl )
|
|
|
|
m_details_ctrl->ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
|
2018-06-06 06:47:53 +00:00
|
|
|
#endif /* __WXGTK__ */
|
2017-04-10 14:22:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-26 10:57:07 +00:00
|
|
|
LIB_TREE::~LIB_TREE()
|
|
|
|
{
|
2021-07-11 23:17:24 +00:00
|
|
|
// Stop the timer during destruction early to avoid potential race conditions (that do happen)
|
|
|
|
m_debounceTimer->Stop();
|
|
|
|
|
2019-09-18 23:00:48 +00:00
|
|
|
// Save the column widths to the config file
|
|
|
|
m_adapter->SaveColWidths();
|
2020-02-07 17:06:24 +00:00
|
|
|
|
|
|
|
m_adapter->SavePinnedItems();
|
2019-08-26 10:57:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
LIB_ID LIB_TREE::GetSelectedLibId( int* aUnit ) const
|
2017-04-10 14:22:41 +00:00
|
|
|
{
|
2021-08-03 16:53:30 +00:00
|
|
|
wxDataViewItem sel = m_tree_ctrl->GetSelection();
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2017-09-15 14:17:44 +00:00
|
|
|
if( !sel )
|
2021-08-03 16:53:30 +00:00
|
|
|
return LIB_ID();
|
2017-09-15 14:17:44 +00:00
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
if( aUnit )
|
|
|
|
*aUnit = m_adapter->GetUnitFor( sel );
|
|
|
|
|
|
|
|
return m_adapter->GetAliasFor( sel );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-07 17:06:24 +00:00
|
|
|
LIB_TREE_NODE* LIB_TREE::GetCurrentTreeNode() const
|
|
|
|
{
|
2021-08-03 16:53:30 +00:00
|
|
|
wxDataViewItem sel = m_tree_ctrl->GetSelection();
|
2020-02-07 17:06:24 +00:00
|
|
|
|
|
|
|
if( !sel )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return m_adapter->GetTreeNodeFor( sel );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::SelectLibId( const LIB_ID& aLibId )
|
2017-11-14 11:03:19 +00:00
|
|
|
{
|
|
|
|
selectIfValid( m_adapter->FindItem( aLibId ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-29 15:33:58 +00:00
|
|
|
void LIB_TREE::CenterLibId( const LIB_ID& aLibId )
|
|
|
|
{
|
|
|
|
centerIfValid( m_adapter->FindItem( aLibId ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::Unselect()
|
2018-01-09 12:48:00 +00:00
|
|
|
{
|
|
|
|
m_tree_ctrl->UnselectAll();
|
|
|
|
}
|
|
|
|
|
2018-08-19 16:53:01 +00:00
|
|
|
void LIB_TREE::ExpandLibId( const LIB_ID& aLibId )
|
|
|
|
{
|
|
|
|
expandIfValid( m_adapter->FindItem( aLibId ) );
|
|
|
|
}
|
|
|
|
|
2018-01-09 12:48:00 +00:00
|
|
|
|
2018-11-25 01:38:00 +00:00
|
|
|
void LIB_TREE::Regenerate( bool aKeepState )
|
2017-11-30 11:31:36 +00:00
|
|
|
{
|
|
|
|
STATE current;
|
|
|
|
|
|
|
|
// Store the state
|
2018-11-25 01:38:00 +00:00
|
|
|
if( aKeepState )
|
2019-11-26 21:38:57 +00:00
|
|
|
current = getState();
|
2017-11-30 11:31:36 +00:00
|
|
|
|
2017-12-13 09:33:04 +00:00
|
|
|
wxString filter = m_query_ctrl->GetValue();
|
2021-01-04 17:12:18 +00:00
|
|
|
m_adapter->UpdateSearchString( filter, aKeepState );
|
2017-11-30 11:31:36 +00:00
|
|
|
postPreselectEvent();
|
|
|
|
|
|
|
|
// Restore the state
|
2018-11-25 01:38:00 +00:00
|
|
|
if( aKeepState )
|
2019-11-26 21:38:57 +00:00
|
|
|
setState( current );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_TREE::RefreshLibTree()
|
|
|
|
{
|
2020-03-08 15:14:22 +00:00
|
|
|
m_adapter->RefreshTree();
|
2017-11-30 11:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-08 17:44:44 +00:00
|
|
|
wxWindow* LIB_TREE::GetFocusTarget()
|
2018-06-08 23:50:06 +00:00
|
|
|
{
|
|
|
|
if( m_query_ctrl )
|
2020-12-08 17:44:44 +00:00
|
|
|
return m_query_ctrl;
|
2018-06-08 23:50:06 +00:00
|
|
|
else
|
2020-12-08 17:44:44 +00:00
|
|
|
return m_tree_ctrl;
|
2018-06-08 23:50:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::toggleExpand( const wxDataViewItem& aTreeId )
|
2017-12-20 11:25:12 +00:00
|
|
|
{
|
|
|
|
if( !aTreeId.IsOk() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( m_tree_ctrl->IsExpanded( aTreeId ) )
|
|
|
|
m_tree_ctrl->Collapse( aTreeId );
|
|
|
|
else
|
|
|
|
m_tree_ctrl->Expand( aTreeId );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::selectIfValid( const wxDataViewItem& aTreeId )
|
2017-04-10 14:22:41 +00:00
|
|
|
{
|
|
|
|
if( aTreeId.IsOk() )
|
|
|
|
{
|
|
|
|
m_tree_ctrl->EnsureVisible( aTreeId );
|
|
|
|
m_tree_ctrl->Select( aTreeId );
|
2017-06-25 21:13:39 +00:00
|
|
|
postPreselectEvent();
|
2017-04-10 14:22:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-29 15:33:58 +00:00
|
|
|
void LIB_TREE::centerIfValid( const wxDataViewItem& aTreeId )
|
|
|
|
{
|
2021-10-02 09:40:12 +00:00
|
|
|
/*
|
|
|
|
* This doesn't actually center because the wxWidgets API is poorly suited to that (and
|
|
|
|
* it might be too noisy as well).
|
|
|
|
*
|
|
|
|
* It does try to keep the given item a bit off the top or bottom of the window.
|
|
|
|
*/
|
|
|
|
|
2018-07-29 15:33:58 +00:00
|
|
|
if( aTreeId.IsOk() )
|
2021-10-02 09:40:12 +00:00
|
|
|
{
|
|
|
|
LIB_TREE_NODE* node = m_adapter->GetTreeNodeFor( aTreeId );
|
|
|
|
LIB_TREE_NODE* parent = node->m_Parent;
|
|
|
|
LIB_TREE_NODE* grandParent = parent ? parent->m_Parent : nullptr;
|
|
|
|
|
|
|
|
if( parent )
|
|
|
|
{
|
|
|
|
wxDataViewItemArray siblings;
|
|
|
|
m_adapter->GetChildren( wxDataViewItem( parent ), siblings );
|
|
|
|
|
|
|
|
int idx = siblings.Index( aTreeId );
|
|
|
|
|
|
|
|
if( idx + 5 < (int) siblings.GetCount() )
|
|
|
|
{
|
2021-10-02 11:39:33 +00:00
|
|
|
m_tree_ctrl->EnsureVisible( siblings.Item( idx + 5 ) );
|
2021-10-02 09:40:12 +00:00
|
|
|
}
|
|
|
|
else if( grandParent )
|
|
|
|
{
|
|
|
|
wxDataViewItemArray parentsSiblings;
|
|
|
|
m_adapter->GetChildren( wxDataViewItem( grandParent ), parentsSiblings );
|
|
|
|
|
|
|
|
int p_idx = parentsSiblings.Index( wxDataViewItem( parent ) );
|
|
|
|
|
|
|
|
if( p_idx + 1 < (int) parentsSiblings.GetCount() )
|
2021-10-02 11:39:33 +00:00
|
|
|
m_tree_ctrl->EnsureVisible( parentsSiblings.Item( p_idx + 1 ) );
|
2021-10-02 09:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( idx - 5 >= 0 )
|
2021-10-02 11:39:33 +00:00
|
|
|
m_tree_ctrl->EnsureVisible( siblings.Item( idx - 5 ) );
|
2021-10-02 09:40:12 +00:00
|
|
|
else
|
|
|
|
m_tree_ctrl->EnsureVisible( wxDataViewItem( parent ) );
|
|
|
|
}
|
|
|
|
|
2018-07-29 15:33:58 +00:00
|
|
|
m_tree_ctrl->EnsureVisible( aTreeId );
|
2021-10-02 09:40:12 +00:00
|
|
|
}
|
2018-07-29 15:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-19 16:53:01 +00:00
|
|
|
void LIB_TREE::expandIfValid( const wxDataViewItem& aTreeId )
|
|
|
|
{
|
|
|
|
if( aTreeId.IsOk() && !m_tree_ctrl->IsExpanded( aTreeId ) )
|
|
|
|
m_tree_ctrl->Expand( aTreeId );
|
|
|
|
}
|
|
|
|
|
2018-07-29 15:33:58 +00:00
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::postPreselectEvent()
|
2017-04-10 14:22:41 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
wxCommandEvent event( SYMBOL_PRESELECTED );
|
2017-06-25 21:13:39 +00:00
|
|
|
wxPostEvent( this, event );
|
2017-04-10 14:22:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::postSelectEvent()
|
2017-04-10 14:22:41 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
wxCommandEvent event( SYMBOL_SELECTED );
|
2017-06-25 21:13:39 +00:00
|
|
|
wxPostEvent( this, event );
|
2017-04-10 14:22:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
LIB_TREE::STATE LIB_TREE::getState() const
|
2017-04-10 14:22:41 +00:00
|
|
|
{
|
2017-11-30 11:31:36 +00:00
|
|
|
STATE state;
|
|
|
|
wxDataViewItemArray items;
|
|
|
|
m_adapter->GetChildren( wxDataViewItem( nullptr ), items );
|
|
|
|
|
2021-10-02 09:40:12 +00:00
|
|
|
for( const wxDataViewItem& item : items )
|
2017-11-21 13:54:30 +00:00
|
|
|
{
|
2017-11-30 11:31:36 +00:00
|
|
|
if( m_tree_ctrl->IsExpanded( item ) )
|
|
|
|
state.expanded.push_back( item );
|
2017-11-21 13:54:30 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 10:22:24 +00:00
|
|
|
state.selection = GetSelectedLibId();
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2017-11-30 11:31:36 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::setState( const STATE& aState )
|
2017-11-30 11:31:36 +00:00
|
|
|
{
|
2017-12-20 11:05:25 +00:00
|
|
|
m_tree_ctrl->Freeze();
|
2017-11-30 11:31:36 +00:00
|
|
|
|
2021-10-02 09:40:12 +00:00
|
|
|
for( const wxDataViewItem& item : aState.expanded )
|
2017-11-30 11:31:36 +00:00
|
|
|
m_tree_ctrl->Expand( item );
|
|
|
|
|
2017-12-20 11:05:25 +00:00
|
|
|
// wxDataViewCtrl cannot be frozen when a selection
|
|
|
|
// command is issued, otherwise it selects a random item (Windows)
|
|
|
|
m_tree_ctrl->Thaw();
|
|
|
|
|
2018-01-09 12:48:00 +00:00
|
|
|
if( !aState.selection.GetLibItemName().empty() || !aState.selection.GetLibNickname().empty() )
|
2017-12-11 10:22:24 +00:00
|
|
|
SelectLibId( aState.selection );
|
2017-11-30 11:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::onQueryText( wxCommandEvent& aEvent )
|
2017-11-30 11:31:36 +00:00
|
|
|
{
|
2021-07-05 01:59:51 +00:00
|
|
|
m_debounceTimer->StartOnce( 200 );
|
2017-11-21 13:54:30 +00:00
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
// Required to avoid interaction with SetHint()
|
|
|
|
// See documentation for wxTextEntry::SetHint
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::onQueryEnter( wxCommandEvent& aEvent )
|
2017-04-10 14:22:41 +00:00
|
|
|
{
|
2017-09-15 14:17:44 +00:00
|
|
|
if( GetSelectedLibId().IsValid() )
|
2017-06-25 21:13:39 +00:00
|
|
|
postSelectEvent();
|
2017-04-10 14:22:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-05 01:59:51 +00:00
|
|
|
void LIB_TREE::onDebounceTimer( wxTimerEvent& aEvent )
|
|
|
|
{
|
|
|
|
Regenerate( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke )
|
2017-04-10 14:22:41 +00:00
|
|
|
{
|
|
|
|
auto const sel = m_tree_ctrl->GetSelection();
|
2018-07-27 20:47:51 +00:00
|
|
|
auto type = sel.IsOk() ? m_adapter->GetTypeFor( sel ) : LIB_TREE_NODE::INVALID;
|
2017-04-10 14:22:41 +00:00
|
|
|
|
|
|
|
switch( aKeyStroke.GetKeyCode() )
|
|
|
|
{
|
2017-12-20 11:23:05 +00:00
|
|
|
case WXK_UP:
|
|
|
|
selectIfValid( GetPrevItem( *m_tree_ctrl, sel ) );
|
|
|
|
break;
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2017-12-20 11:23:05 +00:00
|
|
|
case WXK_DOWN:
|
|
|
|
selectIfValid( GetNextItem( *m_tree_ctrl, sel ) );
|
|
|
|
break;
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2019-01-23 06:33:00 +00:00
|
|
|
case WXK_ADD:
|
|
|
|
if( type == LIB_TREE_NODE::LIB )
|
|
|
|
m_tree_ctrl->Expand( sel );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_SUBTRACT:
|
|
|
|
if( type == LIB_TREE_NODE::LIB )
|
|
|
|
m_tree_ctrl->Collapse( sel );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2017-12-20 11:25:12 +00:00
|
|
|
case WXK_RETURN:
|
2018-07-27 20:47:51 +00:00
|
|
|
if( type == LIB_TREE_NODE::LIB )
|
2017-12-20 11:25:12 +00:00
|
|
|
{
|
|
|
|
toggleExpand( sel );
|
|
|
|
break;
|
|
|
|
}
|
2021-06-10 14:10:55 +00:00
|
|
|
// Intentionally fall through, so the selected symbol will be treated as the selected one
|
2020-04-24 23:44:09 +00:00
|
|
|
KI_FALLTHROUGH;
|
2017-12-20 11:25:12 +00:00
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
default:
|
|
|
|
aKeyStroke.Skip(); // Any other key: pass on to search box directly.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::onTreeSelect( wxDataViewEvent& aEvent )
|
2017-06-25 21:13:39 +00:00
|
|
|
{
|
2021-02-25 20:13:42 +00:00
|
|
|
if( !m_tree_ctrl->IsFrozen() )
|
|
|
|
postPreselectEvent();
|
2017-06-25 21:13:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::onTreeActivate( wxDataViewEvent& aEvent )
|
2017-06-25 21:13:39 +00:00
|
|
|
{
|
2017-09-15 14:17:44 +00:00
|
|
|
if( !GetSelectedLibId().IsValid() )
|
2017-06-25 21:13:39 +00:00
|
|
|
{
|
|
|
|
// Expand library/part units subtree
|
2017-12-20 11:25:12 +00:00
|
|
|
toggleExpand( m_tree_ctrl->GetSelection() );
|
2017-06-25 21:13:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
postSelectEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::onDetailsLink( wxHtmlLinkEvent& aEvent )
|
2017-06-25 21:13:39 +00:00
|
|
|
{
|
|
|
|
const wxHtmlLinkInfo& info = aEvent.GetLinkInfo();
|
|
|
|
::wxLaunchDefaultBrowser( info.GetHref() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::onPreselect( wxCommandEvent& aEvent )
|
2017-04-10 14:22:41 +00:00
|
|
|
{
|
2017-04-10 14:43:25 +00:00
|
|
|
if( m_details_ctrl )
|
|
|
|
{
|
|
|
|
int unit = 0;
|
2017-09-15 14:17:44 +00:00
|
|
|
LIB_ID id = GetSelectedLibId( &unit );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2017-09-15 14:17:44 +00:00
|
|
|
if( id.IsValid() )
|
2021-10-10 12:52:37 +00:00
|
|
|
m_details_ctrl->SetPage( m_adapter->GenerateInfo( id, unit ) );
|
|
|
|
else
|
|
|
|
m_details_ctrl->SetPage( wxEmptyString );
|
2017-04-10 14:43:25 +00:00
|
|
|
}
|
2017-04-10 14:22:41 +00:00
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::onContextMenu( wxDataViewEvent& aEvent )
|
2017-10-28 16:59:49 +00:00
|
|
|
{
|
2019-06-05 19:15:57 +00:00
|
|
|
TOOL_INTERACTIVE* tool = m_adapter->GetContextMenuTool();
|
2019-09-18 23:00:48 +00:00
|
|
|
|
2019-06-05 19:15:57 +00:00
|
|
|
if( tool )
|
2017-10-28 16:59:49 +00:00
|
|
|
{
|
2019-06-05 19:15:57 +00:00
|
|
|
tool->Activate();
|
2019-06-06 11:45:28 +00:00
|
|
|
tool->GetManager()->VetoContextMenuMouseWarp();
|
2019-06-05 19:15:57 +00:00
|
|
|
tool->GetToolMenu().ShowContextMenu();
|
|
|
|
|
|
|
|
TOOL_EVENT evt( TC_MOUSE, TA_MOUSE_CLICK, BUT_RIGHT );
|
|
|
|
tool->GetManager()->DispatchContextMenu( evt );
|
2017-10-28 16:59:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
wxDEFINE_EVENT( SYMBOL_PRESELECTED, wxCommandEvent );
|
|
|
|
wxDEFINE_EVENT( SYMBOL_SELECTED, wxCommandEvent );
|