diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2015-11-11 22:40:58 +0200 |
---|---|---|
committer | Maxim Monastirsky <momonasmon@gmail.com> | 2015-11-11 22:48:51 +0200 |
commit | 318c3a48c66dd4ceba801ef410f89b8bf900d5c7 (patch) | |
tree | 28da31161ac5a4c7f84193495a25c00fd2b539bf | |
parent | 5c6119eeaaaed322c884504a53bb558258233fe9 (diff) |
tdf#93837 Support nice UI names for context menus
Can be configured in various *WindowState.xcu files,
like toolbars.
Change-Id: I55a827344f03b31491cb793b9b211b59ff92287c
-rw-r--r-- | cui/source/customize/cfg.cxx | 43 | ||||
-rw-r--r-- | cui/source/inc/cfg.hxx | 2 |
2 files changed, 41 insertions, 4 deletions
diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx index 94912286a906..c7aeb29eeafe 100644 --- a/cui/source/customize/cfg.cxx +++ b/cui/source/customize/cfg.cxx @@ -1351,12 +1351,40 @@ ContextMenuSaveInData::ContextMenuSaveInData( const OUString& aModuleId, bool bIsDocConfig ) : SaveInData( xCfgMgr, xParentCfgMgr, aModuleId, bIsDocConfig ) { + css::uno::Reference< css::uno::XComponentContext > xContext( comphelper::getProcessComponentContext() ); + css::uno::Reference< css::container::XNameAccess > xConfig( css::ui::theWindowStateConfiguration::get( xContext ) ); + xConfig->getByName( aModuleId ) >>= m_xPersistentWindowState; } ContextMenuSaveInData::~ContextMenuSaveInData() { } +OUString ContextMenuSaveInData::GetUIName( const OUString& rResourceURL ) +{ + if ( m_xPersistentWindowState.is() ) + { + css::uno::Sequence< css::beans::PropertyValue > aProps; + try + { + m_xPersistentWindowState->getByName( rResourceURL ) >>= aProps; + } + catch ( const css::uno::Exception& ) + {} + + for ( const auto& aProp : aProps ) + { + if ( aProp.Name == ITEM_DESCRIPTOR_UINAME ) + { + OUString aResult; + aProp.Value >>= aResult; + return aResult; + } + } + } + return OUString(); +} + SvxEntries* ContextMenuSaveInData::GetEntries() { if ( !m_pRootEntry ) @@ -1393,14 +1421,17 @@ SvxEntries* ContextMenuSaveInData::GetEntries() if ( xPopupMenu.is() ) { OUString aMenuName = aUrl.copy( aUrl.lastIndexOf( '/' ) + 1 ); + OUString aUIMenuName = GetUIName( aUrl ); + if ( aUIMenuName.isEmpty() ) + aUIMenuName = aMenuName; // insert into std::unordered_map to filter duplicates from the parent aMenuInfo.insert( MenuInfo::value_type( aMenuName, true ) ); - SvxConfigEntry* pEntry = new SvxConfigEntry( aMenuName, aUrl, true ); + SvxConfigEntry* pEntry = new SvxConfigEntry( aUIMenuName, aUrl, true ); pEntry->SetMain(); m_pRootEntry->GetEntries()->push_back( pEntry ); - LoadSubMenus( xPopupMenu, aMenuName, pEntry ); + LoadSubMenus( xPopupMenu, aUIMenuName, pEntry ); } } @@ -1438,10 +1469,14 @@ SvxEntries* ContextMenuSaveInData::GetEntries() if ( xPopupMenu.is() ) { - SvxConfigEntry* pEntry = new SvxConfigEntry( aMenuName, aUrl, true, true ); + OUString aUIMenuName = GetUIName( aUrl ); + if ( aUIMenuName.isEmpty() ) + aUIMenuName = aMenuName; + + SvxConfigEntry* pEntry = new SvxConfigEntry( aUIMenuName, aUrl, true, true ); pEntry->SetMain(); m_pRootEntry->GetEntries()->push_back( pEntry ); - LoadSubMenus( xPopupMenu, aMenuName, pEntry ); + LoadSubMenus( xPopupMenu, aUIMenuName, pEntry ); } } std::sort( m_pRootEntry->GetEntries()->begin(), m_pRootEntry->GetEntries()->end(), EntrySort ); diff --git a/cui/source/inc/cfg.hxx b/cui/source/inc/cfg.hxx index 9066bad31a56..1ea1a986e0ed 100644 --- a/cui/source/inc/cfg.hxx +++ b/cui/source/inc/cfg.hxx @@ -204,6 +204,8 @@ class ContextMenuSaveInData : public SaveInData { private: std::unique_ptr< SvxConfigEntry > m_pRootEntry; + css::uno::Reference< css::container::XNameAccess > m_xPersistentWindowState; + OUString GetUIName( const OUString& rResourceURL ); public: ContextMenuSaveInData( |