diff options
author | Oliver Specht <oliver.specht@cib.de> | 2016-02-17 12:07:59 +0100 |
---|---|---|
committer | Oliver Specht <oliver.specht@cib.de> | 2016-02-18 07:56:11 +0000 |
commit | a6e8910a3c5d33e671a13559438b7228596b8bca (patch) | |
tree | 64e29c3548a87cb55cccb3150a21c5aa24df76aa /framework | |
parent | fa20b651d61edb7bf9487cb79140bb57fc668967 (diff) |
allow disabling file/new, wizards, recent documents menu entries
disabling the dispatches '.uno:AutoPilotMenu' and '.uno:AddDirect' and
.uno:RecentFileList via UNO API now results in disabled
menu entries as expected
Change-Id: Id99be9374306ff8c0cea919ea94ed96f715a8058
Reviewed-on: https://gerrit.libreoffice.org/22422
Reviewed-by: Oliver Specht <oliver.specht@cib.de>
Tested-by: Oliver Specht <oliver.specht@cib.de>
Diffstat (limited to 'framework')
-rw-r--r-- | framework/source/classes/menumanager.cxx | 46 | ||||
-rw-r--r-- | framework/source/uielement/menubarmanager.cxx | 26 | ||||
-rw-r--r-- | framework/source/uielement/newmenucontroller.cxx | 11 |
3 files changed, 47 insertions, 36 deletions
diff --git a/framework/source/classes/menumanager.cxx b/framework/source/classes/menumanager.cxx index 8140cdfcd391..3e76f14f4e9f 100644 --- a/framework/source/classes/menumanager.cxx +++ b/framework/source/classes/menumanager.cxx @@ -177,33 +177,33 @@ MenuManager::MenuManager( } else { - if ( nItemId == SID_NEWDOCDIRECT || aItemCommand == aSlotNewDocDirect ) + bool isNewDoc = nItemId == SID_NEWDOCDIRECT || aItemCommand == aSlotNewDocDirect; + bool isAutoPilot = nItemId == SID_AUTOPILOTMENU || aItemCommand == aSlotAutoPilot; + if(isNewDoc || isAutoPilot) { - MenuConfiguration aMenuCfg( m_xContext ); - BmkMenu* pSubMenu = static_cast<BmkMenu*>(aMenuCfg.CreateBookmarkMenu( rFrame, BOOKMARK_NEWMENU )); - pMenu->SetPopupMenu( nItemId, pSubMenu ); - - AddMenu(pSubMenu,OUString(),nItemId,true,false); - if ( bShowMenuImages && !pMenu->GetItemImage( nItemId )) + Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); + URL aTargetURL; + aTargetURL.Complete = OUString::createFromAscii(isNewDoc ? aSlotNewDocDirect : aSlotAutoPilot); + m_xURLTransformer->parseStrict( aTargetURL ); + Reference< XDispatch > xMenuItemDispatch = xDispatchProvider->queryDispatch( + aTargetURL, OUString(), 0 ); + if(xMenuItemDispatch == nullptr) { - Image aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand(aItemCommand, false, rFrame ); - if ( !!aImage ) - pMenu->SetItemImage( nItemId, aImage ); + m_pVCLMenu->EnableItem( nItemId, false ); } - } - else if ( nItemId == SID_AUTOPILOTMENU || aItemCommand == aSlotAutoPilot ) - { - MenuConfiguration aMenuCfg( m_xContext ); - BmkMenu* pSubMenu = static_cast<BmkMenu*>(aMenuCfg.CreateBookmarkMenu( rFrame, BOOKMARK_WIZARDMENU )); - pMenu->SetPopupMenu( nItemId, pSubMenu ); - - AddMenu(pSubMenu,OUString(),nItemId,true,false); - - if ( bShowMenuImages && !pMenu->GetItemImage( nItemId )) + else { - Image aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand(aItemCommand, false, rFrame ); - if ( !!aImage ) - pMenu->SetItemImage( nItemId, aImage ); + MenuConfiguration aMenuCfg( m_xContext ); + BmkMenu* pSubMenu = static_cast<BmkMenu*>(aMenuCfg.CreateBookmarkMenu( rFrame, + OUString::createFromAscii(isNewDoc ? BOOKMARK_NEWMENU : BOOKMARK_WIZARDMENU))); + pMenu->SetPopupMenu( nItemId, pSubMenu ); + AddMenu(pSubMenu,OUString(),nItemId,true,false); + if ( bShowMenuImages && !pMenu->GetItemImage( nItemId )) + { + Image aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand(aItemCommand, false, rFrame ); + if ( !!aImage ) + pMenu->SetItemImage( nItemId, aImage ); + } } } else if ( pMenu->GetItemType( i ) != MenuItemType::SEPARATOR ) diff --git a/framework/source/uielement/menubarmanager.cxx b/framework/source/uielement/menubarmanager.cxx index d5ae1d6ea4bd..9e97edf03508 100644 --- a/framework/source/uielement/menubarmanager.cxx +++ b/framework/source/uielement/menubarmanager.cxx @@ -867,20 +867,22 @@ IMPL_LINK_TYPED( MenuBarManager, Activate, Menu *, pMenu, bool ) xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 ); bool bPopupMenu( false ); - if ( !pMenuItemHandler->xPopupMenuController.is() && - m_xPopupMenuControllerFactory->hasController( aItemCommand, m_aModuleIdentifier ) ) + if(xMenuItemDispatch != nullptr) { - bPopupMenu = CreatePopupMenuController( pMenuItemHandler ); - } - else if ( pMenuItemHandler->xPopupMenuController.is() ) - { - // Force update of popup menu - pMenuItemHandler->xPopupMenuController->updatePopupMenu(); - bPopupMenu = true; - if (PopupMenu* pThisPopup = pMenu->GetPopupMenu( pMenuItemHandler->nItemId )) - pMenu->EnableItem( pMenuItemHandler->nItemId, pThisPopup->GetItemCount() != 0 ); + if ( !pMenuItemHandler->xPopupMenuController.is() && + m_xPopupMenuControllerFactory->hasController( aItemCommand, m_aModuleIdentifier ) ) + { + bPopupMenu = CreatePopupMenuController( pMenuItemHandler ); + } + else if ( pMenuItemHandler->xPopupMenuController.is() ) + { + // Force update of popup menu + pMenuItemHandler->xPopupMenuController->updatePopupMenu(); + bPopupMenu = true; + if (PopupMenu* pThisPopup = pMenu->GetPopupMenu( pMenuItemHandler->nItemId )) + pMenu->EnableItem( pMenuItemHandler->nItemId, pThisPopup->GetItemCount() != 0 ); + } } - lcl_CheckForChildren(pMenu, pMenuItemHandler->nItemId); if ( xMenuItemDispatch.is() ) diff --git a/framework/source/uielement/newmenucontroller.cxx b/framework/source/uielement/newmenucontroller.cxx index d4a421382031..5e848bb57ea9 100644 --- a/framework/source/uielement/newmenucontroller.cxx +++ b/framework/source/uielement/newmenucontroller.cxx @@ -48,6 +48,8 @@ #include <memory> // Defines +#define aSlotNewDocDirect ".uno:AddDirect" +#define aSlotAutoPilot ".uno:AutoPilotMenu" using namespace com::sun::star::uno; using namespace com::sun::star::lang; @@ -332,6 +334,13 @@ void NewMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopup MenuConfiguration aMenuCfg( m_xContext ); std::unique_ptr<BmkMenu> pSubMenu; + Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); + URL aTargetURL; + aTargetURL.Complete = rtl::OUString::createFromAscii(m_bNewMenu ? aSlotNewDocDirect : aSlotAutoPilot); + m_xURLTransformer->parseStrict( aTargetURL ); + Reference< XDispatch > xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 ); + if(xMenuItemDispatch == nullptr) + return; if ( m_bNewMenu ) pSubMenu.reset(static_cast<BmkMenu*>(aMenuCfg.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU ))); else @@ -522,7 +531,7 @@ void SAL_CALL NewMenuController::initialize( const Sequence< Any >& aArguments ) const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); m_bShowImages = rSettings.GetUseImagesInMenus(); - m_bNewMenu = m_aCommandURL == ".uno:AddDirect"; + m_bNewMenu = m_aCommandURL == aSlotNewDocDirect; } } } |