From 58e70ffbbf4098b154cedf0ed8ef2db281e51a85 Mon Sep 17 00:00:00 2001 From: Maxim Monastirsky Date: Thu, 2 Nov 2017 16:09:23 +0200 Subject: [PATCH] aliases WIP Change-Id: I8bfcf5a8518d8e2063d77eacebe45c0915ead502 --- framework/inc/uielement/uicommanddescription.hxx | 1 + .../source/uielement/uicommanddescription.cxx | 130 +++++++++++++++++---- icon-themes/tango/links.txt | 2 +- .../openoffice/Office/UI/DrawImpressCommands.xcu | 18 ++- .../org/openoffice/Office/UI/GenericCommands.xcu | 15 +++ .../schema/org/openoffice/Office/UI/Commands.xcs | 5 + sd/uiconfig/simpress/menubar/menubar.xml | 2 +- sd/uiconfig/simpress/toolbar/commontaskbar.xml | 2 +- sw/uiconfig/swriter/menubar/menubar.xml | 2 +- sw/uiconfig/swriter/toolbar/standardbar.xml | 2 +- 10 files changed, 141 insertions(+), 38 deletions(-) diff --git a/framework/inc/uielement/uicommanddescription.hxx b/framework/inc/uielement/uicommanddescription.hxx index 92a2362b25a3..b86e8dfc4ed1 100644 --- a/framework/inc/uielement/uicommanddescription.hxx +++ b/framework/inc/uielement/uicommanddescription.hxx @@ -87,6 +87,7 @@ public: css::uno::Reference< css::uno::XComponentContext > m_xContext; ModuleToCommandFileMap m_aModuleToCommandFileMap; UICommandsHashMap m_aUICommandsHashMap; + UICommandsHashMap m_aWrapCommandsHashMap; css::uno::Reference< css::container::XNameAccess > m_xGenericUICommands; css::uno::Reference< css::frame::XModuleManager2 > m_xModuleManager; }; diff --git a/framework/source/uielement/uicommanddescription.cxx b/framework/source/uielement/uicommanddescription.cxx index bd199b6891b1..b50738db1cb0 100644 --- a/framework/source/uielement/uicommanddescription.cxx +++ b/framework/source/uielement/uicommanddescription.cxx @@ -26,16 +26,19 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -60,12 +63,13 @@ const sal_Int32 COMMAND_PROPERTY_MIRROR = 4; namespace framework { - +class UICommandWrapper; // Configuration access class for PopupMenuControllerFactory implementation class ConfigurationAccess_UICommand : // Order is necessary for right initialization! public ::cppu::WeakImplHelper { + friend class UICommandWrapper; osl::Mutex m_aMutex; public: ConfigurationAccess_UICommand( const OUString& aModuleName, const Reference< XNameAccess >& xGenericUICommands, const Reference< XComponentContext >& rxContext ); @@ -122,12 +126,15 @@ class ConfigurationAccess_UICommand : // Order is necessary for right initializa void impl_fill(const Reference< XNameAccess >& _xConfigAccess,bool _bPopup, std::vector< OUString >& aImageCommandVector, std::vector< OUString >& aImageRotateVector, - std::vector< OUString >& aImageMirrorVector); + std::vector< OUString >& aImageMirrorVector, + const OUString& rMainCommand = OUString(), + CmdToInfoMap* pCmdInfo = nullptr); private: typedef std::unordered_map< OUString, CmdToInfoMap > CommandToInfoCache; - + typedef std::unordered_map< OUString, + std::unordered_map< OUString, CmdToInfoMap > > CommandContextsCache; void initializeConfigAccess(); OUString m_aConfigCmdAccess; @@ -156,13 +163,68 @@ class ConfigurationAccess_UICommand : // Order is necessary for right initializa Sequence< OUString > m_aCommandImageList; Sequence< OUString > m_aCommandRotateImageList; Sequence< OUString > m_aCommandMirrorImageList; - CommandToInfoCache m_aCmdInfoCache; + CommandToInfoCache m_aCmdInfoCache; + CommandContextsCache m_aAliasesCache; bool m_bConfigAccessInitialized; bool m_bCacheFilled; bool m_bGenericDataRetrieved; }; -// XInterface, XTypeProvider +class UICommandWrapper : public ::cppu::WeakImplHelper +{ +public: + UICommandWrapper( const OUString& rModuleName, ConfigurationAccess_UICommand* rUICommands ) : + aModuleName( rModuleName ), aUICommands( rUICommands ) {} + + // XElementAccess + css::uno::Type SAL_CALL getElementType() override + { + return aUICommands->getElementType(); + } + sal_Bool SAL_CALL hasElements() override + { + return aUICommands->hasElements(); + } + + // XNameAccess + css::uno::Any SAL_CALL getByName( const OUString& aName ) override + { + const auto& item = aUICommands->m_aAliasesCache.find(aName); + if (item != aUICommands->m_aAliasesCache.end()) + { + const auto& iitem = item->second.find(aModuleName); + if (iitem != item->second.end() ) + { + if ( !iitem->second.bCommandNameCreated ) + aUICommands->fillInfoFromResult( iitem->second, iitem->second.aLabel ); + + return Any( comphelper::InitPropertySequence( { + { aUICommands->m_aPropLabel, makeAny( !iitem->second.aContextLabel.isEmpty() ? + iitem->second.aContextLabel : iitem->second.aLabel ) }, + { aUICommands->m_aPropName, makeAny( iitem->second.aCommandName ) }, + { aUICommands->m_aPropPopup, makeAny( iitem->second.bPopup ) }, + { aUICommands->m_aPropProperties, makeAny( iitem->second.nProperties ) }, + { aUICommands->m_aPropPopupLabel, makeAny( iitem->second.aPopupLabel ) }, + { aUICommands->m_aPropTooltipLabel, makeAny( iitem->second.aTooltipLabel ) }, + { aUICommands->m_aPropIsExperimental, makeAny( iitem->second.bIsExperimental ) }, + } ) ); + } + } + return aUICommands->getByName( aName ); + } + css::uno::Sequence< OUString > SAL_CALL getElementNames() override + { + return aUICommands->getElementNames(); + } + sal_Bool SAL_CALL hasByName( const OUString& aName ) override + { + return aUICommands->hasByName( aName ); + } + +private: + OUString aModuleName; + rtl::Reference< ConfigurationAccess_UICommand > aUICommands; +}; ConfigurationAccess_UICommand::ConfigurationAccess_UICommand( const OUString& aModuleName, const Reference< XNameAccess >& rGenericUICommands, const Reference< XComponentContext>& rxContext ) : m_aConfigCmdAccess( CONFIGURATION_ROOT_ACCESS ), @@ -317,10 +379,15 @@ Any ConfigurationAccess_UICommand::getSequenceFromCache( const OUString& aComman void ConfigurationAccess_UICommand::impl_fill(const Reference< XNameAccess >& _xConfigAccess,bool _bPopup, std::vector< OUString >& aImageCommandVector, std::vector< OUString >& aImageRotateVector, - std::vector< OUString >& aImageMirrorVector) + std::vector< OUString >& aImageMirrorVector, + const OUString& rMainCommand, CmdToInfoMap* pCmdInfo) { if ( _xConfigAccess.is() ) { + Reference< XNameAccess > xUIDesc; + if ( !rMainCommand.isEmpty() ) + xUIDesc = css::frame::theUICommandDescription::get(comphelper::getProcessComponentContext()); + Sequence< OUString> aNameSeq = _xConfigAccess->getElementNames(); const sal_Int32 nCount = aNameSeq.getLength(); for ( sal_Int32 i = 0; i < nCount; i++ ) @@ -331,6 +398,12 @@ void ConfigurationAccess_UICommand::impl_fill(const Reference< XNameAccess >& _x if ( xNameAccess.is() ) { CmdToInfoMap aCmdToInfo; + if ( pCmdInfo ) + { + aCmdToInfo.bIsExperimental = pCmdInfo->bIsExperimental; + aCmdToInfo.nProperties = pCmdInfo->nProperties; + aCmdToInfo.aTargetURL = rMainCommand; + } aCmdToInfo.bPopup = _bPopup; xNameAccess->getByName( m_aPropUILabel ) >>= aCmdToInfo.aLabel; @@ -341,14 +414,25 @@ void ConfigurationAccess_UICommand::impl_fill(const Reference< XNameAccess >& _x xNameAccess->getByName( m_aPropUIIsExperimental ) >>= aCmdToInfo.bIsExperimental; xNameAccess->getByName( m_aPropProperties ) >>= aCmdToInfo.nProperties; - m_aCmdInfoCache.emplace( aNameSeq[i], aCmdToInfo ); + if ( xUIDesc.is() && xUIDesc->hasByName( aNameSeq[i]) ) + { + m_aAliasesCache[rMainCommand][aNameSeq[i]] = aCmdToInfo; + continue; + } + + Reference< XNameAccess > xContextNameAccess; + xNameAccess->getByName( "Contexts" ) >>= xContextNameAccess; + impl_fill( xContextNameAccess, _bPopup, aImageCommandVector, aImageRotateVector, aImageMirrorVector, aNameSeq[i], &aCmdToInfo ); + + const OUString aCommandName( rMainCommand.isEmpty() ? aNameSeq[i] : rMainCommand + "-" + aNameSeq[i] ); + m_aCmdInfoCache.emplace( aCommandName, aCmdToInfo ); if ( aCmdToInfo.nProperties & COMMAND_PROPERTY_IMAGE ) - aImageCommandVector.push_back( aNameSeq[i] ); + aImageCommandVector.push_back( aCommandName ); if ( aCmdToInfo.nProperties & COMMAND_PROPERTY_ROTATE ) - aImageRotateVector.push_back( aNameSeq[i] ); + aImageRotateVector.push_back( aCommandName ); if ( aCmdToInfo.nProperties & COMMAND_PROPERTY_MIRROR ) - aImageMirrorVector.push_back( aNameSeq[i] ); + aImageMirrorVector.push_back( aCommandName ); } } catch (const css::lang::WrappedTargetException&) @@ -654,6 +738,13 @@ Any SAL_CALL UICommandDescription::getByName( const OUString& aName ) osl::MutexGuard g(rBHelper.rMutex); + UICommandsHashMap::iterator pWrapIter = m_aWrapCommandsHashMap.find( aName ); + if ( pWrapIter != m_aWrapCommandsHashMap.end() ) + { + a <<= pWrapIter->second; + return a; + } + ModuleToCommandFileMap::const_iterator pM2CIter = m_aModuleToCommandFileMap.find( aName ); if ( pM2CIter != m_aModuleToCommandFileMap.end() ) { @@ -661,18 +752,13 @@ Any SAL_CALL UICommandDescription::getByName( const OUString& aName ) UICommandsHashMap::iterator pIter = m_aUICommandsHashMap.find( aCommandFile ); if ( pIter != m_aUICommandsHashMap.end() ) { - if ( pIter->second.is() ) - a <<= pIter->second; - else - { - Reference< XNameAccess > xUICommands; - ConfigurationAccess_UICommand* pUICommands = new ConfigurationAccess_UICommand( aCommandFile, - m_xGenericUICommands, - m_xContext ); - xUICommands.set( static_cast< cppu::OWeakObject* >( pUICommands ),UNO_QUERY ); - pIter->second = xUICommands; - a <<= xUICommands; - } + if ( !pIter->second.is() ) + pIter->second.set( new ConfigurationAccess_UICommand( aCommandFile, m_xGenericUICommands, m_xContext ) ); + + ConfigurationAccess_UICommand* pUICommands = static_cast< ConfigurationAccess_UICommand* >( pIter->second.get() ); + Reference< XNameAccess > xUICommands( new UICommandWrapper( aName, pUICommands ) ); + m_aWrapCommandsHashMap.emplace( aName, xUICommands ); + a <<= xUICommands; } } else if ( !m_aPrivateResourceURL.isEmpty() && aName.startsWith( m_aPrivateResourceURL ) ) diff --git a/icon-themes/tango/links.txt b/icon-themes/tango/links.txt index e73922a59a92..d84df38b50cd 100644 --- a/icon-themes/tango/links.txt +++ b/icon-themes/tango/links.txt @@ -558,7 +558,6 @@ cmd/lc_mailmergepreventry.png cmd/lc_prevrecord.png cmd/sc_mailmergepreventry.png cmd/sc_prevrecord.png # Slide command aliases -cmd/lc_insertslide.png cmd/lc_insertpage.png cmd/lc_duplicateslide.png cmd/lc_duplicatepage.png cmd/lc_deleteslide.png cmd/lc_deletepage.png cmd/lc_moveslidefirst.png cmd/lc_movepagefirst.png @@ -624,3 +623,4 @@ cmd/sc_formatframemenu.png cmd/sc_inserttextframe.png cmd/lc_charmapcontrol.png cmd/lc_insertsymbol.png cmd/sc_charmapcontrol.png cmd/sc_insertsymbol.png +cmd/lc_adddirect-toolbar.png cmd/lc_adddirect.png diff --git a/officecfg/registry/data/org/openoffice/Office/UI/DrawImpressCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/DrawImpressCommands.xcu index 03f2f4ce606c..6339d3cc9d15 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/DrawImpressCommands.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/DrawImpressCommands.xcu @@ -695,17 +695,13 @@ 1 - - - - ~New Slide - - - .uno:InsertPage - - - 1 - + + + + ~New Slide + + + diff --git a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu index 69ee7b984ae9..c4ec1252e88b 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu @@ -2743,6 +2743,21 @@ 1 + + + + toolbar label + + + 1 + + + + + another label + + + diff --git a/officecfg/registry/schema/org/openoffice/Office/UI/Commands.xcs b/officecfg/registry/schema/org/openoffice/Office/UI/Commands.xcs index b82a25ac835a..a4bed8d399e1 100644 --- a/officecfg/registry/schema/org/openoffice/Office/UI/Commands.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/UI/Commands.xcs @@ -26,6 +26,11 @@ Provides a mapping between commands and their textual representation on the user interface. + + + aliases + + A localized text that describes the command. Will be used instead of ContextLabel, PopupLabel and TooltipLabel if those are not specified. diff --git a/sd/uiconfig/simpress/menubar/menubar.xml b/sd/uiconfig/simpress/menubar/menubar.xml index 0de1b9dadd42..63e1397b9f2b 100644 --- a/sd/uiconfig/simpress/menubar/menubar.xml +++ b/sd/uiconfig/simpress/menubar/menubar.xml @@ -483,7 +483,7 @@ - + diff --git a/sd/uiconfig/simpress/toolbar/commontaskbar.xml b/sd/uiconfig/simpress/toolbar/commontaskbar.xml index 9df003a0e0dc..73999372725a 100644 --- a/sd/uiconfig/simpress/toolbar/commontaskbar.xml +++ b/sd/uiconfig/simpress/toolbar/commontaskbar.xml @@ -18,7 +18,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - + diff --git a/sw/uiconfig/swriter/menubar/menubar.xml b/sw/uiconfig/swriter/menubar/menubar.xml index a87ff5fea7f0..c875513fb891 100644 --- a/sw/uiconfig/swriter/menubar/menubar.xml +++ b/sw/uiconfig/swriter/menubar/menubar.xml @@ -19,7 +19,7 @@ - + diff --git a/sw/uiconfig/swriter/toolbar/standardbar.xml b/sw/uiconfig/swriter/toolbar/standardbar.xml index 10c5b6edf05b..37102d61d6b6 100644 --- a/sw/uiconfig/swriter/toolbar/standardbar.xml +++ b/sw/uiconfig/swriter/toolbar/standardbar.xml @@ -19,7 +19,7 @@ --> - + -- 2.14.3