diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2016-02-26 12:47:43 +0200 |
---|---|---|
committer | Maxim Monastirsky <momonasmon@gmail.com> | 2016-02-28 09:10:30 +0200 |
commit | 010b034cd6195c96a21633c328e9693275d27d72 (patch) | |
tree | 5a9cb79e5c68edee741b4dcc79d0fd3ccb240aa0 | |
parent | 7affe26a1291eef8c77e890228061f13e987bff1 (diff) |
tdf#84258 Allow creation of command aliases
We already can use different labels for commands, based on
whether they're in a menu, context menu or a toolbar. But in
some cases we need different labels for the same type of UI
element, or even different icons.
One example is page/slide commands in Draw/Impress, as they
share same commands, but need different icons/labels.
Creating full-fledged duplicate slots just to satisfy the
need of UI representation seems like overkill, and isn't
flexible enough.
The proposed solution is to allow creation of command entries,
that do not correspond to real application slots, but instead
link to another existing commands. The "real" commands will be
used for controller factory and dispatch (execute/status) APIs,
thus fully retaining functionality.
This can be useful also for giving icons to complex commands
(i.e. commands with arguments).
Change-Id: I9b261b406ec8fc781cae06cf283963386379d4ad
-rw-r--r-- | framework/source/uielement/menubarmanager.cxx | 16 | ||||
-rw-r--r-- | framework/source/uielement/toolbarmanager.cxx | 7 | ||||
-rw-r--r-- | framework/source/uielement/uicommanddescription.cxx | 12 | ||||
-rw-r--r-- | include/vcl/commandinfoprovider.hxx | 3 | ||||
-rw-r--r-- | officecfg/registry/schema/org/openoffice/Office/UI/Commands.xcs | 5 | ||||
-rw-r--r-- | sfx2/source/appl/sfxhelp.cxx | 19 | ||||
-rw-r--r-- | vcl/source/helper/commandinfoprovider.cxx | 8 |
7 files changed, 57 insertions, 13 deletions
diff --git a/framework/source/uielement/menubarmanager.cxx b/framework/source/uielement/menubarmanager.cxx index 9e97edf03508..e81b58070aa4 100644 --- a/framework/source/uielement/menubarmanager.cxx +++ b/framework/source/uielement/menubarmanager.cxx @@ -844,14 +844,7 @@ IMPL_LINK_TYPED( MenuBarManager, Activate, Menu *, pMenu, bool ) { Reference< XDispatch > xMenuItemDispatch; - OUString aItemCommand = pMenu->GetItemCommand( pMenuItemHandler->nItemId ); - if ( aItemCommand.isEmpty() ) - { - aItemCommand = "slot:" + OUString::number( pMenuItemHandler->nItemId ); - pMenu->SetItemCommand( pMenuItemHandler->nItemId, aItemCommand ); - } - - aTargetURL.Complete = aItemCommand; + aTargetURL.Complete = pMenuItemHandler->aMenuItemURL; m_xURLTransformer->parseStrict( aTargetURL ); @@ -870,7 +863,7 @@ IMPL_LINK_TYPED( MenuBarManager, Activate, Menu *, pMenu, bool ) if(xMenuItemDispatch != nullptr) { if ( !pMenuItemHandler->xPopupMenuController.is() && - m_xPopupMenuControllerFactory->hasController( aItemCommand, m_aModuleIdentifier ) ) + m_xPopupMenuControllerFactory->hasController( pMenuItemHandler->aMenuItemURL, m_aModuleIdentifier ) ) { bPopupMenu = CreatePopupMenuController( pMenuItemHandler ); } @@ -1183,6 +1176,11 @@ void MenuBarManager::FillMenuManager( Menu* pMenu, const Reference< XFrame >& rF { sal_uInt16 nItemId = FillItemCommand(aItemCommand,pMenu, i ); + // Command can be just an alias to another command. + OUString aRealCommand = vcl::CommandInfoProvider::Instance().GetRealCommandForCommand( aItemCommand, m_xFrame ); + if ( !aRealCommand.isEmpty() ) + aItemCommand = aRealCommand; + // Set module identifier when provided from outside if ( !rModuleIdentifier.isEmpty() ) { diff --git a/framework/source/uielement/toolbarmanager.cxx b/framework/source/uielement/toolbarmanager.cxx index af416c2fa935..1b79d3de5120 100644 --- a/framework/source/uielement/toolbarmanager.cxx +++ b/framework/source/uielement/toolbarmanager.cxx @@ -650,13 +650,18 @@ void ToolBarManager::CreateControllers() continue; OUString aLoadURL( ".uno:OpenUrl" ); - OUString aCommandURL( m_pToolBar->GetItemCommand( nId )); bool bInit( true ); bool bCreate( true ); Reference< XStatusListener > xController; svt::ToolboxController* pController( nullptr ); + OUString aCommandURL( m_pToolBar->GetItemCommand( nId ) ); + // Command can be just an alias to another command. + OUString aRealCommandURL( vcl::CommandInfoProvider::Instance().GetRealCommandForCommand( aCommandURL, m_xFrame ) ); + if ( !aRealCommandURL.isEmpty() ) + aCommandURL = aRealCommandURL; + if ( bHasDisabledEntries ) { aURL.Complete = aCommandURL; diff --git a/framework/source/uielement/uicommanddescription.cxx b/framework/source/uielement/uicommanddescription.cxx index 9b024cb2f32c..bbdea7ed0351 100644 --- a/framework/source/uielement/uicommanddescription.cxx +++ b/framework/source/uielement/uicommanddescription.cxx @@ -55,6 +55,7 @@ static const char CONFIGURATION_PROPERTY_LABEL[] = "Label"; static const char CONFIGURATION_PROPERTY_CONTEXT_LABEL[] = "ContextLabel"; static const char CONFIGURATION_PROPERTY_POPUP_LABEL[] = "PopupLabel"; static const char CONFIGURATION_PROPERTY_TOOLTIP_LABEL[] = "TooltipLabel"; +static const char CONFIGURATION_PROPERTY_TARGET_URL[] = "TargetURL"; // Property names of the resulting Property Set static const char PROPSET_LABEL[] = "Label"; @@ -62,6 +63,7 @@ static const char PROPSET_NAME[] = "Name"; static const char PROPSET_POPUP[] = "Popup"; static const char PROPSET_POPUPLABEL[] = "PopupLabel"; static const char PROPSET_TOOLTIPLABEL[] = "TooltipLabel"; +static const char PROPSET_TARGETURL[] = "TargetURL"; static const char PROPSET_PROPERTIES[] = "Properties"; // Special resource URLs to retrieve additional information @@ -123,6 +125,7 @@ class ConfigurationAccess_UICommand : // Order is necessary for right initializa OUString aCommandName; OUString aPopupLabel; OUString aTooltipLabel; + OUString aTargetURL; bool bPopup : 1, bCommandNameCreated : 1; sal_Int32 nProperties; @@ -153,11 +156,13 @@ class ConfigurationAccess_UICommand : // Order is necessary for right initializa OUString m_aPropUIContextLabel; OUString m_aPropUIPopupLabel; OUString m_aPropUITooltipLabel; + OUString m_aPropUITargetURL; OUString m_aPropLabel; OUString m_aPropName; OUString m_aPropPopup; OUString m_aPropPopupLabel; OUString m_aPropTooltipLabel; + OUString m_aPropTargetURL; OUString m_aPropProperties; OUString m_aPrivateResourceURL; Reference< XNameAccess > m_xGenericUICommands; @@ -184,11 +189,13 @@ ConfigurationAccess_UICommand::ConfigurationAccess_UICommand( const OUString& aM m_aPropUIContextLabel( CONFIGURATION_PROPERTY_CONTEXT_LABEL ), m_aPropUIPopupLabel( CONFIGURATION_PROPERTY_POPUP_LABEL ), m_aPropUITooltipLabel( CONFIGURATION_PROPERTY_TOOLTIP_LABEL ), + m_aPropUITargetURL( CONFIGURATION_PROPERTY_TARGET_URL ), m_aPropLabel( PROPSET_LABEL ), m_aPropName( PROPSET_NAME ), m_aPropPopup( PROPSET_POPUP ), m_aPropPopupLabel( PROPSET_POPUPLABEL ), m_aPropTooltipLabel( PROPSET_TOOLTIPLABEL ), + m_aPropTargetURL( PROPSET_TARGETURL ), m_aPropProperties( PROPSET_PROPERTIES ), m_aPrivateResourceURL( PRIVATE_RESOURCE_URL ), m_xGenericUICommands( rGenericUICommands ), @@ -307,7 +314,7 @@ Any ConfigurationAccess_UICommand::getSequenceFromCache( const OUString& aComman if ( !pIter->second.bCommandNameCreated ) fillInfoFromResult( pIter->second, pIter->second.aLabel ); - Sequence< PropertyValue > aPropSeq( 6 ); + Sequence< PropertyValue > aPropSeq( 7 ); aPropSeq[0].Name = m_aPropLabel; aPropSeq[0].Value = !pIter->second.aContextLabel.isEmpty() ? makeAny( pIter->second.aContextLabel ): makeAny( pIter->second.aLabel ); @@ -321,6 +328,8 @@ Any ConfigurationAccess_UICommand::getSequenceFromCache( const OUString& aComman aPropSeq[4].Value <<= pIter->second.aPopupLabel; aPropSeq[5].Name = m_aPropTooltipLabel; aPropSeq[5].Value <<= pIter->second.aTooltipLabel; + aPropSeq[6].Name = m_aPropTargetURL; + aPropSeq[6].Value <<= pIter->second.aTargetURL; return makeAny( aPropSeq ); } @@ -349,6 +358,7 @@ void ConfigurationAccess_UICommand::impl_fill(const Reference< XNameAccess >& _x xNameAccess->getByName( m_aPropUIContextLabel ) >>= aCmdToInfo.aContextLabel; xNameAccess->getByName( m_aPropUIPopupLabel ) >>= aCmdToInfo.aPopupLabel; xNameAccess->getByName( m_aPropUITooltipLabel ) >>= aCmdToInfo.aTooltipLabel; + xNameAccess->getByName( m_aPropUITargetURL ) >>= aCmdToInfo.aTargetURL; xNameAccess->getByName( m_aPropProperties ) >>= aCmdToInfo.nProperties; m_aCmdInfoCache.insert( CommandToInfoCache::value_type( aNameSeq[i], aCmdToInfo )); diff --git a/include/vcl/commandinfoprovider.hxx b/include/vcl/commandinfoprovider.hxx index d6aa358e7192..29a9bf8f3c0f 100644 --- a/include/vcl/commandinfoprovider.hxx +++ b/include/vcl/commandinfoprovider.hxx @@ -84,6 +84,9 @@ public: OUString GetCommandShortcut (const OUString& rCommandName, const css::uno::Reference<css::frame::XFrame>& rxFrame); + OUString GetRealCommandForCommand( const OUString& rCommandName, + const css::uno::Reference<css::frame::XFrame>& rxFrame ); + Image GetImageForCommand( const OUString& rsCommandName, bool bLarge, diff --git a/officecfg/registry/schema/org/openoffice/Office/UI/Commands.xcs b/officecfg/registry/schema/org/openoffice/Office/UI/Commands.xcs index 1fec9f765777..54714b6fa088 100644 --- a/officecfg/registry/schema/org/openoffice/Office/UI/Commands.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/UI/Commands.xcs @@ -46,6 +46,11 @@ <desc>Used for Tooltips (Toolbar and Glade Widgets that have their 'action_name' specified.)</desc> </info> </prop> + <prop oor:name="TargetURL" oor:type="xs:string" oor:localized="false"> + <info> + <desc>The actual command to use for everything except label/icon, typically when the main command doesn't map to a valid application slot.</desc> + </info> + </prop> <prop oor:name="Properties" oor:type="xs:int" oor:nillable="false"> <info> <desc> diff --git a/sfx2/source/appl/sfxhelp.cxx b/sfx2/source/appl/sfxhelp.cxx index 6fe553f93c5a..4140f8d6d05b 100644 --- a/sfx2/source/appl/sfxhelp.cxx +++ b/sfx2/source/appl/sfxhelp.cxx @@ -53,6 +53,7 @@ #include <osl/file.hxx> #include <unotools/bootstrap.hxx> #include <rtl/uri.hxx> +#include <vcl/commandinfoprovider.hxx> #include <vcl/layout.hxx> #include <svtools/ehdl.hxx> #include <svtools/sfxecode.hxx> @@ -263,6 +264,13 @@ OUString getDefaultModule_Impl() return sDefaultModule; } +Reference< XFrame > getCurrentFrame() +{ + Reference < XComponentContext > xContext = ::comphelper::getProcessComponentContext(); + Reference < XDesktop2 > xDesktop = Desktop::create(xContext); + return xDesktop->getCurrentFrame(); +} + OUString getCurrentModuleIdentifier_Impl() { OUString sIdentifier; @@ -443,7 +451,8 @@ SfxHelpWindow_Impl* impl_createHelp(Reference< XFrame2 >& rHelpTask , OUString SfxHelp::GetHelpText( const OUString& aCommandURL, const vcl::Window* pWindow ) { OUString sModuleName = GetHelpModuleName_Impl(); - OUString sHelpText = SfxHelp_Impl::GetHelpText( aCommandURL, sModuleName ); + OUString sRealCommand = vcl::CommandInfoProvider::Instance().GetRealCommandForCommand( aCommandURL, getCurrentFrame() ); + OUString sHelpText = SfxHelp_Impl::GetHelpText( sRealCommand.isEmpty() ? aCommandURL : sRealCommand, sModuleName ); OString aNewHelpId; @@ -556,8 +565,14 @@ bool SfxHelp::Start_Impl(const OUString& rURL, const vcl::Window* pWindow, const default: { OUString aHelpModuleName( GetHelpModuleName_Impl() ); + OUString aRealCommand; + + if ( nProtocol == INetProtocol::Uno ) + // Command can be just an alias to another command. + aRealCommand = vcl::CommandInfoProvider::Instance().GetRealCommandForCommand( rURL, getCurrentFrame() ); + // no URL, just a HelpID (maybe empty in case of keyword search) - aHelpURL = CreateHelpURL_Impl( rURL, aHelpModuleName ); + aHelpURL = CreateHelpURL_Impl( aRealCommand.isEmpty() ? rURL : aRealCommand, aHelpModuleName ); if ( impl_hasHelpInstalled() && pWindow && SfxContentHelper::IsHelpErrorDocument( aHelpURL ) ) { diff --git a/vcl/source/helper/commandinfoprovider.cxx b/vcl/source/helper/commandinfoprovider.cxx index 6cf0adf4cb53..121aacfeda17 100644 --- a/vcl/source/helper/commandinfoprovider.cxx +++ b/vcl/source/helper/commandinfoprovider.cxx @@ -194,6 +194,14 @@ OUString CommandInfoProvider::GetCommandShortcut (const OUString& rsCommandName, return OUString(); } +OUString CommandInfoProvider::GetRealCommandForCommand(const OUString& rCommandName, + const css::uno::Reference<frame::XFrame>& rxFrame) +{ + SetFrame(rxFrame); + + return GetCommandProperty("TargetURL", rCommandName); +} + Image CommandInfoProvider::GetImageForCommand(const OUString& rsCommandName, bool bLarge, const Reference<frame::XFrame>& rxFrame) { |