35#include <wx/srchctrl.h>
36#include <wx/settings.h>
45 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter,
int aFlags,
47 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
48 wxWANTS_CHARS | wxTAB_TRAVERSAL | wxNO_BORDER ),
49 m_lib_table( aLibTable ), m_adapter( aAdapter ), m_query_ctrl( nullptr ),
50 m_details_ctrl( nullptr ),
51 m_inTimerEvent( false ),
52 m_recentSearchesKey( aRecentSearchesKey ),
53 m_skipNextRightClick( false )
55 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
60 wxBoxSizer* search_sizer =
new wxBoxSizer( wxHORIZONTAL );
69 m_query_ctrl->SetMinSize( wxSize( -1, GetTextExtent( wxT(
"qb" ) ).y + 10 ) );
76 sizer->Add( search_sizer, 0, wxEXPAND, 5 );
80#if wxCHECK_VERSION( 3, 1, 1 )
88 [
this] ( wxMouseEvent& aEvt )
90 SetCursor( wxCURSOR_ARROW );
94 [
this]( wxCommandEvent& aEvent )
97 size_t idx = aEvent.GetId() - 1;
108 int dvFlags = ( aFlags &
MULTISELECT ) ? wxDV_MULTIPLE : wxDV_SINGLE;
109 m_tree_ctrl =
new wxDataViewCtrl(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, dvFlags );
113 sizer->AddSpacer( 5 );
115 sizer->Add(
m_tree_ctrl, 5, wxRIGHT | wxBOTTOM | wxEXPAND, 1 );
122 wxPoint html_size = ConvertDialogToPixels( wxPoint( 80, 80 ) );
125 wxSize( html_size.x, html_size.y ),
126 wxHW_SCROLLBAR_AUTO );
176 m_details_ctrl->ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
204 wxDataViewItemArray selection;
205 int count =
m_tree_ctrl->GetSelections( selection );
207 for(
const wxDataViewItem& item : selection )
209 aSelection.emplace_back(
m_adapter->GetAliasFor( item ) );
212 aUnit->emplace_back(
m_adapter->GetUnitFor( item ) );
272 if( !newEntry.IsEmpty() )
280 recents.insert( recents.begin(), newEntry );
283 wxMenu* menu =
new wxMenu();
285 for(
const wxString&
recent : recents )
286 menu->Append( menu->GetMenuItemCount() + 1,
recent );
288 if( recents.empty() )
289 menu->Append( wxID_ANY,
_(
"recent searches" ) );
339 if( !aTreeId.IsOk() )
378 wxDataViewItemArray siblings;
379 m_adapter->GetChildren( wxDataViewItem( parent ), siblings );
381 int idx = siblings.Index( aTreeId );
383 if( idx + 5 < (
int) siblings.GetCount() )
385 m_tree_ctrl->EnsureVisible( siblings.Item( idx + 5 ) );
387 else if( grandParent )
389 wxDataViewItemArray parentsSiblings;
390 m_adapter->GetChildren( wxDataViewItem( grandParent ), parentsSiblings );
392 int p_idx = parentsSiblings.Index( wxDataViewItem( parent ) );
394 if( p_idx + 1 < (
int) parentsSiblings.GetCount() )
395 m_tree_ctrl->EnsureVisible( parentsSiblings.Item( p_idx + 1 ) );
399 m_tree_ctrl->EnsureVisible( siblings.Item( idx - 5 ) );
401 m_tree_ctrl->EnsureVisible( wxDataViewItem( parent ) );
411 if( aTreeId.IsOk() && !
m_tree_ctrl->IsExpanded( aTreeId ) )
418 wxCommandEvent event( SYMBOL_PRESELECTED );
419 wxPostEvent(
this, event );
425 wxCommandEvent event( SYMBOL_SELECTED );
426 wxPostEvent(
this, event );
433 wxDataViewItemArray items;
434 m_adapter->GetChildren( wxDataViewItem(
nullptr ), items );
436 for(
const wxDataViewItem& item : items )
452 for(
const wxDataViewItem& item : aState.
expanded )
484 const wxDataViewItem sel =
m_tree_ctrl->GetSelection();
487 switch( aKeyStroke.GetKeyCode() )
534 wxPoint pos = aEvent.GetPosition();
536 int buttonWidth = ctrlRect.GetHeight();
538 if(
m_query_ctrl->IsSearchButtonVisible() && pos.x < buttonWidth )
539 SetCursor( wxCURSOR_ARROW );
540 else if(
m_query_ctrl->IsCancelButtonVisible() && pos.x > ctrlRect.GetWidth() - buttonWidth )
541 SetCursor( wxCURSOR_ARROW );
543 SetCursor( wxCURSOR_IBEAM );
551 if( aKeyStroke.GetSkipped() )
555 int hotkey = aKeyStroke.GetKeyCode();
557 if( aKeyStroke.ShiftDown() )
560 if( aKeyStroke.AltDown() )
563 if( aKeyStroke.ControlDown() )
566 if( tool->GetManager()->GetActionManager()->RunHotKey( hotkey ) )
567 aKeyStroke.Skip(
false );
600 const wxHtmlLinkInfo&
info = aEvent.GetLinkInfo();
601 ::wxLaunchDefaultBrowser(
info.GetHref() );
634 wxPoint pos =
m_tree_ctrl->ScreenToClient( wxGetMousePosition() );
644 pos.y -= headerHeight;
647 wxDataViewColumn* col;
659 tool->GetManager()->VetoContextMenuMouseWarp();
660 tool->GetToolMenu().ShowContextMenu();
663 tool->GetManager()->DispatchContextMenu( evt );
677 if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
684 if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
698 if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
704 if( dlg.ShowModal() == wxID_OK )
708#if !wxCHECK_VERSION( 3, 1, 0 )
static TOOL_ACTION selectColumns
static TOOL_ACTION pinLibrary
static TOOL_ACTION unpinLibrary
A dialog which allows selecting a list of items from a list of available items, and reordering those ...
const std::vector< wxString > & EnabledList()
Add dark theme support to wxHtmlWindow.
bool SetPage(const wxString &aSource) override
A logical library item identifier and consists of various portions much like a URI.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
LIB_TREE(wxWindow *aParent, const wxString &aRecentSearchesKey, LIB_TABLE *aLibTable, wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > &aAdapter, int aFlags=ALL_WIDGETS, HTML_WINDOW *aDetails=nullptr)
Construct a symbol tree.
void RefreshLibTree()
Refreshes the tree (mainly to update highlighting and asterisking)
wxTimer * m_debounceTimer
LIB_TREE_NODE * GetCurrentTreeNode() const
void onQueryMouseMoved(wxMouseEvent &aEvent)
HTML_WINDOW * m_details_ctrl
void onTreeActivate(wxDataViewEvent &aEvent)
wxString m_recentSearchesKey
wxDataViewCtrl * m_tree_ctrl
void onQueryCharHook(wxKeyEvent &aEvent)
void CenterLibId(const LIB_ID &aLibId)
Ensure that an item is visible (preferably centered).
void postSelectEvent()
Post SYMBOL_SELECTED event to notify the selection handler that a part has been selected.
wxWindow * GetFocusTarget()
void onSize(wxSizeEvent &aEvent)
void onItemContextMenu(wxDataViewEvent &aEvent)
void onQueryText(wxCommandEvent &aEvent)
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
bool m_skipNextRightClick
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
void FocusSearchFieldIfExists()
Focus the search widget if it exists.
void expandIfValid(const wxDataViewItem &aTreeId)
void onPreselect(wxCommandEvent &aEvent)
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
void updateRecentSearchMenu()
wxString GetSearchString() const
void onTreeSelect(wxDataViewEvent &aEvent)
int GetSelectedLibIds(std::vector< LIB_ID > &aSelection, std::vector< int > *aUnit=nullptr) const
Retrieves a list of selections for trees that allow multi-selection.
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
void onTreeCharHook(wxKeyEvent &aEvent)
void onDetailsLink(wxHtmlLinkEvent &aEvent)
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit symbols, if the user selects the symbol itself rather than picking an individual unit,...
void SetSearchString(const wxString &aSearchString)
Save/restore search string.
void setState(const STATE &aState)
Restore the symbol tree widget state from an object.
STATE getState() const
Return the symbol tree widget state.
void ExpandLibId(const LIB_ID &aLibId)
Expand and item i the tree widget.
wxSearchCtrl * m_query_ctrl
void centerIfValid(const wxDataViewItem &aTreeId)
void onDebounceTimer(wxTimerEvent &aEvent)
void onHeaderContextMenu(wxDataViewEvent &aEvent)
void Regenerate(bool aKeepState)
Regenerate the tree.
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
constexpr int RECENT_SEARCHES_MAX
wxDEFINE_EVENT(SYMBOL_PRESELECTED, wxCommandEvent)
std::map< wxString, std::vector< wxString > > g_recentSearches
This file contains miscellaneous commonly used macros and functions.
bool IsValid(const std::string &aString, SIM_VALUE::TYPE aValueType=SIM_VALUE::TYPE_FLOAT, NOTATION aNotation=NOTATION::SI)
void delete_matching(_Container &__c, _Value __value)
Covers for the horrifically named std::remove and std::remove_if (neither of which remove anything).
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Structure storing state of the symbol tree widget.
std::vector< wxDataViewItem > expanded
< List of expanded nodes
wxDataViewItem GetPrevItem(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the previous item in list order.
wxDataViewItem GetNextItem(wxDataViewCtrl const &aView, wxDataViewItem const &aItem)
Get the next item in list order.
wxDataViewCtrl helper functions.