From 69b350c9b0d76a8c95e484a58381433ffd44fad0 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 14 Mar 2017 20:31:44 +0100 Subject: [PATCH] Fix can't always group delete in fp-lib-table dialog Fixes: lp:1672760 https://bugs.launchpad.net/kicad/+bug/1672760 --- pcbnew/dialogs/dialog_fp_lib_table.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/pcbnew/dialogs/dialog_fp_lib_table.cpp b/pcbnew/dialogs/dialog_fp_lib_table.cpp index 730716ba15..b41c4fdf7f 100644 --- a/pcbnew/dialogs/dialog_fp_lib_table.cpp +++ b/pcbnew/dialogs/dialog_fp_lib_table.cpp @@ -536,17 +536,36 @@ private: void deleteRowHandler( wxCommandEvent& event ) override { int currRow = getCursorRow(); - wxArrayInt selectedRows = m_cur_grid->GetSelectedRows(); + // In a wxGrid, collect rows that have a selected cell, or are selected + // is not so easy: it depend on the way the selection was made. + // Here, we collect row selected by clicking on a row label, and + // row that contain a cell previously selected. + // If no candidate, just delete the row with the grid cursor. + wxArrayInt selectedRows = m_cur_grid->GetSelectedRows(); + wxGridCellCoordsArray cells = m_cur_grid->GetSelectedCells(); + + // Add all row having cell selected to list: + for( unsigned ii = 0; ii < cells.GetCount(); ii++ ) + selectedRows.Add( cells[ii].GetRow() ); + + // Use the row having the grid cursor only if we have no candidate: if( selectedRows.size() == 0 && getCursorRow() >= 0 ) selectedRows.Add( getCursorRow() ); std::sort( selectedRows.begin(), selectedRows.end() ); + // Remove selected rows (note: a row can be stored more than once in list) + int last_row = -1; for( int ii = selectedRows.GetCount()-1; ii >= 0; ii-- ) { int row = selectedRows[ii]; - m_cur_grid->DeleteRows( row, 1 ); + + if( row != last_row ) + { + last_row = row; + m_cur_grid->DeleteRows( row, 1 ); + } } if( currRow >= m_cur_grid->GetNumberRows() )