Foontote/Endnote numeration functions added

This commit is contained in:
Georgy Litvinov 2021-05-19 17:11:47 +02:00
parent 90207f01d0
commit 55f8f9e79b

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!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 footMark2
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Footnotes" script:language="StarBasic" script:moduleType="normal">sub footMark3
End Sub
Sub openFootNotesDialog
@ -57,15 +57,107 @@ Sub setFootnotesNumberingFrom(dialog)
EndIf
If (stringPageRangeInput &lt;&gt; &quot;&quot;) Then
Dim pageNums() As Integer
getPageNumsFrom(stringPageRangeInput, pageNums())
statusIndicator.Start(getTranslation(&quot;statusNumberingInProcess&quot;),100)
setNotesPaginatedNumbering(noteType, pageArray)
setNotesPaginatedNumbering(noteType, pageNums())
EndIf
statusIndicator.end()
End Sub
Sub setNotesPaginatedNumbering(noteType As Integer, pageNums() As Integer)
Dim enum1Element As Object
Dim enum1 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 cell As Object
Dim cellEnum As Object
Dim cellEnum2 As Object
Dim curPage As String
Dim prevPage As String
prevPage = &quot;&quot;
Dim statusIndicator as Object
statusIndicator = ThisComponent.getCurrentController.statusIndicator
statusIndicator.Start(getTranslation(&quot;statusNumberingInProcess&quot;),30)
curNum = 1
enum1 = ThisComponent.Text.createEnumeration
While enum1.hasMoreElements
enum1Element = enum1.nextElement
If enum1Element.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
enum2 = enum1Element.createEnumeration
While enum2.hasMoreElements
thisPortion = enum2.nextElement
If isTargetNote(thisPortion, noteType) Then
curPage = getPageNumber(thisPortion)
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
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 (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
Wend
EndIf
Wend
Next i
EndIf
Wend
statusIndicator.end()
MsgBox getTranslation(&quot;statusNumberingFinished&quot;)
End Sub
Sub setFootnotesNumberingLevel(level As Integer,noteType As Integer)
Dim enum1Element As Object
Dim enum1 As Object
@ -83,8 +175,6 @@ Sub setFootnotesNumberingLevel(level As Integer,noteType As Integer)
Dim statusIndicator as Object
statusIndicator = ThisComponent.getCurrentController.statusIndicator
statusIndicator.Start(getTranslation(&quot;statusNumberingInProcess&quot;),30)
curNum = 1
enum1 = ThisComponent.Text.createEnumeration
While enum1.hasMoreElements
@ -170,6 +260,66 @@ Function isTargetNote(portion As Object, noteType As Integer) As Boolean
EndIf
End Function
&apos;Sub testRange
&apos; Dim pageNums() As Integer
&apos; getPageNumsFrom(&quot;9-10,8-12,-111-099,99,102,105,187,187&quot;,pageNums())
&apos;End Sub
Sub getPageNumsFrom(inputString As String, pageNums() As Integer)
Dim ranges() As String
ranges = split(inputString,&quot;,&quot;)
For i = Lbound(ranges) To (Ubound(ranges))
processNumRange(ranges(i),pageNums())
Next i
End Sub
Function IsInArray(array, content)
IsInArray = false
For i = LBound(array) To UBound(array)
inArr = array(i)
If inArr = content Then
IsInArray = true
EndIf
Next i
End Function
Sub processNumRange(range As String, pageNums() As Integer)
Dim rangeParts() As String
Dim firstValue As String
Dim secondValue As String
Dim firstNum As Integer
Dim secondNum As Integer
rangeParts = split( range, &quot;-&quot;)
If UBound(rangeParts) = 1 Then
firstValue = trim(rangeParts(0))
secondValue = trim(rangeParts(1))
If ( IsDigit(firstValue) And IsDigit(secondValue)) Then
firstNum = CInt(firstValue)
secondNum = CInt(secondValue)
If firstNum &lt;= secondNum Then
For i = firstNum To secondNum
If (NOT IsInArray(pageNums, i)) Then
addToArray(pageNums, i)
EndIf
Next i
EndIf
EndIf
EndIf
If UBound(rangeParts) = 0 Then
firstValue = trim(rangeParts(0))
If IsDigit(firstValue) Then
firstNum = CInt(firstValue)
If (NOT IsInArray(pageNums, firstNum)) Then
addToArray(pageNums, firstNum)
EndIf
EndIf
EndIf
End Sub
Function isEndNote(portion As Object) As Boolean