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>
This commit is contained in:
Oliver Specht
2016-02-17 12:07:59 +01:00
parent fa20b651d6
commit a6e8910a3c
3 changed files with 47 additions and 36 deletions

View File

@@ -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 )

View File

@@ -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 );
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 );
}
}
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() )

View File

@@ -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;
}
}
}