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 (C) 2014-2023 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>
30#include <html_window.h>
32
33class wxTextCtrl;
34class wxHtmlLinkEvent;
35class wxSearchCtrl;
36class wxTimer;
37class wxTimerEvent;
39class ACTION_MENU;
40class LIB_ID;
41class LIB_TABLE;
42
46class LIB_TREE : public wxPanel
47{
48public:
50 enum FLAGS
51 {
52 NONE = 0x00,
53 SEARCH = 0x01,
54 DETAILS = 0x02,
56 MULTISELECT = 0x10
57 };
58
71 LIB_TREE( wxWindow* aParent, const wxString& aRecentSearchesKey, LIB_TABLE* aLibTable,
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
100 int GetSelectedLibIds( std::vector<LIB_ID>& aSelection,
101 std::vector<int>* aUnit = nullptr ) const;
102
104
108 void SelectLibId( const LIB_ID& aLibId );
109
113 void CenterLibId( const LIB_ID& aLibId );
114
118 void Unselect();
119
123 void ExpandLibId( const LIB_ID& aLibId );
124
128 void SetSearchString( const wxString& aSearchString );
129 wxString GetSearchString() const;
130
134 void SetSortMode( LIB_TREE_MODEL_ADAPTER::SORT_MODE aMode ) { m_adapter->SetSortMode( aMode ); }
135 LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const { return m_adapter->GetSortMode(); }
136
140 void Regenerate( bool aKeepState );
141
145 void RefreshLibTree();
146
147 wxWindow* GetFocusTarget();
148
153
154 void ShowChangedLanguage();
155
156protected:
160 void toggleExpand( const wxDataViewItem& aTreeId );
161
165 void selectIfValid( const wxDataViewItem& aTreeId );
166
167 void centerIfValid( const wxDataViewItem& aTreeId );
168
169 void expandIfValid( const wxDataViewItem& aTreeId );
170
175 void postPreselectEvent();
176
180 void postSelectEvent();
181
185 struct STATE
186 {
188 std::vector<wxDataViewItem> expanded;
189 std::vector<wxString> pinned;
190
193 };
194
198 STATE getState() const;
199
203 void setState( const STATE& aState );
204
206
207 void onQueryText( wxCommandEvent& aEvent );
208 void onQueryCharHook( wxKeyEvent& aEvent );
209 void onQueryMouseMoved( wxMouseEvent& aEvent );
210
211 void onTreeSelect( wxDataViewEvent& aEvent );
212 void onTreeActivate( wxDataViewEvent& aEvent );
213 void onTreeCharHook( wxKeyEvent& aEvent );
214 void onSize( wxSizeEvent& aEvent );
215
216 void onDetailsLink( wxHtmlLinkEvent& aEvent );
217 void onPreselect( wxCommandEvent& aEvent );
218 void onItemContextMenu( wxDataViewEvent& aEvent );
219 void onHeaderContextMenu( wxDataViewEvent& aEvent );
220
221 void onDebounceTimer( wxTimerEvent& aEvent );
222
223protected:
224 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;
225
226 wxSearchCtrl* m_query_ctrl;
232
235
237};
238
240wxDECLARE_EVENT( SYMBOL_PRESELECTED, wxCommandEvent );
241
243wxDECLARE_EVENT( SYMBOL_SELECTED, wxCommandEvent );
244
245#endif /* LIB_TREE_H */
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
Add dark theme support to wxHtmlWindow.
Definition: html_window.h:34
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
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.
Widget displaying a tree of symbols with optional search text control and description panel....
Definition: lib_tree.h:47
void RefreshLibTree()
Refreshes the tree (mainly to update highlighting and asterisking)
Definition: lib_tree.cpp:361
wxTimer * m_debounceTimer
Definition: lib_tree.h:230
LIB_TREE_NODE * GetCurrentTreeNode() const
Definition: lib_tree.cpp:267
void onQueryMouseMoved(wxMouseEvent &aEvent)
Definition: lib_tree.cpp:580
HTML_WINDOW * m_details_ctrl
Definition: lib_tree.h:229
void onTreeActivate(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:631
wxString m_recentSearchesKey
Definition: lib_tree.h:234
void onQueryCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:530
void CenterLibId(const LIB_ID &aLibId)
Ensure that an item is visible (preferably centered).
Definition: lib_tree.cpp:284
void postSelectEvent()
Post SYMBOL_SELECTED event to notify the selection handler that a part has been selected.
Definition: lib_tree.cpp:471
wxWindow * GetFocusTarget()
Definition: lib_tree.cpp:367
int GetSelectionCount() const
Definition: lib_tree.h:88
void onSize(wxSizeEvent &aEvent)
Definition: lib_tree.cpp:640
void onItemContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:670
void ShowChangedLanguage()
Definition: lib_tree.cpp:226
WX_DATAVIEWCTRL * m_tree_ctrl
Definition: lib_tree.h:228
void onQueryText(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:512
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
Definition: lib_tree.cpp:385
bool m_skipNextRightClick
Definition: lib_tree.h:236
bool m_inTimerEvent
Definition: lib_tree.h:231
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition: lib_tree.cpp:397
void FocusSearchFieldIfExists()
Focus the search widget if it exists.
Definition: lib_tree.cpp:376
void expandIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:457
void onPreselect(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:653
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:278
void updateRecentSearchMenu()
Definition: lib_tree.cpp:314
LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const
Definition: lib_tree.h:135
wxString GetSearchString() const
Definition: lib_tree.cpp:308
void onTreeSelect(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:621
LIB_ID m_last_libid
Definition: lib_tree.h:233
int GetSelectedLibIds(std::vector< LIB_ID > &aSelection, std::vector< int > *aUnit=nullptr) const
Retrieves a list of selections for trees that allow multi-selection.
Definition: lib_tree.cpp:250
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:464
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:290
void onTreeCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:595
void onDetailsLink(wxHtmlLinkEvent &aEvent)
Definition: lib_tree.cpp:646
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:236
FLAGS
< Flags to select extra widgets and options
Definition: lib_tree.h:51
@ NONE
Definition: lib_tree.h:52
@ MULTISELECT
Definition: lib_tree.h:56
@ DETAILS
Definition: lib_tree.h:54
@ ALL_WIDGETS
Definition: lib_tree.h:55
@ SEARCH
Definition: lib_tree.h:53
~LIB_TREE() override
Definition: lib_tree.cpp:219
void SetSearchString(const wxString &aSearchString)
Save/restore search string.
Definition: lib_tree.cpp:302
void setState(const STATE &aState)
Restore the symbol tree widget state from an object.
Definition: lib_tree.cpp:496
STATE getState() const
Return the symbol tree widget state.
Definition: lib_tree.cpp:478
void ExpandLibId(const LIB_ID &aLibId)
Expand and item i the tree widget.
Definition: lib_tree.cpp:296
wxSearchCtrl * m_query_ctrl
Definition: lib_tree.h:226
void centerIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:409
void onDebounceTimer(wxTimerEvent &aEvent)
Definition: lib_tree.cpp:522
STD_BITMAP_BUTTON * m_sort_ctrl
Definition: lib_tree.h:227
void onHeaderContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:740
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition: lib_tree.cpp:343
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:224
void SetSortMode(LIB_TREE_MODEL_ADAPTER::SORT_MODE aMode)
Save/restore the sorting mode.
Definition: lib_tree.h:134
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(SYMBOL_PRESELECTED, wxCommandEvent)
Custom event sent when a symbol is selected.
Structure storing state of the symbol tree widget.
Definition: lib_tree.h:186
LIB_ID selection
Definition: lib_tree.h:192
std::vector< wxString > pinned
Current selection, might be not valid if nothing was selected.
Definition: lib_tree.h:189
std::vector< wxDataViewItem > expanded
< List of expanded nodes
Definition: lib_tree.h:188