diff --git a/wizards/source/scriptforge/SF_Services.xba b/wizards/source/scriptforge/SF_Services.xba index ffada4653d2c..ba43968c7ce4 100644 --- a/wizards/source/scriptforge/SF_Services.xba +++ b/wizards/source/scriptforge/SF_Services.xba @@ -357,69 +357,54 @@ Private Function _FindModuleFromMethod(ByVal psLibrary As String _ ''' Returns: ''' The name of the module or a zero-length string if not found +Dim oBasic As Object ' com.sun.star.comp.scripting.ScriptProviderForBasic Dim vCategories As Variant ' "user" or "share" library categories Dim sCategory As String -Dim vLanguages As Variant ' "Basic", "Python", ... programming languages -Dim sLanguage As String Dim vLibraries As Variant ' Library names Dim sLibrary As String Dim vModules As Variant ' Module names Dim sModule As String ' Return value -Dim vMethods As Variant ' Method/properties/subs/functions +Dim vMethods As Variant ' Methods/properties/subs/functions Dim sMethod As String -Dim oRoot As Object ' com.sun.star.script.browse.BrowseNodeFactory -Dim i As Integer, j As Integer, k As Integer, l As Integer, m As Integer +Dim i As Integer, k As Integer, l As Integer, m As Integer _FindModuleFromMethod = "" - Set oRoot = SF_Utils._GetUNOService("BrowseNodeFactory").createView(com.sun.star.script.browse.BrowseNodeFactoryViewTypes.MACROORGANIZER) - ' Exploration is done via tree nodes - If Not IsNull(oRoot) Then - If oRoot.hasChildNodes() Then - vCategories = oRoot.getChildNodes() - For i = 0 To UBound(vCategories) - sCategory = vCategories(i).getName() - ' Consider "My macros & Dialogs" and "LibreOffice Macros & Dialogs" only - If sCategory = "user" Or sCategory = "share" Then - If vCategories(i).hasChildNodes() Then - vLanguages = vCategories(i).getChildNodes() - For j = 0 To UBound(vLanguages) - sLanguage = vLanguages(j).getName() - ' Consider Basic libraries only - If sLanguage = "Basic" Then - If vLanguages(j).hasChildNodes() Then - vLibraries = vLanguages(j).getChildNodes() - For k = 0 To UBound(vLibraries) - sLibrary = vLibraries(k).getName() - ' Consider the given library only - If sLibrary = psLibrary Then - If vLibraries(k).hasChildNodes() Then - vModules = vLibraries(k).getChildNodes() - For l = 0 To UBound(vModules) - sModule = vModules(l).getName() - ' Check if the module contains the targeted method - If vModules(l).hasChildNodes() Then - vMethods = vModules(l).getChildNodes() - For m = 0 To UBound(vMethods) - sMethod = vMethods(m).getName() - If sMethod = psMethod Then - _FindModuleFromMethod = sModule - Exit Function - End If - Next m - End If - Next l - End If - End If - Next k - End If + ' Exploration is done via tree nodes, starting + ' from a com.sun.star.comp.scripting.ScriptProviderForBasic + ' See also bug report https://bugs.documentfoundation.org/show_bug.cgi?id=165147 + vCategories = Array("user", "share") + For i = 0 To UBound(vCategories) + Set oBasic = CreateUnoService("com.sun.star.comp.scripting.ScriptProviderForBasic") + sCategory = vCategories(i) + oBasic.initialize(Array(sCategory)) + If oBasic.hasChildNodes() Then + vLibraries = oBasic.getChildNodes() + For k = 0 To UBound(vLibraries) + sLibrary = vLibraries(k).getName() + ' Consider the given library only + If sLibrary = psLibrary Then + If vLibraries(k).hasChildNodes() Then + vModules = vLibraries(k).getChildNodes() + For l = 0 To UBound(vModules) + sModule = vModules(l).getName() + ' Check if the module contains the targeted method + If vModules(l).hasChildNodes() Then + vMethods = vModules(l).getChildNodes() + For m = 0 To UBound(vMethods) + sMethod = vMethods(m).getName() + If sMethod = psMethod Then + _FindModuleFromMethod = sModule + Exit Function + End If + Next m End If - Next j + Next l End If End If - Next i + Next k End If - End If + Next i End Function ' ScriptForge.SF_Services._FindModuleFromMethod