wizards/source/scriptforge/SF_Services.xba | 85 +++++++++++------------------ 1 file changed, 35 insertions(+), 50 deletions(-)
New commits: commit 6a6c10f25617d492c9db488e31db73c44d687b71 Author: Jean-Pierre Ledure <j...@ledure.be> AuthorDate: Tue Feb 11 17:43:34 2025 +0100 Commit: Jean-Pierre Ledure <j...@ledure.be> CommitDate: Wed Feb 12 14:38:49 2025 +0100 ScriptForge (SF_Services) fix tdf#165147 do not require JRE When a user script invokes CreateScriptService() for a not yet used library, ScriptForge loads the library and searches for the list of services provided by that library. The list can be found in a specific method that the library must contain, RegisterScriptServices() in whatever module. The exploration was done so far through a ScriptProvider UNO service. This service includes all programming languages, including Java, even without Java being used. This caused an inconvenient error message when Java is disabled in the advanced options. This service is now replaced by a com.sun.star.comp.scripting.ScriptProviderForBasic service. This gives a direct access to a lower branch of the scripts tree and skips the Java issue. All the changes are done in the ScriptForge.SF_Services._FindModuleFrom Method() function. No change required in the user documentation. Change-Id: I4a6820e5d1a379bf5b61c6077db8a9a382c1757d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181445 Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <j...@ledure.be> (cherry picked from commit ff298dfebcd5a6772de53d075e960bddcd4aff46) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181482 Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> 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