summaryrefslogtreecommitdiff
path: root/wizards
diff options
context:
space:
mode:
authorJean-Pierre Ledure <jp@ledure.be>2022-02-06 13:33:06 +0100
committerJean-Pierre Ledure <jp@ledure.be>2022-02-07 09:16:03 +0100
commitb52016e5d065ca3fe77ec3c02090ea4b2b3e1ba5 (patch)
treea2df12363dc8065f6b88b0e44e8559b36eb6b6a3 /wizards
parente893606068a82c84103b1466a5eb92e2bd415b4b (diff)
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 <jp@ledure.be> Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Diffstat (limited to 'wizards')
-rw-r--r--wizards/source/scriptforge/SF_FileSystem.xba42
-rw-r--r--wizards/source/scriptforge/SF_Platform.xba20
-rw-r--r--wizards/source/scriptforge/SF_Root.xba2
-rw-r--r--wizards/source/scriptforge/SF_Utils.xba7
-rw-r--r--wizards/source/scriptforge/python/scriptforge.py11
5 files changed, 76 insertions, 6 deletions
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;
@@ -651,6 +651,45 @@ Catch:
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
&apos;&apos;&apos; Args:
@@ -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
@@ -74,6 +74,15 @@ Property Get CurrentUser() As String
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
&apos;&apos;&apos; To get the list sorted, use SF_Array.Sort()
@@ -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'