30#include <com/sun/star/beans/PropertyValue.hpp>
31#include <com/sun/star/frame/ModuleManager.hpp>
32#include <com/sun/star/configuration/theDefaultProvider.hpp>
33#include <com/sun/star/container/XNameAccess.hpp>
34#include <com/sun/star/container/XContainer.hpp>
71class ConfigurationAccess_UICommand :
72 public ::cppu::WeakImplHelper<XNameAccess,XContainerListener>
77 virtual ~ConfigurationAccess_UICommand()
override;
80 virtual css::uno::Any SAL_CALL getByName(
const OUString& aName )
override;
82 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames()
override;
84 virtual sal_Bool SAL_CALL hasByName(
const OUString& aName )
override;
87 virtual css::uno::Type SAL_CALL getElementType()
override;
89 virtual sal_Bool SAL_CALL hasElements()
override;
92 virtual void SAL_CALL
elementInserted(
const ContainerEvent& aEvent )
override;
93 virtual void SAL_CALL
elementRemoved (
const ContainerEvent& aEvent )
override;
94 virtual void SAL_CALL
elementReplaced(
const ContainerEvent& aEvent )
override;
97 virtual void SAL_CALL disposing(
const EventObject& aEvent )
override;
100 css::uno::Any getByNameImpl(
const OUString& aName );
104 CmdToInfoMap() :
bPopup( false ),
121 Any getSequenceFromCache(
const OUString& aCommandURL );
122 Any getInfoFromCommand(
const OUString& rCommandURL );
123 void fillInfoFromResult( CmdToInfoMap& rCmdInfo,
const OUString&
aLabel );
126 void addGenericInfoToCache();
128 std::vector< OUString >& aImageCommandVector,
129 std::vector< OUString >& aImageRotateVector,
130 std::vector< OUString >& aImageMirrorVector);
133 typedef std::unordered_map< OUString,
134 CmdToInfoMap > CommandToInfoCache;
136 void initializeConfigAccess();
176ConfigurationAccess_UICommand::~ConfigurationAccess_UICommand()
181 if ( xContainer.is() )
184 if ( xContainer.is() )
189Any ConfigurationAccess_UICommand::getByNameImpl(
const OUString& rCommandURL )
194 initializeConfigAccess();
203 addGenericInfoToCache();
217 return getInfoFromCommand( rCommandURL );
221Any SAL_CALL ConfigurationAccess_UICommand::getByName(
const OUString& rCommandURL )
223 Any aRet( getByNameImpl( rCommandURL ) );
224 if( !aRet.hasValue() )
225 throw NoSuchElementException();
232 return getAllCommands();
235sal_Bool SAL_CALL ConfigurationAccess_UICommand::hasByName(
const OUString& rCommandURL )
237 return getByNameImpl( rCommandURL ).hasValue();
241Type SAL_CALL ConfigurationAccess_UICommand::getElementType()
246sal_Bool SAL_CALL ConfigurationAccess_UICommand::hasElements()
252void ConfigurationAccess_UICommand::fillInfoFromResult( CmdToInfoMap& rCmdInfo,
const OUString&
aLabel )
255 rCmdInfo.aLabel =
aStr;
258 rCmdInfo.bCommandNameCreated =
true;
261Any ConfigurationAccess_UICommand::getSequenceFromCache(
const OUString& aCommandURL )
263 CommandToInfoCache::iterator pIter =
m_aCmdInfoCache.find( aCommandURL );
266 if ( !pIter->second.bCommandNameCreated )
267 fillInfoFromResult( pIter->second, pIter->second.aLabel );
269 static constexpr OUStringLiteral sLabel =
u"Label";
270 static constexpr OUStringLiteral
sName =
u"Name";
271 static constexpr OUStringLiteral sPopup =
u"Popup";
272 static constexpr OUStringLiteral sPopupLabel =
u"PopupLabel";
273 static constexpr OUStringLiteral sTooltipLabel =
u"TooltipLabel";
274 static constexpr OUStringLiteral sTargetURL =
u"TargetURL";
275 static constexpr OUStringLiteral sIsExperimental =
u"IsExperimental";
278 ?
Any(pIter->second.aContextLabel)
279 :
Any(pIter->second.aLabel)),
288 return Any( aPropSeq );
294 std::vector< OUString >& aImageCommandVector,
295 std::vector< OUString >& aImageRotateVector,
296 std::vector< OUString >& aImageMirrorVector)
298 if ( !_xConfigAccess.is() )
302 const sal_Int32
nCount = aNameSeq.getLength();
303 for ( sal_Int32 i = 0;
i <
nCount;
i++ )
308 if ( xNameAccess.is() )
310 CmdToInfoMap aCmdToInfo;
312 aCmdToInfo.bPopup = _bPopup;
313 xNameAccess->getByName(
"Label" ) >>= aCmdToInfo.aLabel;
314 xNameAccess->getByName(
"ContextLabel" ) >>= aCmdToInfo.aContextLabel;
315 xNameAccess->getByName(
"PopupLabel" ) >>= aCmdToInfo.aPopupLabel;
316 xNameAccess->getByName(
"TooltipLabel" ) >>= aCmdToInfo.aTooltipLabel;
317 xNameAccess->getByName(
"TargetURL" ) >>= aCmdToInfo.aTargetURL;
318 xNameAccess->getByName(
"IsExperimental" ) >>= aCmdToInfo.bIsExperimental;
324 aImageCommandVector.push_back( aNameSeq[i] );
326 aImageRotateVector.push_back( aNameSeq[i] );
328 aImageMirrorVector.push_back( aNameSeq[i] );
331 catch (
const css::lang::WrappedTargetException&)
334 catch (
const css::container::NoSuchElementException&)
339void ConfigurationAccess_UICommand::fillCache()
345 std::vector< OUString > aImageCommandVector;
346 std::vector< OUString > aImageRotateVector;
347 std::vector< OUString > aImageMirrorVector;
349 impl_fill(
m_xConfigAccess,
false,aImageCommandVector,aImageRotateVector,aImageMirrorVector);
359void ConfigurationAccess_UICommand::addGenericInfoToCache()
375 catch (
const Exception&)
389 catch (
const Exception&)
396Any ConfigurationAccess_UICommand::getInfoFromCommand(
const OUString& rCommandURL )
402 a = getSequenceFromCache( rCommandURL );
413 catch (
const css::lang::WrappedTargetException&)
416 catch (
const css::container::NoSuchElementException&)
422 catch (
const css::container::NoSuchElementException&)
425 catch (
const css::lang::WrappedTargetException&)
439 initializeConfigAccess();
454 sal_uInt32 nCount1 = aNameSeq.getLength();
455 sal_uInt32 nCount2 = aGenericNameSeq.getLength();
457 aNameSeq.realloc( nCount1 + nCount2 );
458 OUString* pNameSeq = aNameSeq.getArray();
459 const OUString* pGenericSeq = aGenericNameSeq.getConstArray();
460 for ( sal_uInt32 i = 0;
i < nCount2;
i++ )
461 pNameSeq[nCount1+i] = pGenericSeq[i];
466 catch (
const css::container::NoSuchElementException&)
469 catch (
const css::lang::WrappedTargetException&)
477void ConfigurationAccess_UICommand::initializeConfigAccess()
486 "com.sun.star.configuration.ConfigurationAccess", aArgs ),UNO_QUERY );
491 if ( xContainer.is() )
503 "com.sun.star.configuration.ConfigurationAccess", aArgs2 ),UNO_QUERY );
508 if ( xContainer.is() )
515 catch (
const WrappedTargetException&)
518 catch (
const Exception&)
524void SAL_CALL ConfigurationAccess_UICommand::elementInserted(
const ContainerEvent& )
531void SAL_CALL ConfigurationAccess_UICommand::elementRemoved(
const ContainerEvent& )
538void SAL_CALL ConfigurationAccess_UICommand::elementReplaced(
const ContainerEvent& )
546void SAL_CALL ConfigurationAccess_UICommand::disposing(
const EventObject& aEvent )
554 if ( xIfac1 == xIfac2 )
559 if ( xIfac1 == xIfac2 )
564void UICommandDescription::ensureGenericUICommandsForLanguage(
const LanguageTag& rLanguage)
587 UICommandsHashMap::iterator pIter = rMap.find(
"GenericCommands" );
588 if ( pIter != rMap.end() )
611 for ( OUString
const & aModuleIdentifier : aElementNames )
616 OUString aCommandStr;
617 for ( PropertyValue
const & prop : std::as_const(
aSeq) )
619 if ( prop.Name.equalsAscii(_pName) )
621 prop.Value >>= aCommandStr;
632 UICommandsHashMap::iterator pIter = rMap.find( aCommandStr );
633 if ( pIter == rMap.end() )
650 OUString aCommandFile( pM2CIter->second );
656 UICommandsHashMap::iterator pIter = rMap.find( aCommandFile );
657 if ( pIter != rMap.end() )
659 if ( pIter->second.is() )
668 pIter->second = xUICommands;
682 throw NoSuchElementException();
717extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
719 css::uno::XComponentContext *context,
720 css::uno::Sequence<css::uno::Any>
const &)
static OUString EraseAllMnemonicChars(const OUString &rStr)
const LanguageTag & GetUILanguageTag() const
css::uno::Type const & get()
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual sal_Bool SAL_CALL hasElements() override
ModuleToCommandFileMap m_aModuleToCommandFileMap
UICommandDescription(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
std::map< LanguageTag, css::uno::Reference< css::container::XNameAccess > > m_xGenericUICommands
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
OUString m_aPrivateResourceURL
css::uno::Reference< css::frame::XModuleManager2 > m_xModuleManager
virtual ~UICommandDescription() override
void impl_fillElements(const char *_pName)
std::map< LanguageTag, UICommandsHashMap > m_aUICommandsHashMap
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
void ensureGenericUICommandsForLanguage(const LanguageTag &rLanguage)
static OUString getProductName()
css::uno::Reference< css::uno::XComponentContext > m_xContext
void SAL_CALL elementReplaced(const css::container::ContainerEvent &Event) override
void SAL_CALL elementRemoved(const css::container::ContainerEvent &Event) override
DECL_LISTENERMULTIPLEXER_END void SAL_CALL elementInserted(const css::container::ContainerEvent &Event) override
Sequence< sal_Int8 > aSeq
OString stripEnd(const OString &rIn, char c)
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
constexpr OUStringLiteral UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDIMAGELIST
properties for "UICommandDescription" class
constexpr OUStringLiteral UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDMIRRORIMAGELIST
constexpr OUStringLiteral UICOMMANDDESCRIPTION_NAMEACCESS_COMMANDROTATEIMAGELIST
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
Reference< XMultiServiceFactory > m_xConfigProvider
Sequence< OUString > m_aCommandMirrorImageList
Reference< XNameAccess > m_xConfigAccessPopups
CommandToInfoCache m_aCmdInfoCache
Sequence< OUString > m_aCommandImageList
const sal_Int32 COMMAND_PROPERTY_ROTATE
Reference< XContainerListener > m_xConfigAccessListener
Reference< XNameAccess > m_xGenericUICommands
bool m_bGenericDataRetrieved
const char CONFIGURATION_ROOT_ACCESS[]
OUString m_aConfigPopupAccess
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_framework_UICommandDescription_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Reference< XContainerListener > m_xConfigListener
OUString m_aPropProperties
Sequence< OUString > m_aCommandRotateImageList
bool m_bConfigAccessInitialized
OUString m_aConfigCmdAccess
Reference< XNameAccess > m_xConfigAccess
const sal_Int32 COMMAND_PROPERTY_IMAGE
constexpr OUStringLiteral PRIVATE_RESOURCE_URL
const sal_Int32 COMMAND_PROPERTY_MIRROR