Added dialog and functions to convert native endnotes to custom endnotes
This commit is contained in:
parent
ffa704353a
commit
58bab11323
6 changed files with 315 additions and 1 deletions
293
ePublishing/Endnotes.xba
Normal file
293
ePublishing/Endnotes.xba
Normal file
|
@ -0,0 +1,293 @@
|
|||
<?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="Endnotes" script:language="StarBasic" script:moduleType="normal">Global Const endnoteFieldPrefix = "custom_endnote_"
|
||||
Global Const endnoteInTextAnchorSuffix = "-text_anchor"
|
||||
Global Const endnoteInBodyAnchorSuffix = "-body_anchor"
|
||||
|
||||
Sub convertEndnotesExecution
|
||||
Dim oSelections As Object
|
||||
Dim oAnchor1 As Object
|
||||
Dim oAnchor2 As Object
|
||||
Dim oAnchor1Name As String
|
||||
Dim oAnchor2Name As String
|
||||
Dim foundEndNotes() As Object
|
||||
Dim textSelection As Object
|
||||
Dim nativeEndnotesCounter As Integer
|
||||
Dim customEndnotesCounter As Integer
|
||||
If IsNull(ThisComponent) Then
|
||||
MsgBox getTranslation("something weird happened error text")
|
||||
Exit Sub
|
||||
End If
|
||||
oSelections = ThisComponent.getCurrentSelection()
|
||||
If IsNull(oSelections) Then
|
||||
MsgBox getTranslation("something weird happened error text")
|
||||
Exit Sub
|
||||
End If
|
||||
objectsCount = oSelections.getCount()
|
||||
If objectsCount > 1 Then
|
||||
MsgBox getTranslation("too much selections")
|
||||
Exit Sub
|
||||
End If
|
||||
textSelection = oSelections.getByIndex(0)
|
||||
foundEndNotes() = findEndNotesInSelection(textSelection)
|
||||
nativeEndnotesCounter = UBound(foundEndNotes(0))
|
||||
customEndnotesCounter = UBound(foundEndNotes(1))
|
||||
If (nativeEndnotesCounter = -1 And customEndnotesCounter = -1 ) Then
|
||||
MsgBox getTranslation("EndnotesNotFound")
|
||||
Exit Sub
|
||||
EndIf
|
||||
If ( customEndnotesCounter = -1 ) Then
|
||||
'only native found window convert to custom?
|
||||
'Window Select paragraph for endnotes output or cancel
|
||||
runEndnotesConversionDialog(foundEndNotes(0))
|
||||
Exit Sub
|
||||
EndIf
|
||||
If (nativeEndnotesCounter = -1 ) Then
|
||||
'only custom endnotes found. Window convert to native?
|
||||
Exit Sub
|
||||
EndIf
|
||||
'both custom and native endnotes found
|
||||
'convert to custom all or
|
||||
'convert to native
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Sub runEndnotesConversionDialog(foundEndNotes As Variant)
|
||||
Dim dialog As Object
|
||||
waitingForDialog = true
|
||||
dialog = notModalDialog("EndnotesConversion")
|
||||
dialog.getControl("found").SetText(getTranslation("EndnotesNativeDialogFound") & CStr(UBound(foundEndNotes)+1))
|
||||
dialog.getControl("description").SetText(getTranslation("EndnotesNativeDialogDescriptionSelect"))
|
||||
dialog.getControl("cancel").Label = getTranslation("buttonCancel")
|
||||
dialog.getControl("start").Label = getTranslation("buttonOk")
|
||||
dialog.setvisible(true)
|
||||
Do While waitingForDialog
|
||||
If dialog.getControl("cancel").model.state = 1 then
|
||||
exit Do
|
||||
EndIf
|
||||
If dialog.getControl("start").model.state = 1 then
|
||||
convertEndnotesToCustom(foundEndNotes)
|
||||
exit Do
|
||||
EndIf
|
||||
wait (100)
|
||||
Loop
|
||||
dialog.dispose
|
||||
|
||||
End Sub
|
||||
|
||||
Sub convertEndnotesToCustom(foundEndNotes As Variant)
|
||||
Dim oViewCursor As Object
|
||||
Dim outputPosition As Object
|
||||
Dim endnoteSigns() As String
|
||||
Dim fieldPrefix As String
|
||||
Dim i As Integer
|
||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||
oViewCursor.goToStartOfLine(false)
|
||||
outputPosition = oViewCursor.Text.createTextCursorByRange(oViewCursor)
|
||||
endnoteSigns = getEndnoteSigns(foundEndNotes)
|
||||
fieldPrefix = createEndnoteFieldPrefix()
|
||||
For i = LBound(foundEndNotes) To Ubound(foundEndNotes)
|
||||
convertNativeEndnoteToCustom(endnoteSigns(i), foundEndNotes(i),outputPosition,fieldPrefix, i)
|
||||
Next i
|
||||
End Sub
|
||||
|
||||
Function createEndnoteFieldPrefix As String
|
||||
Dim names() As String
|
||||
Dim i As Integer
|
||||
Dim prefix As String
|
||||
names = ThisComponent.getTextFieldMasters().getElementNames()
|
||||
For i = 0 To 10000
|
||||
prefix = endnoteFieldPrefix & i & "_"
|
||||
If NOT startsWithInArray(prefix, names) Then
|
||||
createEndnoteFieldPrefix = prefix
|
||||
Exit Function
|
||||
EndIf
|
||||
Next i
|
||||
createEndnoteFieldPrefix = prefix
|
||||
End Function
|
||||
|
||||
Function startsWithInArray(prefix As String, names As Variant) As Boolean
|
||||
Dim i As Long
|
||||
For i = LBound(names) To Ubound(names)
|
||||
If InStr(names(i), "com.sun.star.text.fieldmaster.User." & prefix) = 1 Then
|
||||
startsWithInArray = true
|
||||
Exit Function
|
||||
EndIf
|
||||
Next i
|
||||
startsWithInArray = false
|
||||
End Function
|
||||
|
||||
|
||||
Sub convertNativeEndnoteToCustom(sign As String, nativeEndNoteTextRange As Object,outputPosition As Object, fieldPrefix As String, num As Integer)
|
||||
'Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
||||
Dim oViewCursor As Object
|
||||
Dim oTextCursor As Object
|
||||
Dim endNote As Object
|
||||
Dim anchorInBody As Object
|
||||
Dim anchorInText As Object
|
||||
Dim bodyAnchorName As String
|
||||
Dim textAnchorName As String
|
||||
endNote = nativeEndNoteTextRange.Footnote
|
||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||
oViewCursor.goToRange(nativeEndNoteTextRange.Footnote.Text.Start,false)
|
||||
oViewCursor.goToRange(nativeEndNoteTextRange.Footnote.Text.End,true)
|
||||
unoCut()
|
||||
oViewCursor.goToRange(outputPosition,false)
|
||||
getEndnotePara()
|
||||
oViewCursor.ParaStyleName = "Endnote"
|
||||
anchorInBody = createEndnoteSign(outputPosition, sign, fieldPrefix & num, true)
|
||||
addEndnoteSpacer(fieldPrefix)
|
||||
unoPaste()
|
||||
outputPosition = oViewCursor.End
|
||||
oViewCursor.goToRange(nativeEndNoteTextRange,false)
|
||||
endNote.dispose()
|
||||
anchorInText = createEndnoteSign(oViewCursor, sign, fieldPrefix & num, false)
|
||||
bodyAnchorName = fieldPrefix & num & endnoteInBodyAnchorSuffix
|
||||
textAnchorName = fieldPrefix & num & endnoteInTextAnchorSuffix
|
||||
anchorInBody.goRight(1,true)
|
||||
anchorInText.goRight(1,true)
|
||||
createAnchor(anchorInBody, bodyAnchorName )
|
||||
createAnchor(anchorInText,textAnchorName )
|
||||
createLink(anchorInBody,anchorInBody.String, textAnchorName)
|
||||
createLink(anchorInText,anchorInText.String, bodyAnchorName)
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Sub getEndnotePara()
|
||||
Dim oViewCursor As Object
|
||||
Dim oTextCursor As Object
|
||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor.Start)
|
||||
oTextCursor.gotoStartOfParagraph(false)
|
||||
oTextCursor.gotoEndOfParagraph(true)
|
||||
If Len(oTextCursor.String) > 0 Then
|
||||
oViewCursor.Text.insertControlCharacter(oViewCursor.End,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
|
||||
EndIf
|
||||
End Sub
|
||||
|
||||
Function createEndnoteSign(cursor As Object,sign As String,fieldName As String, inBody As Boolean) As Object
|
||||
Dim oField As Object 'Field to insert
|
||||
Dim oFieldMaster As Object
|
||||
Dim oTextCursor As Object
|
||||
Dim oMasters As Object
|
||||
oTextCursor = cursor.Text.createTextCursorByRange(cursor.Start)
|
||||
If inBody Then
|
||||
oTextCursor.CharStyleName = "Endnote Symbol"
|
||||
Else
|
||||
oTextCursor.CharStyleName = "Endnote anchor"
|
||||
EndIf
|
||||
oField = ThisComponent.createInstance("com.sun.star.text.textfield.User")
|
||||
oMasters = ThisComponent.getTextFieldMasters()
|
||||
If oMasters.hasByName("com.sun.star.text.FieldMaster.User" & "." & fieldName) Then
|
||||
oFieldMaster = oMasters.getByName("com.sun.star.text.FieldMaster.User" & "." & fieldName)
|
||||
oFieldMaster.Name = fieldName
|
||||
oFieldMaster.Content = sign
|
||||
Else
|
||||
oFieldMaster = ThisComponent.createInstance("com.sun.star.text.FieldMaster.User")
|
||||
oFieldMaster.Name = fieldName
|
||||
oFieldMaster.Content = sign
|
||||
EndIf
|
||||
oField.attachTextFieldMaster(oFieldMaster)
|
||||
oTextCursor.Text.insertTextContent(oTextCursor, oField, False)
|
||||
oTextCursor.CharStyleName = "Standard"
|
||||
oTextCursor.goLeft(1,false)
|
||||
createEndnoteSign = oTextCursor
|
||||
End Function
|
||||
|
||||
Sub addEndnoteSpacer(fieldPrefix As String)
|
||||
Dim oViewCursor As Object
|
||||
oViewCursor = ThisComponent.CurrentController.getViewCursor()
|
||||
insertUserField(oViewCursor,fieldPrefix & "spacer"," ")
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
|
||||
Function getEndnoteSigns(foundEndNotes As Variant) As Variant
|
||||
Dim i As Integer
|
||||
Dim signs() As String
|
||||
For i = LBound(foundEndNotes) To Ubound(foundEndNotes)
|
||||
AddToArray(signs, foundEndNotes(i).String)
|
||||
Next i
|
||||
getEndnoteSigns = signs
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Function notModalDialog(dialogName As String) As Variant
|
||||
Dim windowProvider As Object
|
||||
Dim containerWindow As Object
|
||||
Dim handler As Object
|
||||
Dim dialogUrl As String
|
||||
Dim dialog As Object
|
||||
containerWindow = ThisComponent.getCurrentController().getFrame().getContainerWindow()
|
||||
dialogUrl = "vnd.sun.star.script:ePublishing." & dialogName & "?location=application"
|
||||
windowProvider = CreateUnoService("com.sun.star.awt.ContainerWindowProvider")
|
||||
dialog = windowProvider.createContainerWindow(dialogUrl, "", containerWindow, handler)
|
||||
notModalDialog = dialog
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Function findEndNotesInSelection(textSelection) As Variant
|
||||
Dim nativeEndNotes() As Object
|
||||
Dim customEndNotes() As Object
|
||||
Dim outerArray() As Object
|
||||
findEndNotesInSelection = Array()
|
||||
|
||||
Dim enum1Element As Object
|
||||
Dim cellEnumElement 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
|
||||
|
||||
enum1 = textSelection.createEnumeration
|
||||
While enum1.hasMoreElements
|
||||
enum1Element = enum1.nextElement
|
||||
If enum1Element.supportsService("com.sun.star.text.Paragraph") Then
|
||||
findEndNotesInParagraph(enum1Element, nativeEndNotes, customEndNotes)
|
||||
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
|
||||
findEndNotesInParagraph(cellEnumElement, nativeEndNotes, customEndNotes)
|
||||
EndIf
|
||||
Wend
|
||||
Next i
|
||||
EndIf
|
||||
Wend
|
||||
|
||||
addToArray(outerArray, nativeEndNotes)
|
||||
addToArray(outerArray, customEndNotes)
|
||||
findEndNotesInSelection = outerArray
|
||||
End Function
|
||||
|
||||
Sub findEndNotesInParagraph(enum1Element As Object,nativeEndNotes As Variant, customEndNotes As Variant)
|
||||
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,1) Then
|
||||
AddToArray(nativeEndNotes, thisPortion)
|
||||
' ElseIf isCustomEndnote(thisPortion)
|
||||
' AddToArray(customEndNotesd, thisPortion)
|
||||
EndIf
|
||||
Wend
|
||||
End Sub
|
||||
</script:module>
|
10
ePublishing/EndnotesConversion.xdl
Normal file
10
ePublishing/EndnotesConversion.xdl
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
|
||||
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="EndnotesConversion" dlg:left="199" dlg:top="0" dlg:width="144" dlg:height="72" dlg:closeable="true" dlg:moveable="true">
|
||||
<dlg:bulletinboard>
|
||||
<dlg:text dlg:id="description" dlg:tab-index="0" dlg:left="8" dlg:top="20" dlg:width="130" dlg:height="28" dlg:value="Для вывода концевых сносок установите курсор в целевом параграфе и нажмите Конвертация" dlg:multiline="true"/>
|
||||
<dlg:text dlg:id="found" dlg:tab-index="1" dlg:left="8" dlg:top="8" dlg:width="85" dlg:height="8" dlg:value="Найдено концевых сносок"/>
|
||||
<dlg:button dlg:id="cancel" dlg:tab-index="2" dlg:left="9" dlg:top="55" dlg:width="61" dlg:height="13" dlg:value="Отмена" dlg:toggled="1"/>
|
||||
<dlg:button dlg:id="start" dlg:tab-index="3" dlg:left="75" dlg:top="55" dlg:width="61" dlg:height="13" dlg:value="Конвертация" dlg:toggled="1"/>
|
||||
</dlg:bulletinboard>
|
||||
</dlg:window>
|
|
@ -271,6 +271,15 @@ Function getRussian(identifier As String) As String
|
|||
Case "FootnotesConfigDialogNotesPerPageRangeLabel"
|
||||
getRussian = "Введите диапазон страниц"
|
||||
Exit Function
|
||||
Case "EndnotesNativeDialogFound"
|
||||
getRussian = "Найдено концевых сносок: "
|
||||
Exit Function
|
||||
Case "EndnotesNativeDialogDescriptionSelect"
|
||||
getRussian = "Для вывода концевых сносок установите курсор в нужном параграфе и нажмите кнопку Применить"
|
||||
Exit Function
|
||||
Case "EndnotesNotFound"
|
||||
getRussian = "В текущем выделении концевых сносок не найдено. Выделите текст с концевыми сносками."
|
||||
Exit Function
|
||||
Case Else
|
||||
getRussian = "Перевод не найден"
|
||||
End Select
|
||||
|
|
|
@ -4,4 +4,5 @@
|
|||
<library:element library:name="FootnotesConfig"/>
|
||||
<library:element library:name="replaceParaStyle"/>
|
||||
<library:element library:name="PageConfig"/>
|
||||
<library:element library:name="EndnotesConversion"/>
|
||||
</library:library>
|
|
@ -11,4 +11,5 @@
|
|||
<library:element library:name="MakeUp"/>
|
||||
<library:element library:name="PageStyles"/>
|
||||
<library:element library:name="Translations"/>
|
||||
<library:element library:name="Endnotes"/>
|
||||
</library:library>
|
BIN
translations.ods
BIN
translations.ods
Binary file not shown.
Loading…
Add table
Reference in a new issue