diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2022-03-07 13:26:36 +0100 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2022-03-07 16:13:46 +0100 |
commit | 2598c35dbac8dc4492ad1fc79925c5347e683af0 (patch) | |
tree | 4b308308864d9aef030f51b7ca87381f70b389c1 /wizards/source | |
parent | a7e5c48b3d6d98ea35916cae9bd85a87f8ddf8e9 (diff) |
ScriptForge - (SF_Document) new Import/ExportFilters properties
The ImportFilters and ExportFilters properties
of the Document, Calc and Writer services
return a zero-based array (Basic) or a list (Python)
of all filters available for the current document
instance.
These properties are NOT applicable to Base documents.
ImportFilter contains the filters flagged for import
or for Import/Export. Idem for ExportFilters.
Both lists overlap each other partially.
The filter selection is done thanks to the
- filter type, to be compared with the Identifier of
the document's component
- filter flags, last 2 bits determine the import or export
orientation
The filter names are potential arguments of the OpenDocument()
and SaveAs() methods (and alike).
Both properties are callable from Basic and Python user scripts.
Change-Id: I8ce5312a58a013bc7e1e68101ff9f50f3233155d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131106
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Diffstat (limited to 'wizards/source')
-rw-r--r-- | wizards/source/scriptforge/python/scriptforge.py | 18 | ||||
-rw-r--r-- | wizards/source/sfdocuments/SF_Calc.xba | 12 | ||||
-rw-r--r-- | wizards/source/sfdocuments/SF_Document.xba | 84 | ||||
-rw-r--r-- | wizards/source/sfdocuments/SF_Writer.xba | 12 |
4 files changed, 117 insertions, 9 deletions
diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py index ec76835befd2..8843d0627b63 100644 --- a/wizards/source/scriptforge/python/scriptforge.py +++ b/wizards/source/scriptforge/python/scriptforge.py @@ -1788,9 +1788,9 @@ class SFDocuments: serviceimplementation = 'basic' servicename = 'SFDocuments.Document' servicesynonyms = ('document', 'sfdocuments.document') - serviceproperties = dict(Description = True, DocumentType = False, IsBase = False, IsCalc = False, - IsDraw = False, IsImpress = False, IsMath = False, IsWriter = False, - Keywords = True, Readonly = False, Subject = True, Title = True, + serviceproperties = dict(Description = True, DocumentType = False, ExportFilters = False, ImportFilters = False, + IsBase = False, IsCalc = False, IsDraw = 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 @@ -1902,9 +1902,9 @@ class SFDocuments: servicename = 'SFDocuments.Calc' servicesynonyms = ('calc', 'sfdocuments.calc') serviceproperties = dict(CurrentSelection = True, Sheets = False, - Description = True, DocumentType = False, IsBase = False, IsCalc = False, - IsDraw = False, IsImpress = False, IsMath = False, IsWriter = False, - Keywords = True, Readonly = False, Subject = True, Title = True, + Description = True, DocumentType = False, ExportFilters = False, ImportFilters = False, + IsBase = False, IsCalc = False, IsDraw = 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 @@ -2241,9 +2241,9 @@ class SFDocuments: serviceimplementation = 'basic' servicename = 'SFDocuments.Writer' servicesynonyms = ('writer', 'sfdocuments.writer') - serviceproperties = dict(Description = True, DocumentType = False, IsBase = False, IsCalc = False, - IsDraw = False, IsImpress = False, IsMath = False, IsWriter = False, - Keywords = True, Readonly = False, Subject = True, Title = True, + serviceproperties = dict(Description = True, DocumentType = False, ExportFilters = False, ImportFilters = False, + IsBase = False, IsCalc = False, IsDraw = 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_Calc.xba b/wizards/source/sfdocuments/SF_Calc.xba index 66fc9c19800f..bc5681992eec 100644 --- a/wizards/source/sfdocuments/SF_Calc.xba +++ b/wizards/source/sfdocuments/SF_Calc.xba @@ -2208,10 +2208,12 @@ Public Function Properties() As Variant , "Description" _ , "DocumentProperties" _ , "DocumentType" _ + , "ExportFilters" _ , "FirstCell" _ , "FirstColumn" _ , "FirstRow" _ , "Height" _ + , "ImportFilters" _ , "IsBase" _ , "IsCalc" _ , "IsDraw" _ @@ -3087,6 +3089,16 @@ Property Get DocumentType() As String End Property ' SFDocuments.SF_Calc.DocumentType REM ----------------------------------------------------------------------------- +Property Get ExportFilters() As Variant + ExportFilters = [_Super].GetProperty("ExportFilters") +End Property ' SFDocuments.SF_Calc.ExportFilters + +REM ----------------------------------------------------------------------------- +Property Get ImportFilters() As Variant + ImportFilters = [_Super].GetProperty("ImportFilters") +End Property ' SFDocuments.SF_Calc.ImportFilters + +REM ----------------------------------------------------------------------------- Property Get IsBase() As Boolean IsBase = [_Super].GetProperty("IsBase") End Property ' SFDocuments.SF_Calc.IsBase diff --git a/wizards/source/sfdocuments/SF_Document.xba b/wizards/source/sfdocuments/SF_Document.xba index 9f95470d2903..2ea99eab9a20 100644 --- a/wizards/source/sfdocuments/SF_Document.xba +++ b/wizards/source/sfdocuments/SF_Document.xba @@ -238,6 +238,22 @@ Property Get DocumentType() As String End Property ' SFDocuments.SF_Document.DocumentType REM ----------------------------------------------------------------------------- +Property Get ExportFilters() As Variant +''' Returns the list of the export filter names applicable to the current document +''' as a zero-based array of strings +''' Import/Export filters are included + ExportFilters = _PropertyGet("ExportFilters") +End Property ' SFDocuments.SF_Document.ExportFilters + +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 +''' Import/Export filters are included + ImportFilters = _PropertyGet("ImportFilters") +End Property ' SFDocuments.SF_Document.ImportFilters + +REM ----------------------------------------------------------------------------- Property Get IsBase() As Boolean IsBase = _PropertyGet("IsBase") End Property ' SFDocuments.SF_Document.IsBase @@ -730,6 +746,8 @@ Public Function Properties() As Variant , "Description" _ , "DocumentProperties" _ , "DocumentType" _ + , "ExportFilters" _ + , "ImportFilters" _ , "IsBase" _ , "IsCalc" _ , "IsDraw" _ @@ -1266,6 +1284,68 @@ Private Function _FileIdent() As String End Function ' SFDocuments.SF_Document._FileIdent REM ----------------------------------------------------------------------------- +Private Function _GetFilterNames(ByVal pbExport As Boolean) As Variant +''' Returns the list of export (pbExport = True) or import filters +''' applicable to the current document +''' Args: +''' pbExport: True for export, False for import +''' Returns: +''' A zero-based array of strings + +Dim vFilters As Variant ' Return value +Dim sIdentifier As String ' Document service, like com.sun.star.text.TextDocument +Dim oFilterFactory As Object ' com.sun.star.document.FilterFactory +Dim vAllFilters As Variant ' The full list of installed filters +Dim sFilter As String ' A single filter name +Dim iCount As Integer ' Filters counter +Dim vFilter As Variant ' A filter descriptor as an array of Name/Value pairs +Dim sType As String ' The filter type to be compared with the document service +Dim lFlags As Long ' Read https://wiki.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Properties_of_a_Filter +Dim bExport As Boolean ' Filter valid for export when True +Dim bImport As Boolean ' Filter valid for import when True +Dim bImportExport As Boolean ' Filter valid both for import and export when True + + vFilters = Array() + On Local Error GoTo Finally ' Return empty or partial list if error + +Try: + sIdentifier = _Component.Identifier + Set oFilterFactory = ScriptForge.SF_Utils._GetUNOService("FilterFactory") + vAllFilters = oFilterFactory.getElementNames() + ReDim vFilters(0 To UBound(vAllFilters)) + iCount = -1 + + For Each sFilter In vAllFilters + vFilter = oFilterFactory.getByName(sFilter) + sType = vFilter(12).Value ' Hard-coded index for document types + If sType = sIdentifier Then + lFlags = vFilter(10).Value ' Hard-coded index for flags + ' export: flag is even + ' import: flag is odd and flag/2 is even + ' import/export: flag is odd and flag/2 is odd + bExport = ( lFlags Mod 2 = 0 ) + bImport = ( (lFlags Mod 2 = 1) And ((lFlags \ 2) Mod 2 = 0) ) + bImportExport = ( (lFlags Mod 2 = 1) And ((lFlags \ 2) Mod 2 = 1) ) + ' Select filter ? + If bImportExport _ + Or (pbExport And bExport) _ + Or (Not pbExport And bImport) Then + iCount = iCount + 1 + vFilters(iCount) = sFilter + End If + End If + Next sFilter + + If iCount > -1 Then + ReDim Preserve vFilters(0 To iCount) + End If + +Finally: + _GetFilterNames = vFilters + Exit Function +End Function ' SFDocuments.SF_Document._GetFilterNames + +REM ----------------------------------------------------------------------------- Private Function _IsStillAlive(Optional ByVal pbForUpdate As Boolean _ , Optional ByVal pbError As Boolean _ ) As Boolean @@ -1384,6 +1464,10 @@ Const cstSubArgs = "" Set _PropertyGet = _DocumentProperties Case "DocumentType" _PropertyGet = _DocumentType + Case "ExportFilters" + _PropertyGet = _GetFilterNames(True) + Case "ImportFilters" + _PropertyGet = _GetFilterNames(False) Case "IsBase", "IsCalc", "IsDraw", "IsImpress", "IsMath", "IsWriter" _PropertyGet = ( Mid(psProperty, 3) = _DocumentType ) Case "Keywords" diff --git a/wizards/source/sfdocuments/SF_Writer.xba b/wizards/source/sfdocuments/SF_Writer.xba index 12d3136df65f..eded35de9a96 100644 --- a/wizards/source/sfdocuments/SF_Writer.xba +++ b/wizards/source/sfdocuments/SF_Writer.xba @@ -307,6 +307,8 @@ Public Function Properties() As Variant , "Description" _ , "DocumentProperties" _ , "DocumentType" _ + , "ExportFilters" _ + , "ImportFilters" _ , "IsBase" _ , "IsCalc" _ , "IsDraw" _ @@ -403,6 +405,16 @@ Property Get DocumentType() As String End Property ' SFDocuments.SF_Writer.DocumentType REM ----------------------------------------------------------------------------- +Property Get ExportFilters() As Variant + ExportFilters = [_Super].GetProperty("ExportFilters") +End Property ' SFDocuments.SF_Writer.ExportFilters + +REM ----------------------------------------------------------------------------- +Property Get ImportFilters() As Variant + ImportFilters = [_Super].GetProperty("ImportFilters") +End Property ' SFDocuments.SF_Writer.ImportFilters + +REM ----------------------------------------------------------------------------- Property Get IsBase() As Boolean IsBase = [_Super].GetProperty("IsBase") End Property ' SFDocuments.SF_Writer.IsBase |