diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2023-07-14 17:11:14 +0200 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2023-07-15 09:54:01 +0200 |
commit | 44334328f75dd0023122a4cb446ccba0d507720c (patch) | |
tree | 0b814e6a7d4480d45d16646121610ca47e6fe363 /wizards | |
parent | ddb483509113e469b771320fea52f1b089574021 (diff) |
ScriptForge (SF_FileSystem) support document(s internal file structure
1. The SF_Document services (document, base, calc,
formdocument, writer) receive a new FileSystem
property that returns the "root" of the
component's file structure under the format:
"vnd.sun.star.tdoc:/XXX"
XXX being the document's identifier.
The implementation does not use the RuntimeUID
(UNO property of the OfficeDocument service) which
is optional and, f.i. not present for Base documents.
Instead the
css.frame.TransientDocumentsDocumentContentFactory
service is used.
2. The SF_FileSystem and SF_TextStream modules have been
reviewed to support the new context.
Next restrictions have been met:
- The FileNaming property is always cnsidered as 'URL'
- CompareFiles() is not applicable
- GetFileLen() always returns zero
- HashFile() is not applicable
- Normalize() always returns the input string unchanged
- PickFile() is not applicable
- PickFolder() is not applicable
Additionally,
- CreatetextFile()
- OpenTextFile() in write or append modes
copy or initialize the file in a temporary storage
and write it back in the document when it is being closed.
The process is transparent for the user.
3. The GetTempName() method accepts an option
Extension
argument, for better convenience.
The new functionalities are available in Basic and Python.
Changes require an update of the help documentation.
Change-Id: Ibf8dd9983656923cf6ab43d9f48398dc4d1e6307
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154443
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Diffstat (limited to 'wizards')
-rw-r--r-- | wizards/source/scriptforge/SF_Exception.xba | 5 | ||||
-rw-r--r-- | wizards/source/scriptforge/SF_FileSystem.xba | 177 | ||||
-rw-r--r-- | wizards/source/scriptforge/SF_Region.xba | 2 | ||||
-rw-r--r-- | wizards/source/scriptforge/SF_Root.xba | 15 | ||||
-rw-r--r-- | wizards/source/scriptforge/SF_TextStream.xba | 27 | ||||
-rw-r--r-- | wizards/source/scriptforge/SF_Utils.xba | 7 | ||||
-rw-r--r-- | wizards/source/scriptforge/po/ScriptForge.pot | 15 | ||||
-rw-r--r-- | wizards/source/scriptforge/po/en.po | 15 | ||||
-rw-r--r-- | wizards/source/scriptforge/python/scriptforge.py | 42 | ||||
-rw-r--r-- | wizards/source/sfdocuments/SF_Base.xba | 6 | ||||
-rw-r--r-- | wizards/source/sfdocuments/SF_Calc.xba | 6 | ||||
-rw-r--r-- | wizards/source/sfdocuments/SF_Document.xba | 23 | ||||
-rw-r--r-- | wizards/source/sfdocuments/SF_FormDocument.xba | 6 | ||||
-rw-r--r-- | wizards/source/sfdocuments/SF_Writer.xba | 6 |
14 files changed, 290 insertions, 62 deletions
diff --git a/wizards/source/scriptforge/SF_Exception.xba b/wizards/source/scriptforge/SF_Exception.xba index 6add0b158990..38e5b2ef24e0 100644 --- a/wizards/source/scriptforge/SF_Exception.xba +++ b/wizards/source/scriptforge/SF_Exception.xba @@ -72,6 +72,7 @@ Const OVERWRITEERROR = "OVERWRITEERROR" Const READONLYERROR = "READONLYERROR" Const NOFILEMATCHERROR = "NOFILEMATCHFOUND" Const FOLDERCREATIONERROR = "FOLDERCREATIONERROR" +Const FILESYSTEMERROR = "FILESYSTEMERROR" ' SF_Services Const UNKNOWNSERVICEERROR = "UNKNOWNSERVICEERROR" @@ -884,6 +885,10 @@ Try: sMessage = sLocation _ & "\n" & "\n" & "\n" & .GetText("VALIDATEERROR", pvArgs(0)) _ & "\n" & "\n" & .GetText("FOLDERCREATION", pvArgs(0), pvArgs(1)) + Case FILESYSTEMERROR ' SF_FileSystem.---(ArgName, MethodName, ArgValue) + pvArgs(0) = _RightCase(pvArgs(0)) + sMessage = sLocation _ + & "\n" & "\n" & .GetText("FILESYSTEM", pvArgs(0), pvArgs(1), pvArgs(2)) Case UNKNOWNSERVICEERROR ' SF_Services.CreateScriptService(ArgName, Value, Library, Service) pvArgs(0) = _RightCase(pvArgs(0)) sMessage = sLocation _ diff --git a/wizards/source/scriptforge/SF_FileSystem.xba b/wizards/source/scriptforge/SF_FileSystem.xba index b09f980429f4..aeeafc4dc73d 100644 --- a/wizards/source/scriptforge/SF_FileSystem.xba +++ b/wizards/source/scriptforge/SF_FileSystem.xba @@ -27,7 +27,7 @@ Option Explicit ''' File and folder names may be expressed either in the (preferable because portable) URL form ''' or in the more usual operating system notation (e.g. C:\... for Windows) ''' The notation, both for arguments and for returned values -''' is determined by the FileNaming property: either "URL" (default) or "SYS" +''' is determined by the FileNaming property: either "ANY" (default), "URL" or "SYS" ''' ''' FileName: the full name of the file including the path without any ending path separator ''' FolderName: the full name of the folder including the path and the ending path separator @@ -37,6 +37,23 @@ Option Explicit ''' Admitted wildcards are: the "?" represents any single character ''' the "*" represents zero, one, or multiple characters ''' +''' Disk file sstems and document's internal file systems +''' All the implemented properties and methods are applicable on usual disk file systems. +''' Root is usually something like "C:\" or "/" or their URL equivalents +''' Now, Libreoffice documents have an internal file system as well. Many of the proposed methods +''' support document's file systems too, however, for some of them, with restrictions. +''' Read the comments in the individual methods below. +''' It makes browing folders and files, adding, replacing files possible. Updates will be +''' saved with the document. +''' VERY POWERFUL but KNOW WHAT YOU'RE DOING !! +''' The root of a document's file system is obtained from the "FileSystem" property of a document instance, like in: +''' Dim root As String, doc As Object, ui As Object +''' Set ui = CreateScriptService("ui") +''' Set doc = ui.GetDocument(ThisComponent) +''' root = doc.FileSystem +''' The file manifest.xml is managed automatically. +''' The FileNaming setting is ignored. +''' ''' Service invocation example: ''' Dim FSO As Variant ''' Set FSO = CreateScriptService("FileSystem") @@ -55,6 +72,7 @@ Const OVERWRITEERROR = "OVERWRITEERROR" ' Destination can not Const READONLYERROR = "READONLYERROR" ' Destination has its read-only attribute set Const NOFILEMATCHERROR = "NOFILEMATCHFOUND" ' No file matches Source containing wildcards Const FOLDERCREATIONERROR = "FOLDERCREATIONERROR" ' FolderName is an existing folder or file +Const FILESYSTEMERROR = "FILESYSTEMERROR" ' The method is not applicable on document's file systems REM ============================================================ MODULE CONSTANTS @@ -63,6 +81,9 @@ Const cstForReading = 1 Const cstForWriting = 2 Const cstForAppending = 8 +''' Document file system +Const DOCFILESYSTEM = "vnd.sun.star.tdoc:/" + REM ===================================================== CONSTRUCTOR/DESTRUCTOR REM ----------------------------------------------------------------------------- @@ -286,6 +307,7 @@ Public Function CompareFiles(Optional ByVal FileName1 As Variant _ ''' Compare 2 files and return True if they seem identical ''' The comparison may be based on the file attributes, like modification time, ''' or on their contents. +''' The method is not supporte for document's internal file systems. ''' Args: ''' FileName1: The 1st file to compare ''' FileName2: The 2nd file to compare @@ -294,6 +316,7 @@ Public Function CompareFiles(Optional ByVal FileName1 As Variant _ ''' True when the files seem identical ''' Exceptions: ''' UNKNOWNFILEERROR One of the files does not exist +''' FILESYSTEMERROR The method is not applicable on document's file systems ''' Example: ''' FSO.FileNaming = "SYS" ''' MsgBox FSO.CompareFiles("C:\myFile1.txt", "C:\myFile2.txt", CompareContents := True) @@ -322,6 +345,11 @@ Check: sFile = FileName2 : iFile = 2 If Not SF_FileSystem.FileExists(sFile) Then GoTo CatchNotExists + sFile = FileName1 : iFile = 1 + If SF_FileSystem._IsDocFileSystem(sFile) Then GoTo CatchNotSupported + sFile = FileName2 : iFile = 2 + If SF_FileSystem._IsDocFileSystem(sFile) Then GoTo CatchNotSupported + Try: With ScriptForge.SF_Session bCompare = .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper & cstPyHelper _ @@ -339,6 +367,9 @@ Catch: CatchNotExists: SF_Exception.RaiseFatal(UNKNOWNFILEERROR, "FileName" & iFile, sFile) GoTo Finally +CatchNotSupported: + SF_Exception.RaiseFatal(FILESYSTEMERROR, "FileName" & iFile, Split(cstThisSub, ".")(1), sFile) + GoTo Finally End Function ' ScriptForge.SF_FileSystem.CompareFiles REM ----------------------------------------------------------------------------- @@ -750,6 +781,7 @@ Dim vFiles As Variant ' Return value Dim oSfa As Object ' com.sun.star.ucb.SimpleFileAccess Dim sFolderName As String ' URL lias for FolderName Dim sFile As String ' Single file +Dim bDocFileSystem As Boolean ' When True, a document file system is being explored Dim i As Long Const cstThisSub = "FileSystem.Files" @@ -768,20 +800,30 @@ Check: If SF_FileSystem.FileExists(FolderName) Then GoTo CatchFile ' Must not be a file If Not SF_FileSystem.FolderExists(FolderName) Then GoTo CatchFolder ' Folder must exist + bDocFileSystem = SF_String.StartsWith(sFolderName, DOCFILESYSTEM) + Try: ' Get files Set oSfa = SF_Utils._GetUnoService("FileAccess") - vFiles = oSfa.getFolderContents(sFolderName, False) + vFiles = oSfa.getFolderContents(sFolderName, False) ' NB: The False argumentis ignored in document file systems ' Adjust notations For i = 0 To UBound(vFiles) sFile = SF_FileSystem._ConvertFromUrl(vFiles(i)) vFiles(i) = sFile Next i - ' Reduce list to those passing the filter - If Len(Filter) > 0 Then + + ' Reduce list to valid items: + ' - those passing the filter + ' - files only, not folders: in documents file systems, the False argument of getFolderContents() is ignored. + If Len(Filter) > 0 Or bDocFileSystem Then For i = 0 To UBound(vFiles) sFile = SF_FileSystem.GetName(vFiles(i)) - If Not SF_String.IsLike(sFile, Filter) Then vFiles(i) = "" + If Len(Filter) > 0 Then + If Not SF_String.IsLike(sFile, Filter) Then vFiles(i) = "" + End If + If bDocFileSystem Then + If oSfa.isFolder(ConvertToUrl(vFiles(i))) Then vFiles(i) = "" + End If Next i vFiles = Sf_Array.TrimArray(vFiles) End If @@ -936,6 +978,7 @@ Public Function GetFileLen(Optional ByVal FileName As Variant) As Currency ''' FileName: a string representing a file ''' Returns: ''' File size if FileName exists +''' 0 when FileName belongs to a document's internal file systems. ''' Exceptions: ''' UNKNOWNFILEERROR The file does not exist of is a folder ''' Example: @@ -956,10 +999,14 @@ Check: Try: If SF_FileSystem.FileExists(FileName) Then - With ScriptForge.SF_Session - curSize = .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper & cstPyHelper _ - , _ConvertFromUrl(FileName)) - End With + If SF_FileSystem._IsDocFileSystem(FileName) Then + curSize = 0 + Else + With ScriptForge.SF_Session + curSize = .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper & cstPyHelper _ + , _ConvertFromUrl(FileName)) + End With + End If Else GoTo CatchNotExists End If @@ -978,12 +1025,14 @@ End Function ' ScriptForge.SF_FileSystem.GetFileLen REM ----------------------------------------------------------------------------- Public Function GetFileModified(Optional ByVal FileName As Variant) As Variant ''' Returns the last modified date for the given file +''' The method is not supporte for document's internal file systems. ''' Args: ''' FileName: a string representing an existing file ''' Returns: ''' The modification date and time as a Basic Date ''' Exceptions: ''' UNKNOWNFILEERROR The file does not exist of is a folder +''' FILESYSTEMERROR The method is not applicable on document's file systems ''' Example: ''' Dim a As Date ''' FSO.FileNaming = "SYS" @@ -1003,6 +1052,7 @@ Check: If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then If Not SF_Utils._ValidateFile(FileName, "FileName") Then GoTo Finally End If + If SF_FileSystem._IsDocFileSystem(FileName) Then GoTo CatchNotSupported Try: Set oSfa = SF_Utils._GetUnoService("FileAccess") @@ -1023,6 +1073,9 @@ Catch: CatchNotExists: SF_Exception.RaiseFatal(UNKNOWNFILEERROR, "FileName", FileName) GoTo Finally +CatchNotSupported: + SF_Exception.RaiseFatal(FILESYSTEMERROR, "FileName", Split(cstThisSub, ".")(1), FileName) + GoTo Finally End Function ' ScriptForge.SF_FileSystem.GetFileModified REM ----------------------------------------------------------------------------- @@ -1152,20 +1205,21 @@ Catch: End Function ' ScriptForge.SF_FileSystem.GetProperty REM ----------------------------------------------------------------------------- -Public Function GetTempName() As String +Public Function GetTempName(Optional ByVal Extension As Variant) As String ''' Returns a randomly generated temporary file name that is useful for performing ''' operations that require a temporary file : the method does not create any file ''' Args: ''' Returns: ''' A FileName as a String that can be used f.i. with CreateTextFile() -''' The FileName does not have any suffix +''' The FileName has as suffix the given extension. ''' Example: ''' Dim a As String ''' FSO.FileNaming = "SYS" -''' a = FSO.GetTempName() & ".txt" +''' a = FSO.GetTempName("txt") ' /tmp/SF_123456.txt +''' a = FSO.GetTempName() ' /tmp/SF_234567 Dim sFile As String ' Return value -Dim sTempDir As String ' The path to a temporary folder +Dim sExtension As String ' The given extension preceded by a dot Dim lRandom As Long ' Random integer Const cstThisSub = "FileSystem.GetTempName" @@ -1175,11 +1229,15 @@ Const cstSubArgs = "" sFile = "" Check: - SF_Utils._EnterFunction(cstThisSub, cstSubArgs) + If IsMissing(Extension) Or IsEmpty(Extension) Then Extension = "" + If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then + If Not SF_Utils._Validate(Extension, "Extension", V_STRING) Then GoTo Catch + End If Try: lRandom = SF_Session.ExecuteCalcFunction("RANDBETWEEN.NV", 1, 999999) - sFile = SF_FileSystem.TemporaryFolder & "SF_" & Right("000000" & lRandom, 6) + If Len(Extension) > 0 Then sExtension = "." & Extension Else sExtension = "" + sFile = SF_FileSystem.TemporaryFolder & "SF_" & Right("000000" & lRandom, 6) & sExtension Finally: GetTempName = SF_FileSystem._ConvertFromUrl(sFile) @@ -1195,6 +1253,7 @@ Public Function HashFile(Optional ByVal FileName As Variant _ ) As String ''' Return an hexadecimal string representing a checksum of the given file ''' Next algorithms are supported: MD5, SHA1, SHA224, SHA256, SHA384 and SHA512 +''' The method is not supporte for document's internal file systems. ''' Args: ''' FileName: a string representing a file ''' Algorithm: The hashing algorithm to use @@ -1203,6 +1262,7 @@ Public Function HashFile(Optional ByVal FileName As Variant _ ''' A zero-length string when an error occurred ''' Exceptions: ''' UNKNOWNFILEERROR The file does not exist of is a folder +''' FILESYSTEMERROR The method is not applicable on document's file systems ''' Example: ''' Print SF_FileSystem.HashFile("C:\pagefile.sys", "MD5") @@ -1220,6 +1280,7 @@ Check: If Not SF_Utils._Validate(Algorithm, "Algorithm", V_STRING _ , Array("MD5", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512")) Then GoTo Finally End If + If SF_FileSystem._IsDocFileSystem(FileName) Then GoTo CatchNotSupported Try: If SF_FileSystem.FileExists(FileName) Then @@ -1240,6 +1301,9 @@ Catch: CatchNotExists: SF_Exception.RaiseFatal(UNKNOWNFILEERROR, "FileName", FileName) GoTo Finally +CatchNotSupported: + SF_Exception.RaiseFatal(FILESYSTEMERROR, "FileName", Split(cstThisSub, ".")(1), FileName) + GoTo Finally End Function ' ScriptForge.SF_FileSystem.HashFile REM ----------------------------------------------------------------------------- @@ -1389,6 +1453,7 @@ Public Function Normalize(Optional ByVal FileName As Variant) As String ''' Normalize a pathname by collapsing redundant separators and up-level references ''' so that A//B, A/B/, A/./B and A/foo/../B all become A/B. ''' On Windows, it converts forward slashes to backward slashes. +''' The method returns the input string when the file is from a document's internal file systems. ''' Args: ''' FileName: a string representing a file. The file may not exist. ''' Returns: @@ -1410,12 +1475,16 @@ Check: End If Try: - With ScriptForge.SF_Session - sNorm = .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper & cstPyHelper _ - , _ConvertFromUrl(FileName)) - ' The Python os.path expects and returns a file name in os notation - If SF_FileSystem.FileNaming <> "SYS" Then sNorm = ConvertToUrl(sNorm) - End With + If SF_FileSystem._IsDocFileSystem(FileName) Then + sNorm = FileName + Else + With ScriptForge.SF_Session + sNorm = .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper & cstPyHelper _ + , _ConvertFromUrl(FileName)) + ' The Python os.path expects and returns a file name in os notation + If SF_FileSystem.FileNaming <> "SYS" Then sNorm = ConvertToUrl(sNorm) + End With + End If Finally: Normalize = sNorm @@ -1454,22 +1523,24 @@ Public Function OpenTextFile(Optional ByVal FileName As Variant _ ''' If Not IsNull(myFile) Then ' ... Go ahead with reading text lines Dim oTextStream As Object ' Return value -Dim bExists As Boolean ' File to open does exist +Dim bExists As Boolean ' When True, file to open does exist +Dim bEmbeddedFile As Boolean ' When True, file to open is embedded in a document's internal file system +Dim oSfa As Object ' com.sun.star.ucb.SimpleFileAccess Const cstThisSub = "FileSystem.OpenTextFile" -Const cstSubArgs = "FileName, [IOMode=1], [Create=False], [Encoding=""UTF-8""]" +Const cstSubArgs = "FileName, [IOMode=1|2|8], [Create=False], [Encoding=""UTF-8""]" If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch Set oTextStream = Nothing Check: With SF_FileSystem - If IsMissing(IOMode) Or IsEmpty(IOMode) Then IOMode = ForReading + If IsMissing(IOMode) Or IsEmpty(IOMode) Then IOMode = cstForReading If IsMissing(Create) Or IsEmpty(Create) Then Create = False If IsMissing(Encoding) Or IsEmpty(Encoding) Then Encoding = "UTF-8" If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then If Not SF_Utils._ValidateFile(FileName, "FileName") Then GoTo Finally If Not SF_Utils._Validate(IOMode, "IOMode", V_NUMERIC _ - , Array(ForReading, ForWriting, ForAppending)) _ + , Array(cstForReading, cstForWriting, cstForAppending)) _ Then GoTo Finally If Not SF_Utils._Validate(Create, "Create", V_BOOLEAN) Then GoTo Finally If Not SF_Utils._Validate(Encoding, "Encoding", V_STRING) Then GoTo Finally @@ -1482,6 +1553,8 @@ Check: End Select If IOMode = ForAppending And Not bExists Then IOMode = ForWriting + + bEmbeddedFile = SF_FileSystem._IsDocFileSystem(FileName) End With Try: @@ -1490,7 +1563,19 @@ Try: With oTextStream .[Me] = oTextStream .[_Parent] = SF_FileSystem - ._FileName = SF_FileSystem._ConvertToUrl(FileName) + ._IsEmbeddedFile = bEmbeddedFile + If bEmbeddedFile And (IOMode = cstForWriting Or IOMode = cstForAppending) Then + ' Updates of an embedded file are done on a copy + ._EmbeddedFileName = SF_FileSystem._ConvertToUrl(FileName) + ._FileName = SF_FileSystem._ConvertToUrl(SF_FileSystem.GetTempName(SF_FileSystem.GetExtension(FileName))) + ' Create the copy if relevant + If bExists Then + Set oSfa = SF_Utils._GetUnoService("FileAccess") + oSfa.copy(._EmbeddedFileName, ._FileName) + End If + Else + ._FileName = SF_FileSystem._ConvertToUrl(FileName) + End If ._IOMode = IOMode ._Encoding = Encoding ._FileExists = bExists @@ -1517,14 +1602,17 @@ Public Function PickFile(Optional ByVal DefaultFile As Variant _ ''' The mode, OPEN or SAVE, and the filter may be preset ''' If mode = SAVE and the picked file exists, a warning message will be displayed ''' Modified from Andrew Pitonyak's Base Macro Programming §10.4 +''' The method is not supporte for document's internal file systems. ''' Args: ''' DefaultFile: Folder part: the FolderName from which to start. Default = the last selected folder ''' File part: the default file to open or save ''' Mode: "OPEN" (input file) or "SAVE" (output file) ''' Filter: by default only files having the given suffix will be displayed. Default = all suffixes -''' The filter combo box will contain the given SuffixFilter (if not "*") and "*.*" +''' The filter combo box will contain the given suffix filter (if not "*") and "*.*" ''' Returns: -''' The selected FileName in URL format or "" if the dialog was cancelled +''' The selected FileName in FileNaming format or "" if the dialog was cancelled +''' Exceptions: +''' FILESYSTEMERROR The method is not applicable on document's file systems ''' Example: ''' FSO.FileNaming = "SYS" ''' FSO.PickFile("C:\", "OPEN", "txt") ' Only *.txt files are displayed @@ -1553,6 +1641,7 @@ Check: If Not SF_Utils._Validate(Mode, "Mode", V_STRING, Array("OPEN", "SAVE")) Then GoTo Finally If Not SF_Utils._Validate(Filter, "Filter", V_STRING) Then GoTo Finally End If + If SF_FileSystem._IsDocFileSystem(DefaultFile) Then GoTo CatchNotSupported DefaultFile = SF_FileSystem._ConvertToUrl(DefaultFile) Try: @@ -1600,6 +1689,9 @@ Finally: Exit Function Catch: GoTo Finally +CatchNotSupported: + SF_Exception.RaiseFatal(FILESYSTEMERROR, "DefaultFile", Split(cstThisSub, ".")(1), DefaultFile) + GoTo Finally End Function ' ScriptForge.SF_FileSystem.PickFile REM ----------------------------------------------------------------------------- @@ -1607,12 +1699,15 @@ Public Function PickFolder(Optional ByVal DefaultFolder As Variant _ , Optional ByVal FreeText As Variant _ ) As String ''' Display a FolderPicker dialog box +''' The method is not supporte for document's internal file systems. ''' Args: ''' DefaultFolder: the FolderName from which to start. Default = the last selected folder ''' FreeText: text to display in the dialog. Default = "" ''' Returns: ''' The selected FolderName in URL or operating system format ''' The zero-length string if the dialog was cancelled +''' Exceptions: +''' FILESYSTEMERROR The method is not applicable on document's file systems ''' Example: ''' FSO.FileNaming = "SYS" ''' FSO.PickFolder("C:\", "Choose a folder or press Cancel") @@ -1634,6 +1729,7 @@ Check: If Not SF_Utils._ValidateFile(DefaultFolder, "DefaultFolder", , True) Then GoTo Finally If Not SF_Utils._Validate(FreeText, "FreeText", V_STRING) Then GoTo Finally End If + If SF_FileSystem._IsDocFileSystem(DefaultFolder) Then GoTo CatchNotSupported DefaultFolder = SF_FileSystem._ConvertToUrl(DefaultFolder) Try: @@ -1657,6 +1753,9 @@ Finally: Exit Function Catch: GoTo Finally +CatchNotSupported: + SF_Exception.RaiseFatal(FILESYSTEMERROR, "DefaultFolder", Split(cstThisSub, ".")(1), DefaultFolder) + GoTo Finally End Function ' ScriptForge.SF_FileSystem.PickFolder REM ----------------------------------------------------------------------------- @@ -1788,11 +1887,12 @@ Private Function _ConvertFromUrl(psFile) As String ''' Execute the builtin ConvertFromUrl function only when relevant ''' i.e. when FileNaming (how arguments and return values are provided) = "SYS" ''' Called at the bottom of methods returning file names -''' Remark: psFile might contain wildcards +''' Remarks: psFile might contain wildcards +''' Files from document's file systems are never converted Const cstQuestion = "$QUESTION$", cstStar = "$STAR$" ' Special tokens to replace wildcards - If SF_FileSystem.FileNaming = "SYS" Then + If SF_FileSystem.FileNaming = "SYS" And Not SF_FileSystem._IsDocFileSystem(psFile) Then _ConvertFromUrl = Replace(Replace( _ ConvertFromUrl(Replace(Replace(psFile, "?", cstQuestion), "*", cstStar)) _ , cstQuestion, "?"), cstStar, "*") @@ -1807,12 +1907,13 @@ Private Function _ConvertToUrl(psFile) As String ''' Execute the builtin ConvertToUrl function only when relevant ''' i.e. when FileNaming (how arguments and return values are provided) <> "URL" ''' Called at the top of methods receiving file names as arguments -''' Remark: psFile might contain wildcards +''' Remarks: psFile might contain wildcards +''' Files from document's file systems are never converted - If SF_FileSystem.FileNaming = "URL" Then + If SF_FileSystem.FileNaming = "URL" Or SF_FileSystem._IsDocFileSystem(psFile) Then _ConvertToUrl = psFile Else - ' ConvertToUrl encodes "?" + ' ConvertToUrl() encodes "?" _ConvertToUrl = Replace(ConvertToUrl(psFile), "%3F", "?") End If @@ -1886,7 +1987,7 @@ Check: Select Case bFile Case True ' File If Not .FileExists(psSource) Then GoTo CatchFileNotExists - If Not .FolderExists(.GetParentFolderName(psDestination)) Then GoTo CatchSourceFolderNotExists + If Not .FolderExists(.GetParentFolderName(psDestination)) Then GoTo CatchDestFolderNotExists If .FolderExists(psDestination) Then GoTo CatchFolderNotFile bDestExists = .FileExists(psDestination) If pbOverWrite = False And bDestExists = True Then GoTo CatchDestinationExists @@ -2131,6 +2232,14 @@ Dim sConfig As String ' Return value End Function ' ScriptForge.FileSystem._GetConfigFolder REM ----------------------------------------------------------------------------- +Public Function _IsDocFileSystem(psFile As String) As Boolean +''' ReturnsTrue when the argument designates a document's internal file system + + _IsDocFileSystem = SF_String.StartsWith(psFile, DOCFILESYSTEM, CaseSensitive := True) + +End Function ' ScriptForge.SF_FileSystem._IsDocFileSystem + +REM ----------------------------------------------------------------------------- Public Function _ParseUrl(psUrl As String) As Object ''' Returns a com.sun.star.util.URL structure based on the argument diff --git a/wizards/source/scriptforge/SF_Region.xba b/wizards/source/scriptforge/SF_Region.xba index 9ceccbbc94a6..4c13da75afac 100644 --- a/wizards/source/scriptforge/SF_Region.xba +++ b/wizards/source/scriptforge/SF_Region.xba @@ -858,4 +858,4 @@ Finally: End Function ' ScriptForge.SF_Region._PropertyGet REM ================================================ END OF SCRIPTFORGE.SF_REGION -</script:module> +</script:module>
\ No newline at end of file diff --git a/wizards/source/scriptforge/SF_Root.xba b/wizards/source/scriptforge/SF_Root.xba index e2649d0ce1d1..488e8bfc2e8f 100644 --- a/wizards/source/scriptforge/SF_Root.xba +++ b/wizards/source/scriptforge/SF_Root.xba @@ -74,14 +74,15 @@ Private URLTransformer As Object ' com.sun.star.util.URLTransformer Private Introspection As Object ' com.sun.star.beans.Introspection Private BrowseNodeFactory As Object ' com.sun.star.script.browse.BrowseNodeFactory Private DatabaseContext As Object ' com.sun.star.sdb.DatabaseContext -Private ConfigurationProvider _ - As Object ' com.sun.star.configuration.ConfigurationProvider +Private ConfigurationProvider As Object + ' com.sun.star.configuration.ConfigurationProvider Private PackageProvider As Object ' com.sun.star.comp.deployment.PackageInformationProvider Private MailService As Object ' com.sun.star.system.SimpleCommandMail or com.sun.star.system.SimpleSystemMail Private GraphicExportFilter As Object ' com.sun.star.drawing.GraphicExportFilter Private Toolkit As Object ' com.sun.star.awt.Toolkit Private ModuleUIConfigurationManagerSupplier As Object ' com.sun.star.ui.ModuleUIConfigurationManagerSupplier +Private TransientDocument As Object ' com.sun.star.frame.TransientDocumentsDocumentContentFactory ' Specific persistent services objects or properties Private FileSystemNaming As String ' If "SYS", file and folder naming is based on operating system notation @@ -152,6 +153,7 @@ Private Sub Class_Initialize() Set GraphicExportFilter = Nothing Set Toolkit = Nothing Set ModuleUIConfigurationManagerSupplier = Nothing + Set TransientDocument = Nothing OSName = "" SFDialogs = Empty SFForms = Empty @@ -610,6 +612,15 @@ Try: & "%1: An identifier\n" _ & "%2: A file or folder name" _ ) + ' SF_FileSystem.Any + .AddText( Context := "FILESYSTEM" _ + , MsgId := "The method « %2 » is not applicable on a document's internal file system.\n\n" _ + & "« %1 » = '%3'" _ + , Comment := "SF_FileSystem not supported method error message\n" _ + & "%1: A method name\n" _ + & "%2: An identifier\n" _ + & "%3: A file or folder name" _ + ) ' SF_Services.CreateScriptService .AddText( Context := "UNKNOWNSERVICE" _ , MsgId := "No service named '%4' has been registered for the library '%3'.\n\n" _ diff --git a/wizards/source/scriptforge/SF_TextStream.xba b/wizards/source/scriptforge/SF_TextStream.xba index 35f1b6fb2b49..3da9a773f08e 100644 --- a/wizards/source/scriptforge/SF_TextStream.xba +++ b/wizards/source/scriptforge/SF_TextStream.xba @@ -31,6 +31,12 @@ Option Explicit ''' https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1io_1_1XTextInputStream.html ''' https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1io_1_1XTextOutputStream.html ''' +''' Disk file sstems and document's internal file systems +''' All methods and properties are applicable without restrictions on both file systems. +''' However, when updates are operated on text files embedded in a document, (with the WriteXXX() methods), +''' the updates are first done on a copy of the original file. When the file is closed, the copy +''' will overwrite the original file. The whole process is transparent for the user script. +''' ''' Instantiation example: ''' Dim FSO As Object, myFile As Object ''' Set FSO = CreateScriptService("FileSystem") @@ -52,7 +58,7 @@ Private [Me] As Object Private [_Parent] As Object Private ObjectType As String ' Must be TEXTSTREAM Private ServiceName As String -Private _FileName As String ' File where it is about +Private _FileName As String ' File where it is about in URL format Private _IOMode As Integer ' ForReading, ForWriting or ForAppending Private _Encoding As String ' https://www.iana.org/assignments/character-sets/character-sets.xhtml Private _NewLine As String ' Line break in write mode @@ -65,6 +71,12 @@ Private _InputStream As Object ' com.sun.star.io.TextInputStream Private _OutputStream As Object ' com.sun.star.io.TextOutputStream Private _ForceBlankLine As Boolean ' Workaround: XTextInputStream misses last line if file ends with newline +' Document's file system only +Private _IsEmbeddedFile As Boolean ' True when concerned file is embedded in a document +Private _EmbeddedFileName As String ' When not blank and in update mode, the full embedded file name + ' This file is initially copied in a temporary storage, modified by the actual class, + ' and rewritten in the document when the textstream.CloseFile() method is run + REM ============================================================ MODULE CONSTANTS REM ===================================================== CONSTRUCTOR/DESTRUCTOR @@ -85,6 +97,8 @@ Private Sub Class_Initialize() Set _InputStream = Nothing Set _OutputStream = Nothing _ForceBlankLine = False + _IsEmbeddedFile = False + _EmbeddedFileName = "" End Sub ' ScriptForge.SF_TextStream Constructor REM ----------------------------------------------------------------------------- @@ -208,6 +222,7 @@ Public Function CloseFile() As Boolean ''' myFile.CloseFile() Dim bClose As Boolean ' Return value +Dim oSfa As Object ' com.sun.star.ucb.SimpleFileAccess Const cstThisSub = "TextStream.CloseFile" Const cstSubArgs = "" @@ -227,6 +242,13 @@ Try: Set _InputStream = Nothing Set _OutputStream = Nothing Set _FileHandler = Nothing + + ' Manage embedded file closure: copy temporary file to document internal storage + If _IsEmbeddedFile Then + Set oSfa = SF_Utils._GetUnoService("FileAccess") + oSfa.copy(_FileName, _EmbeddedFileName) + End If + bClose = True Finally: @@ -664,7 +686,8 @@ Dim cstSubArgs As String Case UCase("Encoding") _PropertyGet = _Encoding Case UCase("FileName") - _PropertyGet = SF_FileSystem._ConvertFromUrl(_FileName) ' Depends on FileNaming + ' Requested is the user visible file name in FileNaming notation + _PropertyGet = SF_FileSystem._ConvertFromUrl(Iif(_IsEmbeddedFile, _EmbeddedFileName, _FileName)) Case UCase("IOMode") With SF_FileSystem Select Case _IOMode diff --git a/wizards/source/scriptforge/SF_Utils.xba b/wizards/source/scriptforge/SF_Utils.xba index 11753704c461..608a2e8422ca 100644 --- a/wizards/source/scriptforge/SF_Utils.xba +++ b/wizards/source/scriptforge/SF_Utils.xba @@ -508,6 +508,11 @@ Dim oDefaultContext As Object Set .Toolkit = CreateUnoService("com.sun.star.awt.Toolkit") End If Set _GetUNOService = .Toolkit + Case "TransientDocumentFactory" + If IsEmpty(.TransientDocument) Or IsNull(.TransientDocument) Then + Set .TransientDocument = CreateUnoService("com.sun.star.frame.TransientDocumentsDocumentContentFactory") + End If + Set _GetUNOService = .TransientDocument Case "URLTransformer" If IsEmpty(.URLTransformer) Or IsNull(.URLTransformer) Then Set .URLTransformer = CreateUnoService("com.sun.star.util.URLTransformer") @@ -951,6 +956,7 @@ Dim bValid As Boolean ' Returned value Dim sFileNaming As String ' Alias of SF_FileSystem.FileNaming Dim oArgument As Variant ' Workaround "Object variable not set" error on 1st executable statement Const cstMaxLength = 256 ' Maximum length of readable value +Const DOCFILESYSTEM = "vnd.sun.star.tdoc:/" ' To avoid useless recursions, keep main function, only increase stack depth @@ -984,6 +990,7 @@ Try: If bValid Then With SF_FileSystem sFileNaming = .FileNaming + If SF_String.StartsWith(sFile, DOCFILESYSTEM) Then sFileNaming = "URL" Select Case sFileNaming Case "ANY" : bValid = SF_String.IsUrl(ConvertToUrl(sFile)) Case "URL" : bValid = SF_String.IsUrl(sFile) diff --git a/wizards/source/scriptforge/po/ScriptForge.pot b/wizards/source/scriptforge/po/ScriptForge.pot index 58d9a4afeaab..1f18806679ac 100644 --- a/wizards/source/scriptforge/po/ScriptForge.pot +++ b/wizards/source/scriptforge/po/ScriptForge.pot @@ -14,7 +14,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: https://bugs.libreoffice.org/enter_bug.cgi?product=LibreOffice&bug_status=UNCONFIRMED&component=UI\n" -"POT-Creation-Date: 2023-05-15 16:22:55\n" +"POT-Creation-Date: 2023-07-14 16:26:26\n" "PO-Revision-Date: YYYY-MM-DD HH:MM:SS\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <EMAIL@ADDRESS>\n" @@ -412,6 +412,19 @@ msgid "" "« %1 » = %2" msgstr "" +#. SF_FileSystem not supported method error message +#. %1: A method name +#. %2: An identifier +#. %3: A file or folder name +#, kde-format +msgctxt "FILESYSTEM" +msgid "" +"The method « %2 » is not applicable on a document's internal file " +"system.\n" +"\n" +"« %1 » = '%3'" +msgstr "" + #. SF_Services.CreateScriptService error message #. %1: An identifier #. %2: A string diff --git a/wizards/source/scriptforge/po/en.po b/wizards/source/scriptforge/po/en.po index 58d9a4afeaab..1f18806679ac 100644 --- a/wizards/source/scriptforge/po/en.po +++ b/wizards/source/scriptforge/po/en.po @@ -14,7 +14,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: https://bugs.libreoffice.org/enter_bug.cgi?product=LibreOffice&bug_status=UNCONFIRMED&component=UI\n" -"POT-Creation-Date: 2023-05-15 16:22:55\n" +"POT-Creation-Date: 2023-07-14 16:26:26\n" "PO-Revision-Date: YYYY-MM-DD HH:MM:SS\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <EMAIL@ADDRESS>\n" @@ -412,6 +412,19 @@ msgid "" "« %1 » = %2" msgstr "" +#. SF_FileSystem not supported method error message +#. %1: A method name +#. %2: An identifier +#. %3: A file or folder name +#, kde-format +msgctxt "FILESYSTEM" +msgid "" +"The method « %2 » is not applicable on a document's internal file " +"system.\n" +"\n" +"« %1 » = '%3'" +msgstr "" + #. SF_Services.CreateScriptService error message #. %1: An identifier #. %2: A string diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py index 96474e4eb4de..631ac00eb0df 100644 --- a/wizards/source/scriptforge/python/scriptforge.py +++ b/wizards/source/scriptforge/python/scriptforge.py @@ -694,7 +694,7 @@ class SFScriptForge: """ unodate = uno.createUnoStruct('com.sun.star.util.DateTime') unodate.Year, unodate.Month, unodate.Day, unodate.Hours, unodate.Minutes, unodate.Seconds, \ - unodate.NanoSeconds, unodate.IsUTC = \ + unodate.NanoSeconds, unodate.IsUTC = \ 1899, 12, 30, 0, 0, 0, 0, False # Identical to Basic TimeSerial() function if isinstance(date, float): @@ -1156,8 +1156,8 @@ class SFScriptForge: def GetParentFolderName(self, filename): return self.ExecMethod(self.vbMethod, 'GetParentFolderName', filename) - def GetTempName(self): - return self.ExecMethod(self.vbMethod, 'GetTempName') + def GetTempName(self, extension = ''): + return self.ExecMethod(self.vbMethod, 'GetTempName', extension) def HashFile(self, filename, algorithm): py = ScriptForge.pythonhelpermodule + '$' + '_SF_FileSystem__HashFile' @@ -2107,10 +2107,10 @@ class SFDocuments: serviceimplementation = 'basic' servicename = 'SFDocuments.Document' servicesynonyms = ('document', 'sfdocuments.document') - serviceproperties = dict(Description = True, DocumentType = False, ExportFilters = False, ImportFilters = False, - IsBase = False, IsCalc = False, IsDraw = False, IsFormDocument = False, - IsImpress = False, IsMath = False, IsWriter = False, Keywords = True, Readonly = False, - Subject = True, Title = True, XComponent = False) + serviceproperties = dict(Description = True, DocumentType = False, ExportFilters = False, FileSystem = False, + ImportFilters = False, IsBase = False, IsCalc = False, IsDraw = False, + IsFormDocument = False, IsImpress = False, IsMath = False, IsWriter = False, + Keywords = True, Readonly = False, Subject = True, Title = True, XComponent = False) # Force for each property to get its value from Basic - due to intense interactivity with user forceGetProperty = True @@ -2175,9 +2175,9 @@ class SFDocuments: serviceimplementation = 'basic' servicename = 'SFDocuments.Base' servicesynonyms = ('base', 'scriptforge.base') - serviceproperties = dict(DocumentType = False, IsBase = False, IsCalc = False, IsDraw = False, - IsFormDocument = False, IsImpress = False, IsMath = False, IsWriter = False, - XComponent = False) + serviceproperties = dict(DocumentType = False, FileSystem = False, IsBase = False, IsCalc = False, + IsDraw = False, IsFormDocument = False, IsImpress = False, IsMath = False, + IsWriter = False, XComponent = False) @classmethod def ReviewServiceArgs(cls, windowname = ''): @@ -2233,10 +2233,10 @@ class SFDocuments: servicename = 'SFDocuments.Calc' servicesynonyms = ('calc', 'sfdocuments.calc') serviceproperties = dict(CurrentSelection = True, Sheets = False, - Description = True, DocumentType = False, ExportFilters = False, ImportFilters = False, - IsBase = False, IsCalc = False, IsDraw = False, IsFormDocument = False, - IsImpress = False, IsMath = False, IsWriter = False, Keywords = True, Readonly = False, - Subject = True, Title = True, XComponent = False) + Description = True, DocumentType = False, ExportFilters = False, FileSystem = False, + ImportFilters = False, IsBase = False, IsCalc = False, IsDraw = False, + IsFormDocument = False, IsImpress = False, IsMath = False, IsWriter = False, + Keywords = True, Readonly = False, Subject = True, Title = True, XComponent = False) # Force for each property to get its value from Basic - due to intense interactivity with user forceGetProperty = True @@ -2590,9 +2590,9 @@ class SFDocuments: serviceimplementation = 'basic' servicename = 'SFDocuments.FormDocument' servicesynonyms = ('formdocument', 'sfdocuments.formdocument') - serviceproperties = dict(DocumentType = False, IsBase = False, IsCalc = False, IsDraw = False, - IsFormDocument = False, IsImpress = False, IsMath = False, IsWriter = False, - Readonly = False, XComponent = False) + serviceproperties = dict(DocumentType = False, FileSystem = False, IsBase = False, IsCalc = False, + IsDraw = False, IsFormDocument = False, IsImpress = False, IsMath = False, + IsWriter = False, Readonly = False, XComponent = False) @classmethod def ReviewServiceArgs(cls, windowname = ''): @@ -2627,10 +2627,10 @@ class SFDocuments: serviceimplementation = 'basic' servicename = 'SFDocuments.Writer' servicesynonyms = ('writer', 'sfdocuments.writer') - serviceproperties = dict(Description = True, DocumentType = False, ExportFilters = False, ImportFilters = False, - IsBase = False, IsCalc = False, IsDraw = False, IsFormDocument = False, - IsImpress = False, IsMath = False, IsWriter = False, Keywords = True, Readonly = False, - Subject = True, Title = True, XComponent = False) + serviceproperties = dict(Description = True, DocumentType = False, ExportFilters = False, FileSystem = False, + ImportFilters = False, IsBase = False, IsCalc = False, IsDraw = False, + IsFormDocument = False, IsImpress = False, IsMath = False, IsWriter = False, + Keywords = True, Readonly = False, Subject = True, Title = True, XComponent = False) # Force for each property to get its value from Basic - due to intense interactivity with user forceGetProperty = True diff --git a/wizards/source/sfdocuments/SF_Base.xba b/wizards/source/sfdocuments/SF_Base.xba index cc5ab488365e..efc8bfeb148c 100644 --- a/wizards/source/sfdocuments/SF_Base.xba +++ b/wizards/source/sfdocuments/SF_Base.xba @@ -683,6 +683,7 @@ Public Function Properties() As Variant Properties = Array( _ "DocumentType" _ + , "FileSystem" _ , "IsBase" _ , "IsCalc" _ , "IsDraw " _ @@ -822,6 +823,11 @@ Property Get DocumentType() As String End Property ' SFDocuments.SF_Base.DocumentType REM ----------------------------------------------------------------------------- +Property Get FileSystem() As String + FileSystem = [_Super].GetProperty("FileSystem") +End Property ' SFDocuments.SF_Base.FileSystem + +REM ----------------------------------------------------------------------------- Property Get IsBase() As Boolean IsBase = [_Super].GetProperty("IsBase") End Property ' SFDocuments.SF_Base.IsBase diff --git a/wizards/source/sfdocuments/SF_Calc.xba b/wizards/source/sfdocuments/SF_Calc.xba index 0138730c11f3..a78762056fb0 100644 --- a/wizards/source/sfdocuments/SF_Calc.xba +++ b/wizards/source/sfdocuments/SF_Calc.xba @@ -2551,6 +2551,7 @@ Public Function Properties() As Variant , "DocumentProperties" _ , "DocumentType" _ , "ExportFilters" _ + , "FileSystem" _ , "FirstCell" _ , "FirstColumn" _ , "FirstRow" _ @@ -3619,6 +3620,11 @@ Property Get ExportFilters() As Variant End Property ' SFDocuments.SF_Calc.ExportFilters REM ----------------------------------------------------------------------------- +Property Get FileSystem() As String + FileSystem = [_Super].GetProperty("FileSystem") +End Property ' SFDocuments.SF_Calc.FileSystem + +REM ----------------------------------------------------------------------------- Property Get ImportFilters() As Variant ImportFilters = [_Super].GetProperty("ImportFilters") End Property ' SFDocuments.SF_Calc.ImportFilters diff --git a/wizards/source/sfdocuments/SF_Document.xba b/wizards/source/sfdocuments/SF_Document.xba index 2233aeb5c650..37cb39fa2010 100644 --- a/wizards/source/sfdocuments/SF_Document.xba +++ b/wizards/source/sfdocuments/SF_Document.xba @@ -250,6 +250,19 @@ Property Get ExportFilters() As Variant End Property ' SFDocuments.SF_Document.ExportFilters REM ----------------------------------------------------------------------------- +Property Get FileSystem() As String +''' Returns the root of the document's virtual file system +''' The "FileSystem" service may be used to explore it, as long as the document remains open +''' The property is not applicable to Base documents +''' Example: +''' Dim sRoot As String, FSO +''' sRoot = oDoc.FileSystem +''' Set FSO = CreateScriptService("FileSystem") +''' MsgBox FSO.FolderExists(FSO.BuildPath(sRoot, "Pictures")) + FileSystem = _PropertyGet("FileSystem") +End Property ' SFDocuments.SF_Document.FileSystem + +REM ----------------------------------------------------------------------------- Property Get ImportFilters() As Variant ''' Returns the list of the import filter names applicable to the current document ''' as a zero-based array of strings @@ -833,6 +846,7 @@ Public Function Properties() As Variant , "DocumentProperties" _ , "DocumentType" _ , "ExportFilters" _ + , "FileSystem" _ , "ImportFilters" _ , "IsBase" _ , "IsCalc" _ @@ -1573,6 +1587,8 @@ Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant ''' psProperty: the name of the property Dim oProperties As Object ' Document or Custom properties +Dim oTransient As Object ' com.sun.star.frame.TransientDocumentsDocumentContentFactory +Dim oContent As Object ' com.sun.star.comp.ucb.TransientDocumentsContent Dim cstThisSub As String Const cstSubArgs = "" @@ -1599,6 +1615,13 @@ Const cstSubArgs = "" _PropertyGet = _DocumentType Case "ExportFilters" _PropertyGet = _GetFilterNames(True) + Case "FileSystem" + ' Natural choice would have been to use the component.RunTimeUID property + ' However it is optional in the OfficeDocument service and not available for Base documents + ' Below a more generic alternative derived from the get_document_uri() method found in apso.py + Set oTransient = ScriptForge.SF_Utils._GetUnoService("TransientDocumentFactory") + Set oContent = oTransient.createDocumentContent(_Component) + _PropertyGet = oContent.getIdentifier().ContentIdentifier & "/" Case "ImportFilters" _PropertyGet = _GetFilterNames(False) Case "IsBase", "IsCalc", "IsDraw", "IsFormDocument", "IsImpress", "IsMath", "IsWriter" diff --git a/wizards/source/sfdocuments/SF_FormDocument.xba b/wizards/source/sfdocuments/SF_FormDocument.xba index a619ac113aa4..ddddca2f8e70 100644 --- a/wizards/source/sfdocuments/SF_FormDocument.xba +++ b/wizards/source/sfdocuments/SF_FormDocument.xba @@ -419,6 +419,7 @@ Public Function Properties() As Variant Properties = Array( _ "DocumentType" _ + , "FileSystem" _ , "IsBase" _ , "IsCalc" _ , "IsDraw" _ @@ -434,6 +435,11 @@ End Function ' SFDocuments.SF_FormDocument.Properties REM ======================================================= SUPERCLASS PROPERTIES REM ----------------------------------------------------------------------------- +Property Get FileSystem() As String + FileSystem = [_Super].GetProperty("FileSystem") +End Property ' SFDocuments.SF_FormDocument.FileSystem + +REM ----------------------------------------------------------------------------- Property Get IsBase() As Boolean IsBase = [_Super].GetProperty("IsBase") End Property ' SFDocuments.SF_FormDocument.IsBase diff --git a/wizards/source/sfdocuments/SF_Writer.xba b/wizards/source/sfdocuments/SF_Writer.xba index 685fd2023a20..bc41e0fef7bc 100644 --- a/wizards/source/sfdocuments/SF_Writer.xba +++ b/wizards/source/sfdocuments/SF_Writer.xba @@ -310,6 +310,7 @@ Public Function Properties() As Variant , "DocumentProperties" _ , "DocumentType" _ , "ExportFilters" _ + , "FileSystem" _ , "ImportFilters" _ , "IsBase" _ , "IsCalc" _ @@ -413,6 +414,11 @@ Property Get ExportFilters() As Variant End Property ' SFDocuments.SF_Writer.ExportFilters REM ----------------------------------------------------------------------------- +Property Get FileSystem() As String + FileSystem = [_Super].GetProperty("FileSystem") +End Property ' SFDocuments.SF_Writer.FileSystem + +REM ----------------------------------------------------------------------------- Property Get ImportFilters() As Variant ImportFilters = [_Super].GetProperty("ImportFilters") End Property ' SFDocuments.SF_Writer.ImportFilters |