22#include <com/sun/star/uno/XInterface.hpp>
23#include <com/sun/star/beans/XPropertySet.hpp>
24#include <com/sun/star/frame/XDispatchInformationProvider.hpp>
25#include <com/sun/star/frame/theUICommandDescription.hpp>
26#include <com/sun/star/ui/theUICategoryDescription.hpp>
27#include <com/sun/star/script/browse/XBrowseNode.hpp>
28#include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
29#include <com/sun/star/script/browse/theBrowseNodeFactory.hpp>
30#include <com/sun/star/script/browse/BrowseNodeFactoryViewTypes.hpp>
36#include <com/sun/star/util/SearchFlags.hpp>
37#include <com/sun/star/util/SearchAlgorithms2.hpp>
47#include <officecfg/Office/Common.hxx>
55 : pStylesInfo(nullptr)
62 | css::util::SearchFlags::REG_NOT_ENDOFLINE);
79 OUString* pScriptURI =
static_cast<OUString*
>(It->pObject);
84 css::uno::XInterface* xi =
static_cast<css::uno::XInterface*
>(It->pObject);
97 const css::uno::Reference<css::frame::XFrame>& xFrame,
98 const OUString& sModuleLongName)
110 css::uno::UNO_QUERY_THROW);
114 css::uno::Reference<css::frame::XController>
xController;
115 css::uno::Reference<css::frame::XModel>
xModel;
126 css::uno::Reference<css::frame::XDispatchInformationProvider> xProvider(
127 m_xFrame, css::uno::UNO_QUERY_THROW);
128 css::uno::Sequence<sal_Int16> lGroups = xProvider->getSupportedCommandGroups();
130 sal_Int32 nGroupsLength = lGroups.getLength();
132 if (nGroupsLength > 0)
144 typedef std::pair<OUString, sal_Int16> str_id;
145 std::vector<str_id> aCategories;
148 for (sal_Int32
i = 0;
i < nGroupsLength; ++
i)
150 sal_Int16 nGroupID = lGroups[
i];
151 OUString sGroupID = OUString::number(nGroupID);
157 if (sGroupName.isEmpty())
160 catch (
const css::container::NoSuchElementException&)
164 aCategories.emplace_back(std::make_pair(sGroupName, nGroupID));
171 std::sort(aCategories.begin(), aCategories.end(),
172 [&sort](
const str_id&
a,
const str_id& b) {
173 return sort.compare(a.first, b.first) < 0;
177 for (
const auto&
a : aCategories)
179 const OUString& rGroupName =
a.first;
180 sal_Int16 nGroupID =
a.second;
201 catch (
const css::uno::RuntimeException&)
205 catch (
const css::uno::Exception&)
215 const css::uno::Sequence<css::frame::DispatchInformation>& xCommands,
222 const bool bInExperimentalMode = officecfg::Office::Common::Misc::ExperimentalMode::get();
224 for (
const auto& rInfo : xCommands)
231 OUString sTooltipLabel
234 .replaceFirst(
"~",
"");
242 if (bHideExperimental
243 || (!filterTerm.isEmpty() && !textSearch.
searchForward(sUIName)
250 css::uno::Reference<css::graphic::XGraphic> xImage;
251 if (pCurrentSaveInData)
252 xImage = pCurrentSaveInData->
GetImage(rInfo.Command);
257 pGrpInfo->
sLabel = sUIName;
268 css::uno::Reference<css::container::XNameAccess> xModuleConf;
270 if (xModuleConf.is())
276 catch (
const css::uno::RuntimeException&)
280 catch (css::uno::Exception&)
286 if (sUIName.isEmpty())
295 const OUString& filterTerm,
299 std::vector<std::unique_ptr<weld::TreeIter>> aNodesToExpand;
300 pFunctionListBox->
freeze();
303 switch (pInfo->
nKind)
307 css::uno::Reference<css::frame::XDispatchInformationProvider> xProvider(
309 sal_Int32 nEntryCount =
m_xControl->get_count();
311 for (sal_Int32 nCurPos = 0; nCurPos < nEntryCount; ++nCurPos)
314 = weld::fromId<SfxGroupInfo_Impl*>(
m_xControl->get_id(nCurPos));
321 css::uno::Sequence<css::frame::DispatchInformation> lCommands;
324 lCommands = xProvider->getConfigurableDispatchInformation(
329 catch (css::container::NoSuchElementException&)
340 css::uno::Reference<css::frame::XDispatchInformationProvider> xProvider(
341 m_xFrame, css::uno::UNO_QUERY_THROW);
342 css::uno::Sequence<css::frame::DispatchInformation> lCommands
343 = xProvider->getConfigurableDispatchInformation(nGroup);
349 SAL_INFO(
"cui.customize",
"** ** About to initialise SF Scripts");
351 css::uno::Reference<css::script::browse::XBrowseNode> rootNode;
354 css::uno::Reference<css::script::browse::XBrowseNodeFactory> xFac
355 = css::script::browse::theBrowseNodeFactory::get(
m_xContext);
356 rootNode.set(xFac->createView(
357 css::script::browse::BrowseNodeFactoryViewTypes::MACROSELECTOR));
359 catch (css::uno::Exception
const&)
363 "Caught some exception whilst retrieving browse nodes from factory");
367 if (rootNode.is() && rootNode->hasChildNodes())
373 m_aGroupInfo.push_back(std::make_unique<SfxGroupInfo_Impl>(
377 const css::uno::Sequence<css::uno::Reference<css::script::browse::XBrowseNode>>
378 aChildNodes = rootNode->getChildNodes();
379 for (
auto const& childGroup : aChildNodes)
381 childGroup->acquire();
383 if (childGroup->hasChildNodes())
386 if (childGroup->getName() ==
"user")
388 sUIName =
CuiResId(RID_CUISTR_MYMACROS);
390 else if (childGroup->getName() ==
"share")
392 sUIName =
CuiResId(RID_CUISTR_PRODMACROS);
396 sUIName = childGroup->getName();
399 if (sUIName.isEmpty())
404 m_aGroupInfo.push_back(std::make_unique<SfxGroupInfo_Impl>(
406 std::unique_ptr<weld::TreeIter> xMacroGroup(pFunctionListBox->
tree_append(
412 css::uno::ContextLayer layer(
415 addChildren(xMacroGroup.get(), childGroup, pFunctionListBox, filterTerm,
416 pCurrentSaveInData, aNodesToExpand);
422 pFunctionListBox->
remove(*xMacroGroup);
424 else if (!filterTerm.isEmpty())
426 aNodesToExpand.emplace_back(std::move(xMacroGroup));
438 for (
const auto& pIt : lStyleFamilies)
440 if (pIt.sLabel.isEmpty())
448 std::unique_ptr<weld::TreeIter> xFuncEntry(pFunctionListBox->
tree_append(
458 for (
const auto& pStyleIt : lStyles)
460 OUString sUIName = pStyleIt.sLabel;
461 sal_Int32 aStartPos = 0;
462 sal_Int32 aEndPos = sUIName.getLength();
465 if (!filterTerm.isEmpty()
486 pFunctionListBox->
remove(*xFuncEntry);
488 else if (!filterTerm.isEmpty())
490 aNodesToExpand.emplace_back(std::move(xFuncEntry));
499 "Ignoring unexpected SfxCfgKind: " <<
static_cast<int>(pInfo->
nKind));
503 pFunctionListBox->
thaw();
506 pFunctionListBox->
select(0);
509 for (
const auto& it : aNodesToExpand)
517 const css::uno::Reference<css::script::browse::XBrowseNode>& parentNode,
519 SaveInData* pCurrentSaveInData, std::vector<std::unique_ptr<weld::TreeIter>>& rNodesToExpand)
525 const css::uno::Sequence<css::uno::Reference<css::script::browse::XBrowseNode>> aChildNodes
526 = parentNode->getChildNodes();
527 for (
auto const& child : aChildNodes)
532 if (child->hasChildNodes())
534 OUString sUIName = child->getName();
536 m_aGroupInfo.push_back(std::make_unique<SfxGroupInfo_Impl>(
538 std::unique_ptr<weld::TreeIter> xNewEntry(pFunctionListBox->
tree_append(
541 addChildren(xNewEntry.get(), child, pFunctionListBox, filterTerm, pCurrentSaveInData,
546 pFunctionListBox->
remove(*xNewEntry);
548 rNodesToExpand.emplace_back(std::move(xNewEntry));
550 else if (child->getType() == css::script::browse::BrowseNodeTypes::SCRIPT)
553 OUString sUIName = child->getName();
554 sal_Int32 aStartPos = 0;
555 sal_Int32 aEndPos = sUIName.getLength();
558 if (!filterTerm.isEmpty() && !textSearch.
SearchForward(sUIName, &aStartPos, &aEndPos))
563 OUString uri, description;
565 css::uno::Reference<css::beans::XPropertySet> xPropSet(child, css::uno::UNO_QUERY);
572 css::uno::Any
value = xPropSet->getPropertyValue(
"URI");
577 value = xPropSet->getPropertyValue(
"Description");
578 value >>= description;
580 catch (css::uno::Exception&)
585 if (description.isEmpty())
587 description =
CuiResId(RID_CUISTR_NOMACRODESC);
590 OUString* pScriptURI =
new OUString(uri);
592 css::uno::Reference<css::graphic::XGraphic> xImage;
593 if (pCurrentSaveInData)
594 xImage = pCurrentSaveInData->
GetImage(uri);
PropertiesInfo aProperties
static const AllSettings & GetSettings()
css::uno::Reference< css::container::XNameAccess > m_xModuleCategoryInfo
css::uno::Reference< css::uno::XComponentContext > m_xContext
void addChildren(const weld::TreeIter *parentEntry, const css::uno::Reference< com::sun::star::script::browse::XBrowseNode > &parentNode, CuiConfigFunctionListBox *pFunctionListBox, const OUString &filterTerm, SaveInData *pCurrentSaveInData, std::vector< std::unique_ptr< weld::TreeIter > > &rNodesToExpand)
std::unique_ptr< weld::ComboBox > m_xControl
void SetStylesInfo(SfxStylesInfo_Impl *pStyles)
css::uno::Reference< css::frame::XFrame > m_xFrame
~CommandCategoryListBox()
SfxStylesInfo_Impl * pStylesInfo
OUString m_sModuleLongName
void Init(const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XFrame > &xFrame, const OUString &sModuleLongName)
SfxStylesInfo_Impl m_aStylesInfo
CommandCategoryListBox(std::unique_ptr< weld::ComboBox > xControl)
SfxGroupInfoArr_Impl m_aGroupInfo
css::uno::Reference< css::container::XNameAccess > m_xUICmdDescription
i18nutil::SearchOptions2 m_searchOptions
OUString getCommandName(const OUString &sCommand)
css::uno::Reference< css::container::XNameAccess > m_xGlobalCategoryInfo
void FillFunctionsList(const css::uno::Sequence< css::frame::DispatchInformation > &xCommands, CuiConfigFunctionListBox *pFunctionListBox, const OUString &filterTerm, SaveInData *pCurrentSaveInData)
void categorySelected(CuiConfigFunctionListBox *pFunctionListBox, const OUString &filterTerm, SaveInData *pCurrentSaveInData=nullptr)
Signals that a command category has been selected.
std::unique_ptr< weld::TreeIter > tree_append(const OUString &rId, const OUString &rStr, const weld::TreeIter *pParent=nullptr)
void expand_row(const weld::TreeIter &rIter)
void append(const OUString &rId, const OUString &rStr, const weld::TreeIter *pParent=nullptr)
bool iter_has_child(const weld::TreeIter &rIter) const
css::uno::Reference< css::graphic::XGraphic > GetImage(const OUString &rCommandURL)
TValueType getUnpackedValueOrDefault(const OUString &sKey, const TValueType &aDefault) const
bool SearchForward(const OUString &rStr, sal_Int32 *pStart, sal_Int32 *pEnd, css::util::SearchResult *pRes=nullptr)
bool searchForward(const OUString &rStr)
OUString CuiResId(TranslateId aKey)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define SAL_INFO(area, stream)
const LanguageTag & getLocale()
css::uno::Reference< css::uno::XCurrentContext > NoEnableJavaInteractionContext()
Reference< XComponentContext > getProcessComponentContext()
Sequence< beans::PropertyValue > GetCommandProperties(const OUString &rsCommandName, const OUString &rsModuleName)
OUString GetTooltipForCommand(const OUString &rsCommandName, const css::uno::Sequence< css::beans::PropertyValue > &rProperties, const Reference< frame::XFrame > &rxFrame)
OUString GetPopupLabelForCommand(const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
OUString GetLabelForCommand(const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
bool IsExperimental(const OUString &rsCommandName, const OUString &rModuleName)
OUString toId(const void *pValue)
void init(const OUString &rModuleName, const css::uno::Reference< css::frame::XModel > &xModel)
std::vector< SfxStyleInfo_Impl > getStyleFamilies() const
std::vector< SfxStyleInfo_Impl > getStyles(const OUString &sFamily)
TransliterationFlags transliterateFlags
Reference< XController > xController
Reference< XFrame > xFrame
Reference< XModel > xModel