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, you may find one here:
20 * https://www.gnu.org/licenses/gpl-3.0.html
21 * or you may search the http://www.gnu.org website for the version 3 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include "symbol_tree_pane.h"
27#include <widgets/lib_tree.h>
29#include <symbol_edit_frame.h>
30#include <tool/tool_manager.h>
31#include <tools/sch_actions.h>
32
35 : wxPanel( aParent ),
36 m_symbolEditFrame( aParent ),
37 m_tree( nullptr ),
38 m_libMgr( aLibMgr )
39{
40 // Create widgets
41 wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
42 m_tree = new LIB_TREE( this, wxT( "symbols" ),
44 boxSizer->Add( m_tree, 1, wxEXPAND, 5 );
45
46 SetSizer( boxSizer ); // should remove the previous sizer according to wxWidgets docs
47 Layout();
48 boxSizer->Fit( this );
49
50 m_libMgr->GetAdapter()->FinishTreeInitialization();
51
52 // Event handlers
53 Bind( EVT_LIBITEM_CHOSEN, &SYMBOL_TREE_PANE::onSymbolSelected, this );
54 m_tree->Bind( wxEVT_UPDATE_UI, &SYMBOL_TREE_PANE::onUpdateUI, this );
55 m_symbolEditFrame->Bind( wxEVT_MENU_OPEN, &SYMBOL_TREE_PANE::onMenuOpen, this );
56 m_symbolEditFrame->Bind( wxEVT_MENU_CLOSE, &SYMBOL_TREE_PANE::onMenuClose, this );
57}
58
59
61{
62 m_symbolEditFrame->Unbind( wxEVT_MENU_OPEN, &SYMBOL_TREE_PANE::onMenuOpen, this );
63 m_symbolEditFrame->Unbind( wxEVT_MENU_CLOSE, &SYMBOL_TREE_PANE::onMenuClose, this );
64 m_tree->Unbind( wxEVT_UPDATE_UI, &SYMBOL_TREE_PANE::onUpdateUI, this );
65 Unbind( EVT_LIBITEM_CHOSEN, &SYMBOL_TREE_PANE::onSymbolSelected, this );
66 m_tree->Destroy();
67}
68
69
70void SYMBOL_TREE_PANE::onMenuOpen( wxMenuEvent& aEvent )
71{
72 m_tree->BlockPreview( true );
73 aEvent.Skip();
74}
75
76
77void SYMBOL_TREE_PANE::onMenuClose( wxMenuEvent& aEvent )
78{
79 m_tree->BlockPreview( false );
80 aEvent.Skip();
81}
82
83
84void SYMBOL_TREE_PANE::onSymbolSelected( wxCommandEvent& aEvent )
85{
86 m_symbolEditFrame->GetToolManager()->RunAction( SCH_ACTIONS::editSymbol );
87
88 // Make sure current-part highlighting doesn't get lost in selection highlighting
89 m_tree->Unselect();
90
91 // Turn off any previous current-part highlighting
92 m_tree->RefreshLibTree();
93}
94
95
96void SYMBOL_TREE_PANE::onUpdateUI( wxUpdateUIEvent& aEvent )
97{
98 if( m_symbolEditFrame->GetCanvas()->HasFocus() )
99 {
100 // Don't allow a selected item in the tree when the canvas has focus: it's too easy
101 // to confuse the selected-highlighting with the being-edited-on-canvas-highlighting.
102 if( m_symbolEditFrame->GetCurSymbol() != nullptr )
103 {
104 m_tree->Unselect();
105 }
106 }
107}
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:48
@ MULTISELECT
Definition lib_tree.h:58
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