Fixes for footnotes configuration

This commit is contained in:
Georgy Litvinov 2021-05-20 14:17:50 +02:00
parent 4d687b4923
commit edeef39f82

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Footnotes" script:language="StarBasic" script:moduleType="normal">sub footMark4 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Footnotes" script:language="StarBasic" script:moduleType="normal">sub footMark6
End Sub End Sub
Sub openFootNotesDialog Sub openFootNotesDialog
@ -64,98 +64,56 @@ Sub setFootnotesNumberingFrom(dialog As Object)
EndIf EndIf
statusIndicator.end() statusIndicator.end()
MsgBox getTranslation(&quot;statusNumberingFinished&quot;)
End Sub End Sub
Sub setNotesPaginatedNumbering(noteType As Integer, pageNums() As Integer) Sub setNotesPaginatedNumbering(noteType As Integer, pageNums() As Integer)
Dim enum1Element As Object Dim allNotes As Object
Dim enum1 As Object Dim statusIndicator as Object
Dim enum2 As Object
Dim thisPortion As Object
Dim curNum As Integer
Dim footnoteText As Object
Dim label As String
Dim labelNum As Long
Dim i As Integer Dim i As Integer
Dim cell As Object Dim curNote As Object
Dim cellEnum As Object
Dim cellEnum2 As Object
Dim curPage As String Dim curPage As String
Dim prevPage As String Dim prevPage As String
prevPage = &quot;&quot; Dim curNum As Integer
Dim statusIndicator as Object Dim notesToValidate() As Object
statusIndicator = ThisComponent.getCurrentController.statusIndicator statusIndicator = ThisComponent.getCurrentController.statusIndicator
statusIndicator.Start(getTranslation(&quot;statusNumberingInProcess&quot;),30) statusIndicator.Start(getTranslation(&quot;statusNumberingInProcess&quot;),30)
curNum = 1 curNum = 1
enum1 = ThisComponent.Text.createEnumeration prevPage = &quot;&quot;
While enum1.hasMoreElements If noteType = 0 Then
enum1Element = enum1.nextElement allNotes = thisComponent.FootNotes
If enum1Element.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then Else
enum2 = enum1Element.createEnumeration allNotes = thisComponent.EndNotes
While enum2.hasMoreElements EndIf
thisPortion = enum2.nextElement For i = 0 to allNotes.Count -1
If isTargetNote(thisPortion, noteType) Then curNote = allNotes.getByIndex(i)
curPage = getPageNumber(thisPortion) curPage = getPageNumberVCurs(curNote.Anchor)
If ( IsInArray(pageNums, CInt(curPage) ) ) Then If ( IsInArray(pageNums, CInt(curPage) ) ) Then
If (curPage &lt;&gt; prevPage) Then If (curPage &lt;&gt; prevPage) Then
curNum = 1 curNum = 1
prevPage = curPage prevPage = curPage
EndIf EndIf
footnoteText = thisPortion.Footnote label = curNote.getLabel
label = footnoteText.getLabel If label = &quot;&quot; Or IsNumeric(label) Then
If label = &quot;&quot; Then curNote.setLabel(CStr(curNum))
footnoteText.setLabel(CStr(curNum)) addToArray(notesToValidate,curnote)
curNum = curNum + 1
Else
labelNum = CLng(label)
If labelNum &gt; 0 Then
footnoteText.setLabel(CStr(curNum))
curNum = curNum + 1 curNum = curNum + 1
EndIf EndIf
EndIf EndIf
EndIf
EndIf
Wend
ElseIf enum1Element.supportsService(&quot;com.sun.star.text.TextTable&quot;) Then
cellNames = enum1Element.cellNames
For i = LBound(cellNames) To Ubound(cellNames)
cell = enum1Element.getCellByName(cellNames(i))
cellEnum = cell.getText().createEnumeration()
While cellEnum.hasMoreElements
cellEnumElement = cellEnum.nextElement
If cellEnumElement.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
cellEnum2 = cellEnumElement.createEnumeration
While cellEnum2.hasMoreElements
thisPortion = cellEnum2.nextElement
If isTargetNote(thisPortion, noteType) Then
curPage = getPageNumber(thisPortion)
If ( IsInArray(pageNums, CInt(curPage) ) ) Then
If (curPage &lt;&gt; prevPage) Then
curNum = 1
prevPage = curPage
EndIf
footnoteText = thisPortion.Footnote
label = footnoteText.getLabel
If label = &quot;&quot; Then
footnoteText.setLabel(CStr(curNum))
curNum = curNum + 1
Else
labelNum = CLng(label)
If labelNum &gt; 0 Then
footnoteText.setLabel(CStr(curNum))
curNum = curNum + 1
EndIf
EndIf
EndIf
EndIf
Wend
EndIf
Wend
Next i Next i
&apos;Second pass in case layout has changed
For i = 0 To Ubound(notesToValidate)
curNote = notesToValidate(i)
curPage = getPageNumberVCurs(curNote.Anchor)
If (curPage &lt;&gt; prevPage) Then
curNum = 1
prevPage = curPage
EndIf EndIf
Wend curNote.setLabel(CStr(curNum))
curNum = curNum + 1
Next i
statusIndicator.end() statusIndicator.end()
MsgBox getTranslation(&quot;statusNumberingFinished&quot;)
End Sub End Sub
@ -163,17 +121,12 @@ Sub setFootnotesNumberingLevel(level As Integer,noteType As Integer)
Dim enum1Element As Object Dim enum1Element As Object
Dim enum1 As Object Dim enum1 As Object
Dim enum2 As Object Dim enum2 As Object
Dim thisPortion As Object
Dim curNum As Integer Dim curNum As Integer
Dim footnoteText As Object
Dim label As String
Dim labelNum As Long
Dim i As Integer Dim i As Integer
Dim cell As Object Dim cell As Object
Dim cellEnum As Object Dim cellEnum As Object
Dim cellEnum2 As Object
Dim statusIndicator as Object Dim statusIndicator as Object
statusIndicator = ThisComponent.getCurrentController.statusIndicator statusIndicator = ThisComponent.getCurrentController.statusIndicator
statusIndicator.Start(getTranslation(&quot;statusNumberingInProcess&quot;),30) statusIndicator.Start(getTranslation(&quot;statusNumberingInProcess&quot;),30)
curNum = 1 curNum = 1
@ -181,34 +134,7 @@ Sub setFootnotesNumberingLevel(level As Integer,noteType As Integer)
While enum1.hasMoreElements While enum1.hasMoreElements
enum1Element = enum1.nextElement enum1Element = enum1.nextElement
If enum1Element.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then If enum1Element.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
If enum1Element.OutlineLevel = level Then traverseNoteParagraphs(curNum, enum1Element ,noteType, level)
curNum = 1
EndIf
enum2 = enum1Element.createEnumeration
While enum2.hasMoreElements
thisPortion = enum2.nextElement
If isTargetNote(thisPortion, noteType) Then
footnoteText = thisPortion.Footnote
label = footnoteText.getLabel
If label = &quot;&quot; Then
If level &gt; 0 Then
footnoteText.setLabel(CStr(curNum))
curNum = curNum + 1
EndIf
Else
labelNum = CLng(label)
If labelNum &gt; 0 Then
If level &lt; 1 Then
footnoteText.setLabel(&quot;&quot;)
Else
footnoteText.setLabel(CStr(curNum))
EndIf
curNum = curNum + 1
EndIf
EndIf
EndIf
Wend
ElseIf enum1Element.supportsService(&quot;com.sun.star.text.TextTable&quot;) Then ElseIf enum1Element.supportsService(&quot;com.sun.star.text.TextTable&quot;) Then
cellNames = enum1Element.cellNames cellNames = enum1Element.cellNames
For i = LBound(cellNames) To Ubound(cellNames) For i = LBound(cellNames) To Ubound(cellNames)
@ -217,12 +143,27 @@ Sub setFootnotesNumberingLevel(level As Integer,noteType As Integer)
While cellEnum.hasMoreElements While cellEnum.hasMoreElements
cellEnumElement = cellEnum.nextElement cellEnumElement = cellEnum.nextElement
If cellEnumElement.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then If cellEnumElement.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
If cellEnumElement.OutlineLevel = level Then traverseNoteParagraphs(curNum, cellEnumElement ,noteType, level)
EndIf
Wend
Next i
EndIf
Wend
statusIndicator.end()
End Sub
Sub traverseNoteParagraphs(curNum As Integer, enum1Element As Object, noteType As Integer, level As Integer)
Dim textPortions As Object
Dim thisPortion As Object
Dim footnoteText As Object
Dim label As String
Dim labelNum As Long
If enum1Element.OutlineLevel = level Then
curNum = 1 curNum = 1
EndIf EndIf
cellEnum2 = cellEnumElement.createEnumeration textPortions = enum1Element.createEnumeration
While cellEnum2.hasMoreElements While textPortions.hasMoreElements
thisPortion = cellEnum2.nextElement thisPortion = textPortions.nextElement
If isTargetNote(thisPortion, noteType) Then If isTargetNote(thisPortion, noteType) Then
footnoteText = thisPortion.Footnote footnoteText = thisPortion.Footnote
label = footnoteText.getLabel label = footnoteText.getLabel
@ -232,33 +173,30 @@ Sub setFootnotesNumberingLevel(level As Integer,noteType As Integer)
curNum = curNum + 1 curNum = curNum + 1
EndIf EndIf
Else Else
labelNum = CLng(label) If IsNumeric(label) Then
If labelNum &gt; 0 Then
If level &lt; 1 Then If level &lt; 1 Then
footnoteText.setLabel(&quot;&quot;) footnoteText.setLabel(&quot;&quot;)
Else Else
footnoteText.setLabel(CStr(curNum)) footnoteText.setLabel(CStr(curNum))
EndIf
curNum = curNum + 1 curNum = curNum + 1
EndIf EndIf
EndIf EndIf
EndIf EndIf
Wend
EndIf EndIf
Wend Wend
Next i
EndIf
Wend
statusIndicator.end()
MsgBox getTranslation(&quot;statusNumberingFinished&quot;)
End Sub End Sub
Function isTargetNote(portion As Object, noteType As Integer) As Boolean Function isTargetNote(portion As Object, noteType As Integer) As Boolean
If ( portion.TextPortionType = &quot;Footnote&quot; And isEndNote(portion) = CBool(noteType) ) Then If ( portion.TextPortionType &lt;&gt; &quot;Footnote&quot; ) Then
isTargetNote = true
Else
isTargetNote = false isTargetNote = false
Exit Function
EndIf EndIf
If ( isEndNote(portion) = CBool(noteType) ) Then
isTargetNote = true
Exit Function
EndIf
isTargetNote = false
End Function End Function
&apos;Sub testRange &apos;Sub testRange
@ -281,6 +219,7 @@ Function IsInArray(array As Variant, content As Variant) As Boolean
inArr = array(i) inArr = array(i)
If inArr = content Then If inArr = content Then
IsInArray = true IsInArray = true
Exit Function
EndIf EndIf
Next i Next i
End Function End Function