Work around wxGrid boolean editor issues
Fixes: lp:1667240 * https://bugs.launchpad.net/kicad/+bug/1667240
This commit is contained in:
parent
71d8a1ea1e
commit
2f86b497d9
|
@ -85,6 +85,8 @@ BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME )
|
|||
EVT_LISTBOX( ID_FOOTPRINT_WIZARD_PAGE_LIST, FOOTPRINT_WIZARD_FRAME::ClickOnPageList )
|
||||
EVT_GRID_CMD_CELL_CHANGED( ID_FOOTPRINT_WIZARD_PARAMETER_LIST,
|
||||
FOOTPRINT_WIZARD_FRAME::ParametersUpdated )
|
||||
EVT_GRID_CMD_CELL_LEFT_CLICK( ID_FOOTPRINT_WIZARD_PARAMETER_LIST,
|
||||
FOOTPRINT_WIZARD_FRAME::OnParameterCellClick )
|
||||
|
||||
EVT_MENU( ID_SET_RELATIVE_OFFSET, FOOTPRINT_WIZARD_FRAME::OnSetRelativeOffset )
|
||||
END_EVENT_TABLE()
|
||||
|
@ -306,7 +308,12 @@ void FOOTPRINT_WIZARD_FRAME::initParameterGrid()
|
|||
m_parameterGrid->DisableDragGridSize();
|
||||
m_parameterGrid->DisableDragColSize();
|
||||
|
||||
m_parameterGrid->Connect( wxEVT_SIZE, wxSizeEventHandler(FOOTPRINT_WIZARD_FRAME::OnGridSize), NULL, this );
|
||||
m_parameterGrid->Connect( wxEVT_SIZE,
|
||||
wxSizeEventHandler( FOOTPRINT_WIZARD_FRAME::OnGridSize ),
|
||||
NULL, this );
|
||||
m_parameterGrid->Connect( wxEVT_KEY_UP,
|
||||
wxKeyEventHandler( FOOTPRINT_WIZARD_FRAME::OnParameterGridKeyPress ),
|
||||
NULL, this );
|
||||
}
|
||||
|
||||
|
||||
|
@ -389,9 +396,10 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
|
|||
// Boolean parameters are displayed using a checkbox
|
||||
if( units == WIZARD_PARAM_UNITS_BOOL )
|
||||
{
|
||||
wxGridCellBoolEditor *boolEditor = new wxGridCellBoolEditor;
|
||||
boolEditor->UseStringValues( "1", "0" );
|
||||
m_parameterGrid->SetCellEditor( i, WIZ_COL_VALUE, boolEditor );
|
||||
// NOTE: Not using wxGridCellBoolEditor because it doesn't work well
|
||||
// Setting read-only to disable the grid editor; value will be
|
||||
// updated by the OnParameterCellClick event handler.
|
||||
m_parameterGrid->SetReadOnly( i, WIZ_COL_VALUE );
|
||||
m_parameterGrid->SetCellRenderer( i, WIZ_COL_VALUE, new wxGridCellBoolRenderer );
|
||||
}
|
||||
// Parameters that can be selected from a list of multiple options
|
||||
|
|
|
@ -195,6 +195,10 @@ private:
|
|||
*/
|
||||
void ParametersUpdated( wxGridEvent& event );
|
||||
|
||||
void OnParameterCellClick( wxGridEvent& event );
|
||||
|
||||
void OnParameterGridKeyPress( wxKeyEvent& event );
|
||||
|
||||
bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) override;
|
||||
|
||||
/**
|
||||
|
|
|
@ -288,6 +288,93 @@ void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
|
|||
}
|
||||
|
||||
|
||||
void FOOTPRINT_WIZARD_FRAME::OnParameterCellClick( wxGridEvent& event )
|
||||
{
|
||||
auto footprintWizard = GetMyWizard();
|
||||
|
||||
if( !footprintWizard )
|
||||
return;
|
||||
|
||||
if( m_parameterGridPage < 0 )
|
||||
return;
|
||||
|
||||
if( event.GetCol() != WIZ_COL_VALUE )
|
||||
return;
|
||||
|
||||
auto types = footprintWizard->GetParameterTypes( m_parameterGridPage );
|
||||
auto values = footprintWizard->GetParameterValues( m_parameterGridPage );
|
||||
|
||||
int row = event.GetRow();
|
||||
bool has_changed = false;
|
||||
|
||||
// Handle toggling of boolean parameters
|
||||
if( types[row] == WIZARD_PARAM_UNITS_BOOL )
|
||||
{
|
||||
has_changed = true;
|
||||
values[row] = ( values[row] == "1" ) ? "0" : "1";
|
||||
m_parameterGrid->SetCellValue( row, WIZ_COL_VALUE, values[row] );
|
||||
}
|
||||
else
|
||||
{
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
if( has_changed )
|
||||
{
|
||||
wxString res = footprintWizard->SetParameterValues( m_parameterGridPage, values );
|
||||
|
||||
if( !res.IsEmpty() )
|
||||
wxMessageBox( res );
|
||||
|
||||
ReloadFootprint();
|
||||
DisplayWizardInfos();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FOOTPRINT_WIZARD_FRAME::OnParameterGridKeyPress( wxKeyEvent& event )
|
||||
{
|
||||
auto footprintWizard = GetMyWizard();
|
||||
int row = m_parameterGrid->GetGridCursorRow();
|
||||
int col = m_parameterGrid->GetGridCursorCol();
|
||||
bool has_changed = false;
|
||||
|
||||
|
||||
if( !footprintWizard || m_parameterGridPage < 0 ||
|
||||
col != WIZ_COL_VALUE || event.GetKeyCode() != ' ' )
|
||||
{
|
||||
event.Skip();
|
||||
return;
|
||||
}
|
||||
|
||||
auto types = footprintWizard->GetParameterTypes( m_parameterGridPage );
|
||||
auto values = footprintWizard->GetParameterValues( m_parameterGridPage );
|
||||
|
||||
// Handle toggling of boolean parameters when user presses space
|
||||
if( types[row] == WIZARD_PARAM_UNITS_BOOL )
|
||||
{
|
||||
has_changed = true;
|
||||
values[row] = ( values[row] == "1" ) ? "0" : "1";
|
||||
m_parameterGrid->SetCellValue( row, WIZ_COL_VALUE, values[row] );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_parameterGrid->EnableCellEditControl();
|
||||
}
|
||||
|
||||
if( has_changed )
|
||||
{
|
||||
wxString res = footprintWizard->SetParameterValues( m_parameterGridPage, values );
|
||||
|
||||
if( !res.IsEmpty() )
|
||||
wxMessageBox( res );
|
||||
|
||||
ReloadFootprint();
|
||||
DisplayWizardInfos();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function RedrawActiveWindow
|
||||
* Display the current selected component.
|
||||
|
|
Loading…
Reference in New Issue