37#include <wx/settings.h>
39#include <wx/srchctrl.h>
40#include <wx/popupwin.h>
52 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter,
int aFlags,
54 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
55 wxWANTS_CHARS | wxTAB_TRAVERSAL | wxNO_BORDER ),
56 m_adapter( aAdapter ),
57 m_query_ctrl( nullptr ),
58 m_sort_ctrl( nullptr ),
59 m_details_ctrl( nullptr ),
60 m_inTimerEvent( false ),
61 m_recentSearchesKey( aRecentSearchesKey ),
62 m_skipNextRightClick( false ),
63 m_previewWindow( nullptr ),
64 m_previewDisabled( false )
66 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
74 wxBoxSizer* search_sizer =
new wxBoxSizer( wxHORIZONTAL );
83 m_query_ctrl->SetMinSize( wxSize( -1, GetTextExtent( wxT(
"qb" ) ).y + 10 ) );
88 search_sizer->Add(
m_query_ctrl, 1, wxEXPAND | wxRIGHT, 5 );
91 wxDefaultSize, wxBU_AUTODRAW|0 );
94 [&]( wxMouseEvent& aEvent )
99 menu.Append( 4201,
_(
"Sort by Best Match" ), wxEmptyString, wxITEM_CHECK );
100 menu.Append( 4202,
_(
"Sort Alphabetically" ), wxEmptyString, wxITEM_CHECK );
101 menu.AppendSeparator();
106 menu.Check( 4201,
true );
108 menu.Check( 4202,
true );
111 int menu_id =
m_sort_ctrl->GetPopupMenuSelectionFromUser( menu );
113 if( menu_id == 0 || menu_id == 4201 )
115 m_adapter->SetSortMode( LIB_TREE_MODEL_ADAPTER::BEST_MATCH );
118 else if( menu_id == 1 || menu_id == 4202 )
120 m_adapter->SetSortMode( LIB_TREE_MODEL_ADAPTER::ALPHABETIC );
123 else if( menu_id == 3 || menu_id == 4203 )
127 else if( menu_id == 4 || menu_id == 4204 )
135 search_sizer->Add(
m_sort_ctrl, 0, wxEXPAND | wxRIGHT, 5 );
137 sizer->Add( search_sizer, 0, wxEXPAND | wxBOTTOM, 5 );
145#if defined( __WXOSX__ ) || wxCHECK_VERSION( 3, 3, 0 )
147 [
this]( wxMouseEvent& aEvt )
149 SetCursor( wxCURSOR_ARROW );
154 [
this]( wxCommandEvent& aEvent )
157 size_t idx = aEvent.GetId() - 1;
168 int dvFlags = ( aFlags &
MULTISELECT ) ? wxDV_MULTIPLE : wxDV_SINGLE;
174 int rowHeight = FromDIP( 8 ) + GetTextExtent( wxS(
"pdI" ) ).y;
178 sizer->Add(
m_tree_ctrl, 5, wxRIGHT | wxBOTTOM | wxEXPAND, 5 );
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 );
310 wxDataViewItemArray selection;
311 int count =
m_tree_ctrl->GetSelections( selection );
313 for(
const wxDataViewItem& item : selection )
315 aSelection.emplace_back(
m_adapter->GetAliasFor( item ) );
318 aUnit->emplace_back(
m_adapter->GetUnitFor( item ) );
390 if( !newEntry.IsEmpty() )
398 recents.insert( recents.begin(), newEntry );
401 wxMenu* menu =
new wxMenu();
403 for(
const wxString&
recent : recents )
404 menu->Append( menu->GetMenuItemCount() + 1,
recent );
406 if( recents.empty() )
407 menu->Append( wxID_ANY,
_(
"recent searches" ) );
455 if( !aTreeId.IsOk() )
494 wxDataViewItemArray siblings;
495 m_adapter->GetChildren( wxDataViewItem( parent ), siblings );
497 int idx = siblings.Index( aTreeId );
499 if( idx + 5 < (
int) siblings.GetCount() )
501 m_tree_ctrl->EnsureVisible( siblings.Item( idx + 5 ) );
503 else if( grandParent )
505 wxDataViewItemArray parentsSiblings;
506 m_adapter->GetChildren( wxDataViewItem( grandParent ), parentsSiblings );
508 int p_idx = parentsSiblings.Index( wxDataViewItem( parent ) );
510 if( p_idx + 1 < (
int) parentsSiblings.GetCount() )
511 m_tree_ctrl->EnsureVisible( parentsSiblings.Item( p_idx + 1 ) );
515 m_tree_ctrl->EnsureVisible( siblings.Item( idx - 5 ) );
517 m_tree_ctrl->EnsureVisible( wxDataViewItem( parent ) );
527 if( aTreeId.IsOk() && !
m_tree_ctrl->IsExpanded( aTreeId ) )
534 wxCommandEvent event( EVT_LIBITEM_SELECTED );
535 wxPostEvent(
this, event );
541 wxCommandEvent event( EVT_LIBITEM_CHOSEN );
542 wxPostEvent(
this, event );
549 wxDataViewItemArray items;
550 m_adapter->GetChildren( wxDataViewItem(
nullptr ), items );
552 for(
const wxDataViewItem& item : items )
568 for(
const wxDataViewItem& item : aState.
expanded )
600 int hotkey = aKeyStroke.GetKeyCode();
602 if( aKeyStroke.GetModifiers() & wxMOD_CONTROL )
605 if( aKeyStroke.GetModifiers() & wxMOD_ALT )
608 if( aKeyStroke.GetModifiers() & wxMOD_SHIFT )
627 sel =
m_adapter->GetCurrentDataViewItem();
631 switch( aKeyStroke.GetKeyCode() )
660 case WXK_NUMPAD_ENTER:
679#if defined( __WXOSX__ ) || wxCHECK_VERSION( 3, 3, 0 )
680 wxPoint pos = aEvent.GetPosition();
682 int buttonWidth = ctrlRect.GetHeight();
684 if(
m_query_ctrl->IsSearchButtonVisible() && pos.x < buttonWidth )
685 SetCursor( wxCURSOR_ARROW );
686 else if(
m_query_ctrl->IsCancelButtonVisible() && pos.x > ctrlRect.GetWidth() - buttonWidth )
687 SetCursor( wxCURSOR_ARROW );
689 SetCursor( wxCURSOR_IBEAM );
694#define PREVIEW_SIZE wxSize( 240, 200 )
695#define HOVER_TIMER_MILLIS 400
700 if( aItem.IsOk() &&
m_adapter->HasPreview( aItem ) )
705 wxWindow* topLevelParent = wxGetTopLevelParent( m_parent );
753 wxWindow* topLevelParent = wxGetTopLevelParent( m_parent );
754 wxWindow* topLevelFocus = wxGetTopLevelParent( wxWindow::FindFocus() );
756 bool mouseOverWindow =
false;
757 wxPoint screenPos = wxGetMousePosition();
760 mouseOverWindow |=
m_tree_ctrl->GetScreenRect().Contains( screenPos );
769 wxPoint clientPos =
m_tree_ctrl->ScreenToClient( screenPos );
771 wxDataViewColumn* col =
nullptr;
793 if( wxGetDisplayInfo().type == wxDisplayType::wxDisplayWayland )
823 wxDataViewColumn* col =
nullptr;
844 if( aKeyStroke.GetSkipped() )
848 int hotkey = aKeyStroke.GetKeyCode();
850 if( aKeyStroke.ShiftDown() )
853 if( aKeyStroke.AltDown() )
856 if( aKeyStroke.ControlDown() )
859 if( tool->GetManager()->GetActionManager()->RunHotKey( hotkey ) )
860 aKeyStroke.Skip(
false );
894 const wxHtmlLinkInfo&
info = aEvent.GetLinkInfo();
895 wxString docname =
info.GetHref();
937 wxPoint pos =
m_tree_ctrl->ScreenToClient( wxGetMousePosition() );
940 wxDataViewColumn* col;
952 tool->GetManager()->VetoContextMenuMouseWarp();
953 tool->GetToolMenu().ShowContextMenu();
956 tool->GetManager()->DispatchContextMenu( evt );
970 if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
977 if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
996 if( GetPopupMenuSelectionFromUser( menu ) != wxID_NONE )
1002 if( dlg.ShowModal() == wxID_OK )
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
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.
bool SetPage(const wxString &aSource) override
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
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
void onHoverTimer(wxTimerEvent &aEvent)
LIB_TREE_NODE * GetCurrentTreeNode() const
void onQueryMouseMoved(wxMouseEvent &aEvent)
wxDataViewItem m_previewItem
HTML_WINDOW * m_details_ctrl
void onTreeActivate(wxDataViewEvent &aEvent)
wxString m_recentSearchesKey
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.
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.
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
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,...
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)
STD_BITMAP_BUTTON * m_sort_ctrl
void onHeaderContextMenu(wxDataViewEvent &aEvent)
void Regenerate(bool aKeepState)
Regenerate the tree.
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Container for project specific data.
Extension of the wxDataViewCtrl to include some helper functions for working with items.
wxDataViewItem GetNextItem(wxDataViewItem const &aItem)
Get the next item in list order.
wxDataViewItem GetPrevItem(wxDataViewItem const &aItem)
Get the previous item in list order.
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths)
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.
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.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Structure storing state of the symbol tree widget.
std::vector< wxDataViewItem > expanded
< List of expanded nodes