You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.5 KiB

2 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 3
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * https://www.gnu.org/licenses/gpl-3.0.html
  19. * or you may search the http://www.gnu.org website for the version 3 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include "footprint_tree_pane.h"
  24. #include "fp_tree_synchronizing_adapter.h"
  25. #include <widgets/lib_tree.h>
  26. #include <footprint_edit_frame.h>
  27. #include <fp_lib_table.h>
  28. FOOTPRINT_TREE_PANE::FOOTPRINT_TREE_PANE( FOOTPRINT_EDIT_FRAME* aParent )
  29. : wxPanel( aParent ),
  30. m_frame( aParent ),
  31. m_tree( nullptr )
  32. {
  33. // Create widgets
  34. wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
  35. m_tree = new LIB_TREE( this, wxT( "footprints" ), &GFootprintTable,
  36. m_frame->GetLibTreeAdapter(), LIB_TREE::SEARCH );
  37. boxSizer->Add( m_tree, 1, wxEXPAND, 5 );
  38. SetSizer( boxSizer ); // should remove the previous sizer according to wxWidgets docs
  39. Layout();
  40. boxSizer->Fit( this );
  41. m_frame->GetLibTreeAdapter()->FinishTreeInitialization();
  42. // Event handlers
  43. Bind( EVT_LIBITEM_CHOSEN, &FOOTPRINT_TREE_PANE::onComponentSelected, this );
  44. m_tree->Bind( wxEVT_UPDATE_UI, &FOOTPRINT_TREE_PANE::onUpdateUI, this );
  45. m_frame->Bind( wxEVT_MENU_OPEN, &FOOTPRINT_TREE_PANE::onMenuOpen, this );
  46. m_frame->Bind( wxEVT_MENU_CLOSE, &FOOTPRINT_TREE_PANE::onMenuClose, this );
  47. }
  48. void FOOTPRINT_TREE_PANE::FocusSearchFieldIfExists()
  49. {
  50. if( m_tree )
  51. {
  52. m_tree->FocusSearchFieldIfExists();
  53. }
  54. }
  55. FOOTPRINT_TREE_PANE::~FOOTPRINT_TREE_PANE()
  56. {
  57. m_frame->Unbind( wxEVT_MENU_OPEN, &FOOTPRINT_TREE_PANE::onMenuOpen, this );
  58. m_frame->Unbind( wxEVT_MENU_CLOSE, &FOOTPRINT_TREE_PANE::onMenuClose, this );
  59. m_tree->Unbind( wxEVT_UPDATE_UI, &FOOTPRINT_TREE_PANE::onUpdateUI, this );
  60. Unbind( EVT_LIBITEM_CHOSEN, &FOOTPRINT_TREE_PANE::onComponentSelected, this );
  61. m_tree->Destroy();
  62. }
  63. void FOOTPRINT_TREE_PANE::onMenuOpen( wxMenuEvent& aEvent )
  64. {
  65. m_tree->BlockPreview( true );
  66. aEvent.Skip();
  67. }
  68. void FOOTPRINT_TREE_PANE::onMenuClose( wxMenuEvent& aEvent )
  69. {
  70. m_tree->BlockPreview( false );
  71. aEvent.Skip();
  72. }
  73. void FOOTPRINT_TREE_PANE::onComponentSelected( wxCommandEvent& aEvent )
  74. {
  75. m_frame->LoadFootprintFromLibrary( GetLibTree()->GetSelectedLibId() );
  76. // Make sure current-part highlighting doesn't get lost in seleciton highlighting
  77. m_tree->Unselect();
  78. }
  79. void FOOTPRINT_TREE_PANE::onUpdateUI( wxUpdateUIEvent& aEvent )
  80. {
  81. if( m_frame->GetCanvas()->HasFocus() )
  82. {
  83. // Don't allow a selected item in the tree when the canvas has focus: it's too easy
  84. // to confuse the selected-highlighting with the being-edited-on-canvas-highlighting.
  85. m_tree->Unselect();
  86. }
  87. }