LibreOffice Module sfx2 (master) 1
CommandPopup.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#pragma once
11
12#include <utility>
13#include <vcl/weld.hxx>
14
15#include <com/sun/star/uno/XComponentContext.hpp>
16#include <com/sun/star/frame/XFrame.hpp>
17#include <com/sun/star/container/XIndexAccess.hpp>
18#include <com/sun/star/i18n/XCharacterClassification.hpp>
19#include <com/sun/star/util/XURLTransformer.hpp>
20
21#include <functional>
22#include <unordered_set>
23
24struct CurrentEntry final
25{
26 OUString m_aCommandURL;
27 OUString m_aTooltip;
28
29 CurrentEntry(OUString aCommandURL, OUString aTooltip)
30 : m_aCommandURL(std::move(aCommandURL))
31 , m_aTooltip(std::move(aTooltip))
32 {
33 }
34};
35
36struct MenuContent final
37{
38 OUString m_aCommandURL;
39 OUString m_aMenuLabel;
42 OUString m_aTooltip;
43 std::vector<MenuContent> m_aSubMenuContent;
44};
45
47{
48private:
49 css::uno::Reference<css::uno::XComponentContext> m_xContext;
50 css::uno::Reference<css::frame::XFrame> m_xFrame;
51 css::uno::Reference<css::i18n::XCharacterClassification> m_xCharacterClassification;
52 css::uno::Reference<css::util::XURLTransformer> m_xURLTransformer;
53
56 OUString toLower(OUString const& rString);
57 std::unordered_set<OUString> m_aAdded;
58
59public:
60 MenuContentHandler(css::uno::Reference<css::frame::XFrame> const& xFrame);
61
62 void gatherMenuContent(css::uno::Reference<css::container::XIndexAccess> const& xIndexAccess,
63 MenuContent& rMenuContent);
64
65 void findInMenu(OUString const& rText, std::unique_ptr<weld::TreeView>& rpCommandTreeView,
66 std::vector<CurrentEntry>& rCommandList);
67
68private:
70 MenuContent const& rMenuContent, OUString const& rText,
71 std::unique_ptr<weld::TreeView>& rpCommandTreeView, std::vector<CurrentEntry>& rCommandList,
72 std::function<bool(MenuContent const&, OUString const&)> const& rSearchCriterium);
73
74 void addCommandIfPossible(MenuContent const& rMenuContent,
75 const std::unique_ptr<weld::TreeView>& rpCommandTreeView,
76 std::vector<CurrentEntry>& rCommandList);
77};
78
79class CommandListBox final
80{
81private:
82 std::unique_ptr<weld::Builder> mxBuilder;
83 std::unique_ptr<weld::Popover> mxPopover;
84 std::unique_ptr<weld::Entry> mpEntry;
85 std::unique_ptr<weld::TreeView> mpCommandTreeView;
86
87 std::vector<CurrentEntry> maCommandList;
88 std::unique_ptr<MenuContentHandler> mpMenuContentHandler;
89
90 DECL_LINK(QueryTooltip, const weld::TreeIter&, OUString);
91 DECL_LINK(RowActivated, weld::TreeView&, bool);
92 DECL_LINK(ModifyHdl, weld::Entry&, void);
93 DECL_LINK(TreeViewKeyPress, const KeyEvent&, bool);
94
95 void dispatchCommandAndClose(OUString const& rCommand);
96
97public:
98 CommandListBox(weld::Window* pParent, css::uno::Reference<css::frame::XFrame> const& xFrame);
100 {
101 mxPopover->connect_closed(rLink);
102 }
103};
104
106{
107private:
108 std::unique_ptr<CommandListBox> mpListBox;
109
110public:
111 void showPopup(weld::Window* pParent, css::uno::Reference<css::frame::XFrame> const& xFrame);
112 DECL_LINK(PopupModeEnd, weld::Popover&, void);
113};
114
115/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Entry > mpEntry
void connect_closed(const Link< weld::Popover &, void > &rLink)
void dispatchCommandAndClose(OUString const &rCommand)
std::unique_ptr< MenuContentHandler > mpMenuContentHandler
std::unique_ptr< weld::Builder > mxBuilder
std::unique_ptr< weld::Popover > mxPopover
DECL_LINK(TreeViewKeyPress, const KeyEvent &, bool)
std::vector< CurrentEntry > maCommandList
CommandListBox(weld::Window *pParent, css::uno::Reference< css::frame::XFrame > const &xFrame)
DECL_LINK(RowActivated, weld::TreeView &, bool)
std::unique_ptr< weld::TreeView > mpCommandTreeView
DECL_LINK(QueryTooltip, const weld::TreeIter &, OUString)
DECL_LINK(ModifyHdl, weld::Entry &, void)
DECL_LINK(PopupModeEnd, weld::Popover &, void)
void showPopup(weld::Window *pParent, css::uno::Reference< css::frame::XFrame > const &xFrame)
std::unique_ptr< CommandListBox > mpListBox
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
CurrentEntry(OUString aCommandURL, OUString aTooltip)
OUString m_aCommandURL
OUString m_aTooltip
OUString m_aCommandURL
std::vector< MenuContent > m_aSubMenuContent
OUString m_aMenuLabel
OUString m_aSearchableMenuLabel
OUString m_aTooltip
OUString m_aFullLabelWithPath