From 5ee806c3a36987d75a1f7df81ccc8a7d283f668b Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 23 Jun 2020 11:21:16 +0100 Subject: [PATCH] The dispatch-behind & whitelist stuff got broken again, so I've retired them in favour of a much dumber hack that special-cases only ctrl-U for units switch. --- common/dialog_shim.cpp | 13 +++++++++---- common/eda_draw_frame.cpp | 20 +++++--------------- common/tool/action_manager.cpp | 5 +---- common/tool/tool_manager.cpp | 5 ++--- include/eda_base_frame.h | 2 +- include/eda_draw_frame.h | 6 ++---- include/tool/action_manager.h | 2 +- include/tool/tool_manager.h | 4 +--- 8 files changed, 22 insertions(+), 35 deletions(-) diff --git a/common/dialog_shim.cpp b/common/dialog_shim.cpp index eae7a9d9aa..5ad10912d6 100644 --- a/common/dialog_shim.cpp +++ b/common/dialog_shim.cpp @@ -487,11 +487,16 @@ void DIALOG_SHIM::OnButton( wxCommandEvent& aEvent ) void DIALOG_SHIM::OnCharHook( wxKeyEvent& aEvt ) { - if( m_parentFrame && m_parentFrame->DispatchBehindModalDialog( aEvt ) ) - return; - + if( aEvt.GetKeyCode() == 'U' && aEvt.GetModifiers() == wxMOD_CONTROL ) + { + if( m_parentFrame ) + { + m_parentFrame->ToggleUserUnits(); + return; + } + } // shift-return (Mac default) or Ctrl-Return (GTK) for OK - if( aEvt.GetKeyCode() == WXK_RETURN && ( aEvt.ShiftDown() || aEvt.ControlDown() ) ) + else if( aEvt.GetKeyCode() == WXK_RETURN && ( aEvt.ShiftDown() || aEvt.ControlDown() ) ) { wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) ); return; diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index 476ded36e9..34bbf79bba 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -195,23 +195,13 @@ void EDA_DRAW_FRAME::unitsChangeRefresh() } -bool EDA_DRAW_FRAME::DispatchBehindModalDialog( wxKeyEvent& aEvent ) +void EDA_DRAW_FRAME::ToggleUserUnits() { - // Never process hotkeys when a text entry field is focused - if( dynamic_cast( FindFocus() ) ) - return false; + SetUserUnits( m_userUnits == EDA_UNITS::INCHES ? EDA_UNITS::MILLIMETRES : EDA_UNITS::INCHES ); + unitsChangeRefresh(); - static std::set whiteList = { &ACTIONS::toggleUnits, - &ACTIONS::imperialUnits, - &ACTIONS::metricUnits }; - - bool dummy; - OPT evt = m_toolDispatcher->GetToolEvent( &aEvent, &dummy ); - - if( evt && evt->Action() == TA_KEY_PRESSED ) - return m_toolManager->DispatchHotKey( *evt, &whiteList ); - - return false; + wxCommandEvent e( UNITS_CHANGED ); + ProcessEventLocally( e ); } diff --git a/common/tool/action_manager.cpp b/common/tool/action_manager.cpp index 34b7d15097..3d8d2b95c1 100644 --- a/common/tool/action_manager.cpp +++ b/common/tool/action_manager.cpp @@ -85,7 +85,7 @@ TOOL_ACTION* ACTION_MANAGER::FindAction( const std::string& aActionName ) const } -bool ACTION_MANAGER::RunHotKey( int aHotKey, std::set* aWhiteList ) const +bool ACTION_MANAGER::RunHotKey( int aHotKey ) const { int key = aHotKey & ~MD_MODIFIER_MASK; int mod = aHotKey & MD_MODIFIER_MASK; @@ -125,9 +125,6 @@ bool ACTION_MANAGER::RunHotKey( int aHotKey, std::set* aWhit for( const TOOL_ACTION* action : actions ) { - if( aWhiteList && !aWhiteList->count( action ) ) - continue; - if( action->GetScope() == AS_GLOBAL ) { // Store the global action in case there are no context actions to run diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index e13d252ddf..cce320e9bf 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -767,11 +767,10 @@ bool TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent ) } -bool TOOL_MANAGER::DispatchHotKey( const TOOL_EVENT& aEvent, - std::set* aWhiteList ) +bool TOOL_MANAGER::DispatchHotKey( const TOOL_EVENT& aEvent ) { if( aEvent.Action() == TA_KEY_PRESSED ) - return m_actionMgr->RunHotKey( aEvent.Modifier() | aEvent.KeyCode(), aWhiteList ); + return m_actionMgr->RunHotKey( aEvent.Modifier() | aEvent.KeyCode() ); return false; } diff --git a/include/eda_base_frame.h b/include/eda_base_frame.h index 81d617e7f5..9e538fb4c9 100644 --- a/include/eda_base_frame.h +++ b/include/eda_base_frame.h @@ -222,7 +222,7 @@ public: void ChangeUserUnits( EDA_UNITS aUnits ); - virtual bool DispatchBehindModalDialog( wxKeyEvent& aEvent ) { return false; } + virtual void ToggleUserUnits() { } SETTINGS_MANAGER* GetSettingsManager() const { return m_settingsManager; } diff --git a/include/eda_draw_frame.h b/include/eda_draw_frame.h index 690d5c1e1a..ee76db8f13 100644 --- a/include/eda_draw_frame.h +++ b/include/eda_draw_frame.h @@ -60,8 +60,6 @@ using KIGFX::RENDER_SETTINGS; #define FOOTPRINT_VIEWER_FRAME_NAME wxT( "ModViewFrame" ) #define FOOTPRINT_VIEWER_FRAME_NAME_MODAL wxT( "ModViewFrameModal" ) #define PCB_EDIT_FRAME_NAME wxT( "PcbFrame" ) -#define SHAPE_EDIT_FRAME_NAME wxT( "ShapeEditFrame" ) -#define SHAPE_EDIT_FRAME_NAME_MODAL wxT( "ShapeEditFrameModal" ) /** @@ -117,8 +115,6 @@ protected: void unitsChangeRefresh() override; - bool DispatchBehindModalDialog( wxKeyEvent& aEvent ) override; - void CommonSettingsChanged( bool aEnvVarsChanged ) override; /** @@ -187,6 +183,8 @@ public: bool GetShowPolarCoords() const { return m_PolarCoords; } void SetShowPolarCoords( bool aShow ) { m_PolarCoords = aShow; } + void ToggleUserUnits() override; + /** * Return the origin of the axis used for plotting and various exports. */ diff --git a/include/tool/action_manager.h b/include/tool/action_manager.h index bf64bd3961..5260aeefa6 100644 --- a/include/tool/action_manager.h +++ b/include/tool/action_manager.h @@ -87,7 +87,7 @@ public: * @param aHotKey is the hotkey to be handled. * @return True if there was an action associated with the hotkey, false otherwise. */ - bool RunHotKey( int aHotKey, std::set* aWhiteList ) const; + bool RunHotKey( int aHotKey ) const; /** * Function GetHotKey() diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index 610cca8fc4..b5e0b99cd1 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -420,11 +420,9 @@ public: * Function dispatchHotKey() * Handles specific events, that are intended for TOOL_MANAGER rather than tools. * @param aEvent is the event to be processed. - * @param aWhiteList an optional list of allowed actions to run * @return true if the event was processed and should not go any further. */ - bool DispatchHotKey( const TOOL_EVENT& aEvent, - std::set* aWhiteList = nullptr ); + bool DispatchHotKey( const TOOL_EVENT& aEvent ); private: typedef std::pair TRANSITION;