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
31 : wxPanel( aParent ),
32 m_symbolEditFrame( aParent ),
33 m_tree( nullptr ),
34 m_libMgr( aLibMgr )
35{
36 // Create widgets
37 wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
38 m_tree = new LIB_TREE( this, wxT( "symbols" ),
40 boxSizer->Add( m_tree, 1, wxEXPAND, 5 );
41
42 SetSizer( boxSizer ); // should remove the previous sizer according to wxWidgets docs
43 Layout();
44 boxSizer->Fit( this );
45
46 m_libMgr->GetAdapter()->FinishTreeInitialization();
47
48 // Event handlers
49 Bind( EVT_LIBITEM_CHOSEN, &SYMBOL_TREE_PANE::onSymbolSelected, this );
50 m_tree->Bind( wxEVT_UPDATE_UI, &SYMBOL_TREE_PANE::onUpdateUI, this );
51 m_symbolEditFrame->Bind( wxEVT_MENU_OPEN, &SYMBOL_TREE_PANE::onMenuOpen, this );
52 m_symbolEditFrame->Bind( wxEVT_MENU_CLOSE, &SYMBOL_TREE_PANE::onMenuClose, this );
53}
54
55
57{
58 m_symbolEditFrame->Unbind( wxEVT_MENU_OPEN, &SYMBOL_TREE_PANE::onMenuOpen, this );
59 m_symbolEditFrame->Unbind( wxEVT_MENU_CLOSE, &SYMBOL_TREE_PANE::onMenuClose, this );
60 m_tree->Unbind( wxEVT_UPDATE_UI, &SYMBOL_TREE_PANE::onUpdateUI, this );
61 Unbind( EVT_LIBITEM_CHOSEN, &SYMBOL_TREE_PANE::onSymbolSelected, this );
62 m_tree->Destroy();
63}
64
65
66void SYMBOL_TREE_PANE::onMenuOpen( wxMenuEvent& aEvent )
67{
68 m_tree->BlockPreview( true );
69 aEvent.Skip();
70}
71
72
73void SYMBOL_TREE_PANE::onMenuClose( wxMenuEvent& aEvent )
74{
75 m_tree->BlockPreview( false );
76 aEvent.Skip();
77}
78
79
80void SYMBOL_TREE_PANE::onSymbolSelected( wxCommandEvent& aEvent )
81{
82 m_symbolEditFrame->GetToolManager()->RunAction( SCH_ACTIONS::editSymbol );
83
84 // Make sure current-part highlighting doesn't get lost in selection highlighting
85 m_tree->Unselect();
86
87 // Turn off any previous current-part highlighting
88 m_tree->RefreshLibTree();
89}
90
91
92void SYMBOL_TREE_PANE::onUpdateUI( wxUpdateUIEvent& aEvent )
93{
94 if( m_symbolEditFrame->GetCanvas()->HasFocus() )
95 {
96 // Don't allow a selected item in the tree when the canvas has focus: it's too easy
97 // to confuse the selected-highlighting with the being-edited-on-canvas-highlighting.
98 if( m_symbolEditFrame->GetCurSymbol() != nullptr )
99 {
100 m_tree->Unselect();
101 }
102 }
103}
Symbol library management helper that is specific to the symbol library editor frame.
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)
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