20#include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
21#include <com/sun/star/util/URL.hpp>
22#include <com/sun/star/util/URLTransformer.hpp>
23#include <com/sun/star/i18n/CharacterClassification.hpp>
35 , m_xCharacterClassification(i18n::CharacterClassification::
create(
m_xContext))
39 uno::Reference<ui::XModuleUIConfigurationManagerSupplier> xModuleConfigSupplier;
40 xModuleConfigSupplier.set(ui::theModuleUIConfigurationManagerSupplier::get(
m_xContext));
42 uno::Reference<ui::XUIConfigurationManager> xConfigurationManager;
43 xConfigurationManager = xModuleConfigSupplier->getUIConfigurationManager(
m_sModuleLongName);
45 uno::Reference<container::XIndexAccess> xConfigData;
46 xConfigData = xConfigurationManager->getSettings(
"private:resource/menubar/menubar",
false);
52 uno::Reference<container::XIndexAccess>
const& xIndexAccess,
MenuContent& rMenuContent)
54 for (sal_Int32
n = 0;
n < xIndexAccess->getCount();
n++)
58 uno::Reference<container::XIndexAccess> xIndexContainer;
63 bool bIsVisible =
true;
66 for (
auto const& rProperty : std::as_const(
aProperties))
68 OUString aPropertyName = rProperty.Name;
69 if (aPropertyName ==
"CommandURL")
71 else if (aPropertyName ==
"ItemDescriptorContainer")
72 rProperty.Value >>= xIndexContainer;
73 else if (aPropertyName ==
"IsVisible")
74 rProperty.Value >>= bIsVisible;
75 else if (aPropertyName ==
"Enabled")
95 if (xIndexContainer.is())
103 std::unique_ptr<weld::TreeView>& rpCommandTreeView,
104 std::vector<CurrentEntry>& rCommandList)
108 OUString aLowerCaseText =
toLower(rText);
110 auto aTextStartCriterium = [](
MenuContent const& rMenuContent, OUString
const& rSearchText) {
115 aTextStartCriterium);
117 auto aTextAllCriterium = [](
MenuContent const& rMenuContent, OUString
const& rSearchText) {
126 MenuContent const& rMenuContent, OUString
const& rText,
127 std::unique_ptr<weld::TreeView>& rpCommandTreeView, std::vector<CurrentEntry>& rCommandList,
128 std::function<
bool(
MenuContent const&, OUString
const&)>
const& rSearchCriterium)
132 if (rSearchCriterium(aSubContent, rText))
136 findInMenuRecursive(aSubContent, rText, rpCommandTreeView, rCommandList, rSearchCriterium);
141 MenuContent const& rMenuContent,
const std::unique_ptr<weld::TreeView>& rpCommandTreeView,
142 std::vector<CurrentEntry>& rCommandList)
148 util::URL aCommandURL;
149 aCommandURL.Complete = sCommandURL;
163 std::unique_ptr<SfxPoolItem> pState;
165 if (eState == SfxItemState::DISABLED)
169 rCommandList.emplace_back(sCommandURL, rMenuContent.
m_aTooltip);
171 auto pIter = rpCommandTreeView->make_iterator();
173 nullptr,
false, pIter.get());
174 rpCommandTreeView->set_image(*pIter, xGraphic);
186 : mxBuilder(
Application::CreateBuilder(pParent,
"sfx/ui/commandpopup.ui"))
187 , mxPopover(mxBuilder->weld_popover(
"CommandPopup"))
188 , mpEntry(mxBuilder->weld_entry(
"command_entry"))
189 , mpCommandTreeView(mxBuilder->weld_tree_view(
"command_treeview"))
205 mxPopover->popup_at_rect(pParent, aRect);
211 size_t nSelected = mpCommandTreeView->get_selected_index();
212 if (nSelected < maCommandList.size())
214 auto const& rCurrent = maCommandList[nSelected];
215 return rCurrent.m_aTooltip;
222 OUString aCommandURL;
223 int nSelected = mpCommandTreeView->get_selected_index();
224 if (nSelected != -1 && nSelected <
int(maCommandList.size()))
226 auto const& rCurrent = maCommandList[nSelected];
227 aCommandURL = rCurrent.m_aCommandURL;
229 dispatchCommandAndClose(aCommandURL);
235 if (rKeyEvent.GetKeyCode().GetCode() ==
KEY_DOWN || rKeyEvent.GetKeyCode().GetCode() ==
KEY_UP)
237 int nDirection = rKeyEvent.GetKeyCode().GetCode() ==
KEY_DOWN ? 1 : -1;
238 int nNewIndex = mpCommandTreeView->get_selected_index() + nDirection;
239 nNewIndex = std::clamp(nNewIndex, 0, mpCommandTreeView->n_children() - 1);
240 mpCommandTreeView->select(nNewIndex);
241 mpCommandTreeView->set_cursor(nNewIndex);
244 else if (rKeyEvent.GetKeyCode().GetCode() ==
KEY_RETURN)
246 RowActivated(*mpCommandTreeView);
255 mpCommandTreeView->clear();
256 maCommandList.clear();
258 OUString sText = mpEntry->get_text();
262 mpCommandTreeView->freeze();
263 mpMenuContentHandler->findInMenu(sText, mpCommandTreeView, maCommandList);
264 mpCommandTreeView->thaw();
266 if (mpCommandTreeView->n_children() > 0)
268 mpCommandTreeView->set_cursor(0);
269 mpCommandTreeView->select(0);
272 mpEntry->grab_focus();
279 if (!rCommand.isEmpty())
284 css::uno::Reference<css::frame::XFrame>
const& xFrame)
286 auto pCommandListBox = std::make_unique<CommandListBox>(pParent,
xFrame);
IMPL_LINK(CommandListBox, TreeViewKeyPress, const KeyEvent &, rKeyEvent, bool)
IMPL_LINK_NOARG(CommandListBox, QueryTooltip, const weld::TreeIter &, OUString)
Reference< XComponentContext > m_xContext
PropertiesInfo aProperties
css::uno::Reference< css::lang::XComponent > m_xFrame
const LanguageTag & GetUILanguageTag() const
static const AllSettings & GetSettings()
std::unique_ptr< weld::Entry > mpEntry
void dispatchCommandAndClose(OUString const &rCommand)
std::unique_ptr< weld::Popover > mxPopover
CommandListBox(weld::Window *pParent, css::uno::Reference< css::frame::XFrame > const &xFrame)
std::unique_ptr< weld::TreeView > mpCommandTreeView
void showPopup(weld::Window *pParent, css::uno::Reference< css::frame::XFrame > const &xFrame)
std::unique_ptr< CommandListBox > mpListBox
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
void findInMenu(OUString const &rText, std::unique_ptr< weld::TreeView > &rpCommandTreeView, std::vector< CurrentEntry > &rCommandList)
MenuContent m_aMenuContent
css::uno::Reference< css::frame::XFrame > m_xFrame
void addCommandIfPossible(MenuContent const &rMenuContent, const std::unique_ptr< weld::TreeView > &rpCommandTreeView, std::vector< CurrentEntry > &rCommandList)
std::unordered_set< OUString > m_aAdded
void findInMenuRecursive(MenuContent const &rMenuContent, OUString const &rText, std::unique_ptr< weld::TreeView > &rpCommandTreeView, std::vector< CurrentEntry > &rCommandList, std::function< bool(MenuContent const &, OUString const &)> const &rSearchCriterium)
css::uno::Reference< css::util::XURLTransformer > m_xURLTransformer
void gatherMenuContent(css::uno::Reference< css::container::XIndexAccess > const &xIndexAccess, MenuContent &rMenuContent)
css::uno::Reference< css::uno::XComponentContext > m_xContext
OUString toLower(OUString const &rString)
MenuContentHandler(css::uno::Reference< css::frame::XFrame > const &xFrame)
css::uno::Reference< css::i18n::XCharacterClassification > m_xCharacterClassification
OUString m_sModuleLongName
static SfxSlotPool & GetSlotPool(SfxViewFrame *pFrame=nullptr)
const SfxSlot * GetUnoSlot(const OUString &rUnoName) const
sal_uInt16 GetSlotId() const
static SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
constexpr tools::Long Width() const
virtual Size get_size() const=0
constexpr sal_uInt16 KEY_RETURN
constexpr sal_uInt16 KEY_UP
constexpr sal_uInt16 KEY_DOWN
#define LINK(Instance, Class, Member)
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
Reference< XComponentContext > getProcessComponentContext()
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
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)
Reference< graphic::XGraphic > GetXGraphicForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
OUString GetLabelForCommand(const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
VCL_DLLPUBLIC OUString GetModuleIdentifier(const css::uno::Reference< css::frame::XFrame > &rxFrame)
Reference< XFrame > xFrame