2022-06-08 21:05:47 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-04-12 06:12:22 +00:00
|
|
|
* Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2022-06-08 21:05:47 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lib_table_grid_tricks.h"
|
|
|
|
#include "lib_table_grid.h"
|
|
|
|
|
2023-05-28 19:10:07 +00:00
|
|
|
|
2022-06-08 21:05:47 +00:00
|
|
|
LIB_TABLE_GRID_TRICKS::LIB_TABLE_GRID_TRICKS( WX_GRID* aGrid ) : GRID_TRICKS( aGrid )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-04-12 06:12:22 +00:00
|
|
|
|
2023-02-05 20:47:27 +00:00
|
|
|
void LIB_TABLE_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
|
2022-06-08 21:05:47 +00:00
|
|
|
{
|
2023-05-28 20:09:20 +00:00
|
|
|
menu.Append( LIB_TABLE_GRID_TRICKS_OPTIONS_EDITOR,
|
|
|
|
_( "Edit options..." ),
|
|
|
|
_( "Edit options for this library entry" ) );
|
|
|
|
|
|
|
|
menu.AppendSeparator();
|
2023-05-28 19:10:07 +00:00
|
|
|
|
2022-06-08 21:05:47 +00:00
|
|
|
bool showActivate = false;
|
|
|
|
bool showDeactivate = false;
|
2023-09-25 23:31:08 +00:00
|
|
|
bool showSetVisible = false;
|
|
|
|
bool showUnsetVisible = false;
|
2022-06-08 21:05:47 +00:00
|
|
|
LIB_TABLE_GRID* tbl = static_cast<LIB_TABLE_GRID*>( m_grid->GetTable() );
|
|
|
|
|
2023-04-12 06:12:22 +00:00
|
|
|
// Ensure selection parameters are up to date
|
|
|
|
getSelectedArea();
|
|
|
|
|
2022-06-08 21:05:47 +00:00
|
|
|
for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
|
|
|
|
{
|
|
|
|
if( tbl->GetValueAsBool( row, 0 ) )
|
|
|
|
showDeactivate = true;
|
|
|
|
else
|
|
|
|
showActivate = true;
|
|
|
|
|
2023-09-25 23:31:08 +00:00
|
|
|
if( tbl->GetValueAsBool( row, 1 ) )
|
|
|
|
showUnsetVisible = true;
|
|
|
|
else
|
|
|
|
showSetVisible = true;
|
|
|
|
|
|
|
|
if( showActivate && showDeactivate && showSetVisible && showUnsetVisible )
|
2022-06-08 21:05:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( showActivate )
|
|
|
|
menu.Append( LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED, _( "Activate selected" ) );
|
2023-02-05 20:47:27 +00:00
|
|
|
|
2022-06-08 21:05:47 +00:00
|
|
|
if( showDeactivate )
|
|
|
|
menu.Append( LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED, _( "Deactivate selected" ) );
|
2023-02-05 20:47:27 +00:00
|
|
|
|
2023-09-25 23:31:08 +00:00
|
|
|
if( showSetVisible )
|
|
|
|
menu.Append( LIB_TABLE_GRID_TRICKS_SET_VISIBLE, _( "Set visible flag" ) );
|
|
|
|
|
|
|
|
if( showUnsetVisible )
|
|
|
|
menu.Append( LIB_TABLE_GRID_TRICKS_UNSET_VISIBLE, _( "Unset visible flag" ) );
|
|
|
|
|
2023-02-26 23:39:31 +00:00
|
|
|
bool showSettings = false;
|
|
|
|
|
|
|
|
if( m_sel_row_count == 1 && tbl->At( m_sel_row_start )->SupportsSettingsDialog() )
|
|
|
|
{
|
|
|
|
showSettings = true;
|
|
|
|
menu.Append( LIB_TABLE_GRID_TRICKS_LIBRARY_SETTINGS,
|
|
|
|
wxString::Format( _( "Library settings for %s..." ),
|
|
|
|
tbl->GetValue( m_sel_row_start, 2 ) ) );
|
|
|
|
}
|
|
|
|
|
2023-09-25 23:31:08 +00:00
|
|
|
if( showActivate || showDeactivate || showSetVisible || showUnsetVisible || showSettings )
|
2023-04-12 06:12:22 +00:00
|
|
|
menu.AppendSeparator();
|
|
|
|
|
2023-02-05 20:47:27 +00:00
|
|
|
GRID_TRICKS::showPopupMenu( menu, aEvent );
|
2022-06-08 21:05:47 +00:00
|
|
|
}
|
|
|
|
|
2023-04-12 06:12:22 +00:00
|
|
|
|
2022-06-08 21:05:47 +00:00
|
|
|
void LIB_TABLE_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
int menu_id = event.GetId();
|
2023-02-26 23:39:31 +00:00
|
|
|
LIB_TABLE_GRID* tbl = (LIB_TABLE_GRID*) m_grid->GetTable();
|
2023-02-05 20:47:27 +00:00
|
|
|
|
2023-05-28 19:10:07 +00:00
|
|
|
if( menu_id == LIB_TABLE_GRID_TRICKS_OPTIONS_EDITOR )
|
|
|
|
{
|
|
|
|
optionsEditor( m_grid->GetGridCursorRow() );
|
|
|
|
}
|
|
|
|
else if( menu_id == LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED
|
|
|
|
|| menu_id == LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED )
|
2022-06-08 21:05:47 +00:00
|
|
|
{
|
2023-04-11 16:38:03 +00:00
|
|
|
bool selected_state = menu_id == LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED;
|
|
|
|
|
2022-06-08 21:05:47 +00:00
|
|
|
for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
|
2023-04-11 16:38:03 +00:00
|
|
|
tbl->SetValueAsBool( row, 0, selected_state );
|
|
|
|
|
|
|
|
// Ensure the new state (on/off) of the widgets is immediately shown:
|
|
|
|
m_grid->Refresh();
|
2022-06-08 21:05:47 +00:00
|
|
|
}
|
2023-09-25 23:31:08 +00:00
|
|
|
else if( menu_id == LIB_TABLE_GRID_TRICKS_SET_VISIBLE
|
|
|
|
|| menu_id == LIB_TABLE_GRID_TRICKS_UNSET_VISIBLE )
|
|
|
|
{
|
|
|
|
bool selected_state = menu_id == LIB_TABLE_GRID_TRICKS_SET_VISIBLE;
|
|
|
|
|
|
|
|
for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
|
|
|
|
tbl->SetValueAsBool( row, 1, selected_state );
|
|
|
|
|
|
|
|
// Ensure the new state (on/off) of the widgets is immediately shown:
|
|
|
|
m_grid->Refresh();
|
|
|
|
}
|
2023-02-26 23:39:31 +00:00
|
|
|
else if( menu_id == LIB_TABLE_GRID_TRICKS_LIBRARY_SETTINGS )
|
|
|
|
{
|
|
|
|
LIB_TABLE_ROW* row = tbl->At( m_sel_row_start );
|
|
|
|
row->Refresh();
|
|
|
|
row->ShowSettingsDialog( m_grid->GetParent() );
|
|
|
|
}
|
2022-06-08 21:05:47 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
GRID_TRICKS::doPopupSelection( event );
|
|
|
|
}
|
|
|
|
}
|
2023-05-28 19:10:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool LIB_TABLE_GRID_TRICKS::handleDoubleClick( wxGridEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( aEvent.GetCol() == COL_OPTIONS )
|
|
|
|
{
|
|
|
|
optionsEditor( aEvent.GetRow() );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|