Promote to cell selection for spreadsheet-style paste.

Fixes https://gitlab.com/kicad/code/kicad/issues/9211

(cherry picked from commit 9de62d1dd4)
This commit is contained in:
Jeff Young 2021-10-23 15:48:12 +01:00
parent fecb625459
commit 2e324aa845
2 changed files with 34 additions and 1 deletions

View File

@ -57,6 +57,7 @@ GRID_TRICKS::GRID_TRICKS( WX_GRID* aGrid ):
wxGridEventHandler( GRID_TRICKS::onGridLabelLeftClick ), nullptr, this );
aGrid->Connect( GRIDTRICKS_FIRST_ID, GRIDTRICKS_LAST_ID, wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler( GRID_TRICKS::onPopupSelection ), nullptr, this );
aGrid->Connect( wxEVT_CHAR_HOOK, wxCharEventHandler( GRID_TRICKS::onCharHook ), nullptr, this );
aGrid->Connect( wxEVT_KEY_DOWN, wxKeyEventHandler( GRID_TRICKS::onKeyDown ), nullptr, this );
aGrid->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( GRID_TRICKS::onUpdateUI ),
nullptr, this );
@ -361,6 +362,37 @@ void GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
}
void GRID_TRICKS::onCharHook( wxKeyEvent& ev )
{
bool handled = false;
if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'V' )
{
if( m_grid->IsCellEditControlShown() && wxTheClipboard->Open() )
{
if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
{
wxTextDataObject data;
wxTheClipboard->GetData( data );
if( data.GetText().Contains( COL_SEP ) || data.GetText().Contains( ROW_SEP ) )
{
m_grid->CommitPendingChanges( true /* quiet mode */ );
paste_text( data.GetText() );
handled = true;
}
}
wxTheClipboard->Close();
m_grid->ForceRefresh();
}
}
if( !handled )
ev.Skip( true );
}
void GRID_TRICKS::onKeyDown( wxKeyEvent& ev )
{
if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'A' )

View File

@ -91,7 +91,8 @@ protected:
void onGridLabelLeftClick( wxGridEvent& event );
void onGridLabelRightClick( wxGridEvent& event );
void onPopupSelection( wxCommandEvent& event );
void onKeyDown( wxKeyEvent& ev );
void onKeyDown( wxKeyEvent& event );
void onCharHook( wxKeyEvent& event );
void onUpdateUI( wxUpdateUIEvent& event );
void onGridMotion( wxMouseEvent& event );