Grid tricks: paste to selection.
NEW: By default a clipboard is pasted to a grid starting from the cursor position and doesn't matter is a selection of cells present or not. Often a grid represents the data of a few similar objects like components, for example. Some number of cells (fields) may have the same value for a few rows (components). In this case, when filling data we must copy the range of identical cells from the first row of similar components and then paste it to every row of the rest components (by default). From now it may be done easier. We must copy the range of identical cells from first row of similar components (here is no changes) and then select rectangular range of cells (for multiple rows) where must be placed copied data. After pasting copied cells will be pasted to every selected row. So in general, we can copy cells from one row and paste it to multiple rows at a time. This new feature also makes possible to copy value from one cell and to paste it to all from the selection. If copied range of cells is larger than the selection then only the part of clipboard that matches the selection will be pasted.
This commit is contained in:
parent
65f5bd6a01
commit
3526c9a37a
|
@ -388,6 +388,11 @@ void GRID_TRICKS::paste_text( const wxString& cb_text )
|
||||||
|
|
||||||
const int cur_row = m_grid->GetGridCursorRow();
|
const int cur_row = m_grid->GetGridCursorRow();
|
||||||
const int cur_col = m_grid->GetGridCursorCol();
|
const int cur_col = m_grid->GetGridCursorCol();
|
||||||
|
int start_row;
|
||||||
|
int end_row;
|
||||||
|
int start_col;
|
||||||
|
int end_col;
|
||||||
|
bool is_selection = false;
|
||||||
|
|
||||||
if( cur_row < 0 || cur_col < 0 )
|
if( cur_row < 0 || cur_col < 0 )
|
||||||
{
|
{
|
||||||
|
@ -395,23 +400,66 @@ void GRID_TRICKS::paste_text( const wxString& cb_text )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
|
||||||
|
{
|
||||||
|
if( m_sel_row_count > 1 )
|
||||||
|
is_selection = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( m_grid->IsSelection() )
|
||||||
|
is_selection = true;
|
||||||
|
}
|
||||||
|
|
||||||
wxStringTokenizer rows( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
|
wxStringTokenizer rows( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
|
||||||
|
|
||||||
for( int row = cur_row; rows.HasMoreTokens(); ++row )
|
// If selection of cells is present
|
||||||
|
// then a clipboard pastes to selected cells only.
|
||||||
|
if( is_selection )
|
||||||
{
|
{
|
||||||
// If table can't be expanded just paste the part of clipboard
|
start_row = m_sel_row_start;
|
||||||
// that may be placed.
|
end_row = m_sel_row_start + m_sel_row_count;
|
||||||
if( row >= tbl->GetNumberRows() )
|
start_col = m_sel_col_start;
|
||||||
break;
|
end_col = m_sel_col_start + m_sel_col_count;
|
||||||
|
}
|
||||||
|
// Otherwise, paste whole clipboard
|
||||||
|
// starting from cell with cursor.
|
||||||
|
else
|
||||||
|
{
|
||||||
|
start_row = cur_row;
|
||||||
|
end_row = cur_row + rows.CountTokens();
|
||||||
|
if( end_row > tbl->GetNumberRows() )
|
||||||
|
end_row = tbl->GetNumberRows();
|
||||||
|
start_col = cur_col;
|
||||||
|
// end_col calculates later
|
||||||
|
}
|
||||||
|
|
||||||
|
for( int row = start_row; row < end_row; ++row )
|
||||||
|
{
|
||||||
|
// If number of selected rows bigger than count of rows in
|
||||||
|
// the clipboard, paste from the clipboard again and again
|
||||||
|
// while end of the selection is reached.
|
||||||
|
if( !rows.HasMoreTokens() )
|
||||||
|
rows.SetString( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
|
||||||
|
|
||||||
wxString rowTxt = rows.GetNextToken();
|
wxString rowTxt = rows.GetNextToken();
|
||||||
|
|
||||||
wxStringTokenizer cols( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
|
wxStringTokenizer cols( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
|
||||||
|
|
||||||
for( int col = cur_col; cols.HasMoreTokens(); ++col )
|
if( !is_selection )
|
||||||
{
|
{
|
||||||
if( col >= tbl->GetNumberCols() )
|
end_col = cur_col + cols.CountTokens();
|
||||||
break;
|
if( end_col > tbl->GetNumberCols() )
|
||||||
|
end_col = tbl->GetNumberCols();
|
||||||
|
}
|
||||||
|
|
||||||
|
for( int col = start_col; col < end_col; ++col )
|
||||||
|
{
|
||||||
|
// If number of selected columns bigger than count of columns in
|
||||||
|
// the clipboard, paste from the clipboard again and again while
|
||||||
|
// end of the selection is reached.
|
||||||
|
if( !cols.HasMoreTokens() )
|
||||||
|
cols.SetString( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
|
||||||
|
|
||||||
wxString cellTxt = cols.GetNextToken();
|
wxString cellTxt = cols.GetNextToken();
|
||||||
tbl->SetValue( row, col, cellTxt );
|
tbl->SetValue( row, col, cellTxt );
|
||||||
|
|
Loading…
Reference in New Issue