framework/inc/uielement/menubarmanager.hxx | 1 framework/source/uielement/menubarmanager.cxx | 61 +++++++++++--------------- 2 files changed, 28 insertions(+), 34 deletions(-)
New commits: commit bf4d51b46c54a72038fbf46e9a5b025415acdde3 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed Oct 23 16:28:23 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Oct 24 09:08:18 2024 +0200 framework: Deduplicate code setting menu accelerator keys Introduce new helper method MenuBarManager::SetAcceleratorKeys and call that from both places that are setting accelerator keys, to deduplicate code and simplify future maintenance. The use in MenuBarManager::FillMenuManager was introduced in commit 08fe2669a0ed807812d005195b54cc41f092d09a Author: Rüdiger Timm <r...@openoffice.org> Date: Fri May 13 06:29:54 2005 +0000 INTEGRATION: CWS tbe22 (1.25.30); FILE MERGED 2005/05/04 14:21:00 tbe 1.25.30.1: #i48612# Opening a menu with GOK shows Tips instead of entries (fixed by CD) and looks like it was primarily copy-pasted from the other place. Change-Id: I2097619740d45260e534ce06f9941337177f1bde Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175509 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/framework/inc/uielement/menubarmanager.hxx b/framework/inc/uielement/menubarmanager.hxx index 986ed951f9ea..8b14158aee6e 100644 --- a/framework/inc/uielement/menubarmanager.hxx +++ b/framework/inc/uielement/menubarmanager.hxx @@ -152,6 +152,7 @@ class MenuBarManager final : }; void RetrieveShortcuts( std::vector< std::unique_ptr<MenuItemHandler> >& aMenuShortCuts ); + void SetAcceleratorKeys(Menu* pMenu); static void FillMenuImages( css::uno::Reference< css::frame::XFrame > const & xFrame, Menu* _pMenu, bool bShowMenuImages ); static void impl_RetrieveShortcutsFromConfiguration( const css::uno::Reference< css::ui::XAcceleratorConfiguration >& rAccelCfg, const css::uno::Sequence< OUString >& rCommands, diff --git a/framework/source/uielement/menubarmanager.cxx b/framework/source/uielement/menubarmanager.cxx index 014c226e2d47..7264eab1fcde 100644 --- a/framework/source/uielement/menubarmanager.cxx +++ b/framework/source/uielement/menubarmanager.cxx @@ -603,25 +603,7 @@ IMPL_LINK( MenuBarManager, Activate, Menu *, pMenu, bool ) } // Try to set accelerator keys - bool bShowShortcuts = m_bHasMenuBar || rSettings.GetContextMenuShortcuts(); - if ( bShowShortcuts ) - RetrieveShortcuts( m_aMenuItemHandlerVector ); - for (auto const& menuItemHandler : m_aMenuItemHandlerVector) - { - if ( !bShowShortcuts ) - { - pMenu->SetAccelKey( menuItemHandler->nItemId, vcl::KeyCode() ); - } - else if ( menuItemHandler->aMenuItemURL == aCmdHelpIndex ) - { - // Set key code, workaround for hard-coded shortcut F1 mapped to .uno:HelpIndex - // Only non-popup menu items can have a short-cut - vcl::KeyCode aKeyCode( KEY_F1 ); - pMenu->SetAccelKey( menuItemHandler->nItemId, aKeyCode ); - } - else if ( pMenu->GetPopupMenu( menuItemHandler->nItemId ) == nullptr ) - pMenu->SetAccelKey( menuItemHandler->nItemId, menuItemHandler->aKeyCode ); - } + SetAcceleratorKeys(pMenu); URL aTargetURL; @@ -1100,21 +1082,7 @@ void MenuBarManager::FillMenuManager( Menu* pMenu, const Reference< XFrame >& rF } if ( m_bHasMenuBar && bAccessibilityEnabled ) - { - RetrieveShortcuts( m_aMenuItemHandlerVector ); - for (auto const& menuItemHandler : m_aMenuItemHandlerVector) - { - // Set key code, workaround for hard-coded shortcut F1 mapped to .uno:HelpIndex - // Only non-popup menu items can have a short-cut - if ( menuItemHandler->aMenuItemURL == aCmdHelpIndex ) - { - vcl::KeyCode aKeyCode( KEY_F1 ); - pMenu->SetAccelKey( menuItemHandler->nItemId, aKeyCode ); - } - else if ( pMenu->GetPopupMenu( menuItemHandler->nItemId ) == nullptr ) - pMenu->SetAccelKey( menuItemHandler->nItemId, menuItemHandler->aKeyCode ); - } - } + SetAcceleratorKeys(pMenu); SetHdl(); } @@ -1227,6 +1195,31 @@ void MenuBarManager::RetrieveShortcuts( std::vector< std::unique_ptr<MenuItemHan impl_RetrieveShortcutsFromConfiguration( xDocAccelCfg, aSeq, aMenuShortCuts ); } +void MenuBarManager::SetAcceleratorKeys(Menu* pMenu) +{ + const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); + bool bShowShortcuts = m_bHasMenuBar || rSettings.GetContextMenuShortcuts(); + if ( bShowShortcuts ) + RetrieveShortcuts( m_aMenuItemHandlerVector ); + + for (auto const& menuItemHandler : m_aMenuItemHandlerVector) + { + if ( !bShowShortcuts ) + { + pMenu->SetAccelKey( menuItemHandler->nItemId, vcl::KeyCode() ); + } + else if ( menuItemHandler->aMenuItemURL == aCmdHelpIndex ) + { + // Set key code, workaround for hard-coded shortcut F1 mapped to .uno:HelpIndex + // Only non-popup menu items can have a short-cut + vcl::KeyCode aKeyCode( KEY_F1 ); + pMenu->SetAccelKey( menuItemHandler->nItemId, aKeyCode ); + } + else if ( pMenu->GetPopupMenu( menuItemHandler->nItemId ) == nullptr ) + pMenu->SetAccelKey( menuItemHandler->nItemId, menuItemHandler->aKeyCode ); + } +} + void MenuBarManager::RetrieveImageManagers() { if ( !m_xDocImageManager.is() )