summaryrefslogtreecommitdiff
path: root/wizards
diff options
context:
space:
mode:
authorJean-Pierre Ledure <jp@ledure.be>2022-03-07 13:26:36 +0100
committerJean-Pierre Ledure <jp@ledure.be>2022-03-07 16:13:46 +0100
commit2598c35dbac8dc4492ad1fc79925c5347e683af0 (patch)
tree4b308308864d9aef030f51b7ca87381f70b389c1 /wizards
parenta7e5c48b3d6d98ea35916cae9bd85a87f8ddf8e9 (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')
-rw-r--r--wizards/source/scriptforge/python/scriptforge.py18
-rw-r--r--wizards/source/sfdocuments/SF_Calc.xba12
-rw-r--r--wizards/source/sfdocuments/SF_Document.xba84
-rw-r--r--wizards/source/sfdocuments/SF_Writer.xba12
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
, &quot;Description&quot; _
, &quot;DocumentProperties&quot; _
, &quot;DocumentType&quot; _
+ , &quot;ExportFilters&quot; _
, &quot;FirstCell&quot; _
, &quot;FirstColumn&quot; _
, &quot;FirstRow&quot; _
, &quot;Height&quot; _
+ , &quot;ImportFilters&quot; _
, &quot;IsBase&quot; _
, &quot;IsCalc&quot; _
, &quot;IsDraw&quot; _
@@ -3087,6 +3089,16 @@ Property Get DocumentType() As String
End Property &apos; SFDocuments.SF_Calc.DocumentType
REM -----------------------------------------------------------------------------
+Property Get ExportFilters() As Variant
+ ExportFilters = [_Super].GetProperty(&quot;ExportFilters&quot;)
+End Property &apos; SFDocuments.SF_Calc.ExportFilters
+
+REM -----------------------------------------------------------------------------
+Property Get ImportFilters() As Variant
+ ImportFilters = [_Super].GetProperty(&quot;ImportFilters&quot;)
+End Property &apos; SFDocuments.SF_Calc.ImportFilters
+
+REM -----------------------------------------------------------------------------
Property Get IsBase() As Boolean
IsBase = [_Super].GetProperty(&quot;IsBase&quot;)
End Property &apos; 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 &apos; SFDocuments.SF_Document.DocumentType
REM -----------------------------------------------------------------------------
+Property Get ExportFilters() As Variant
+&apos;&apos;&apos; Returns the list of the export filter names applicable to the current document
+&apos;&apos;&apos; as a zero-based array of strings
+&apos;&apos;&apos; Import/Export filters are included
+ ExportFilters = _PropertyGet(&quot;ExportFilters&quot;)
+End Property &apos; SFDocuments.SF_Document.ExportFilters
+
+REM -----------------------------------------------------------------------------
+Property Get ImportFilters() As Variant
+&apos;&apos;&apos; Returns the list of the import filter names applicable to the current document
+&apos;&apos;&apos; as a zero-based array of strings
+&apos;&apos;&apos; Import/Export filters are included
+ ImportFilters = _PropertyGet(&quot;ImportFilters&quot;)
+End Property &apos; SFDocuments.SF_Document.ImportFilters
+
+REM -----------------------------------------------------------------------------
Property Get IsBase() As Boolean
IsBase = _PropertyGet(&quot;IsBase&quot;)
End Property &apos; SFDocuments.SF_Document.IsBase
@@ -730,6 +746,8 @@ Public Function Properties() As Variant
, &quot;Description&quot; _
, &quot;DocumentProperties&quot; _
, &quot;DocumentType&quot; _
+ , &quot;ExportFilters&quot; _
+ , &quot;ImportFilters&quot; _
, &quot;IsBase&quot; _
, &quot;IsCalc&quot; _
, &quot;IsDraw&quot; _
@@ -1266,6 +1284,68 @@ Private Function _FileIdent() As String
End Function &apos; SFDocuments.SF_Document._FileIdent
REM -----------------------------------------------------------------------------
+Private Function _GetFilterNames(ByVal pbExport As Boolean) As Variant
+&apos;&apos;&apos; Returns the list of export (pbExport = True) or import filters
+&apos;&apos;&apos; applicable to the current document
+&apos;&apos;&apos; Args:
+&apos;&apos;&apos; pbExport: True for export, False for import
+&apos;&apos;&apos; Returns:
+&apos;&apos;&apos; A zero-based array of strings
+
+Dim vFilters As Variant &apos; Return value
+Dim sIdentifier As String &apos; Document service, like com.sun.star.text.TextDocument
+Dim oFilterFactory As Object &apos; com.sun.star.document.FilterFactory
+Dim vAllFilters As Variant &apos; The full list of installed filters
+Dim sFilter As String &apos; A single filter name
+Dim iCount As Integer &apos; Filters counter
+Dim vFilter As Variant &apos; A filter descriptor as an array of Name/Value pairs
+Dim sType As String &apos; The filter type to be compared with the document service
+Dim lFlags As Long &apos; Read https://wiki.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Properties_of_a_Filter
+Dim bExport As Boolean &apos; Filter valid for export when True
+Dim bImport As Boolean &apos; Filter valid for import when True
+Dim bImportExport As Boolean &apos; Filter valid both for import and export when True
+
+ vFilters = Array()
+ On Local Error GoTo Finally &apos; Return empty or partial list if error
+
+Try:
+ sIdentifier = _Component.Identifier
+ Set oFilterFactory = ScriptForge.SF_Utils._GetUNOService(&quot;FilterFactory&quot;)
+ vAllFilters = oFilterFactory.getElementNames()
+ ReDim vFilters(0 To UBound(vAllFilters))
+ iCount = -1
+
+ For Each sFilter In vAllFilters
+ vFilter = oFilterFactory.getByName(sFilter)
+ sType = vFilter(12).Value &apos; Hard-coded index for document types
+ If sType = sIdentifier Then
+ lFlags = vFilter(10).Value &apos; Hard-coded index for flags
+ &apos; export: flag is even
+ &apos; import: flag is odd and flag/2 is even
+ &apos; 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) )
+ &apos; 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 &gt; -1 Then
+ ReDim Preserve vFilters(0 To iCount)
+ End If
+
+Finally:
+ _GetFilterNames = vFilters
+ Exit Function
+End Function &apos; 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 = &quot;&quot;
Set _PropertyGet = _DocumentProperties
Case &quot;DocumentType&quot;
_PropertyGet = _DocumentType
+ Case &quot;ExportFilters&quot;
+ _PropertyGet = _GetFilterNames(True)
+ Case &quot;ImportFilters&quot;
+ _PropertyGet = _GetFilterNames(False)
Case &quot;IsBase&quot;, &quot;IsCalc&quot;, &quot;IsDraw&quot;, &quot;IsImpress&quot;, &quot;IsMath&quot;, &quot;IsWriter&quot;
_PropertyGet = ( Mid(psProperty, 3) = _DocumentType )
Case &quot;Keywords&quot;
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
, &quot;Description&quot; _
, &quot;DocumentProperties&quot; _
, &quot;DocumentType&quot; _
+ , &quot;ExportFilters&quot; _
+ , &quot;ImportFilters&quot; _
, &quot;IsBase&quot; _
, &quot;IsCalc&quot; _
, &quot;IsDraw&quot; _
@@ -403,6 +405,16 @@ Property Get DocumentType() As String
End Property &apos; SFDocuments.SF_Writer.DocumentType
REM -----------------------------------------------------------------------------
+Property Get ExportFilters() As Variant
+ ExportFilters = [_Super].GetProperty(&quot;ExportFilters&quot;)
+End Property &apos; SFDocuments.SF_Writer.ExportFilters
+
+REM -----------------------------------------------------------------------------
+Property Get ImportFilters() As Variant
+ ImportFilters = [_Super].GetProperty(&quot;ImportFilters&quot;)
+End Property &apos; SFDocuments.SF_Writer.ImportFilters
+
+REM -----------------------------------------------------------------------------
Property Get IsBase() As Boolean
IsBase = [_Super].GetProperty(&quot;IsBase&quot;)
End Property &apos; SFDocuments.SF_Writer.IsBase