From 30ec895c96868690735f63f2a6fec3ff66433080 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 9 Jul 2019 21:38:18 +0100 Subject: [PATCH] Cleanup event processing stuff to keep better track of "handled". See: https://lists.launchpad.net/kicad-developers/msg41471.html . --- common/tool/tool_dispatcher.cpp | 2 -- common/tool/tool_manager.cpp | 42 ++++++++++++++++----------- eeschema/tools/sch_editor_control.cpp | 2 +- include/tool/tool_manager.h | 6 ++-- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index e556a600fb..5e9711ff97 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -489,10 +489,8 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) // Not handled wxEVT_CHAR must be Skipped (sent to GUI). // Otherwise accelerators and shortcuts in main menu or toolbars are not seen. -#ifndef __APPLE__ if( (type == wxEVT_CHAR || type == wxEVT_CHAR_HOOK) && !keyIsSpecial && !handled ) aEvent.Skip(); -#endif } diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 7e17cec7fe..250985c75b 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -524,8 +524,10 @@ TOOL_EVENT* TOOL_MANAGER::ScheduleWait( TOOL_BASE* aTool, const TOOL_EVENT_LIST& } -void TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent ) +bool TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent ) { + bool handled = false; + // iterate over active tool stack for( auto it = m_activeTools.begin(); it != m_activeTools.end(); ++it ) { @@ -562,7 +564,10 @@ void TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent ) // If the tool did not request the event be passed to other tools, we're done if( !st->wakeupEvent.PassEvent() ) + { + handled = true; break; + } } } } @@ -603,6 +608,7 @@ void TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent ) setActiveState( st ); st->idle = false; st->cofunc->Call( aEvent ); + handled = true; if( !st->cofunc->Running() ) finishTool( st ); // The couroutine has finished immediately? @@ -619,19 +625,17 @@ void TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent ) if( finished ) break; // only the first tool gets the event } + + return handled; } -bool TOOL_MANAGER::dispatchStandardEvents( const TOOL_EVENT& aEvent ) +bool TOOL_MANAGER::dispatchHotKey( const TOOL_EVENT& aEvent ) { if( aEvent.Action() == TA_KEY_PRESSED ) - { - // Check if there is a hotkey associated - if( m_actionMgr->RunHotKey( aEvent.Modifier() | aEvent.KeyCode() ) ) - return false; // hotkey event was handled so it does not go any further - } + return m_actionMgr->RunHotKey( aEvent.Modifier() | aEvent.KeyCode() ); - return true; + return false; } @@ -775,10 +779,12 @@ TOOL_MANAGER::ID_LIST::iterator TOOL_MANAGER::finishTool( TOOL_STATE* aState ) bool TOOL_MANAGER::ProcessEvent( const TOOL_EVENT& aEvent ) { - bool hotkey_handled = processEvent( aEvent ); + bool handled = processEvent( aEvent ); - if( TOOL_STATE* active = GetCurrentToolState() ) - setActiveState( active ); + TOOL_STATE* activeTool = GetCurrentToolState(); + + if( activeTool ) + setActiveState( activeTool ); if( m_view && m_view->IsDirty() ) { @@ -791,7 +797,7 @@ bool TOOL_MANAGER::ProcessEvent( const TOOL_EVENT& aEvent ) UpdateUI( aEvent ); - return hotkey_handled; + return handled; } @@ -925,12 +931,14 @@ void TOOL_MANAGER::applyViewControls( TOOL_STATE* aState ) bool TOOL_MANAGER::processEvent( const TOOL_EVENT& aEvent ) { - // Early dispatch of events destined for the TOOL_MANAGER - if( !dispatchStandardEvents( aEvent ) ) + if( dispatchHotKey( aEvent ) ) return true; - dispatchInternal( aEvent ); - dispatchActivation( aEvent ); + bool handled = false; + + handled |= dispatchInternal( aEvent ); + handled |= dispatchActivation( aEvent ); + DispatchContextMenu( aEvent ); // Dispatch queue @@ -941,7 +949,7 @@ bool TOOL_MANAGER::processEvent( const TOOL_EVENT& aEvent ) processEvent( event ); } - return false; + return handled; } diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 26a8a33c93..badea219d6 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -764,7 +764,7 @@ int SCH_EDITOR_CONTROL::Redo( const TOOL_EVENT& aEvent ) bool SCH_EDITOR_CONTROL::doCopy() { EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); - EE_SELECTION& selection = selTool->GetSelection(); + EE_SELECTION& selection = selTool->RequestSelection(); if( !selection.GetSize() ) return false; diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index 402329a075..d1056bdbae 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -382,15 +382,15 @@ private: * Function dispatchInternal * Passes an event at first to the active tools, then to all others. */ - void dispatchInternal( const TOOL_EVENT& aEvent ); + bool dispatchInternal( const TOOL_EVENT& aEvent ); /** * Function dispatchStandardEvents() * Handles specific events, that are intended for TOOL_MANAGER rather than tools. * @param aEvent is the event to be processed. - * @return False if the event was processed and should not go any further. + * @return true if the event was processed and should not go any further. */ - bool dispatchStandardEvents( const TOOL_EVENT& aEvent ); + bool dispatchHotKey( const TOOL_EVENT& aEvent ); /** * Function dispatchActivation()