MenuBarManager: Honor visible property of menu items

This became a problem recently with the introduction of
notebookbar customization, as it allows to hide menu items.

As a solution, use the same approach as for toolbars (see
GenericToolbarController::statusChanged): Force menu item
visibility only if it was previously hidden via a special
status update of css::frame::status::Visibility.

Change-Id: Ief9f70a289bd2e6a4855c1f92dbc20e31c62924c
Reviewed-on: https://gerrit.libreoffice.org/82222
Tested-by: Jenkins
Reviewed-by: Maxim Monastirsky <momonasmon@gmail.com>
This commit is contained in:
Maxim Monastirsky
2019-11-06 15:07:42 +02:00
parent 2e9322d765
commit f17fb8824c
2 changed files with 12 additions and 8 deletions

View File

@@ -153,10 +153,12 @@ class MenuBarManager final :
css::uno::Reference< css::frame::XStatusListener > const & xManager, css::uno::Reference< css::frame::XStatusListener > const & xManager,
css::uno::Reference< css::frame::XDispatch > const & rDispatch ) : css::uno::Reference< css::frame::XDispatch > const & rDispatch ) :
nItemId( aItemId ), nItemId( aItemId ),
bMadeInvisible ( false ),
xSubMenuManager( xManager ), xSubMenuManager( xManager ),
xMenuItemDispatch( rDispatch ) {} xMenuItemDispatch( rDispatch ) {}
sal_uInt16 nItemId; sal_uInt16 nItemId;
bool bMadeInvisible;
OUString aTargetFrame; OUString aTargetFrame;
OUString aMenuItemURL; OUString aMenuItemURL;
OUString aParsedItemURL; OUString aParsedItemURL;

View File

@@ -338,13 +338,14 @@ void SAL_CALL MenuBarManager::statusChanged( const FeatureStateEvent& Event )
if ( Event.State >>= bCheckmark ) if ( Event.State >>= bCheckmark )
{ {
// Checkmark or RadioButton // Checkmark or RadioButton
m_pVCLMenu->ShowItem( menuItemHandler->nItemId );
m_pVCLMenu->CheckItem( menuItemHandler->nItemId, bCheckmark ); m_pVCLMenu->CheckItem( menuItemHandler->nItemId, bCheckmark );
MenuItemBits nBits = m_pVCLMenu->GetItemBits( menuItemHandler->nItemId );
// If not already designated RadioButton set as CheckMark // If not already designated RadioButton set as CheckMark
MenuItemBits nBits = m_pVCLMenu->GetItemBits( menuItemHandler->nItemId );
if (!(nBits & MenuItemBits::RADIOCHECK)) if (!(nBits & MenuItemBits::RADIOCHECK))
m_pVCLMenu->SetItemBits( menuItemHandler->nItemId, nBits | MenuItemBits::CHECKABLE ); m_pVCLMenu->SetItemBits( menuItemHandler->nItemId, nBits | MenuItemBits::CHECKABLE );
if ( menuItemHandler->bMadeInvisible )
m_pVCLMenu->ShowItem( menuItemHandler->nItemId );
} }
else if ( Event.State >>= aItemText ) else if ( Event.State >>= aItemText )
{ {
@@ -353,11 +354,9 @@ void SAL_CALL MenuBarManager::statusChanged( const FeatureStateEvent& Event )
if ( !aEnumPart.isEmpty() && aURL.GetProtocol() == INetProtocol::Uno ) if ( !aEnumPart.isEmpty() && aURL.GetProtocol() == INetProtocol::Uno )
{ {
// Checkmark or RadioButton // Checkmark or RadioButton
m_pVCLMenu->ShowItem( menuItemHandler->nItemId );
m_pVCLMenu->CheckItem( menuItemHandler->nItemId, aItemText == aEnumPart ); m_pVCLMenu->CheckItem( menuItemHandler->nItemId, aItemText == aEnumPart );
MenuItemBits nBits = m_pVCLMenu->GetItemBits( menuItemHandler->nItemId );
// If not already designated RadioButton set as CheckMark // If not already designated RadioButton set as CheckMark
MenuItemBits nBits = m_pVCLMenu->GetItemBits( menuItemHandler->nItemId );
if (!(nBits & MenuItemBits::RADIOCHECK)) if (!(nBits & MenuItemBits::RADIOCHECK))
m_pVCLMenu->SetItemBits( menuItemHandler->nItemId, nBits | MenuItemBits::CHECKABLE ); m_pVCLMenu->SetItemBits( menuItemHandler->nItemId, nBits | MenuItemBits::CHECKABLE );
} }
@@ -377,16 +376,19 @@ void SAL_CALL MenuBarManager::statusChanged( const FeatureStateEvent& Event )
aItemText = FwkResId(STR_SAVECOPYDOC) + aItemText.copy( 4 ); aItemText = FwkResId(STR_SAVECOPYDOC) + aItemText.copy( 4 );
} }
m_pVCLMenu->ShowItem( menuItemHandler->nItemId );
m_pVCLMenu->SetItemText( menuItemHandler->nItemId, aItemText ); m_pVCLMenu->SetItemText( menuItemHandler->nItemId, aItemText );
} }
if ( menuItemHandler->bMadeInvisible )
m_pVCLMenu->ShowItem( menuItemHandler->nItemId );
} }
else if ( Event.State >>= aVisibilityStatus ) else if ( Event.State >>= aVisibilityStatus )
{ {
// Visibility // Visibility
m_pVCLMenu->ShowItem( menuItemHandler->nItemId, aVisibilityStatus.bVisible ); m_pVCLMenu->ShowItem( menuItemHandler->nItemId, aVisibilityStatus.bVisible );
menuItemHandler->bMadeInvisible = !aVisibilityStatus.bVisible;
} }
else else if ( menuItemHandler->bMadeInvisible )
m_pVCLMenu->ShowItem( menuItemHandler->nItemId ); m_pVCLMenu->ShowItem( menuItemHandler->nItemId );
} }