summaryrefslogtreecommitdiff
path: root/framework/source
diff options
context:
space:
mode:
authorMaxim Monastirsky <momonasmon@gmail.com>2016-02-26 12:47:43 +0200
committerMaxim Monastirsky <momonasmon@gmail.com>2016-02-28 09:10:30 +0200
commit010b034cd6195c96a21633c328e9693275d27d72 (patch)
tree5a9cb79e5c68edee741b4dcc79d0fd3ccb240aa0 /framework/source
parent7affe26a1291eef8c77e890228061f13e987bff1 (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
Diffstat (limited to 'framework/source')
-rw-r--r--framework/source/uielement/menubarmanager.cxx16
-rw-r--r--framework/source/uielement/toolbarmanager.cxx7
-rw-r--r--framework/source/uielement/uicommanddescription.cxx12
3 files changed, 24 insertions, 11 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 ));