framework/source/uielement/newmenucontroller.cxx | 42 ++++++++++------------- 1 file changed, 20 insertions(+), 22 deletions(-)
New commits: commit 4172ffad04f4a72d9865612530ae4d9117f1eb59 Author: Mike Kaganski <[email protected]> AuthorDate: Tue Dec 10 15:57:20 2024 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Tue Dec 10 16:34:37 2024 +0100 Simplify the slot status check, and add some comments Change-Id: Ie2a77f0c5157a03a3461ae54d372382b1e57fe2b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178238 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/framework/source/uielement/newmenucontroller.cxx b/framework/source/uielement/newmenucontroller.cxx index f2d43a40643e..27e7aeb31414 100644 --- a/framework/source/uielement/newmenucontroller.cxx +++ b/framework/source/uielement/newmenucontroller.cxx @@ -58,26 +58,12 @@ using namespace com::sun::star::ui; namespace { +/** + * A simple status listener, storing the "enabled" status from the last status notification + */ class SlotStatusGetter : public cppu::WeakImplHelper<css::frame::XStatusListener> { public: - SlotStatusGetter(const css::util::URL& url, - const css::uno::Reference<css::frame::XFrame>& frame) - { - if (auto provider = frame.query<css::frame::XDispatchProvider>()) - { - if (auto xDispatch = provider->queryDispatch(url, {}, 0)) - { - // Avoid self-destruction - osl_atomic_increment(&m_refCount); - // Adding as listener will automatically emit an initial notification - xDispatch->addStatusListener(this, url); - xDispatch->removeStatusListener(this, url); - osl_atomic_decrement(&m_refCount); - } - } - } - bool isEnabled() const { return m_bEnabled; } private: @@ -96,11 +82,23 @@ private: bool isSlotActive(const OUString& slot, const css::uno::Reference<css::frame::XFrame>& frame, const css::uno::Reference<css::util::XURLTransformer>& transformer) { - css::util::URL url; - url.Complete = slot; - transformer->parseStrict(url); - rtl::Reference slotStatus(new SlotStatusGetter(url, frame)); - return slotStatus->isEnabled(); + if (auto provider = frame.query<css::frame::XDispatchProvider>()) + { + css::util::URL url; + url.Complete = slot; + transformer->parseStrict(url); + if (auto dispatch = provider->queryDispatch(url, {}, 0)) + { + rtl::Reference pSlotStatus(new SlotStatusGetter); + // Adding as listener will automatically emit an initial notification. The status + // reported in the notification will be stored in the SlotStatusGetter instance. + dispatch->addStatusListener(pSlotStatus, url); + dispatch->removeStatusListener(pSlotStatus, url); + return pSlotStatus->isEnabled(); + } + } + + return false; } }
