diff options
author | Susobhan Ghosh <susobhang70@gmail.com> | 2016-03-05 01:48:55 +0530 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2016-03-14 13:48:26 +0000 |
commit | bf8f926acc8afd6a2dcd2b889d427c01e06dbf85 (patch) | |
tree | 693384f87178cbe142b7fe8df3bdfc72a162293d | |
parent | 0ee0e8010f986b67d696111ff4ea269ccf904aba (diff) |
tdf#95845 Use CommandInfoProvider to receive UNO command labels
Added GetCommandPropertyFromModule to CommandInfoProvider.
Removed GetCommandText.
Change-Id: Ie987984b6465d540029196df371c0c0467999a59
Reviewed-on: https://gerrit.libreoffice.org/22918
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
-rw-r--r-- | dbaccess/source/ui/control/opendoccontrols.cxx | 52 | ||||
-rw-r--r-- | include/vcl/commandinfoprovider.hxx | 2 | ||||
-rw-r--r-- | vcl/source/helper/commandinfoprovider.cxx | 33 |
3 files changed, 37 insertions, 50 deletions
diff --git a/dbaccess/source/ui/control/opendoccontrols.cxx b/dbaccess/source/ui/control/opendoccontrols.cxx index caa0e1c6049d..1e5db4be08e6 100644 --- a/dbaccess/source/ui/control/opendoccontrols.cxx +++ b/dbaccess/source/ui/control/opendoccontrols.cxx @@ -32,6 +32,7 @@ #include <comphelper/processfactory.hxx> #include <vcl/graph.hxx> #include <vcl/help.hxx> +#include <vcl/commandinfoprovider.hxx> #include <unotools/historyoptions.hxx> #include <comphelper/sequenceashashmap.hxx> #include <tools/urlobj.hxx> @@ -59,55 +60,6 @@ namespace dbaui using ::com::sun::star::frame::theUICommandDescription; using ::com::sun::star::graphic::XGraphic; - OUString GetCommandText( const sal_Char* _pCommandURL, const OUString& _rModuleName ) - { - OUString sLabel; - if ( !_pCommandURL || !*_pCommandURL ) - return sLabel; - - Reference< XNameAccess > xUICommandLabels; - OUString sCommandURL = OUString::createFromAscii( _pCommandURL ); - - try - { - do - { - // Retrieve popup menu labels - Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() ); - if ( !xContext.is() ) - break; - - Reference< XNameAccess> xNameAccess( theUICommandDescription::get(xContext) ); - - xNameAccess->getByName( _rModuleName ) >>= xUICommandLabels; - if ( !xUICommandLabels.is() ) - break; - - Sequence< PropertyValue > aProperties; - if ( !( xUICommandLabels->getByName(sCommandURL) >>= aProperties ) ) - break; - - sal_Int32 nCount( aProperties.getLength() ); - for ( sal_Int32 i=0; i<nCount; ++i ) - { - OUString sPropertyName( aProperties[i].Name ); - if ( sPropertyName == "Label" ) - { - aProperties[i].Value >>= sLabel; - break; - } - } - } - while ( false ); - } - catch( Exception& rException ) - { - (void)rException; - } - - return sLabel; - } - Image GetCommandIcon( const sal_Char* _pCommandURL, const OUString& _rModuleName ) { Image aIcon; @@ -170,7 +122,7 @@ namespace dbaui m_sModule = OUString::createFromAscii( _pAsciiModuleName ); // our label should equal the UI text of the "Open" command - OUString sLabel(GetCommandText(".uno:Open", m_sModule)); + OUString sLabel(vcl::CommandInfoProvider::Instance().GetCommandPropertyFromModule(".uno:Open", m_sModule)); SetText(" " + sLabel.replaceAll("~", "")); // Place icon left of text and both centered in the button. diff --git a/include/vcl/commandinfoprovider.hxx b/include/vcl/commandinfoprovider.hxx index 29a9bf8f3c0f..67a7ab3f5e22 100644 --- a/include/vcl/commandinfoprovider.hxx +++ b/include/vcl/commandinfoprovider.hxx @@ -87,6 +87,8 @@ public: OUString GetRealCommandForCommand( const OUString& rCommandName, const css::uno::Reference<css::frame::XFrame>& rxFrame ); + OUString GetCommandPropertyFromModule( const sal_Char* pCommandURL, const OUString& rModuleName ); + Image GetImageForCommand( const OUString& rsCommandName, bool bLarge, diff --git a/vcl/source/helper/commandinfoprovider.cxx b/vcl/source/helper/commandinfoprovider.cxx index 121aacfeda17..c878a94323bc 100644 --- a/vcl/source/helper/commandinfoprovider.cxx +++ b/vcl/source/helper/commandinfoprovider.cxx @@ -477,6 +477,39 @@ OUString CommandInfoProvider::GetCommandProperty(const OUString& rsProperty, con return OUString(); } +OUString CommandInfoProvider::GetCommandPropertyFromModule( const sal_Char* pCommandURL, const OUString& rModuleName ) +{ + OUString sLabel; + if ( !pCommandURL || !*pCommandURL ) + return sLabel; + + Sequence<beans::PropertyValue> aProperties; + OUString sCommandURL = OUString::createFromAscii( pCommandURL ); + try + { + if( rModuleName.getLength() > 0) + { + Reference<container::XNameAccess> xNameAccess = frame::theUICommandDescription::get(mxContext); + Reference<container::XNameAccess> xUICommandLabels; + if (xNameAccess->getByName( rModuleName ) >>= xUICommandLabels ) + xUICommandLabels->getByName(sCommandURL) >>= aProperties; + + for (sal_Int32 nIndex=0; nIndex<aProperties.getLength(); ++nIndex) + { + if(aProperties[nIndex].Name == "Label") + { + aProperties[nIndex].Value >>= sLabel; + return sLabel; + } + } + } + } + catch (Exception&) + { + } + return OUString(); +} + vcl::KeyCode CommandInfoProvider::AWTKey2VCLKey(const awt::KeyEvent& aAWTKey) { bool bShift = ((aAWTKey.Modifiers & awt::KeyModifier::SHIFT) == awt::KeyModifier::SHIFT ); |