KiCad PCB EDA Suite
Loading...
Searching...
No Matches
symbol_tree_pane.cpp
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) 2017 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 3
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include "symbol_tree_pane.h"
23#include <widgets/lib_tree.h>
25#include <symbol_edit_frame.h>
26#include <tool/tool_manager.h>
27#include <tools/sch_actions.h>
28
30 wxPanel( aParent ),
31 m_symbolEditFrame( aParent ),
32 m_tree( nullptr ),
33 m_libMgr( aLibMgr )
34{
35 // Create widgets
36 wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
37 m_tree = new LIB_TREE( this, wxT( "symbols" ), m_libMgr->GetAdapter(), LIB_TREE::SEARCH | LIB_TREE::MULTISELECT );
38 boxSizer->Add( m_tree, 1, wxEXPAND, 5 );
39
40 SetSizer( boxSizer ); // should remove the previous sizer according to wxWidgets docs
41 Layout();
42 boxSizer->Fit( this );
43
44 m_filter = [this]( LIB_TREE_NODE& aNode ) -> bool
45 {
46 if( m_tree->GetSearchString().StartsWith( "::" ) )
47 return aNode.m_IsRoot;
48 else
49 return true;
50 };
51
52 m_libMgr->GetAdapter()->FinishTreeInitialization();
53 m_libMgr->GetAdapter()->SetFilter( &m_filter );
54
55 // Event handlers
56 Bind( EVT_LIBITEM_CHOSEN, &SYMBOL_TREE_PANE::onSymbolSelected, this );
57 m_tree->Bind( wxEVT_UPDATE_UI, &SYMBOL_TREE_PANE::onUpdateUI, this );
58 m_symbolEditFrame->Bind( wxEVT_MENU_OPEN, &SYMBOL_TREE_PANE::onMenuOpen, this );
59 m_symbolEditFrame->Bind( wxEVT_MENU_CLOSE, &SYMBOL_TREE_PANE::onMenuClose, this );
60}
61
62
64{
65 m_symbolEditFrame->Unbind( wxEVT_MENU_OPEN, &SYMBOL_TREE_PANE::onMenuOpen, this );
66 m_symbolEditFrame->Unbind( wxEVT_MENU_CLOSE, &SYMBOL_TREE_PANE::onMenuClose, this );
67 m_tree->Unbind( wxEVT_UPDATE_UI, &SYMBOL_TREE_PANE::onUpdateUI, this );
68 Unbind( EVT_LIBITEM_CHOSEN, &SYMBOL_TREE_PANE::onSymbolSelected, this );
69 m_tree->Destroy();
70}
71
72
73void SYMBOL_TREE_PANE::onMenuOpen( wxMenuEvent& aEvent )
74{
75 m_tree->BlockPreview( true );
76 aEvent.Skip();
77}
78
79
80void SYMBOL_TREE_PANE::onMenuClose( wxMenuEvent& aEvent )
81{
82 m_tree->BlockPreview( false );
83 aEvent.Skip();
84}
85
86
87void SYMBOL_TREE_PANE::onSymbolSelected( wxCommandEvent& aEvent )
88{
89 m_symbolEditFrame->GetToolManager()->RunAction( SCH_ACTIONS::editSymbol );
90
91 // Make sure current-part highlighting doesn't get lost in selection highlighting
92 m_tree->Unselect();
93
94 // Turn off any previous current-part highlighting
95 m_tree->RefreshLibTree();
96}
97
98
99void SYMBOL_TREE_PANE::onUpdateUI( wxUpdateUIEvent& aEvent )
100{
101 if( m_symbolEditFrame->GetCanvas()->HasFocus() )
102 {
103 // Don't allow a selected item in the tree when the canvas has focus: it's too easy
104 // to confuse the selected-highlighting with the being-edited-on-canvas-highlighting.
105 if( m_symbolEditFrame->GetCurSymbol() != nullptr )
106 {
107 m_tree->Unselect();
108 }
109 }
110}
Symbol library management helper that is specific to the symbol library editor frame.
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:46
@ MULTISELECT
Definition lib_tree.h:56
static TOOL_ACTION editSymbol
The symbol library editor main window.
void onUpdateUI(wxUpdateUIEvent &aEvent)
LIB_SYMBOL_LIBRARY_MANAGER * m_libMgr
SYMBOL_TREE_PANE(SYMBOL_EDIT_FRAME *aParent, LIB_SYMBOL_LIBRARY_MANAGER *aLibMgr)
SYMBOL_EDIT_FRAME * m_symbolEditFrame
void onSymbolSelected(wxCommandEvent &aEvent)
void onMenuClose(wxMenuEvent &aEvent)
std::function< bool(LIB_TREE_NODE &)> m_filter
void onMenuOpen(wxMenuEvent &aEvent)
Handle parent menu events to block preview updates while the menu is open.
LIB_TREE * m_tree
symbol search tree widget