34#include <wx/settings.h>
36#include <wx/srchctrl.h>
37#include <wx/statline.h>
38#include <wx/popupwin.h>
50 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter,
int aFlags,
52 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
53 wxWANTS_CHARS | wxTAB_TRAVERSAL | wxNO_BORDER ),
65 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
73 wxBoxSizer* search_sizer =
new wxBoxSizer( wxHORIZONTAL );
81 search_sizer->Add(
m_query_ctrl, 1, wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 );
83 wxStaticLine* separator =
new wxStaticLine(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL );
84 search_sizer->Add( separator, 0, wxEXPAND|wxTOP|wxBOTTOM, 3 );
87 wxDefaultSize, wxBU_AUTODRAW|0 );
90 [&]( wxMouseEvent& aEvent )
95 menu.Append( 4201,
_(
"Sort by Best Match" ), wxEmptyString, wxITEM_CHECK );
96 menu.Append( 4202,
_(
"Sort Alphabetically" ), wxEmptyString, wxITEM_CHECK );
97 menu.AppendSeparator();
102 menu.Check( 4201,
true );
104 menu.Check( 4202,
true );
107 int menu_id =
m_sort_ctrl->GetPopupMenuSelectionFromUser( menu );
109 if( menu_id == 0 || menu_id == 4201 )
114 else if( menu_id == 1 || menu_id == 4202 )
119 else if( menu_id == 3 || menu_id == 4203 )
123 else if( menu_id == 4 || menu_id == 4204 )
130 search_sizer->Add(
m_sort_ctrl, 0, wxALIGN_CENTER_VERTICAL, 5 );
132 sizer->Add( search_sizer, 0, wxEXPAND, 5 );
140#if defined( __WXOSX__ )
142 [
this]( wxMouseEvent& aEvt )
144 SetCursor( wxCURSOR_ARROW );
149 [
this]( wxCommandEvent& aEvent )
151 size_t idx = aEvent.GetId() - 1;
168 int dvFlags = ( aFlags &
MULTISELECT ) ? wxDV_MULTIPLE : wxDV_SINGLE;
174 int rowHeight = FromDIP( 6 ) + GetTextExtent( wxS(
"pdI" ) ).y;
185 wxPoint html_size = ConvertDialogToPixels( wxPoint( 80, 80 ) );
188 wxSize( html_size.x, html_size.y ) );
241 m_details_ctrl->ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
317 if(
m_adapter->GetTreeNodeFor( sel )->m_IsAlreadyPlacedGroup
318 ||
m_adapter->GetTreeNodeFor( sel )->m_IsRecentlyUsedGroup )
332 wxDataViewItemArray selection;
333 int count =
m_tree_ctrl->GetSelections( selection );
335 for(
const wxDataViewItem& item : selection )
337 aSelection.emplace_back(
m_adapter->GetAliasFor( item ) );
340 aUnit->emplace_back(
m_adapter->GetUnitFor( item ) );
359 wxDataViewItemArray selection;
360 int count =
m_tree_ctrl->GetSelections( selection );
362 for(
const wxDataViewItem& item : selection )
364 aSelection.push_back(
m_adapter->GetTreeNodeFor( item ) );
373 wxDataViewItem item =
m_adapter->FindItem( aLibId );
405 std::vector<LIB_ID> expanded;
406 wxDataViewItemArray items;
407 m_adapter->GetChildren( wxDataViewItem(
nullptr ), items );
409 for(
const wxDataViewItem& item : items )
414 expanded.push_back( node->m_LibId );
452 if( !newEntry.IsEmpty() )
455 std::erase( recents, newEntry );
460 recents.insert( recents.begin(), newEntry );
463 wxMenu* menu =
new wxMenu();
465 for(
const wxString&
recent : recents )
466 menu->Append( menu->GetMenuItemCount() + 1,
recent );
468 if( recents.empty() )
469 menu->Append( wxID_ANY,
_(
"recent searches" ) );
517 if( !aTreeId.IsOk() )
556 wxDataViewItemArray siblings;
557 m_adapter->GetChildren( wxDataViewItem( parent ), siblings );
559 int idx = siblings.Index( aTreeId );
561 if( idx + 5 < (
int) siblings.GetCount() )
565 else if( grandParent )
567 wxDataViewItemArray parentsSiblings;
568 m_adapter->GetChildren( wxDataViewItem( grandParent ), parentsSiblings );
570 int p_idx = parentsSiblings.Index( wxDataViewItem( parent ) );
572 if( p_idx + 1 < (
int) parentsSiblings.GetCount() )
589 if( aTreeId.IsOk() && !
m_tree_ctrl->IsExpanded( aTreeId ) )
596 wxCommandEvent event( EVT_LIBITEM_SELECTED );
597 wxPostEvent(
this, event );
603 wxCommandEvent event( EVT_LIBITEM_CHOSEN );
604 wxPostEvent(
this, event );
611 wxDataViewItemArray items;
612 m_adapter->GetChildren( wxDataViewItem(
nullptr ), items );
614 for(
const wxDataViewItem& item : items )
635 for(
const wxDataViewItem& item : aState.
expanded )
671 int hotkey = aKeyStroke.GetKeyCode();
673 int mods = aKeyStroke.GetModifiers();
678 if( wxmods & wxMOD_ALTGR )
683 if( mods & wxMOD_CONTROL )
686 if( mods & wxMOD_ALT )
690 if( mods & wxMOD_SHIFT )
694 if( mods & wxMOD_META )
699 if( mods & wxMOD_WIN )
719 sel =
m_adapter->GetCurrentDataViewItem();
722 : LIB_TREE_NODE::TYPE::INVALID;
724 switch( aKeyStroke.GetKeyCode() )
739 if( type == LIB_TREE_NODE::TYPE::LIBRARY )
747 if( type == LIB_TREE_NODE::TYPE::LIBRARY )
753 case WXK_NUMPAD_ENTER:
758 else if( type == LIB_TREE_NODE::TYPE::LIBRARY )
772#if defined( __WXOSX__ )
773 wxPoint pos = aEvent.GetPosition();
775 int buttonWidth = ctrlRect.GetHeight();
777 if(
m_query_ctrl->IsSearchButtonVisible() && pos.x < buttonWidth )
778 SetCursor( wxCURSOR_ARROW );
779 else if(
m_query_ctrl->IsCancelButtonVisible() && pos.x > ctrlRect.GetWidth() - buttonWidth )
780 SetCursor( wxCURSOR_ARROW );
782 SetCursor( wxCURSOR_IBEAM );
787#define PREVIEW_SIZE wxSize( 240, 200 )
788#define HOVER_TIMER_MILLIS 400
793 if( aItem.IsOk() &&
m_adapter->HasPreview( aItem ) )
798 wxWindow* topLevelParent = wxGetTopLevelParent( m_parent );
832 wxWindow* topLevelParent = wxGetTopLevelParent( m_parent );
833 wxWindow* topLevelFocus = wxGetTopLevelParent( wxWindow::FindFocus() );
835 bool mouseOverWindow =
false;
836 wxPoint screenPos = wxGetMousePosition();
839 mouseOverWindow |=
m_tree_ctrl->GetScreenRect().Contains( screenPos );
848 wxPoint clientPos =
m_tree_ctrl->ScreenToClient( screenPos );
850 wxDataViewColumn* col =
nullptr;
860 if( wxGetDisplayInfo().type == wxDisplayType::wxDisplayWayland )
887 wxDataViewColumn* col =
nullptr;
908 if( aKeyStroke.GetSkipped() )
912 int hotkey = aKeyStroke.GetKeyCode();
914 int mods = aKeyStroke.GetModifiers();
916 if( mods & wxMOD_ALTGR )
920 if( mods & wxMOD_ALT )
923 if( mods & wxMOD_CONTROL )
927 if( mods & wxMOD_SHIFT )
931 if( mods & wxMOD_META )
936 if( mods & wxMOD_WIN )
940 if( tool->GetManager()->GetActionManager()->RunHotKey( hotkey ) )
941 aKeyStroke.Skip(
false );
975 const wxHtmlLinkInfo&
info = aEvent.GetLinkInfo();
976 wxString docname =
info.GetHref();
1018 wxPoint pos =
m_tree_ctrl->ScreenToClient( wxGetMousePosition() );
1020 wxDataViewItem item;
1021 wxDataViewColumn* col;
1033 tool->GetManager()->VetoContextMenuMouseWarp();
1034 tool->GetToolMenu().ShowContextMenu();
1037 tool->GetManager()->DispatchContextMenu( evt );
1043 if( current && current->
m_Type == LIB_TREE_NODE::TYPE::LIBRARY )
1051 if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
1058 if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
1077 if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
static TOOL_ACTION pinLibrary
static TOOL_ACTION selectLibTreeColumns
static TOOL_ACTION unpinLibrary
static TOOL_ACTION expandAll
static TOOL_ACTION collapseAll
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.
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.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
void RefreshLibTree()
Refresh the tree (mainly to update highlighting and asterisking)
wxTimer * m_debounceTimer
void onHoverTimer(wxTimerEvent &aEvent)
LIB_TREE_NODE * GetCurrentTreeNode() const
Retrieve the tree node for the first selected item.
void onQueryMouseMoved(wxMouseEvent &aEvent)
wxDataViewItem m_previewItem
HTML_WINDOW * m_details_ctrl
void onTreeActivate(wxDataViewEvent &aEvent)
wxString m_recentSearchesKey
LIB_TREE(wxWindow *aParent, const wxString &aRecentSearchesKey, wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > &aAdapter, int aFlags=ALL_WIDGETS, HTML_WINDOW *aDetails=nullptr)
Construct a symbol tree.
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 onItemContextMenu(wxDataViewEvent &aEvent)
void ShowChangedLanguage()
WX_DATAVIEWCTRL * m_tree_ctrl
void onQueryText(wxCommandEvent &aEvent)
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
int GetSelectedTreeNodes(std::vector< LIB_TREE_NODE * > &aSelection) const
Retrieve a list of pointers to selected tree nodes for trees that allow multi-selection.
bool m_skipNextRightClick
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
void onIdle(wxIdleEvent &aEvent)
void FocusSearchFieldIfExists()
Focus the search widget if it exists.
std::vector< LIB_ID > GetExpandedLibraries() const
void expandIfValid(const wxDataViewItem &aTreeId)
void onPreselect(wxCommandEvent &aEvent)
wxPopupWindow * m_previewWindow
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
void updateRecentSearchMenu()
void showPreview(wxDataViewItem aItem)
wxString GetSearchString() const
void onTreeSelect(wxDataViewEvent &aEvent)
int GetSelectedLibIds(std::vector< LIB_ID > &aSelection, std::vector< int > *aUnit=nullptr) const
Retrieve 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.
BITMAP_BUTTON * m_sort_ctrl
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,...
wxBoxSizer * m_filtersSizer
wxDataViewItem m_hoverItem
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
virtual SETTINGS_MANAGER & GetSettingsManager() const
Container for project specific data.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
Extension of the wxDataViewCtrl to include some helper functions for working with items.
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths, std::vector< EMBEDDED_FILES * > aFilesStack)
Open a document (file) with the suitable browser.
This file is part of the common library.
#define HOVER_TIMER_MILLIS
constexpr int RECENT_SEARCHES_MAX
std::map< wxString, std::vector< wxString > > g_recentSearches
wxDEFINE_EVENT(EVT_LIBITEM_SELECTED, wxCommandEvent)
This file contains miscellaneous commonly used macros and functions.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
PGM_BASE & Pgm()
The global program "get" accessor.
Structure storing state of the symbol tree widget.
LIB_ID selection
Current selection, might be not valid if nothing was selected.
std::vector< wxDataViewItem > expanded
List of expanded nodes.
void EnsureVisibleIfEnabled(wxDataViewCtrl *aWidget, const wxDataViewItem &aItem)
Scroll aItem into view only when aWidget is currently enabled.