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.
This commit is contained in:
Jeff Young 2020-06-23 11:21:16 +01:00
parent 1a7c270dcd
commit 5ee806c3a3
8 changed files with 22 additions and 35 deletions

View File

@ -487,11 +487,16 @@ void DIALOG_SHIM::OnButton( wxCommandEvent& aEvent )
void DIALOG_SHIM::OnCharHook( wxKeyEvent& aEvt )
{
if( m_parentFrame && m_parentFrame->DispatchBehindModalDialog( aEvt ) )
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;

View File

@ -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<wxTextEntry*>( FindFocus() ) )
return false;
SetUserUnits( m_userUnits == EDA_UNITS::INCHES ? EDA_UNITS::MILLIMETRES : EDA_UNITS::INCHES );
unitsChangeRefresh();
static std::set<const TOOL_ACTION*> whiteList = { &ACTIONS::toggleUnits,
&ACTIONS::imperialUnits,
&ACTIONS::metricUnits };
bool dummy;
OPT<TOOL_EVENT> 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 );
}

View File

@ -85,7 +85,7 @@ TOOL_ACTION* ACTION_MANAGER::FindAction( const std::string& aActionName ) const
}
bool ACTION_MANAGER::RunHotKey( int aHotKey, std::set<const TOOL_ACTION*>* 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<const TOOL_ACTION*>* 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

View File

@ -767,11 +767,10 @@ bool TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent )
}
bool TOOL_MANAGER::DispatchHotKey( const TOOL_EVENT& aEvent,
std::set<const TOOL_ACTION*>* 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;
}

View File

@ -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; }

View File

@ -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.
*/

View File

@ -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<const TOOL_ACTION*>* aWhiteList ) const;
bool RunHotKey( int aHotKey ) const;
/**
* Function GetHotKey()

View File

@ -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<const TOOL_ACTION*>* aWhiteList = nullptr );
bool DispatchHotKey( const TOOL_EVENT& aEvent );
private:
typedef std::pair<TOOL_EVENT_LIST, TOOL_STATE_FUNC> TRANSITION;