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.

149 lines
4.7 KiB

  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 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 ) :
  22. GRID_TRICKS( aGrid )
  23. {
  24. }
  25. void LIB_TABLE_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
  26. {
  27. menu.Append( LIB_TABLE_GRID_TRICKS_OPTIONS_EDITOR,
  28. _( "Edit options..." ),
  29. _( "Edit options for this library entry" ) );
  30. menu.AppendSeparator();
  31. bool showActivate = false;
  32. bool showDeactivate = false;
  33. bool showSetVisible = false;
  34. bool showUnsetVisible = false;
  35. LIB_TABLE_GRID* tbl = static_cast<LIB_TABLE_GRID*>( m_grid->GetTable() );
  36. // Ensure selection parameters are up to date
  37. getSelectedArea();
  38. for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
  39. {
  40. if( tbl->GetValueAsBool( row, 0 ) )
  41. showDeactivate = true;
  42. else
  43. showActivate = true;
  44. if( tbl->GetValueAsBool( row, 1 ) )
  45. showUnsetVisible = true;
  46. else
  47. showSetVisible = true;
  48. if( showActivate && showDeactivate && showSetVisible && showUnsetVisible )
  49. break;
  50. }
  51. if( showActivate )
  52. menu.Append( LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED, _( "Activate selected" ) );
  53. if( showDeactivate )
  54. menu.Append( LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED, _( "Deactivate selected" ) );
  55. if( supportsVisibilityColumn() )
  56. {
  57. if( showSetVisible )
  58. menu.Append( LIB_TABLE_GRID_TRICKS_SET_VISIBLE, _( "Set visible flag" ) );
  59. if( showUnsetVisible )
  60. menu.Append( LIB_TABLE_GRID_TRICKS_UNSET_VISIBLE, _( "Unset visible flag" ) );
  61. }
  62. bool showSettings = false;
  63. if( m_sel_row_count == 1 && tbl->At( m_sel_row_start )->SupportsSettingsDialog() )
  64. {
  65. showSettings = true;
  66. menu.Append( LIB_TABLE_GRID_TRICKS_LIBRARY_SETTINGS,
  67. wxString::Format( _( "Library settings for %s..." ),
  68. tbl->GetValue( m_sel_row_start, 2 ) ) );
  69. }
  70. if( showActivate || showDeactivate || showSetVisible || showUnsetVisible || showSettings )
  71. menu.AppendSeparator();
  72. GRID_TRICKS::showPopupMenu( menu, aEvent );
  73. }
  74. void LIB_TABLE_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
  75. {
  76. int menu_id = event.GetId();
  77. LIB_TABLE_GRID* tbl = (LIB_TABLE_GRID*) m_grid->GetTable();
  78. if( menu_id == LIB_TABLE_GRID_TRICKS_OPTIONS_EDITOR )
  79. {
  80. optionsEditor( m_grid->GetGridCursorRow() );
  81. }
  82. else if( menu_id == LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED
  83. || menu_id == LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED )
  84. {
  85. bool selected_state = menu_id == LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED;
  86. for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
  87. tbl->SetValueAsBool( row, 0, selected_state );
  88. // Ensure the new state (on/off) of the widgets is immediately shown:
  89. m_grid->Refresh();
  90. }
  91. else if( menu_id == LIB_TABLE_GRID_TRICKS_SET_VISIBLE
  92. || menu_id == LIB_TABLE_GRID_TRICKS_UNSET_VISIBLE )
  93. {
  94. bool selected_state = menu_id == LIB_TABLE_GRID_TRICKS_SET_VISIBLE;
  95. for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
  96. tbl->SetValueAsBool( row, 1, selected_state );
  97. // Ensure the new state (on/off) of the widgets is immediately shown:
  98. m_grid->Refresh();
  99. }
  100. else if( menu_id == LIB_TABLE_GRID_TRICKS_LIBRARY_SETTINGS )
  101. {
  102. LIB_TABLE_ROW* row = tbl->At( m_sel_row_start );
  103. row->Refresh();
  104. row->ShowSettingsDialog( m_grid->GetParent() );
  105. }
  106. else
  107. {
  108. GRID_TRICKS::doPopupSelection( event );
  109. }
  110. }
  111. bool LIB_TABLE_GRID_TRICKS::handleDoubleClick( wxGridEvent& aEvent )
  112. {
  113. if( aEvent.GetCol() == COL_OPTIONS )
  114. {
  115. optionsEditor( aEvent.GetRow() );
  116. return true;
  117. }
  118. return false;
  119. }