diff --git a/common/grid_tricks.cpp b/common/grid_tricks.cpp index 4037c27730..f902f2d34a 100644 --- a/common/grid_tricks.cpp +++ b/common/grid_tricks.cpp @@ -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' ) diff --git a/include/grid_tricks.h b/include/grid_tricks.h index 8ff9efb7b3..ebe8d0c658 100644 --- a/include/grid_tricks.h +++ b/include/grid_tricks.h @@ -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 );