From 97d2800f16be896fdb7799936700c336ab2798ab Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 12 Jun 2019 11:22:23 +0100 Subject: [PATCH] Update hotkey maps when the hotkeys are edited. Also removes some legacy code dealing with conflicts. Also disambiguates zoom in/out commands for hotkey list. --- common/hotkey_store.cpp | 4 ++++ common/tool/action_manager.cpp | 40 ++++++++++++++-------------------- common/tool/actions.cpp | 4 ++-- common/tool/tool_manager.cpp | 8 +------ include/tool/action_manager.h | 6 ++--- include/tool/tool_manager.h | 3 +-- 6 files changed, 27 insertions(+), 38 deletions(-) diff --git a/common/hotkey_store.cpp b/common/hotkey_store.cpp index 5e762bac1c..eab8032f1d 100644 --- a/common/hotkey_store.cpp +++ b/common/hotkey_store.cpp @@ -23,6 +23,7 @@ #include #include +#include #include @@ -115,6 +116,9 @@ void HOTKEY_STORE::SaveAllHotkeys() for( HOTKEY& hotkey: section.m_HotKeys ) hotkey.m_Parent->SetHotKey( hotkey.m_EditKeycode ); } + + if( !m_toolManagers.empty() ) + m_toolManagers[ 0 ]->GetActionManager()->UpdateHotKeys( false ); } diff --git a/common/tool/action_manager.cpp b/common/tool/action_manager.cpp index f28589e5ef..d8bf7f1677 100644 --- a/common/tool/action_manager.cpp +++ b/common/tool/action_manager.cpp @@ -140,9 +140,7 @@ bool ACTION_MANAGER::RunHotKey( int aHotKey ) const { if( action->GetScope() == AS_GLOBAL ) { - // Store the global action for the hot key in case there was no possible - // context actions to run - wxASSERT( global == NULL ); // there should be only one global action per hot key + // Store the global action in case there are no context actions to run global = action; continue; } @@ -195,41 +193,35 @@ int ACTION_MANAGER::GetHotKey( const TOOL_ACTION& aAction ) const } -void ACTION_MANAGER::UpdateHotKeys() +void ACTION_MANAGER::UpdateHotKeys( bool aFullUpdate ) { std::map legacyHotKeyMap; std::map userHotKeyMap; m_actionHotKeys.clear(); m_hotkeys.clear(); - - ReadLegacyHotkeyConfig( m_toolMgr->GetEditFrame()->ConfigBaseName(), legacyHotKeyMap ); - ReadHotKeyConfig( wxEmptyString, userHotKeyMap ); + + if( aFullUpdate ) + { + ReadLegacyHotkeyConfig( m_toolMgr->GetEditFrame()->ConfigBaseName(), legacyHotKeyMap ); + ReadHotKeyConfig( wxEmptyString, userHotKeyMap ); + } for( const auto& actionName : m_actionNameIndex ) { TOOL_ACTION* action = actionName.second; - int hotkey = processHotKey( action, legacyHotKeyMap, userHotKeyMap ); + int hotkey = 0; - if( hotkey <= 0 ) - continue; + if( aFullUpdate ) + hotkey = processHotKey( action, legacyHotKeyMap, userHotKeyMap ); + else + hotkey = action->GetHotKey(); - // Second hotkey takes priority as defaults are loaded first and updates - // are loaded after - if( action->GetScope() == AS_GLOBAL && m_actionHotKeys.count( hotkey ) ) + if( hotkey > 0 ) { - for( auto it = m_actionHotKeys[hotkey].begin(); - it != m_actionHotKeys[hotkey].end(); ) - { - if( (*it)->GetScope() == AS_GLOBAL ) - it = m_actionHotKeys[hotkey].erase( it ); - else - it++; - } + m_actionHotKeys[hotkey].push_back( action ); + m_hotkeys[action->GetId()] = hotkey; } - - m_actionHotKeys[hotkey].push_back( action ); - m_hotkeys[action->GetId()] = hotkey; } } diff --git a/common/tool/actions.cpp b/common/tool/actions.cpp index 1d45512d8b..763cce8621 100644 --- a/common/tool/actions.cpp +++ b/common/tool/actions.cpp @@ -235,7 +235,7 @@ TOOL_ACTION ACTIONS::zoomIn( "common.Control.zoomIn", WXK_F1, #endif LEGACY_HK_NAME( "Zoom In" ), - _( "Zoom In" ), "", + _( "Zoom In at Cursor" ), "", zoom_in_xpm ); TOOL_ACTION ACTIONS::zoomOut( "common.Control.zoomOut", @@ -246,7 +246,7 @@ TOOL_ACTION ACTIONS::zoomOut( "common.Control.zoomOut", WXK_F2, #endif LEGACY_HK_NAME( "Zoom Out" ), - _( "Zoom Out" ), "", + _( "Zoom Out at Cursor" ), "", zoom_out_xpm ); TOOL_ACTION ACTIONS::zoomInCenter( "common.Control.zoomInCenter", diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index ef56e54884..d1f403abe9 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -322,12 +322,6 @@ int TOOL_MANAGER::GetHotKey( const TOOL_ACTION& aAction ) } -void TOOL_MANAGER::UpdateHotKeys() -{ - m_actionMgr->UpdateHotKeys(); -} - - bool TOOL_MANAGER::invokeTool( TOOL_BASE* aTool ) { wxASSERT( aTool != NULL ); @@ -469,7 +463,7 @@ void TOOL_MANAGER::InitTools() } } - m_actionMgr->UpdateHotKeys(); + m_actionMgr->UpdateHotKeys( true ); ResetTools( TOOL_BASE::RUN ); } diff --git a/include/tool/action_manager.h b/include/tool/action_manager.h index e6f9b8841c..f851899ff2 100644 --- a/include/tool/action_manager.h +++ b/include/tool/action_manager.h @@ -103,10 +103,10 @@ public: int GetHotKey( const TOOL_ACTION& aAction ) const; /** - * Function ReadHotKeyConfig() - * Updates TOOL_ACTIONs hot key assignment according to the current frame's Hot Key Editor settings. + * Function UpdateHotKeys() + * Optionally reads the hotkey config files and then rebuilds the internal hotkey maps. */ - void UpdateHotKeys(); + void UpdateHotKeys( bool aFullUpdate ); /** * Function GetActionList() diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index e18269a288..a17da8a310 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -163,8 +163,7 @@ public: ///> @copydoc ACTION_MANAGER::GetHotKey() int GetHotKey( const TOOL_ACTION& aAction ); - ///> @copydoc ACTION_MANAGER::UpdateHotKeys() - void UpdateHotKeys(); + ACTION_MANAGER* GetActionManager() { return m_actionMgr; } /** * Function FindTool()