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 <nroberts@libreoffice.org>
Tested-by: Jenkins
This commit is contained in:
Neil Roberts
2026-06-24 14:36:49 +02:00
parent 00bd4b4aef
commit c9ef750019
2 changed files with 60 additions and 0 deletions
+54
View File
@@ -19,6 +19,8 @@
#include <basctl/basctldllpublic.hxx>
#include <basctl/sbxitem.hxx>
#include <basctl/scriptdocument.hxx>
#include <basic/basmgr.hxx>
#include <basic/sbmeth.hxx>
#include <comphelper/SetFlagContextHelper.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <comphelper/documentinfo.hxx>
@@ -2513,4 +2515,56 @@ void MacroManagerDialog::LoadLastUsedMacro()
UpdateUI();
}
SbModule* MacroManagerDialog::GetSelectedBasicModule() const
{
weld::TreeView& rScriptContainersTreeView = m_xScriptContainersListBox->get_widget();
std::unique_ptr<weld::TreeIter> 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: */
+6
View File
@@ -26,6 +26,9 @@
#include <com/sun/star/script/browse/XBrowseNode.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
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: