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.

97 lines
3.2 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "lib_table_grid_tricks.h"
  20. #include "lib_table_grid.h"
  21. LIB_TABLE_GRID_TRICKS::LIB_TABLE_GRID_TRICKS( WX_GRID* aGrid ) : GRID_TRICKS( aGrid )
  22. {
  23. }
  24. void LIB_TABLE_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
  25. {
  26. bool showActivate = false;
  27. bool showDeactivate = false;
  28. LIB_TABLE_GRID* tbl = static_cast<LIB_TABLE_GRID*>( m_grid->GetTable() );
  29. // Ensure selection parameters are up to date
  30. getSelectedArea();
  31. for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
  32. {
  33. if( tbl->GetValueAsBool( row, 0 ) )
  34. showDeactivate = true;
  35. else
  36. showActivate = true;
  37. if( showActivate && showDeactivate )
  38. break;
  39. }
  40. if( showActivate )
  41. menu.Append( LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED, _( "Activate selected" ) );
  42. if( showDeactivate )
  43. menu.Append( LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED, _( "Deactivate selected" ) );
  44. bool showSettings = false;
  45. if( m_sel_row_count == 1 && tbl->At( m_sel_row_start )->SupportsSettingsDialog() )
  46. {
  47. showSettings = true;
  48. menu.Append( LIB_TABLE_GRID_TRICKS_LIBRARY_SETTINGS,
  49. wxString::Format( _( "Library settings for %s..." ),
  50. tbl->GetValue( m_sel_row_start, 2 ) ) );
  51. }
  52. if( showActivate || showDeactivate || showSettings )
  53. menu.AppendSeparator();
  54. GRID_TRICKS::showPopupMenu( menu, aEvent );
  55. }
  56. void LIB_TABLE_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
  57. {
  58. int menu_id = event.GetId();
  59. LIB_TABLE_GRID* tbl = (LIB_TABLE_GRID*) m_grid->GetTable();
  60. if( menu_id == LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED
  61. || menu_id == LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED )
  62. {
  63. bool selected_state = menu_id == LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED;
  64. for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
  65. tbl->SetValueAsBool( row, 0, selected_state );
  66. // Ensure the new state (on/off) of the widgets is immediately shown:
  67. m_grid->Refresh();
  68. }
  69. else if( menu_id == LIB_TABLE_GRID_TRICKS_LIBRARY_SETTINGS )
  70. {
  71. LIB_TABLE_ROW* row = tbl->At( m_sel_row_start );
  72. row->Refresh();
  73. row->ShowSettingsDialog( m_grid->GetParent() );
  74. }
  75. else
  76. {
  77. GRID_TRICKS::doPopupSelection( event );
  78. }
  79. }