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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef LIB_TREE_H
26#define LIB_TREE_H
27
28#include <wx/panel.h>
29#include <wx/timer.h>
31#include <widgets/html_window.h>
33
34class wxTextCtrl;
35class wxHtmlLinkEvent;
36class wxSearchCtrl;
37class wxTimer;
38class wxTimerEvent;
39class wxPopupWindow;
41class ACTION_MENU;
42class LIB_ID;
43
47class LIB_TREE : public wxPanel
48{
49public:
51 enum FLAGS
52 {
53 FLAGS_NONE = 0x00,
54 SEARCH = 0x01,
55 FILTERS = 0x02,
56 DETAILS = 0x04,
59 };
60
73 LIB_TREE( wxWindow* aParent, const wxString& aRecentSearchesKey,
74 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter, int aFlags = ALL_WIDGETS,
75 HTML_WINDOW* aDetails = nullptr );
76
77 ~LIB_TREE() override;
78
88 LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
89
91 {
92 return m_tree_ctrl->GetSelectedItemsCount();
93 }
94
103 int GetSelectedLibIds( std::vector<LIB_ID>& aSelection,
104 std::vector<int>* aUnit = nullptr ) const;
105
112
119 int GetSelectedTreeNodes( std::vector<LIB_TREE_NODE*>& aSelection ) const;
120
124 void SelectLibId( const LIB_ID& aLibId );
125
129 void CenterLibId( const LIB_ID& aLibId );
130
134 void Unselect();
135
139 void ExpandLibId( const LIB_ID& aLibId );
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:47
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:35
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:49
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:472
wxPoint m_hoverPos
Definition lib_tree.h:273
wxTimer * m_debounceTimer
Definition lib_tree.h:264
void onHoverTimer(wxTimerEvent &aEvent)
Definition lib_tree.cpp:858
LIB_TREE_NODE * GetCurrentTreeNode() const
Retrieve the tree node for the first selected item.
Definition lib_tree.cpp:351
void onQueryMouseMoved(wxMouseEvent &aEvent)
Definition lib_tree.cpp:749
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:938
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:53
void onQueryCharHook(wxKeyEvent &aEvent)
Definition lib_tree.cpp:648
void CenterLibId(const LIB_ID &aLibId)
Ensure that an item is visible (preferably centered).
Definition lib_tree.cpp:381
void postSelectEvent()
Post #SYMBOL_SELECTED event to notify the selection handler that a part has been selected.
Definition lib_tree.cpp:580
wxWindow * GetFocusTarget()
Definition lib_tree.cpp:478
int GetSelectionCount() const
Definition lib_tree.h:90
void ShutdownPreviews()
Definition lib_tree.cpp:287
void onItemContextMenu(wxDataViewEvent &aEvent)
Definition lib_tree.cpp:981
void ShowChangedLanguage()
Definition lib_tree.cpp:304
WX_DATAVIEWCTRL * m_tree_ctrl
Definition lib_tree.h:262
void onQueryText(wxCommandEvent &aEvent)
Definition lib_tree.cpp:630
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
Definition lib_tree.cpp:494
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:361
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:506
void onIdle(wxIdleEvent &aEvent)
Definition lib_tree.cpp:803
void FocusSearchFieldIfExists()
Focus the search widget if it exists.
Definition lib_tree.cpp:487
void expandIfValid(const wxDataViewItem &aTreeId)
Definition lib_tree.cpp:566
void onPreselect(wxCommandEvent &aEvent)
Definition lib_tree.cpp:962
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:375
void updateRecentSearchMenu()
Definition lib_tree.cpp:425
void hidePreview()
Definition lib_tree.cpp:794
LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const
Definition lib_tree.h:154
void showPreview(wxDataViewItem aItem)
Definition lib_tree.cpp:770
wxString GetSearchString() const
Definition lib_tree.cpp:419
void onTreeSelect(wxDataViewEvent &aEvent)
Definition lib_tree.cpp:926
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:334
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:573
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition lib_tree.cpp:387
BITMAP_BUTTON * m_sort_ctrl
Definition lib_tree.h:261
void onTreeCharHook(wxKeyEvent &aEvent)
Definition lib_tree.cpp:883
void onDetailsLink(wxHtmlLinkEvent &aEvent)
Definition lib_tree.cpp:952
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:314
FLAGS
< Flags to select extra widgets and options
Definition lib_tree.h:52
@ MULTISELECT
Definition lib_tree.h:58
@ FILTERS
Definition lib_tree.h:55
@ DETAILS
Definition lib_tree.h:56
@ ALL_WIDGETS
Definition lib_tree.h:57
@ FLAGS_NONE
Definition lib_tree.h:53
void ExpandAll()
Definition lib_tree.cpp:401
wxBoxSizer * m_filtersSizer
Definition lib_tree.h:269
wxDataViewItem m_hoverItem
Definition lib_tree.h:274
~LIB_TREE() override
Definition lib_tree.cpp:250
void SetSearchString(const wxString &aSearchString)
Save/restore search string.
Definition lib_tree.cpp:413
void setState(const STATE &aState)
Restore the symbol tree widget state from an object.
Definition lib_tree.cpp:610
STATE getState() const
Return the symbol tree widget state.
Definition lib_tree.cpp:587
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:395
void BlockPreview(bool aBlock)
Definition lib_tree.h:177
wxSearchCtrl * m_query_ctrl
Definition lib_tree.h:260
void CollapseAll()
Definition lib_tree.cpp:407
void centerIfValid(const wxDataViewItem &aTreeId)
Definition lib_tree.cpp:518
void onDebounceTimer(wxTimerEvent &aEvent)
Definition lib_tree.cpp:640
wxRect m_hoverItemRect
Definition lib_tree.h:275
void onHeaderContextMenu(wxDataViewEvent &aEvent)
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition lib_tree.cpp:454
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:695