From c9ef750019bdd1160955d2399995fe0a40b227d9 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Fri, 19 Jun 2026 16:35:20 +0200 Subject: [PATCH] MacroManager: Add methods to get selected BASIC module and method Adds GetSelectedBasicModule and GetSelectedBasicMethod to get the selected SbModule or SbMethod when a node in the BASIC branch of the tree is selected. Change-Id: Id97634698b1c838a20026b249720901490de9f52 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/207057 Reviewed-by: Neil Roberts Tested-by: Jenkins --- cui/source/dialogs/MacroManagerDialog.cxx | 54 +++++++++++++++++++++++ cui/source/inc/MacroManagerDialog.hxx | 6 +++ 2 files changed, 60 insertions(+) diff --git a/cui/source/dialogs/MacroManagerDialog.cxx b/cui/source/dialogs/MacroManagerDialog.cxx index 6a465f379ce7..0bc09dfb3790 100644 --- a/cui/source/dialogs/MacroManagerDialog.cxx +++ b/cui/source/dialogs/MacroManagerDialog.cxx @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include #include @@ -2513,4 +2515,56 @@ void MacroManagerDialog::LoadLastUsedMacro() UpdateUI(); } +SbModule* MacroManagerDialog::GetSelectedBasicModule() const +{ + weld::TreeView& rScriptContainersTreeView = m_xScriptContainersListBox->get_widget(); + std::unique_ptr xIter = rScriptContainersTreeView.get_selected(); + + if (!xIter) + return nullptr; + + OUString aParts[3]; + + // The selected node needs to be at least 4 branches deep, ie, + // Document->Language->Library->Module. Here we store the names of the last three and also check + // that the language part has a parent node. + for (auto& aPart : aParts) + { + aPart = rScriptContainersTreeView.get_text(*xIter); + + if (!rScriptContainersTreeView.iter_parent(*xIter)) + return nullptr; + } + + if (aParts[2] != u"Basic"_ustr) + return nullptr; + + basctl::ScriptDocument aDocument = m_xScriptContainersListBox->GetScriptDocument(xIter.get()); + BasicManager* pBasicManager = aDocument.getBasicManager(); + + if (!pBasicManager) + return nullptr; + + StarBASIC* pLibrary = pBasicManager->GetLib(aParts[1]); + if (!pLibrary) + return nullptr; + + return pLibrary->FindModule(aParts[0]); +} + +SbMethod* MacroManagerDialog::GetSelectedBasicMethod() const +{ + SbModule* pModule = GetSelectedBasicModule(); + + if (!pModule) + return nullptr; + + OUString sScriptName = m_xScriptsListBox->GetSelectedScriptName(); + + if (sScriptName.getLength() <= 0) + return nullptr; + + return pModule->FindMethod(sScriptName, SbxClassType::Method); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/cui/source/inc/MacroManagerDialog.hxx b/cui/source/inc/MacroManagerDialog.hxx index 3373d98a0f58..e97fbada26b2 100644 --- a/cui/source/inc/MacroManagerDialog.hxx +++ b/cui/source/inc/MacroManagerDialog.hxx @@ -26,6 +26,9 @@ #include #include +class SbModule; +class SbMethod; + struct ScriptContainerInfo { css::script::browse::XBrowseNode* pBrowseNode; @@ -235,6 +238,9 @@ class MacroManagerDialog : public weld::GenericDialogController, public SfxListe void UpdateUI(); void CheckButtons(); + SbModule* GetSelectedBasicModule() const; + SbMethod* GetSelectedBasicMethod() const; + virtual void Notify(SfxBroadcaster&, const SfxHint& rHint) override; public: