2020-03-13 16:36:45 +01:00
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
2021-08-24 10:43:44 +02:00
|
|
|
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Footnotes" script:language="StarBasic" script:moduleType="normal">sub footMark8
|
2020-03-13 16:42:10 +01:00
|
|
|
End Sub
|
|
|
|
|
2020-03-13 16:40:24 +01:00
|
|
|
Sub openFootNotesDialog
|
2020-03-13 16:36:45 +01:00
|
|
|
Dim dialog As Object
|
|
|
|
DialogLibraries.LoadLibrary("ePublishing")
|
|
|
|
dialog = CreateUnoDialog(DialogLibraries.ePublishing.FootnotesConfig)
|
2020-05-05 14:01:41 +02:00
|
|
|
dialog.getControl("buttonOK").Label = getTranslation("buttonOk")
|
|
|
|
dialog.getControl("buttonCancel").Label = getTranslation("buttonCancel")
|
|
|
|
dialog.getControl("configText1").setText(getTranslation("configText1"))
|
|
|
|
dialog.getControl("configText2").setText(getTranslation("configText2"))
|
|
|
|
dialog.getControl("configText3").setText(getTranslation("configText3"))
|
|
|
|
dialog.getControl("configText4").setText(getTranslation("configText4"))
|
|
|
|
dialog.getControl("configText5").setText(getTranslation("configText5"))
|
2021-05-19 15:50:10 +02:00
|
|
|
dialog.getControl("notesTypeLabel").setText(getTranslation("FootnotesConfigDialogNotesTypeLabel"))
|
|
|
|
dialog.getControl("PerPageRangeLabel").setText(getTranslation("FootnotesConfigDialogNotesPerPageRangeLabel"))
|
|
|
|
|
|
|
|
dialog.getControl("groupByPages").Model.Label = getTranslation("FootnotesConfigDialogNotesPerPage")
|
|
|
|
dialog.getControl("groupByHeadings").Model.Label = getTranslation("FootnotesConfigDialogNotesByHeadingsLabel")
|
2020-05-05 14:01:41 +02:00
|
|
|
dialog.Title = getTranslation("footnotesConfigDialogTitle")
|
2021-05-19 15:50:10 +02:00
|
|
|
Dim nCount As Integer
|
|
|
|
nCount = dialog.getControl("lb_notes_types").getItemCount()
|
|
|
|
dialog.getControl("lb_notes_types").addItem( getTranslation("FootnotesConfigDialogFootnotesName"), nCount )
|
|
|
|
dialog.getControl("lb_notes_types").addItem( getTranslation("FootnotesConfigDialogEndnotesName"), nCount + 1 )
|
|
|
|
dialog.getControl("lb_notes_types").selectItemPos( 0, True )
|
2020-05-05 14:01:41 +02:00
|
|
|
dialog.setVisible(true)
|
2020-03-13 16:36:45 +01:00
|
|
|
Select Case dialog.Execute()
|
|
|
|
Case 1
|
|
|
|
setFootnotesNumberingFrom(dialog)
|
|
|
|
Case 0
|
|
|
|
End Select
|
|
|
|
dialog.dispose()
|
|
|
|
End Sub
|
|
|
|
|
2021-05-19 17:33:27 +02:00
|
|
|
Sub setFootnotesNumberingFrom(dialog As Object)
|
2020-03-13 16:36:45 +01:00
|
|
|
Dim statusIndicator as Object
|
|
|
|
Dim targetLevel As Integer
|
2021-05-19 15:50:10 +02:00
|
|
|
Dim stringLevelInput As String
|
|
|
|
Dim stringPageRangeInput As String
|
|
|
|
Dim noteType As Integer
|
2020-03-13 16:36:45 +01:00
|
|
|
statusIndicator = ThisComponent.getCurrentController.statusIndicator
|
|
|
|
dialog.setVisible(false)
|
|
|
|
doNotTrack
|
2021-05-19 15:50:10 +02:00
|
|
|
stringLevelInput = dialog.getControl("level").getText
|
|
|
|
stringPageRangeInput = dialog.getControl("pageRange").getText
|
|
|
|
noteType = dialog.getControl("lb_notes_types").getSelectedItemPos()
|
|
|
|
If (stringLevelInput <> "") Then
|
|
|
|
targetLevel = CInt(stringLevelInput)
|
|
|
|
If targetLevel > -1 AND targetLevel < 11 Then
|
|
|
|
statusIndicator.Start(getTranslation("statusNumberingInProcess"),100)
|
|
|
|
setFootnotesNumberingLevel(targetLevel,noteType)
|
|
|
|
Else
|
|
|
|
MsgBox getTranslation("numberingInputOutOfRange")
|
|
|
|
EndIf
|
|
|
|
EndIf
|
2020-03-13 16:36:45 +01:00
|
|
|
|
2021-05-19 15:50:10 +02:00
|
|
|
If (stringPageRangeInput <> "") Then
|
2021-05-19 17:11:47 +02:00
|
|
|
Dim pageNums() As Integer
|
|
|
|
getPageNumsFrom(stringPageRangeInput, pageNums())
|
2020-05-05 14:01:41 +02:00
|
|
|
statusIndicator.Start(getTranslation("statusNumberingInProcess"),100)
|
2021-05-19 17:11:47 +02:00
|
|
|
setNotesPaginatedNumbering(noteType, pageNums())
|
2020-03-13 16:36:45 +01:00
|
|
|
EndIf
|
|
|
|
|
|
|
|
statusIndicator.end()
|
2021-05-20 14:17:50 +02:00
|
|
|
MsgBox getTranslation("statusNumberingFinished")
|
2020-03-13 16:36:45 +01:00
|
|
|
End Sub
|
|
|
|
|
2021-05-19 17:11:47 +02:00
|
|
|
Sub setNotesPaginatedNumbering(noteType As Integer, pageNums() As Integer)
|
2021-05-20 14:17:50 +02:00
|
|
|
Dim allNotes As Object
|
|
|
|
Dim statusIndicator as Object
|
2020-03-13 16:36:45 +01:00
|
|
|
Dim i As Integer
|
2021-05-20 14:17:50 +02:00
|
|
|
Dim curNote As Object
|
2021-05-19 17:11:47 +02:00
|
|
|
Dim curPage As String
|
|
|
|
Dim prevPage As String
|
2021-05-20 14:17:50 +02:00
|
|
|
Dim curNum As Integer
|
|
|
|
Dim notesToValidate() As Object
|
2020-03-13 16:36:45 +01:00
|
|
|
statusIndicator = ThisComponent.getCurrentController.statusIndicator
|
2020-05-05 14:01:41 +02:00
|
|
|
statusIndicator.Start(getTranslation("statusNumberingInProcess"),30)
|
2021-05-19 17:11:47 +02:00
|
|
|
curNum = 1
|
2021-05-20 14:17:50 +02:00
|
|
|
prevPage = ""
|
|
|
|
If noteType = 0 Then
|
|
|
|
allNotes = thisComponent.FootNotes
|
|
|
|
Else
|
|
|
|
allNotes = thisComponent.EndNotes
|
|
|
|
EndIf
|
|
|
|
For i = 0 to allNotes.Count -1
|
|
|
|
curNote = allNotes.getByIndex(i)
|
|
|
|
curPage = getPageNumberVCurs(curNote.Anchor)
|
|
|
|
If ( IsInArray(pageNums, CInt(curPage) ) ) Then
|
|
|
|
If (curPage <> prevPage) Then
|
|
|
|
curNum = 1
|
|
|
|
prevPage = curPage
|
2021-05-19 17:11:47 +02:00
|
|
|
EndIf
|
2021-05-20 14:17:50 +02:00
|
|
|
label = curNote.getLabel
|
|
|
|
If label = "" Or IsNumeric(label) Then
|
|
|
|
curNote.setLabel(CStr(curNum))
|
|
|
|
addToArray(notesToValidate,curnote)
|
|
|
|
curNum = curNum + 1
|
|
|
|
EndIf
|
|
|
|
EndIf
|
|
|
|
Next i
|
|
|
|
'Second pass in case layout has changed
|
|
|
|
For i = 0 To Ubound(notesToValidate)
|
|
|
|
curNote = notesToValidate(i)
|
|
|
|
curPage = getPageNumberVCurs(curNote.Anchor)
|
|
|
|
If (curPage <> prevPage) Then
|
|
|
|
curNum = 1
|
|
|
|
prevPage = curPage
|
|
|
|
EndIf
|
|
|
|
curNote.setLabel(CStr(curNum))
|
|
|
|
curNum = curNum + 1
|
|
|
|
Next i
|
2021-05-19 17:11:47 +02:00
|
|
|
statusIndicator.end()
|
2021-05-20 14:17:50 +02:00
|
|
|
|
2021-05-19 17:11:47 +02:00
|
|
|
End Sub
|
2020-03-13 16:36:45 +01:00
|
|
|
|
|
|
|
|
2021-05-19 17:11:47 +02:00
|
|
|
Sub setFootnotesNumberingLevel(level As Integer,noteType As Integer)
|
|
|
|
Dim enum1Element As Object
|
|
|
|
Dim enum1 As Object
|
|
|
|
Dim enum2 As Object
|
|
|
|
Dim curNum As Integer
|
|
|
|
Dim i As Integer
|
|
|
|
Dim cell As Object
|
|
|
|
Dim cellEnum As Object
|
|
|
|
Dim statusIndicator as Object
|
2021-05-20 14:17:50 +02:00
|
|
|
|
2021-05-19 17:11:47 +02:00
|
|
|
statusIndicator = ThisComponent.getCurrentController.statusIndicator
|
|
|
|
statusIndicator.Start(getTranslation("statusNumberingInProcess"),30)
|
2020-03-13 16:36:45 +01:00
|
|
|
curNum = 1
|
|
|
|
enum1 = ThisComponent.Text.createEnumeration
|
|
|
|
While enum1.hasMoreElements
|
|
|
|
enum1Element = enum1.nextElement
|
|
|
|
If enum1Element.supportsService("com.sun.star.text.Paragraph") Then
|
2021-05-20 14:17:50 +02:00
|
|
|
traverseNoteParagraphs(curNum, enum1Element ,noteType, level)
|
2020-03-13 16:36:45 +01:00
|
|
|
ElseIf enum1Element.supportsService("com.sun.star.text.TextTable") 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("com.sun.star.text.Paragraph") Then
|
2021-05-20 14:17:50 +02:00
|
|
|
traverseNoteParagraphs(curNum, cellEnumElement ,noteType, level)
|
2020-03-13 16:36:45 +01:00
|
|
|
EndIf
|
|
|
|
Wend
|
|
|
|
Next i
|
|
|
|
EndIf
|
|
|
|
Wend
|
|
|
|
statusIndicator.end()
|
2020-03-13 16:40:24 +01:00
|
|
|
End Sub
|
|
|
|
|
2021-05-20 14:17:50 +02:00
|
|
|
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
|
|
|
|
EndIf
|
|
|
|
textPortions = enum1Element.createEnumeration
|
|
|
|
While textPortions.hasMoreElements
|
|
|
|
thisPortion = textPortions.nextElement
|
|
|
|
If isTargetNote(thisPortion, noteType) Then
|
|
|
|
footnoteText = thisPortion.Footnote
|
|
|
|
label = footnoteText.getLabel
|
|
|
|
If label = "" Then
|
|
|
|
If level > 0 Then
|
|
|
|
footnoteText.setLabel(CStr(curNum))
|
|
|
|
curNum = curNum + 1
|
|
|
|
EndIf
|
|
|
|
Else
|
|
|
|
If IsNumeric(label) Then
|
|
|
|
If level < 1 Then
|
|
|
|
footnoteText.setLabel("")
|
|
|
|
Else
|
|
|
|
footnoteText.setLabel(CStr(curNum))
|
|
|
|
curNum = curNum + 1
|
|
|
|
EndIf
|
|
|
|
EndIf
|
|
|
|
EndIf
|
|
|
|
EndIf
|
|
|
|
Wend
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
2021-05-19 15:50:10 +02:00
|
|
|
Function isTargetNote(portion As Object, noteType As Integer) As Boolean
|
2021-05-20 14:17:50 +02:00
|
|
|
If ( portion.TextPortionType <> "Footnote" ) Then
|
2021-05-19 15:50:10 +02:00
|
|
|
isTargetNote = false
|
2021-05-20 14:17:50 +02:00
|
|
|
Exit Function
|
|
|
|
EndIf
|
|
|
|
If ( isEndNote(portion) = CBool(noteType) ) Then
|
|
|
|
isTargetNote = true
|
|
|
|
Exit Function
|
2021-05-19 15:50:10 +02:00
|
|
|
EndIf
|
2021-05-20 14:17:50 +02:00
|
|
|
isTargetNote = false
|
2021-05-19 15:50:10 +02:00
|
|
|
End Function
|
|
|
|
|
2021-05-19 17:11:47 +02:00
|
|
|
'Sub testRange
|
|
|
|
' Dim pageNums() As Integer
|
|
|
|
' getPageNumsFrom("9-10,8-12,-111-099,99,102,105,187,187",pageNums())
|
|
|
|
'End Sub
|
|
|
|
|
|
|
|
|
|
|
|
Sub getPageNumsFrom(inputString As String, pageNums() As Integer)
|
|
|
|
Dim ranges() As String
|
|
|
|
ranges = split(inputString,",")
|
|
|
|
For i = Lbound(ranges) To (Ubound(ranges))
|
|
|
|
processNumRange(ranges(i),pageNums())
|
|
|
|
Next i
|
|
|
|
End Sub
|
|
|
|
|
2021-05-19 17:33:27 +02:00
|
|
|
Function IsInArray(array As Variant, content As Variant) As Boolean
|
2021-05-19 17:11:47 +02:00
|
|
|
IsInArray = false
|
|
|
|
For i = LBound(array) To UBound(array)
|
|
|
|
inArr = array(i)
|
|
|
|
If inArr = content Then
|
|
|
|
IsInArray = true
|
2021-05-20 14:17:50 +02:00
|
|
|
Exit Function
|
2021-05-19 17:11:47 +02:00
|
|
|
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, "-")
|
2021-05-19 20:19:47 +02:00
|
|
|
|
2021-05-19 17:11:47 +02:00
|
|
|
If UBound(rangeParts) = 1 Then
|
|
|
|
firstValue = trim(rangeParts(0))
|
|
|
|
secondValue = trim(rangeParts(1))
|
2021-05-19 20:19:47 +02:00
|
|
|
If ( IsNumeric(firstValue) And IsNumeric(secondValue)) Then
|
2021-05-19 17:11:47 +02:00
|
|
|
firstNum = CInt(firstValue)
|
|
|
|
secondNum = CInt(secondValue)
|
|
|
|
If firstNum <= 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))
|
2021-05-19 20:19:47 +02:00
|
|
|
If IsNumeric(firstValue) Then
|
2021-05-19 17:11:47 +02:00
|
|
|
firstNum = CInt(firstValue)
|
|
|
|
If (NOT IsInArray(pageNums, firstNum)) Then
|
|
|
|
addToArray(pageNums, firstNum)
|
|
|
|
EndIf
|
|
|
|
EndIf
|
|
|
|
EndIf
|
|
|
|
|
|
|
|
End Sub
|
|
|
|
|
2021-05-19 15:50:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
Function isEndNote(portion As Object) As Boolean
|
|
|
|
If (IsEmpty(portion.Start.EndNote)) Then
|
|
|
|
isEndNote = false
|
|
|
|
Else
|
|
|
|
isEndNote = true
|
|
|
|
EndIf
|
|
|
|
End Function
|
|
|
|
|
2020-03-13 16:40:24 +01:00
|
|
|
Private Sub doNotTrack
|
2020-03-21 16:35:38 +01:00
|
|
|
Dim dispatcher As Object
|
|
|
|
Dim document As Object
|
2020-03-13 16:40:24 +01:00
|
|
|
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
|
|
|
|
document = ThisComponent.CurrentController.Frame
|
|
|
|
dim trackProperties(0) as new com.sun.star.beans.PropertyValue
|
|
|
|
trackProperties(0).Name = "TrackChanges"
|
|
|
|
trackProperties(0).Value = false
|
|
|
|
dispatcher.executeDispatch(document, ".uno:TrackChanges", "", 0, trackProperties())
|
|
|
|
dim args1(0) as new com.sun.star.beans.PropertyValue
|
|
|
|
args1(0).Name = "ShowTrackedChanges"
|
|
|
|
args1(0).Value = true
|
|
|
|
dispatcher.executeDispatch(document, ".uno:ShowTrackedChanges", "", 0, args1())
|
2020-03-13 16:36:45 +01:00
|
|
|
End Sub
|
2021-08-24 10:43:44 +02:00
|
|
|
|
|
|
|
Sub FixFootnotes()
|
|
|
|
Dim description As String
|
|
|
|
Dim allNotes As Object
|
|
|
|
Dim aNote As Object
|
|
|
|
Dim oViewCursor As Object
|
|
|
|
turnOffTracking
|
|
|
|
AcceptAllTrackedChanges
|
|
|
|
oViewCursor = ThisComponent.currentController.getViewCursor()
|
|
|
|
'Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
|
|
|
allNotes = ThisComponent.FootNotes
|
|
|
|
For x = 0 to allNotes.Count -1
|
|
|
|
aNote = allNotes.getByIndex(x)
|
|
|
|
anchor = aNote.anchor
|
|
|
|
oViewCursor.goToRange(anchor,false)
|
|
|
|
oViewCursor.collapseToStart()
|
|
|
|
oViewCursor.goToRange(anchor,true)
|
|
|
|
unoCut()
|
|
|
|
oViewCursor.goLeft(1,false)
|
|
|
|
unoPaste()
|
|
|
|
Next
|
|
|
|
|
|
|
|
End Sub
|
2020-03-13 17:48:46 +01:00
|
|
|
</script:module>
|