wizards/source/scriptforge/SF_FileSystem.xba     |   42 ++++++++++++++++++++++-
 wizards/source/scriptforge/SF_Platform.xba       |   20 ++++++++++
 wizards/source/scriptforge/SF_Root.xba           |    2 +
 wizards/source/scriptforge/SF_Utils.xba          |    7 +++
 wizards/source/scriptforge/python/scriptforge.py |   11 +++---
 5 files changed, 76 insertions(+), 6 deletions(-)

New commits:
commit b52016e5d065ca3fe77ec3c02090ea4b2b3e1ba5
Author:     Jean-Pierre Ledure <j...@ledure.be>
AuthorDate: Sun Feb 6 13:33:06 2022 +0100
Commit:     Jean-Pierre Ledure <j...@ledure.be>
CommitDate: Mon Feb 7 09:16:03 2022 +0100

    ScriptForge - (SF_Platform,SF_FileSystem) Manage extensions
    
    New properties and methods
    --------------------------
    
    SF_Platform.Extensions : (property)
       provide a list of the installed extensions
       as an array of strings
    
    SF_FileSystem.ExtensionFolder(Extension as string) : (method)
       provides the location in FileNaming notation of the
       folder where the given extension is installed
    
    The SF_FileSystem.ExtensionsFolder (notice the additional "s")
    is kept as a property providing the folder containing the
    extensions installed by the user.
    
    All methods and properties are available with an identical
    syntax and semantics both from Basic and Python scripts.
    
    The difference between a propert or a method is
    irrelevant for Basic but is essential in Python:
    a property must not have brackets, a method must have them.
    Hence the distinction between
       ExtensionFolder being a method requiring an argument
       ExtensionsFolder being a property without argument
    
    Change-Id: Idd18a5624f4abd84095d146e467e8fdcf497bd0d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129572
    Tested-by: Jean-Pierre Ledure <j...@ledure.be>
    Tested-by: Jenkins
    Reviewed-by: Jean-Pierre Ledure <j...@ledure.be>

diff --git a/wizards/source/scriptforge/SF_FileSystem.xba 
b/wizards/source/scriptforge/SF_FileSystem.xba
index d71937d6e64a..935c559f5c8e 100644
--- a/wizards/source/scriptforge/SF_FileSystem.xba
+++ b/wizards/source/scriptforge/SF_FileSystem.xba
@@ -86,7 +86,7 @@ End Property  &apos;  ScriptForge.SF_FileSystem.ConfigFolder
 
 REM 
-----------------------------------------------------------------------------
 Property Get ExtensionsFolder() As String
-&apos;&apos;&apos;     Return the folder containing the installed extensions
+&apos;&apos;&apos;     Return the folder containing the extensions installed 
for the current user
 
 Dim oMacro As Object           &apos;  
/singletons/com.sun.star.util.theMacroExpander
 Const cstThisSub = &quot;FileSystem.getExtensionsFolder&quot;
@@ -650,6 +650,45 @@ Catch:
        GoTo Finally
 End Function    &apos;   ScriptForge.SF_FileSystem.DeleteFolder
 
+REM 
-----------------------------------------------------------------------------
+Public Function ExtensionFolder(Optional ByVal Extension As Variant) As String
+&apos;&apos;&apos;     Return the folder where the given extension is 
installed. The argument must
+&apos;&apos;&apos;     be in the list of extensions provided by the 
SF_Platform.Extensions property
+&apos;&apos;&apos;     Args:
+&apos;&apos;&apos;             Extension: a valid extension name
+&apos;&apos;&apos;     Returns:
+&apos;&apos;&apos;             The requested folder using the FileNaming 
notation
+&apos;&apos;&apos;     Example:
+&apos;&apos;&apos;             MsgBox 
FSO.ExtensionFolder(&quot;apso.python.script.organizer&quot;)
+
+Dim sFolder As String                  &apos;  Return value
+Static vExtensions As Variant  &apos;  Cached list of existing extension names
+Dim oPackage As Object                 &apos;  
/singletons/com.sun.star.deployment.PackageInformationProvider
+Const cstThisSub = &quot;FileSystem.ExtensionFolder&quot;
+Const cstSubArgs = &quot;Extension&quot;
+
+       If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
+       sFolder = &quot;&quot;
+
+Check:
+       If IsEmpty(vExtensions) Then vExtensions = SF_Platform.Extensions
+       If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
+               If Not SF_Utils._Validate(Extension, &quot;Extension&quot;, 
V_STRING, vExtensions) Then GoTo Finally
+       End If
+
+Try:
+       &apos;  Search an individual folder
+       Set oPackage = 
SF_Utils._GetUnoService(&quot;PackageInformationProvider&quot;)
+       sFolder = oPackage.getPackageLocation(Extension)
+ 
+Finally:
+       ExtensionFolder = SF_FileSystem._ConvertFromUrl(sFolder)
+       SF_Utils._ExitFunction(cstThisSub)
+       Exit Function
+Catch:
+       GoTo Finally
+End Function   &apos;  ScritForge.SF_FileSystem.ExtensionFolder
+
 REM 
-----------------------------------------------------------------------------
 Public Function FileExists(Optional ByVal FileName As Variant) As Boolean
 &apos;&apos;&apos;     Return True if the given file exists
@@ -1215,6 +1254,7 @@ Public Function Methods() As Variant
                                        , &quot;CreateTextFile&quot; _
                                        , &quot;DeleteFile&quot; _
                                        , &quot;DeleteFolder&quot; _
+                                       , &quot;ExtensionFolder&quot; _
                                        , &quot;FileExists&quot; _
                                        , &quot;Files&quot; _
                                        , &quot;FolderExists&quot; _
diff --git a/wizards/source/scriptforge/SF_Platform.xba 
b/wizards/source/scriptforge/SF_Platform.xba
index 8bd7b5cad35f..33bbf7877b9e 100644
--- a/wizards/source/scriptforge/SF_Platform.xba
+++ b/wizards/source/scriptforge/SF_Platform.xba
@@ -73,6 +73,15 @@ Property Get CurrentUser() As String
        CurrentUser = _PropertyGet(&quot;CurrentUser&quot;)
 End Property   &apos;  ScriptForge.SF_Platform.CurrentUser (get)
 
+REM 
-----------------------------------------------------------------------------
+Property Get Extensions() As Variant
+&apos;&apos;&apos;     Returns the list of availableeExtensions as an unsorted 
array of unique strings
+&apos;&apos;&apos;     To get the list sorted, use SF_Array.Sort()
+&apos;&apos;&apos;     Example:
+&apos;&apos;&apos;             myExtensionsList = platform.Extensions
+       Extensions = _PropertyGet(&quot;Extensions&quot;)
+End Property   &apos;  ScriptForge.SF_Platform.Extensions (get)
+
 REM 
-----------------------------------------------------------------------------
 Property Get Fonts() As Variant
 &apos;&apos;&apos;     Returns the list of available fonts as an unsorted 
array of unique strings
@@ -251,6 +260,7 @@ Public Function Properties() As Variant
                                        , &quot;ComputerName&quot; _
                                        , &quot;CPUCount&quot; _
                                        , &quot;CurrentUser&quot; _
+                                       , &quot;Extensions&quot; _
                                        , &quot;Fonts&quot; _
                                        , &quot;FormatLocale&quot; _
                                        , &quot;Locale&quot; _
@@ -350,6 +360,9 @@ Dim oDevice As Object                       &apos;  
com.sun.star.awt.XDevice
 Dim oFontDescriptors As Variant        &apos;  Array of 
com.sun.star.awt.FontDescriptor
 Dim sFonts As String                   &apos;  Comma-separated list of fonts
 Dim sFont As String                            &apos;  A single font name
+Dim vExtensionsList As Variant &apos;  Array of extension descriptors
+Dim sExtensions As String              &apos;  Comma separated list of 
extensions
+Dim sExtension As String               &apos;  A single extension name
 Dim i As Long
 
 Const cstPyHelper = &quot;$&quot; &amp; &quot;_SF_Platform&quot;
@@ -365,6 +378,13 @@ Const cstSubArgs = &quot;&quot;
                        With ScriptForge.SF_Session
                                _PropertyGet = 
.ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper &amp; cstPyHelper, 
psProperty)
                        End With
+               Case &quot;Extensions&quot;
+                       Set vExtensionsList = 
SF_Utils._GetUnoService(&quot;PackageInformationProvider&quot;).ExtensionList
+                       sExtensions = &quot;&quot;
+                       For i = 0 To UBound(vExtensionsList)
+                               sExtensions = sExtensions &amp; &quot;,&quot; 
&amp; vExtensionsList(i)(0)
+                       Next i
+                       If Len(sExtensions) &gt; 0 Then _PropertyGet = 
Split(Mid(sExtensions, 2), &quot;,&quot;) Else _PropertyGet = Array()
                Case &quot;Fonts&quot;
                        Set oToolkit = 
SF_Utils._GetUnoService(&quot;Toolkit&quot;)
                        Set oDevice = oToolkit.createScreenCompatibleDevice(0, 
0)
diff --git a/wizards/source/scriptforge/SF_Root.xba 
b/wizards/source/scriptforge/SF_Root.xba
index d14e121173cd..7df7cd3957a6 100644
--- a/wizards/source/scriptforge/SF_Root.xba
+++ b/wizards/source/scriptforge/SF_Root.xba
@@ -73,6 +73,7 @@ Private BrowseNodeFactory     As Object       &apos; 
com.sun.star.script.browse.BrowseNode
 Private DatabaseContext                As Object       &apos; 
com.sun.star.sdb.DatabaseContext
 Private ConfigurationProvider _
                                                        As Object       &apos; 
com.sun.star.configuration.ConfigurationProvider
+Private PackageProvider                As Object       &apos; 
com.sun.star.comp.deployment.PackageInformationProvider
 Private MailService                    As Object       &apos; 
com.sun.star.system.SimpleCommandMail or com.sun.star.system.SimpleSystemMail
 Private GraphicExportFilter    As Object       &apos; 
com.sun.star.drawing.GraphicExportFilter
 Private Toolkit                                As Object       &apos; 
com.sun.star.awt.Toolkit
@@ -138,6 +139,7 @@ Private Sub Class_Initialize()
        Set BrowseNodeFactory = Nothing
        Set DatabaseContext = Nothing
        Set ConfigurationProvider = Nothing
+       Set PackageProvider = Nothing
        Set MailService = Nothing
        Set GraphicExportFilter = Nothing
        Set Toolkit = Nothing
diff --git a/wizards/source/scriptforge/SF_Utils.xba 
b/wizards/source/scriptforge/SF_Utils.xba
index cbe07ce2b0ae..2ca9a6fe09d3 100644
--- a/wizards/source/scriptforge/SF_Utils.xba
+++ b/wizards/source/scriptforge/SF_Utils.xba
@@ -21,7 +21,7 @@ REM 
===================================================================== GLOBAL
 Global _SF_            As Variant              &apos;  SF_Root (Basic) object)
 
 &apos;&apos;&apos;     ScriptForge version
-Const SF_Version = &quot;7.3&quot;
+Const SF_Version = &quot;7.4&quot;
 
 &apos;&apos;&apos;     Standard symbolic names for VarTypes
 &apos;                         V_EMPTY = 0
@@ -415,6 +415,11 @@ Dim oDefaultContext As Object
                                        .OfficeLocale.Country = Right(sLocale, 
2)
                                End If
                                Set _GetUNOService = .OfficeLocale
+                       Case &quot;PackageInformationProvider&quot;
+                               If IsEmpty(.PackageProvider) Or 
IsNull(.PackageProvider) Then
+                                       Set .PackageProvider = 
GetDefaultContext.getByName(&quot;/singletons/com.sun.star.deployment.PackageInformationProvider&quot;)
+                               End If
+                               Set _GetUNOService = .PackageProvider
                        Case &quot;PathSettings&quot;
                                If IsEmpty(.PathSettings) Or 
IsNull(.PathSettings) Then
                                        Set .PathSettings = 
CreateUnoService(&quot;com.sun.star.util.PathSettings&quot;)
diff --git a/wizards/source/scriptforge/python/scriptforge.py 
b/wizards/source/scriptforge/python/scriptforge.py
index 7edc737acec4..5eb0b08a5863 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -1095,6 +1095,9 @@ class SFScriptForge:
         def DeleteFolder(self, foldername):
             return self.ExecMethod(self.vbMethod, 'DeleteFolder', foldername)
 
+        def ExtensionFolder(self, extension):
+            return self.ExecMethod(self.vbMethod, 'ExtensionFolder', extension)
+
         def FileExists(self, filename):
             return self.ExecMethod(self.vbMethod, 'FileExists', filename)
 
@@ -1218,10 +1221,10 @@ class SFScriptForge:
         servicename = 'ScriptForge.Platform'
         servicesynonyms = ('platform', 'scriptforge.platform')
         serviceproperties = dict(Architecture = False, ComputerName = False, 
CPUCount = False, CurrentUser = False,
-                                 Fonts = False, FormatLocale = False, Locale = 
False, Machine = False,
-                                 OfficeLocale = False, OfficeVersion = False, 
OSName = False, OSPlatform = False,
-                                 OSRelease = False, OSVersion = False, 
Printers = False, Processor = False,
-                                 PythonVersion = False, SystemLocale = False)
+                                 Extensions = False, Fonts = False, 
FormatLocale = False, Locale = False,
+                                 Machine = False, OfficeLocale = False, 
OfficeVersion = False, OSName = False,
+                                 OSPlatform = False, OSRelease = False, 
OSVersion = False, Printers = False,
+                                 Processor = False, PythonVersion = False, 
SystemLocale = False)
         # Python helper functions
         py = ScriptForge.pythonhelpermodule + '$' + '_SF_Platform'
 

Reply via email to