mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-21 00:21:25 +00:00
Fix copy-paste issue for grids with checkboxes
Handle boolean value parsing during paste operation. The boolean value was not being handled correctly in grid_tricks, which prevented the boolean value from being pasted into the target row Fixes https://gitlab.com/kicad/code/kicad/-/issues/18985
This commit is contained in:
parent
cd40c6bbbf
commit
07f96b83b7
common
eeschema/dialogs
include
pcbnew/dialogs
@ -810,6 +810,14 @@ void GRID_TRICKS::paste_text( const wxString& cb_text )
|
||||
{
|
||||
tbl->SetValue( row, col, cellTxt );
|
||||
|
||||
wxGridEvent evt( m_grid->GetId(), wxEVT_GRID_CELL_CHANGED, m_grid, row, col );
|
||||
m_grid->GetEventHandler()->ProcessEvent( evt );
|
||||
}
|
||||
// Allow paste to any cell that can accept a boolean value
|
||||
else if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_BOOL ) )
|
||||
{
|
||||
tbl->SetValueAsBool( row, col, cellTxt == wxT( "1" ) );
|
||||
|
||||
wxGridEvent evt( m_grid->GetId(), wxEVT_GRID_CELL_CHANGED, m_grid, row, col );
|
||||
m_grid->GetEventHandler()->ProcessEvent( evt );
|
||||
}
|
||||
|
@ -350,12 +350,14 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, P
|
||||
m_lastProjectLibDir = m_project->GetProjectPath();
|
||||
|
||||
|
||||
setupGrid( m_global_grid );
|
||||
setupGrid( m_global_grid );
|
||||
m_global_grid->Bind( wxEVT_GRID_CELL_LEFT_CLICK, &PANEL_SYM_LIB_TABLE::onGridCellLeftClickHandler, this );
|
||||
|
||||
if( m_projectTable )
|
||||
{
|
||||
m_project_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *m_projectTable ), true );
|
||||
setupGrid( m_project_grid );
|
||||
m_project_grid->Bind( wxEVT_GRID_CELL_LEFT_CLICK, &PANEL_SYM_LIB_TABLE::onGridCellLeftClickHandler, this );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -393,9 +395,13 @@ PANEL_SYM_LIB_TABLE::~PANEL_SYM_LIB_TABLE()
|
||||
// Delete the GRID_TRICKS.
|
||||
// Any additional event handlers should be popped before the window is deleted.
|
||||
m_global_grid->PopEventHandler( true );
|
||||
m_global_grid->Unbind( wxEVT_GRID_CELL_LEFT_CLICK, &PANEL_SYM_LIB_TABLE::onGridCellLeftClickHandler, this );
|
||||
|
||||
if( m_project_grid )
|
||||
{
|
||||
m_project_grid->PopEventHandler( true );
|
||||
m_project_grid->Unbind( wxEVT_GRID_CELL_LEFT_CLICK, &PANEL_SYM_LIB_TABLE::onGridCellLeftClickHandler, this );
|
||||
}
|
||||
|
||||
m_path_subs_grid->PopEventHandler( true );
|
||||
}
|
||||
@ -1130,6 +1136,33 @@ SYMBOL_LIB_TABLE_GRID* PANEL_SYM_LIB_TABLE::cur_model() const
|
||||
}
|
||||
|
||||
|
||||
void PANEL_SYM_LIB_TABLE::onGridCellLeftClickHandler( wxGridEvent& event )
|
||||
{
|
||||
// Get the grid object that triggered the event
|
||||
wxGrid* grid = dynamic_cast<wxGrid*>( event.GetEventObject() );
|
||||
|
||||
// If the event object is a wxGrid, proceed with the handling
|
||||
if( grid )
|
||||
{
|
||||
int row = event.GetRow();
|
||||
int col = event.GetCol();
|
||||
|
||||
// Get the cell renderer for the clicked cell
|
||||
wxGridCellRenderer* renderer = grid->GetCellRenderer( row, col );
|
||||
|
||||
// Check if the renderer is a wxGridCellBoolRenderer using dynamic_cast
|
||||
if( dynamic_cast<wxGridCellBoolRenderer*>( renderer ) )
|
||||
{
|
||||
// Set the grid cursor to the clicked boolean cell
|
||||
grid->SetGridCursor( row, col );
|
||||
}
|
||||
}
|
||||
|
||||
// Allow the default behavior to continue (toggle the bool)
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
|
||||
size_t PANEL_SYM_LIB_TABLE::m_pageNdx = 0;
|
||||
|
||||
|
||||
@ -1221,4 +1254,4 @@ void InvokeSchEditSymbolLibTable( KIWAY* aKiway, wxWindow *aParent )
|
||||
aKiway->ExpressMail( FRAME_SCH, MAIL_RELOAD_LIB, payload );
|
||||
aKiway->ExpressMail( FRAME_SCH_SYMBOL_EDITOR, MAIL_RELOAD_LIB, payload );
|
||||
aKiway->ExpressMail( FRAME_SCH_VIEWER, MAIL_RELOAD_LIB, payload );
|
||||
}
|
||||
}
|
@ -58,6 +58,7 @@ private:
|
||||
void onSizeGrid( wxSizeEvent& event ) override;
|
||||
void adjustPathSubsGridColumns( int aWidth );
|
||||
void onConvertLegacyLibraries( wxCommandEvent& event ) override;
|
||||
void onGridCellLeftClickHandler( wxGridEvent& event );
|
||||
|
||||
void onPageChange( wxBookCtrlEvent& event ) override;
|
||||
void onReset( wxCommandEvent& event ) override;
|
||||
|
@ -81,6 +81,23 @@ public:
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
bool CanGetValueAs( int aRow, int aCol, const wxString& aTypeName ) override
|
||||
{
|
||||
if( aRow < (int) size() )
|
||||
{
|
||||
LIB_TABLE_ROW* r = at( (size_t) aRow );
|
||||
|
||||
switch( aCol )
|
||||
{
|
||||
case COL_ENABLED:
|
||||
case COL_VISIBLE:
|
||||
return aTypeName == wxGRID_VALUE_BOOL;
|
||||
default:
|
||||
return aTypeName == wxGRID_VALUE_STRING;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GetValueAsBool( int aRow, int aCol ) override
|
||||
{
|
||||
if( aRow < (int) size() && aCol == COL_ENABLED )
|
||||
|
@ -397,7 +397,7 @@ PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, PRO
|
||||
m_projectBasePath( aProjectBasePath ),
|
||||
m_parent( aParent )
|
||||
{
|
||||
m_global_grid->SetTable( new FP_LIB_TABLE_GRID( *aGlobalTable ), true );
|
||||
m_global_grid->SetTable( new FP_LIB_TABLE_GRID( *aGlobalTable ), true );
|
||||
|
||||
// add Cut, Copy, and Paste to wxGrids
|
||||
m_path_subs_grid->PushEventHandler( new GRID_TRICKS( m_path_subs_grid ) );
|
||||
@ -415,7 +415,8 @@ PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, PRO
|
||||
|
||||
m_lastProjectLibDir = m_projectBasePath;
|
||||
|
||||
setupGrid( m_global_grid );
|
||||
setupGrid( m_global_grid );
|
||||
m_global_grid->Bind( wxEVT_GRID_CELL_LEFT_CLICK, &PANEL_FP_LIB_TABLE::onGridCellLeftClickHandler, this );
|
||||
|
||||
populateEnvironReadOnlyTable();
|
||||
|
||||
@ -518,12 +519,13 @@ PANEL_FP_LIB_TABLE::~PANEL_FP_LIB_TABLE()
|
||||
// Delete the GRID_TRICKS.
|
||||
// Any additional event handlers should be popped before the window is deleted.
|
||||
m_global_grid->PopEventHandler( true );
|
||||
m_global_grid->Unbind( wxEVT_GRID_CELL_LEFT_CLICK, &PANEL_FP_LIB_TABLE::onGridCellLeftClickHandler, this );
|
||||
|
||||
if( m_project_grid )
|
||||
{
|
||||
m_project_grid->PopEventHandler( true );
|
||||
m_project_grid->Unbind( wxEVT_GRID_CELL_LEFT_CLICK, &PANEL_FP_LIB_TABLE::onGridCellLeftClickHandler, this );
|
||||
}
|
||||
}
|
||||
|
||||
m_path_subs_grid->PopEventHandler( true );
|
||||
}
|
||||
@ -1231,21 +1233,25 @@ void PANEL_FP_LIB_TABLE::populateEnvironReadOnlyTable()
|
||||
|
||||
void PANEL_FP_LIB_TABLE::onGridCellLeftClickHandler( wxGridEvent& event )
|
||||
{
|
||||
int row = event.GetRow();
|
||||
int col = event.GetCol();
|
||||
// Get the grid object that triggered the event
|
||||
wxGrid* grid = dynamic_cast<wxGrid*>( event.GetEventObject() );
|
||||
|
||||
if( m_project_grid )
|
||||
// If the event object is a wxGrid, proceed with the handling
|
||||
if( grid )
|
||||
{
|
||||
int row = event.GetRow();
|
||||
int col = event.GetCol();
|
||||
|
||||
// Get the cell renderer for the clicked cell
|
||||
wxGridCellRenderer* renderer = m_project_grid->GetCellRenderer( row, col );
|
||||
wxGridCellRenderer* renderer = grid->GetCellRenderer( row, col );
|
||||
|
||||
// Check if the renderer is a wxGridCellBoolRenderer using dynamic_cast
|
||||
if( dynamic_cast<wxGridCellBoolRenderer*>( renderer ) )
|
||||
{
|
||||
// Set the grid cursor to the clicked boolean cell
|
||||
m_project_grid->SetGridCursor( row, col );
|
||||
grid->SetGridCursor( row, col );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Allow the default behavior to continue (toggle the bool)
|
||||
event.Skip();
|
||||
|
Loading…
Reference in New Issue
Block a user