KiCad PCB EDA Suite
Loading...
Searching...
No Matches
lib_tree.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2014 Henner Zeller <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef LIB_TREE_H
22#define LIB_TREE_H
23
24#include <wx/panel.h>
25#include <wx/sizer.h>
26#include <wx/timer.h>
28#include <widgets/html_window.h>
30
31class wxTextCtrl;
32class wxHtmlLinkEvent;
33class wxSearchCtrl;
34class wxTimer;
35class wxTimerEvent;
36class wxPopupWindow;
37class BITMAP_BUTTON;
39class ACTION_MENU;
40class LIB_ID;
41
45class LIB_TREE : public wxPanel
46{
47public:
49 enum FLAGS
50 {
51 FLAGS_NONE = 0x00,
52 SEARCH = 0x01,
53 FILTERS = 0x02,
54 DETAILS = 0x04,
57 };
58
71 LIB_TREE( wxWindow* aParent, const wxString& aRecentSearchesKey,
72 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter, int aFlags = ALL_WIDGETS,
73 HTML_WINDOW* aDetails = nullptr );
74
75 ~LIB_TREE() override;
76
86 LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
87
89 {
90 return m_tree_ctrl->GetSelectedItemsCount();
91 }
92
101 int GetSelectedLibIds( std::vector<LIB_ID>& aSelection,
102 std::vector<int>* aUnit = nullptr ) const;
103
110
117 int GetSelectedTreeNodes( std::vector<LIB_TREE_NODE*>& aSelection ) const;
118
122 void SelectLibId( const LIB_ID& aLibId );
123
127 void CenterLibId( const LIB_ID& aLibId );
128
132 void Unselect();
133
137 void ExpandLibId( const LIB_ID& aLibId );
138
139 std::vector<LIB_ID> GetExpandedLibraries() const;
140
141 void ExpandAll();
142 void CollapseAll();
143
147 void SetSearchString( const wxString& aSearchString );
148 wxString GetSearchString() const;
149
153 void SetSortMode( LIB_TREE_MODEL_ADAPTER::SORT_MODE aMode ) { m_adapter->SetSortMode( aMode ); }
154 LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const { return m_adapter->GetSortMode(); }
155
159 void Regenerate( bool aKeepState );
160
164 void RefreshLibTree();
165
166 wxWindow* GetFocusTarget();
167
168 wxSizer* GetFiltersSizer() { return m_filtersSizer; }
169
174
175 void ShowChangedLanguage();
176
177 void BlockPreview( bool aBlock )
178 {
179 m_previewDisabled = aBlock;
180 }
181
182 void ShutdownPreviews();
183
184protected:
188 void toggleExpand( const wxDataViewItem& aTreeId );
189
193 void selectIfValid( const wxDataViewItem& aTreeId );
194
195 void centerIfValid( const wxDataViewItem& aTreeId );
196
197 void expandIfValid( const wxDataViewItem& aTreeId );
198
203 void postPreselectEvent();
204
208 void postSelectEvent();
209
213 struct STATE
214 {
216 std::vector<wxDataViewItem> expanded;
217
220
222 };
223
227 STATE getState() const;
228
232 void setState( const STATE& aState );
233
235
236 void showPreview( wxDataViewItem aItem );
237 void hidePreview();
238
239 void onQueryText( wxCommandEvent& aEvent );
240 void onQueryCharHook( wxKeyEvent& aEvent );
241 void onQueryMouseMoved( wxMouseEvent& aEvent );
242
243 void onTreeSelect( wxDataViewEvent& aEvent );
244 void onTreeActivate( wxDataViewEvent& aEvent );
245 void onTreeCharHook( wxKeyEvent& aEvent );
246
247 void onIdle( wxIdleEvent& aEvent );
248 void onHoverTimer( wxTimerEvent& aEvent );
249
250 void onDetailsLink( wxHtmlLinkEvent& aEvent );
251 void onPreselect( wxCommandEvent& aEvent );
252 void onItemContextMenu( wxDataViewEvent& aEvent );
253 void onHeaderContextMenu( wxDataViewEvent& aEvent );
254
255 void onDebounceTimer( wxTimerEvent& aEvent );
256
257protected:
258 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;
259
260 wxSearchCtrl* m_query_ctrl;
266
268
269 wxBoxSizer* m_filtersSizer;
270
272
273 wxPoint m_hoverPos;
274 wxDataViewItem m_hoverItem;
277 wxDataViewItem m_previewItem;
279 wxPopupWindow* m_previewWindow;
281};
282
284wxDECLARE_EVENT( EVT_LIBITEM_SELECTED, wxCommandEvent );
285
287wxDECLARE_EVENT( EVT_LIBITEM_CHOSEN, wxCommandEvent );
288
289#endif /* LIB_TREE_H */
Define the structure of a menu based on ACTIONs.
Definition action_menu.h:43
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Add dark theme support to wxHtmlWindow.
Definition html_window.h:31
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
wxRect m_previewItemRect
Definition lib_tree.h:278
void RefreshLibTree()
Refresh the tree (mainly to update highlighting and asterisking)
Definition lib_tree.cpp:493
wxPoint m_hoverPos
Definition lib_tree.h:273
wxTimer * m_debounceTimer
Definition lib_tree.h:264
void onHoverTimer(wxTimerEvent &aEvent)
Definition lib_tree.cpp:879
LIB_TREE_NODE * GetCurrentTreeNode() const
Retrieve the tree node for the first selected item.
Definition lib_tree.cpp:347
void onQueryMouseMoved(wxMouseEvent &aEvent)
Definition lib_tree.cpp:770
wxDataViewItem m_previewItem
Definition lib_tree.h:277
HTML_WINDOW * m_details_ctrl
Definition lib_tree.h:263
void onTreeActivate(wxDataViewEvent &aEvent)
Definition lib_tree.cpp:959
wxString m_recentSearchesKey
Definition lib_tree.h:267
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.
Definition lib_tree.cpp:49
void onQueryCharHook(wxKeyEvent &aEvent)
Definition lib_tree.cpp:669
void CenterLibId(const LIB_ID &aLibId)
Ensure that an item is visible (preferably centered).
Definition lib_tree.cpp:383
void postSelectEvent()
Post #SYMBOL_SELECTED event to notify the selection handler that a part has been selected.
Definition lib_tree.cpp:601
wxWindow * GetFocusTarget()
Definition lib_tree.cpp:499
int GetSelectionCount() const
Definition lib_tree.h:88
void ShutdownPreviews()
Definition lib_tree.cpp:283
void onItemContextMenu(wxDataViewEvent &aEvent)
void ShowChangedLanguage()
Definition lib_tree.cpp:300
WX_DATAVIEWCTRL * m_tree_ctrl
Definition lib_tree.h:262
void onQueryText(wxCommandEvent &aEvent)
Definition lib_tree.cpp:651
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
Definition lib_tree.cpp:515
int GetSelectedTreeNodes(std::vector< LIB_TREE_NODE * > &aSelection) const
Retrieve a list of pointers to selected tree nodes for trees that allow multi-selection.
Definition lib_tree.cpp:357
wxSizer * GetFiltersSizer()
Definition lib_tree.h:168
bool m_skipNextRightClick
Definition lib_tree.h:271
bool m_inTimerEvent
Definition lib_tree.h:265
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition lib_tree.cpp:527
void onIdle(wxIdleEvent &aEvent)
Definition lib_tree.cpp:824
void FocusSearchFieldIfExists()
Focus the search widget if it exists.
Definition lib_tree.cpp:508
std::vector< LIB_ID > GetExpandedLibraries() const
Definition lib_tree.cpp:403
void expandIfValid(const wxDataViewItem &aTreeId)
Definition lib_tree.cpp:587
void onPreselect(wxCommandEvent &aEvent)
Definition lib_tree.cpp:983
wxPopupWindow * m_previewWindow
Definition lib_tree.h:279
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition lib_tree.cpp:371
void updateRecentSearchMenu()
Definition lib_tree.cpp:446
void hidePreview()
Definition lib_tree.cpp:815
LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const
Definition lib_tree.h:154
void showPreview(wxDataViewItem aItem)
Definition lib_tree.cpp:791
wxString GetSearchString() const
Definition lib_tree.cpp:440
void onTreeSelect(wxDataViewEvent &aEvent)
Definition lib_tree.cpp:947
int GetSelectedLibIds(std::vector< LIB_ID > &aSelection, std::vector< int > *aUnit=nullptr) const
Retrieve a list of selections for trees that allow multi-selection.
Definition lib_tree.cpp:330
wxTimer m_hoverTimer
Definition lib_tree.h:276
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition lib_tree.cpp:594
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition lib_tree.cpp:389
BITMAP_BUTTON * m_sort_ctrl
Definition lib_tree.h:261
void onTreeCharHook(wxKeyEvent &aEvent)
Definition lib_tree.cpp:904
void onDetailsLink(wxHtmlLinkEvent &aEvent)
Definition lib_tree.cpp:973
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit symbols, if the user selects the symbol itself rather than picking an individual unit,...
Definition lib_tree.cpp:310
FLAGS
< Flags to select extra widgets and options
Definition lib_tree.h:50
@ MULTISELECT
Definition lib_tree.h:56
@ FILTERS
Definition lib_tree.h:53
@ DETAILS
Definition lib_tree.h:54
@ ALL_WIDGETS
Definition lib_tree.h:55
@ FLAGS_NONE
Definition lib_tree.h:51
void ExpandAll()
Definition lib_tree.cpp:422
wxBoxSizer * m_filtersSizer
Definition lib_tree.h:269
wxDataViewItem m_hoverItem
Definition lib_tree.h:274
~LIB_TREE() override
Definition lib_tree.cpp:246
void SetSearchString(const wxString &aSearchString)
Save/restore search string.
Definition lib_tree.cpp:434
void setState(const STATE &aState)
Restore the symbol tree widget state from an object.
Definition lib_tree.cpp:631
STATE getState() const
Return the symbol tree widget state.
Definition lib_tree.cpp:608
bool m_previewDisabled
Definition lib_tree.h:280
void ExpandLibId(const LIB_ID &aLibId)
Expand and item i the tree widget.
Definition lib_tree.cpp:397
void BlockPreview(bool aBlock)
Definition lib_tree.h:177
wxSearchCtrl * m_query_ctrl
Definition lib_tree.h:260
void CollapseAll()
Definition lib_tree.cpp:428
void centerIfValid(const wxDataViewItem &aTreeId)
Definition lib_tree.cpp:539
void onDebounceTimer(wxTimerEvent &aEvent)
Definition lib_tree.cpp:661
wxRect m_hoverItemRect
Definition lib_tree.h:275
void onHeaderContextMenu(wxDataViewEvent &aEvent)
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition lib_tree.cpp:475
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition lib_tree.h:258
void SetSortMode(LIB_TREE_MODEL_ADAPTER::SORT_MODE aMode)
Save/restore the sorting mode.
Definition lib_tree.h:153
A bitmap button widget that behaves like a standard dialog button except with an icon.
Extension of the wxDataViewCtrl to include some helper functions for working with items.
wxDECLARE_EVENT(EVT_LIBITEM_SELECTED, wxCommandEvent)
Custom event sent when an item is selected in the list.
Structure storing state of the symbol tree widget.
Definition lib_tree.h:214
LIB_ID selection
Current selection, might be not valid if nothing was selected.
Definition lib_tree.h:219
VECTOR2I scrollpos
Definition lib_tree.h:221
std::vector< wxDataViewItem > expanded
List of expanded nodes.
Definition lib_tree.h:216
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683