From e9da02e2d56e028f9e2f26e5ebd548e1f7aaa6d7 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 14 Jul 2020 13:28:55 +0100 Subject: [PATCH] Only reserve hotkeys for focused textCtrls that are editabled. Otherwise just send Ctrl-C to the disabled control, and everything else to the tool framework. Fixes https://gitlab.com/kicad/code/kicad/issues/4801 --- common/grid_tricks.cpp | 8 ++++---- common/scintilla_tricks.cpp | 25 ++++++------------------- common/textentry_tricks.cpp | 19 +++---------------- common/tool/tool_dispatcher.cpp | 25 ++++++++++++++++++++++--- include/grid_tricks.h | 5 ----- include/scintilla_tricks.h | 3 --- 6 files changed, 35 insertions(+), 50 deletions(-) diff --git a/common/grid_tricks.cpp b/common/grid_tricks.cpp index eb5609b2b9..d6036a25c7 100644 --- a/common/grid_tricks.cpp +++ b/common/grid_tricks.cpp @@ -311,24 +311,24 @@ void GRID_TRICKS::doPopupSelection( wxCommandEvent& event ) void GRID_TRICKS::onKeyDown( wxKeyEvent& ev ) { - if( isCtl( 'A', ev ) ) + if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'A' ) { m_grid->SelectAll(); return; } - else if( isCtl( 'C', ev ) ) + else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'C' ) { getSelectedArea(); cutcopy( false ); return; } - else if( isCtl( 'V', ev ) ) + else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'V' ) { getSelectedArea(); paste_clipboard(); return; } - else if( isCtl( 'X', ev ) ) + else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'X' ) { getSelectedArea(); cutcopy( true ); diff --git a/common/scintilla_tricks.cpp b/common/scintilla_tricks.cpp index 53bfa012c3..5add388213 100644 --- a/common/scintilla_tricks.cpp +++ b/common/scintilla_tricks.cpp @@ -63,20 +63,6 @@ SCINTILLA_TRICKS::SCINTILLA_TRICKS( wxStyledTextCtrl* aScintilla, const wxString } -bool SCINTILLA_TRICKS::isCtrl( int aChar, const wxKeyEvent& e ) -{ - return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() && - !e.ShiftDown() && !e.MetaDown(); -} - - -bool SCINTILLA_TRICKS::isShiftCtrl( int aChar, const wxKeyEvent& e ) -{ - return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() && - e.ShiftDown() && !e.MetaDown(); -} - - void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent ) { if( aEvent.GetKeyCode() == WXK_TAB ) @@ -101,23 +87,24 @@ void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent ) m_te->Tab(); } } - else if( isCtrl( 'Z', aEvent ) ) + else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'Z' ) { m_te->Undo(); } - else if( isShiftCtrl( 'Z', aEvent ) || isCtrl( 'Y', aEvent ) ) + else if( ( aEvent.GetModifiers() == wxMOD_SHIFT+wxMOD_CONTROL && aEvent.GetKeyCode() == 'Z' ) + || ( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'Y' ) ) { m_te->Redo(); } - else if( isCtrl( 'X', aEvent ) ) + else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'X' ) { m_te->Cut(); } - else if( isCtrl( 'C', aEvent ) ) + else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'C' ) { m_te->Copy(); } - else if( isCtrl( 'V', aEvent ) ) + else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'V' ) { m_te->Paste(); } diff --git a/common/textentry_tricks.cpp b/common/textentry_tricks.cpp index 4acd3cb1f5..3d089c86bb 100644 --- a/common/textentry_tricks.cpp +++ b/common/textentry_tricks.cpp @@ -26,31 +26,18 @@ #include #include -bool TEXTENTRY_TRICKS::isCtrl( int aChar, const wxKeyEvent& e ) -{ - return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() && - !e.ShiftDown() && !e.MetaDown(); -} - - -bool TEXTENTRY_TRICKS::isShiftCtrl( int aChar, const wxKeyEvent& e ) -{ - return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() && - e.ShiftDown() && !e.MetaDown(); -} - void TEXTENTRY_TRICKS::OnCharHook( wxTextEntry* aTextEntry, wxKeyEvent& aEvent ) { - if( isCtrl( 'X', aEvent ) ) + if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'X' ) { aTextEntry->Cut(); } - else if( isCtrl( 'C', aEvent ) ) + else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'C' ) { aTextEntry->Copy(); } - else if( isCtrl( 'V', aEvent ) ) + else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'V' ) { aTextEntry->Paste(); } diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 93056de393..d5b166dab1 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -485,11 +485,30 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) keyIsEscape = ( ke->GetKeyCode() == WXK_ESCAPE ); - if( dynamic_cast( focus ) || dynamic_cast( focus ) ) + wxTextEntry* textEntry = dynamic_cast( focus ); + wxStyledTextCtrl* styledText = dynamic_cast( focus ); + + if( textEntry || styledText ) { + bool enabled = true; + + if( textEntry ) + enabled = textEntry->IsEditable(); + else if( styledText ) + enabled = styledText->IsEditable(); + // Never process key events for tools when a text entry has focus - aEvent.Skip(); - return; + if( enabled ) + { + aEvent.Skip(); + return; + } + // Even if not enabled, allow a copy out + else if( ke->GetModifiers() == wxMOD_CONTROL && ke->GetKeyCode() == 'C' ) + { + aEvent.Skip(); + return; + } } evt = GetToolEvent( ke, &keyIsSpecial ); diff --git a/include/grid_tricks.h b/include/grid_tricks.h index 9bc6a2b0b4..11e9e83361 100644 --- a/include/grid_tricks.h +++ b/include/grid_tricks.h @@ -67,11 +67,6 @@ protected: /// Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above. void getSelectedArea(); - static bool isCtl( int aChar, const wxKeyEvent& e ) - { - return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() && !e.ShiftDown() && !e.MetaDown(); - } - void onGridCellLeftClick( wxGridEvent& event ); void onGridCellLeftDClick( wxGridEvent& event ); void onGridCellRightClick( wxGridEvent& event ); diff --git a/include/scintilla_tricks.h b/include/scintilla_tricks.h index f9c58f607c..ef33e7cd9e 100644 --- a/include/scintilla_tricks.h +++ b/include/scintilla_tricks.h @@ -41,9 +41,6 @@ public: void DoAutocomplete( const wxString& aPartial, const wxArrayString& aTokens ); protected: - bool isCtrl( int aChar, const wxKeyEvent& e ); - bool isShiftCtrl( int aChar, const wxKeyEvent& e ); - void onCharHook( wxKeyEvent& aEvent ); void onScintillaUpdateUI( wxStyledTextEvent& aEvent );