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>
|
2024-01-05 14:19:54 +00:00
|
|
|
* Copyright (C) 2014-2024 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>
|
2023-05-01 20:26:29 +00:00
|
|
|
#include <widgets/std_bitmap_button.h>
|
2022-09-15 13:32:27 +00:00
|
|
|
#include <core/kicad_algo.h>
|
2020-04-24 23:44:09 +00:00
|
|
|
#include <macros.h>
|
2023-05-01 20:26:29 +00:00
|
|
|
#include <bitmaps.h>
|
2022-09-24 03:45:00 +00:00
|
|
|
#include <dialogs/eda_reorderable_list_dialog.h>
|
2019-06-05 19:15:57 +00:00
|
|
|
#include <tool/tool_interactive.h>
|
|
|
|
#include <tool/tool_manager.h>
|
2022-10-02 21:20:25 +00:00
|
|
|
#include <tool/action_manager.h>
|
2022-09-21 13:44:13 +00:00
|
|
|
#include <tool/actions.h>
|
2024-01-05 14:19:54 +00:00
|
|
|
#include <tool/tool_dispatcher.h>
|
2023-04-07 23:07:33 +00:00
|
|
|
#include <widgets/wx_dataviewctrl.h>
|
2021-05-01 18:04:11 +00:00
|
|
|
#include <wx/settings.h>
|
2023-04-07 23:07:33 +00:00
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/srchctrl.h>
|
2023-09-02 21:13:48 +00:00
|
|
|
#include <wx/popupwin.h>
|
2023-10-30 10:27:08 +00:00
|
|
|
|
|
|
|
#include <eda_doc.h> // for GetAssociatedDocument()
|
|
|
|
#include <pgm_base.h> // for PROJECT
|
|
|
|
#include <settings/settings_manager.h> // for PROJECT
|
2019-08-26 10:57:07 +00:00
|
|
|
|
2022-09-15 13:32:27 +00:00
|
|
|
constexpr int RECENT_SEARCHES_MAX = 10;
|
|
|
|
|
|
|
|
std::map<wxString, std::vector<wxString>> g_recentSearches;
|
|
|
|
|
|
|
|
|
|
|
|
LIB_TREE::LIB_TREE( wxWindow* aParent, const wxString& aRecentSearchesKey, LIB_TABLE* aLibTable,
|
|
|
|
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter, int aFlags,
|
2021-10-10 12:52:37 +00:00
|
|
|
HTML_WINDOW* aDetails ) :
|
|
|
|
wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxWANTS_CHARS | wxTAB_TRAVERSAL | wxNO_BORDER ),
|
2023-05-01 20:26:29 +00:00
|
|
|
m_adapter( aAdapter ),
|
|
|
|
m_query_ctrl( nullptr ),
|
|
|
|
m_sort_ctrl( nullptr ),
|
2022-09-15 13:32:27 +00:00
|
|
|
m_details_ctrl( nullptr ),
|
|
|
|
m_inTimerEvent( false ),
|
2022-09-24 03:45:00 +00:00
|
|
|
m_recentSearchesKey( aRecentSearchesKey ),
|
2023-09-02 21:13:48 +00:00
|
|
|
m_skipNextRightClick( false ),
|
2023-09-06 15:23:13 +00:00
|
|
|
m_previewWindow( nullptr ),
|
|
|
|
m_previewDisabled( false )
|
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
|
|
|
|
2023-09-02 21:13:48 +00:00
|
|
|
m_hoverTimer.SetOwner( this );
|
|
|
|
Bind( wxEVT_TIMER, &LIB_TREE::onHoverTimer, this, m_hoverTimer.GetId() );
|
|
|
|
|
2017-04-10 14:43:25 +00:00
|
|
|
// Search text control
|
2022-09-09 02:15:44 +00:00
|
|
|
if( aFlags & SEARCH )
|
2017-04-10 14:43:25 +00:00
|
|
|
{
|
2021-08-03 16:53:30 +00:00
|
|
|
wxBoxSizer* search_sizer = new wxBoxSizer( wxHORIZONTAL );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
m_query_ctrl = new wxSearchCtrl( this, wxID_ANY );
|
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 );
|
|
|
|
|
2023-12-13 16:07:09 +00:00
|
|
|
search_sizer->Add( m_query_ctrl, 1, wxEXPAND | wxRIGHT, 5 );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2023-05-01 20:26:29 +00:00
|
|
|
m_sort_ctrl = new STD_BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxBU_AUTODRAW|0 );
|
2023-10-21 18:56:19 +00:00
|
|
|
m_sort_ctrl->SetBitmap( KiBitmapBundle( BITMAPS::small_sort_desc ) );
|
2023-05-01 20:26:29 +00:00
|
|
|
m_sort_ctrl->Bind( wxEVT_LEFT_DOWN,
|
|
|
|
[&]( wxMouseEvent& aEvent )
|
|
|
|
{
|
2023-05-02 10:40:20 +00:00
|
|
|
// Build a pop menu:
|
2023-05-01 20:26:29 +00:00
|
|
|
wxMenu menu;
|
|
|
|
|
|
|
|
menu.Append( 4201, _( "Sort by Best Match" ), wxEmptyString, wxITEM_CHECK );
|
|
|
|
menu.Append( 4202, _( "Sort Alphabetically" ), wxEmptyString, wxITEM_CHECK );
|
2024-01-28 18:28:54 +00:00
|
|
|
menu.AppendSeparator();
|
|
|
|
menu.Append( 4203, ACTIONS::expandAll.GetMenuItem() );
|
|
|
|
menu.Append( 4204, ACTIONS::collapseAll.GetMenuItem() );
|
2023-05-01 20:26:29 +00:00
|
|
|
|
|
|
|
if( m_adapter->GetSortMode() == LIB_TREE_MODEL_ADAPTER::BEST_MATCH )
|
|
|
|
menu.Check( 4201, true );
|
|
|
|
else
|
|
|
|
menu.Check( 4202, true );
|
|
|
|
|
2023-05-02 10:40:20 +00:00
|
|
|
// menu_id is the selected submenu id from the popup menu or wxID_NONE
|
|
|
|
int menu_id = m_sort_ctrl->GetPopupMenuSelectionFromUser( menu );
|
|
|
|
|
|
|
|
if( menu_id == 0 || menu_id == 4201 )
|
2023-05-01 20:26:29 +00:00
|
|
|
{
|
|
|
|
m_adapter->SetSortMode( LIB_TREE_MODEL_ADAPTER::BEST_MATCH );
|
|
|
|
Regenerate( true );
|
|
|
|
}
|
2023-05-02 10:40:20 +00:00
|
|
|
else if( menu_id == 1 || menu_id == 4202 )
|
2023-05-01 20:26:29 +00:00
|
|
|
{
|
|
|
|
m_adapter->SetSortMode( LIB_TREE_MODEL_ADAPTER::ALPHABETIC );
|
|
|
|
Regenerate( true );
|
|
|
|
}
|
2024-01-28 18:28:54 +00:00
|
|
|
else if( menu_id == 3 || menu_id == 4203 )
|
|
|
|
{
|
|
|
|
ExpandAll();
|
|
|
|
}
|
|
|
|
else if( menu_id == 4 || menu_id == 4204 )
|
|
|
|
{
|
|
|
|
CollapseAll();
|
|
|
|
}
|
2023-05-01 20:26:29 +00:00
|
|
|
} );
|
|
|
|
|
2024-01-28 18:28:54 +00:00
|
|
|
m_sort_ctrl->Bind( wxEVT_CHAR_HOOK, &LIB_TREE::onTreeCharHook, this );
|
|
|
|
|
2023-12-13 16:07:09 +00:00
|
|
|
search_sizer->Add( m_sort_ctrl, 0, wxEXPAND | wxRIGHT, 5 );
|
2023-05-01 20:26:29 +00:00
|
|
|
|
2023-12-13 16:07:09 +00:00
|
|
|
sizer->Add( search_sizer, 0, wxEXPAND | wxBOTTOM, 5 );
|
2017-04-10 14:43:25 +00:00
|
|
|
|
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-11-17 17:28:23 +00:00
|
|
|
m_query_ctrl->Bind( wxEVT_SEARCH_CANCEL, &LIB_TREE::onQueryText, this );
|
2018-07-27 20:47:51 +00:00
|
|
|
m_query_ctrl->Bind( wxEVT_CHAR_HOOK, &LIB_TREE::onQueryCharHook, this );
|
2021-11-18 18:25:14 +00:00
|
|
|
m_query_ctrl->Bind( wxEVT_MOTION, &LIB_TREE::onQueryMouseMoved, this );
|
2022-10-27 15:26:33 +00:00
|
|
|
m_query_ctrl->Bind( wxEVT_LEAVE_WINDOW,
|
|
|
|
[this] ( wxMouseEvent& aEvt )
|
|
|
|
{
|
|
|
|
SetCursor( wxCURSOR_ARROW );
|
|
|
|
} );
|
2021-07-05 01:59:51 +00:00
|
|
|
|
2022-09-15 13:32:27 +00:00
|
|
|
m_query_ctrl->Bind( wxEVT_MENU,
|
|
|
|
[this]( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
wxString search;
|
|
|
|
size_t idx = aEvent.GetId() - 1;
|
|
|
|
|
|
|
|
if( idx < g_recentSearches[ m_recentSearchesKey ].size() )
|
|
|
|
m_query_ctrl->SetValue( g_recentSearches[ m_recentSearchesKey ][idx] );
|
|
|
|
},
|
|
|
|
1, RECENT_SEARCHES_MAX );
|
|
|
|
|
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
|
2022-09-09 02:15:44 +00:00
|
|
|
int dvFlags = ( aFlags & MULTISELECT ) ? wxDV_MULTIPLE : wxDV_SINGLE;
|
2023-04-07 23:07:33 +00:00
|
|
|
m_tree_ctrl = new WX_DATAVIEWCTRL( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, dvFlags );
|
2017-04-10 14:43:25 +00:00
|
|
|
m_adapter->AttachTo( m_tree_ctrl );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2024-02-28 00:24:53 +00:00
|
|
|
#ifdef __WXGTK__
|
|
|
|
// The GTK renderer seems to calculate row height incorrectly sometimes; but can be overridden
|
|
|
|
int rowHeight = FromDIP( 8 ) + GetTextExtent( wxS( "pdI" ) ).y;
|
|
|
|
m_tree_ctrl->SetRowHeight( rowHeight );
|
|
|
|
#endif
|
|
|
|
|
2023-12-13 16:07:09 +00:00
|
|
|
sizer->Add( m_tree_ctrl, 5, wxRIGHT | wxBOTTOM | wxEXPAND, 5 );
|
2017-04-10 14:43:25 +00:00
|
|
|
|
|
|
|
// Description panel
|
2022-09-09 02:15:44 +00:00
|
|
|
if( aFlags & DETAILS )
|
2017-04-10 14:43:25 +00:00
|
|
|
{
|
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,
|
2023-09-28 13:09:45 +00:00
|
|
|
wxSize( html_size.x, html_size.y ) );
|
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 );
|
2022-09-30 11:27:54 +00:00
|
|
|
m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, &LIB_TREE::onItemContextMenu, this );
|
|
|
|
m_tree_ctrl->Bind( wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, &LIB_TREE::onHeaderContextMenu,
|
2022-09-24 03:45:00 +00:00
|
|
|
this );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2023-09-02 21:13:48 +00:00
|
|
|
// wxDataViewCtrl eats its mouseMoved events, so we're forced to use idle events to track
|
|
|
|
// the hover state
|
|
|
|
Bind( wxEVT_IDLE, &LIB_TREE::onIdle, this );
|
|
|
|
|
2022-10-02 21:20:25 +00:00
|
|
|
// Process hotkeys when the tree control has focus:
|
2022-10-03 17:41:37 +00:00
|
|
|
m_tree_ctrl->Bind( wxEVT_CHAR_HOOK, &LIB_TREE::onTreeCharHook, this );
|
2022-10-02 21:20:25 +00:00
|
|
|
|
2023-09-28 17:18:19 +00:00
|
|
|
Bind( EVT_LIBITEM_SELECTED, &LIB_TREE::onPreselect, this );
|
2017-06-25 21:13:39 +00:00
|
|
|
|
2017-08-19 06:39:55 +00:00
|
|
|
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 );
|
2022-09-15 13:32:27 +00:00
|
|
|
updateRecentSearchMenu();
|
2020-08-11 23:09:08 +00:00
|
|
|
|
|
|
|
// 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()
|
|
|
|
{
|
2023-10-02 02:03:32 +00:00
|
|
|
Unbind( wxEVT_TIMER, &LIB_TREE::onHoverTimer, this, m_hoverTimer.GetId() );
|
|
|
|
|
|
|
|
m_tree_ctrl->Unbind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &LIB_TREE::onTreeActivate, this );
|
|
|
|
m_tree_ctrl->Unbind( wxEVT_DATAVIEW_SELECTION_CHANGED, &LIB_TREE::onTreeSelect, this );
|
|
|
|
m_tree_ctrl->Unbind( wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, &LIB_TREE::onItemContextMenu, this );
|
|
|
|
m_tree_ctrl->Unbind( wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, &LIB_TREE::onHeaderContextMenu,
|
|
|
|
this );
|
|
|
|
|
|
|
|
Unbind( wxEVT_IDLE, &LIB_TREE::onIdle, this );
|
|
|
|
m_tree_ctrl->Unbind( wxEVT_CHAR_HOOK, &LIB_TREE::onTreeCharHook, this );
|
|
|
|
Unbind( EVT_LIBITEM_SELECTED, &LIB_TREE::onPreselect, this );
|
|
|
|
|
|
|
|
if( m_query_ctrl )
|
|
|
|
{
|
|
|
|
m_query_ctrl->Unbind( wxEVT_TEXT, &LIB_TREE::onQueryText, this );
|
|
|
|
|
|
|
|
m_query_ctrl->Unbind( wxEVT_SEARCH_CANCEL, &LIB_TREE::onQueryText, this );
|
|
|
|
m_query_ctrl->Unbind( wxEVT_CHAR_HOOK, &LIB_TREE::onQueryCharHook, this );
|
|
|
|
m_query_ctrl->Unbind( wxEVT_MOTION, &LIB_TREE::onQueryMouseMoved, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop the timer during destruction early to avoid potential race conditions (that do happen)]
|
|
|
|
if( m_debounceTimer )
|
|
|
|
{
|
|
|
|
m_debounceTimer->Stop();
|
|
|
|
Unbind( wxEVT_TIMER, &LIB_TREE::onDebounceTimer, this, m_debounceTimer->GetId() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_details_ctrl )
|
|
|
|
m_details_ctrl->Unbind( wxEVT_HTML_LINK_CLICKED, &LIB_TREE::onDetailsLink, this );
|
2023-09-02 21:13:48 +00:00
|
|
|
|
|
|
|
m_hoverTimer.Stop();
|
2023-11-09 16:02:08 +00:00
|
|
|
destroyPreview();
|
2019-08-26 10:57:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-11 22:51:27 +00:00
|
|
|
void LIB_TREE::ShowChangedLanguage()
|
|
|
|
{
|
|
|
|
if( m_query_ctrl )
|
|
|
|
m_query_ctrl->SetDescriptiveText( _( "Filter" ) );
|
|
|
|
|
|
|
|
if( m_adapter )
|
|
|
|
m_adapter->ShowChangedLanguage();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-09 02:15:44 +00:00
|
|
|
int LIB_TREE::GetSelectedLibIds( std::vector<LIB_ID>& aSelection, std::vector<int>* aUnit ) const
|
|
|
|
{
|
|
|
|
wxDataViewItemArray selection;
|
|
|
|
int count = m_tree_ctrl->GetSelections( selection );
|
|
|
|
|
|
|
|
for( const wxDataViewItem& item : selection )
|
|
|
|
{
|
|
|
|
aSelection.emplace_back( m_adapter->GetAliasFor( item ) );
|
|
|
|
|
|
|
|
if( aUnit )
|
|
|
|
aUnit->emplace_back( m_adapter->GetUnitFor( item ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
|
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
|
|
|
|
2024-01-28 18:28:54 +00:00
|
|
|
void LIB_TREE::ExpandAll()
|
|
|
|
{
|
|
|
|
m_tree_ctrl->ExpandAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_TREE::CollapseAll()
|
|
|
|
{
|
|
|
|
m_tree_ctrl->CollapseAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-16 22:55:19 +00:00
|
|
|
void LIB_TREE::SetSearchString( const wxString& aSearchString )
|
|
|
|
{
|
2022-05-19 16:09:45 +00:00
|
|
|
m_query_ctrl->ChangeValue( aSearchString );
|
2022-04-16 22:55:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString LIB_TREE::GetSearchString() const
|
|
|
|
{
|
|
|
|
return m_query_ctrl->GetValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-15 13:32:27 +00:00
|
|
|
void LIB_TREE::updateRecentSearchMenu()
|
|
|
|
{
|
|
|
|
wxString newEntry = GetSearchString();
|
|
|
|
|
|
|
|
std::vector<wxString>& recents = g_recentSearches[ m_recentSearchesKey ];
|
|
|
|
|
|
|
|
if( !newEntry.IsEmpty() )
|
|
|
|
{
|
|
|
|
if( alg::contains( recents, newEntry ) )
|
|
|
|
alg::delete_matching( recents, newEntry );
|
|
|
|
|
|
|
|
if( recents.size() >= RECENT_SEARCHES_MAX )
|
|
|
|
recents.pop_back();
|
|
|
|
|
|
|
|
recents.insert( recents.begin(), newEntry );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxMenu* menu = new wxMenu();
|
|
|
|
|
|
|
|
for( const wxString& recent : recents )
|
|
|
|
menu->Append( menu->GetMenuItemCount() + 1, recent );
|
|
|
|
|
|
|
|
if( recents.empty() )
|
|
|
|
menu->Append( wxID_ANY, _( "recent searches" ) );
|
|
|
|
|
|
|
|
m_query_ctrl->SetMenu( menu );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-20 19:54:02 +00:00
|
|
|
void LIB_TREE::FocusSearchFieldIfExists()
|
|
|
|
{
|
|
|
|
if( m_query_ctrl )
|
|
|
|
m_query_ctrl->SetFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 );
|
2022-10-03 18:11:06 +00:00
|
|
|
m_tree_ctrl->UnselectAll();
|
2017-04-10 14:22:41 +00:00
|
|
|
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
|
|
|
{
|
2023-09-28 17:18:19 +00:00
|
|
|
wxCommandEvent event( EVT_LIBITEM_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
|
|
|
void LIB_TREE::postSelectEvent()
|
2017-04-10 14:22:41 +00:00
|
|
|
{
|
2023-09-28 17:18:19 +00:00
|
|
|
wxCommandEvent event( EVT_LIBITEM_CHOSEN );
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-05 01:59:51 +00:00
|
|
|
void LIB_TREE::onDebounceTimer( wxTimerEvent& aEvent )
|
|
|
|
{
|
2022-09-15 13:32:27 +00:00
|
|
|
m_inTimerEvent = true;
|
2021-07-05 01:59:51 +00:00
|
|
|
Regenerate( false );
|
2022-09-15 13:32:27 +00:00
|
|
|
m_inTimerEvent = false;
|
2021-07-05 01:59:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke )
|
2017-04-10 14:22:41 +00:00
|
|
|
{
|
2024-01-28 18:28:54 +00:00
|
|
|
int hotkey = aKeyStroke.GetKeyCode();
|
|
|
|
|
|
|
|
if( aKeyStroke.GetModifiers() & wxMOD_CONTROL )
|
|
|
|
hotkey += MD_CTRL;
|
|
|
|
|
|
|
|
if( aKeyStroke.GetModifiers() & wxMOD_ALT )
|
|
|
|
hotkey += MD_ALT;
|
|
|
|
|
|
|
|
if( aKeyStroke.GetModifiers() & wxMOD_SHIFT )
|
|
|
|
hotkey += MD_SHIFT;
|
|
|
|
|
|
|
|
if( hotkey == ACTIONS::expandAll.GetHotKey()
|
|
|
|
|| hotkey == ACTIONS::expandAll.GetHotKeyAlt() )
|
|
|
|
{
|
|
|
|
m_tree_ctrl->ExpandAll();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( hotkey == ACTIONS::collapseAll.GetHotKey()
|
|
|
|
|| hotkey == ACTIONS::collapseAll.GetHotKeyAlt() )
|
|
|
|
{
|
|
|
|
m_tree_ctrl->CollapseAll();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-04 19:51:28 +00:00
|
|
|
wxDataViewItem sel = m_tree_ctrl->GetSelection();
|
|
|
|
|
|
|
|
if( !sel.IsOk() )
|
|
|
|
sel = m_adapter->GetCurrentDataViewItem();
|
|
|
|
|
2024-01-28 18:28:54 +00:00
|
|
|
LIB_TREE_NODE::TYPE 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:
|
2022-09-15 13:32:27 +00:00
|
|
|
updateRecentSearchMenu();
|
2023-04-07 23:07:33 +00:00
|
|
|
selectIfValid( m_tree_ctrl->GetPrevItem( sel ) );
|
2017-12-20 11:23:05 +00:00
|
|
|
break;
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2017-12-20 11:23:05 +00:00
|
|
|
case WXK_DOWN:
|
2022-09-15 13:32:27 +00:00
|
|
|
updateRecentSearchMenu();
|
2023-04-07 23:07:33 +00:00
|
|
|
selectIfValid( m_tree_ctrl->GetNextItem( sel ) );
|
2017-12-20 11:23:05 +00:00
|
|
|
break;
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2019-01-23 06:33:00 +00:00
|
|
|
case WXK_ADD:
|
2022-09-15 13:32:27 +00:00
|
|
|
updateRecentSearchMenu();
|
|
|
|
|
2023-11-08 17:34:14 +00:00
|
|
|
if( type == LIB_TREE_NODE::LIBRARY )
|
2019-01-23 06:33:00 +00:00
|
|
|
m_tree_ctrl->Expand( sel );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_SUBTRACT:
|
2022-09-15 13:32:27 +00:00
|
|
|
updateRecentSearchMenu();
|
|
|
|
|
2023-11-08 17:34:14 +00:00
|
|
|
if( type == LIB_TREE_NODE::LIBRARY )
|
2019-01-23 06:33:00 +00:00
|
|
|
m_tree_ctrl->Collapse( sel );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2017-12-20 11:25:12 +00:00
|
|
|
case WXK_RETURN:
|
2023-06-05 13:20:22 +00:00
|
|
|
case WXK_NUMPAD_ENTER:
|
2022-09-15 13:32:27 +00:00
|
|
|
updateRecentSearchMenu();
|
|
|
|
|
2022-09-16 16:03:35 +00:00
|
|
|
if( GetSelectedLibId().IsValid() )
|
|
|
|
postSelectEvent();
|
2023-11-08 17:34:14 +00:00
|
|
|
else if( type == LIB_TREE_NODE::LIBRARY )
|
2017-12-20 11:25:12 +00:00
|
|
|
toggleExpand( sel );
|
2021-07-21 23:14:56 +00:00
|
|
|
|
|
|
|
break;
|
2017-12-20 11:25:12 +00:00
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
default:
|
2021-07-21 23:14:56 +00:00
|
|
|
aKeyStroke.Skip(); // Any other key: pass on to search box directly.
|
2017-04-10 14:22:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-18 18:25:14 +00:00
|
|
|
void LIB_TREE::onQueryMouseMoved( wxMouseEvent& aEvent )
|
|
|
|
{
|
|
|
|
wxPoint pos = aEvent.GetPosition();
|
|
|
|
wxRect ctrlRect = m_query_ctrl->GetScreenRect();
|
|
|
|
int buttonWidth = ctrlRect.GetHeight(); // Presume buttons are square
|
|
|
|
|
|
|
|
if( m_query_ctrl->IsSearchButtonVisible() && pos.x < buttonWidth )
|
|
|
|
SetCursor( wxCURSOR_ARROW );
|
|
|
|
else if( m_query_ctrl->IsCancelButtonVisible() && pos.x > ctrlRect.GetWidth() - buttonWidth )
|
|
|
|
SetCursor( wxCURSOR_ARROW );
|
|
|
|
else
|
|
|
|
SetCursor( wxCURSOR_IBEAM );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-02 21:13:48 +00:00
|
|
|
#define PREVIEW_SIZE wxSize( 240, 200 )
|
2023-09-06 15:23:13 +00:00
|
|
|
#define HOVER_TIMER_MILLIS 400
|
2023-09-02 21:13:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
void LIB_TREE::showPreview( wxDataViewItem aItem )
|
|
|
|
{
|
|
|
|
if( aItem.IsOk() && m_adapter->HasPreview( aItem ) )
|
|
|
|
{
|
2023-09-06 15:23:13 +00:00
|
|
|
m_previewItem = aItem;
|
|
|
|
m_previewItemRect = m_tree_ctrl->GetItemRect( m_previewItem );
|
2023-09-02 21:13:48 +00:00
|
|
|
|
2023-09-04 10:00:45 +00:00
|
|
|
wxWindow* topLevelParent = wxGetTopLevelParent( m_parent );
|
2023-09-02 21:13:48 +00:00
|
|
|
|
2023-11-09 16:02:08 +00:00
|
|
|
if( !m_previewWindow )
|
|
|
|
m_previewWindow = new wxPopupWindow( topLevelParent );
|
|
|
|
|
|
|
|
m_previewWindow->SetSize( PREVIEW_SIZE );
|
|
|
|
|
|
|
|
m_adapter->ShowPreview( m_previewWindow, aItem );
|
|
|
|
|
2023-09-02 21:13:48 +00:00
|
|
|
m_previewWindow->SetPosition( wxPoint( m_tree_ctrl->GetScreenRect().GetRight() - 10,
|
|
|
|
wxGetMousePosition().y - PREVIEW_SIZE.y / 2 ) );
|
|
|
|
|
|
|
|
m_previewWindow->Show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_TREE::hidePreview()
|
|
|
|
{
|
2023-09-06 15:23:13 +00:00
|
|
|
m_previewItem = wxDataViewItem();
|
2023-09-02 21:13:48 +00:00
|
|
|
|
|
|
|
if( m_previewWindow )
|
|
|
|
{
|
|
|
|
m_previewWindow->Hide();
|
2023-11-09 16:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_TREE::destroyPreview()
|
|
|
|
{
|
|
|
|
hidePreview();
|
|
|
|
|
|
|
|
if( m_previewWindow )
|
|
|
|
{
|
2023-09-02 21:13:48 +00:00
|
|
|
m_previewWindow->Destroy();
|
|
|
|
m_previewWindow = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_TREE::onIdle( wxIdleEvent& aEvent )
|
|
|
|
{
|
|
|
|
// The wxDataViewCtrl won't give us its mouseMoved events so we're forced to use idle
|
|
|
|
// events to track the hover state
|
|
|
|
|
2023-09-06 15:23:13 +00:00
|
|
|
// The dang thing won't give us scroll events either, so we implement a poor-man's
|
|
|
|
// scroll-checker using the last-known positions of the preview or hover items.
|
|
|
|
|
2023-09-04 10:00:45 +00:00
|
|
|
wxWindow* topLevelParent = wxGetTopLevelParent( m_parent );
|
|
|
|
wxWindow* topLevelFocus = wxGetTopLevelParent( wxWindow::FindFocus() );
|
2023-09-02 21:13:48 +00:00
|
|
|
|
2023-09-29 22:13:59 +00:00
|
|
|
bool mouseOverWindow = false;
|
2023-09-02 21:13:48 +00:00
|
|
|
wxPoint screenPos = wxGetMousePosition();
|
|
|
|
|
2021-08-19 21:28:54 +00:00
|
|
|
if( m_tree_ctrl->IsShownOnScreen() )
|
2023-09-29 22:13:59 +00:00
|
|
|
mouseOverWindow |= m_tree_ctrl->GetScreenRect().Contains( screenPos );
|
|
|
|
|
|
|
|
if( m_previewDisabled || topLevelFocus != topLevelParent || !mouseOverWindow )
|
2023-09-02 21:13:48 +00:00
|
|
|
{
|
|
|
|
m_hoverTimer.Stop();
|
|
|
|
hidePreview();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-06 15:23:13 +00:00
|
|
|
wxPoint clientPos = m_tree_ctrl->ScreenToClient( screenPos );
|
|
|
|
wxDataViewItem item;
|
|
|
|
wxDataViewColumn* col = nullptr;
|
2023-09-02 21:13:48 +00:00
|
|
|
|
2023-09-06 15:23:13 +00:00
|
|
|
m_tree_ctrl->HitTest( clientPos, item, col );
|
2023-09-02 21:13:48 +00:00
|
|
|
|
2023-09-06 15:23:13 +00:00
|
|
|
if( m_previewItem.IsOk() )
|
|
|
|
{
|
|
|
|
// Scroll checker
|
|
|
|
if( m_tree_ctrl->GetItemRect( m_previewItem ) != m_previewItemRect )
|
2023-09-02 21:13:48 +00:00
|
|
|
{
|
|
|
|
hidePreview();
|
2023-09-06 15:23:13 +00:00
|
|
|
|
2023-09-02 21:13:48 +00:00
|
|
|
m_hoverPos = clientPos;
|
2023-09-06 15:23:13 +00:00
|
|
|
m_hoverItem = item;
|
|
|
|
m_hoverItemRect = m_tree_ctrl->GetItemRect( m_hoverItem );
|
|
|
|
m_hoverTimer.StartOnce( HOVER_TIMER_MILLIS );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( item != m_previewItem )
|
2023-11-28 15:48:51 +00:00
|
|
|
{
|
|
|
|
#ifdef __WXGTK__
|
|
|
|
// Hide the preview, because Wayland can't move windows.
|
|
|
|
if( wxGetDisplayInfo().type == wxDisplayType::wxDisplayWayland )
|
|
|
|
hidePreview();
|
|
|
|
#endif
|
2023-09-02 21:13:48 +00:00
|
|
|
showPreview( item );
|
2023-11-28 15:48:51 +00:00
|
|
|
}
|
2023-09-02 21:13:48 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_hoverPos != clientPos )
|
|
|
|
{
|
|
|
|
m_hoverPos = clientPos;
|
2023-09-06 15:23:13 +00:00
|
|
|
m_hoverItem = item;
|
|
|
|
m_hoverItemRect = m_tree_ctrl->GetItemRect( m_hoverItem );
|
|
|
|
m_hoverTimer.StartOnce( HOVER_TIMER_MILLIS );
|
2023-09-02 21:13:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_TREE::onHoverTimer( wxTimerEvent& aEvent )
|
|
|
|
{
|
|
|
|
hidePreview();
|
2023-10-02 02:03:32 +00:00
|
|
|
|
2024-01-05 14:19:54 +00:00
|
|
|
TOOL_DISPATCHER* toolDispatcher = m_adapter->GetToolDispatcher();
|
|
|
|
|
2024-01-09 14:49:23 +00:00
|
|
|
if( !m_tree_ctrl->IsShownOnScreen() || m_previewDisabled
|
|
|
|
|| ( toolDispatcher && toolDispatcher->GetCurrentMenu() ) )
|
2023-09-06 15:23:13 +00:00
|
|
|
return;
|
2023-09-02 21:13:48 +00:00
|
|
|
|
|
|
|
wxDataViewItem item;
|
|
|
|
wxDataViewColumn* col = nullptr;
|
|
|
|
m_tree_ctrl->HitTest( m_hoverPos, item, col );
|
|
|
|
|
2023-09-06 15:23:13 +00:00
|
|
|
if( item == m_hoverItem && m_tree_ctrl->GetItemRect( item ) == m_hoverItemRect )
|
|
|
|
{
|
|
|
|
if( item != m_tree_ctrl->GetSelection() )
|
|
|
|
showPreview( item );
|
|
|
|
}
|
|
|
|
else // view must have been scrolled
|
|
|
|
{
|
|
|
|
m_hoverItem = item;
|
|
|
|
m_hoverItemRect = m_tree_ctrl->GetItemRect( m_hoverItem );
|
|
|
|
m_hoverTimer.StartOnce( HOVER_TIMER_MILLIS );
|
|
|
|
}
|
2023-09-02 21:13:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-02 21:20:25 +00:00
|
|
|
void LIB_TREE::onTreeCharHook( wxKeyEvent& aKeyStroke )
|
|
|
|
{
|
|
|
|
onQueryCharHook( aKeyStroke );
|
|
|
|
|
|
|
|
if( aKeyStroke.GetSkipped() )
|
|
|
|
{
|
|
|
|
if( TOOL_INTERACTIVE* tool = m_adapter->GetContextMenuTool() )
|
|
|
|
{
|
2022-10-03 17:41:37 +00:00
|
|
|
int hotkey = aKeyStroke.GetKeyCode();
|
|
|
|
|
|
|
|
if( aKeyStroke.ShiftDown() )
|
|
|
|
hotkey |= MD_SHIFT;
|
|
|
|
|
|
|
|
if( aKeyStroke.AltDown() )
|
|
|
|
hotkey |= MD_ALT;
|
|
|
|
|
|
|
|
if( aKeyStroke.ControlDown() )
|
|
|
|
hotkey |= MD_CTRL;
|
2022-10-02 21:20:25 +00:00
|
|
|
|
|
|
|
if( tool->GetManager()->GetActionManager()->RunHotKey( hotkey ) )
|
|
|
|
aKeyStroke.Skip( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::onTreeSelect( wxDataViewEvent& aEvent )
|
2017-06-25 21:13:39 +00:00
|
|
|
{
|
2023-12-14 12:03:15 +00:00
|
|
|
if( m_tree_ctrl->IsFrozen() )
|
|
|
|
return;
|
|
|
|
|
2022-09-15 13:32:27 +00:00
|
|
|
if( !m_inTimerEvent )
|
|
|
|
updateRecentSearchMenu();
|
|
|
|
|
2023-12-14 12:03:15 +00:00
|
|
|
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
|
|
|
{
|
2023-09-02 21:13:48 +00:00
|
|
|
hidePreview();
|
|
|
|
|
2023-12-14 12:03:15 +00:00
|
|
|
if( !m_inTimerEvent )
|
|
|
|
updateRecentSearchMenu();
|
|
|
|
|
2017-09-15 14:17:44 +00:00
|
|
|
if( !GetSelectedLibId().IsValid() )
|
2021-07-21 23:14:56 +00:00
|
|
|
toggleExpand( m_tree_ctrl->GetSelection() ); // Expand library/part units subtree
|
2017-06-25 21:13:39 +00:00
|
|
|
else
|
2021-07-21 23:14:56 +00:00
|
|
|
postSelectEvent(); // Open symbol/footprint
|
2017-06-25 21:13:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2023-10-30 10:27:08 +00:00
|
|
|
wxString docname = info.GetHref();
|
|
|
|
PROJECT& prj = Pgm().GetSettingsManager().Prj();
|
|
|
|
|
|
|
|
GetAssociatedDocument( this, docname, &prj );
|
2017-06-25 21:13:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
void LIB_TREE::onPreselect( wxCommandEvent& aEvent )
|
2017-04-10 14:22:41 +00:00
|
|
|
{
|
2023-09-02 21:13:48 +00:00
|
|
|
hidePreview();
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-24 03:45:00 +00:00
|
|
|
void LIB_TREE::onItemContextMenu( wxDataViewEvent& aEvent )
|
2017-10-28 16:59:49 +00:00
|
|
|
{
|
2023-09-02 21:13:48 +00:00
|
|
|
hidePreview();
|
|
|
|
|
2022-09-24 03:45:00 +00:00
|
|
|
if( m_skipNextRightClick )
|
|
|
|
{
|
|
|
|
m_skipNextRightClick = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-06 15:23:13 +00:00
|
|
|
m_previewDisabled = true;
|
|
|
|
|
2022-09-21 13:44:13 +00:00
|
|
|
if( TOOL_INTERACTIVE* tool = m_adapter->GetContextMenuTool() )
|
2017-10-28 16:59:49 +00:00
|
|
|
{
|
2022-12-26 14:10:15 +00:00
|
|
|
if( !GetCurrentTreeNode() )
|
|
|
|
{
|
|
|
|
wxPoint pos = m_tree_ctrl->ScreenToClient( wxGetMousePosition() );
|
|
|
|
|
|
|
|
wxDataViewItem item;
|
|
|
|
wxDataViewColumn* col;
|
|
|
|
m_tree_ctrl->HitTest( pos, item, col );
|
|
|
|
|
|
|
|
if( item.IsOk() )
|
|
|
|
{
|
|
|
|
m_tree_ctrl->SetFocus();
|
|
|
|
m_tree_ctrl->Select( item );
|
|
|
|
wxSafeYield();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2022-09-21 13:44:13 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
LIB_TREE_NODE* current = GetCurrentTreeNode();
|
|
|
|
|
2023-11-08 17:34:14 +00:00
|
|
|
if( current && current->m_Type == LIB_TREE_NODE::LIBRARY )
|
2022-09-21 13:44:13 +00:00
|
|
|
{
|
|
|
|
ACTION_MENU menu( true, nullptr );
|
|
|
|
|
|
|
|
if( current->m_Pinned )
|
|
|
|
{
|
|
|
|
menu.Add( ACTIONS::unpinLibrary );
|
|
|
|
|
2022-09-24 03:05:44 +00:00
|
|
|
if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
|
2022-09-21 13:44:13 +00:00
|
|
|
m_adapter->UnpinLibrary( current );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
menu.Add( ACTIONS::pinLibrary );
|
|
|
|
|
2022-09-24 03:05:44 +00:00
|
|
|
if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
|
2022-09-21 13:44:13 +00:00
|
|
|
m_adapter->PinLibrary( current );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-02 02:03:32 +00:00
|
|
|
|
2023-09-06 15:23:13 +00:00
|
|
|
m_previewDisabled = false;
|
2017-10-28 16:59:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-24 03:45:00 +00:00
|
|
|
void LIB_TREE::onHeaderContextMenu( wxDataViewEvent& aEvent )
|
|
|
|
{
|
2023-09-02 21:13:48 +00:00
|
|
|
hidePreview();
|
2023-09-06 15:23:13 +00:00
|
|
|
m_previewDisabled = true;
|
2023-09-02 21:13:48 +00:00
|
|
|
|
2022-09-24 03:45:00 +00:00
|
|
|
ACTION_MENU menu( true, nullptr );
|
|
|
|
|
2024-01-15 17:29:55 +00:00
|
|
|
menu.Add( ACTIONS::selectLibTreeColumns );
|
2022-09-24 03:45:00 +00:00
|
|
|
|
|
|
|
if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
|
|
|
|
{
|
|
|
|
EDA_REORDERABLE_LIST_DIALOG dlg( m_parent, _( "Select Columns" ),
|
|
|
|
m_adapter->GetAvailableColumns(),
|
|
|
|
m_adapter->GetShownColumns() );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
m_adapter->SetShownColumns( dlg.EnabledList() );
|
|
|
|
}
|
2023-09-06 15:23:13 +00:00
|
|
|
|
|
|
|
m_previewDisabled = false;
|
2022-09-24 03:45:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-28 17:18:19 +00:00
|
|
|
wxDEFINE_EVENT( EVT_LIBITEM_SELECTED, wxCommandEvent );
|
|
|
|
wxDEFINE_EVENT( EVT_LIBITEM_CHOSEN, wxCommandEvent );
|