Added custom endnote back to standard conversion

This commit is contained in:
Georgy Litvinov 2021-06-08 14:52:46 +02:00
parent f889f0edb7
commit 1ee8b5f951
4 changed files with 344 additions and 37 deletions

View file

@ -45,15 +45,174 @@ Sub convertEndnotesExecution
EndIf EndIf
If (nativeEndnotesCounter = -1 ) Then If (nativeEndnotesCounter = -1 ) Then
'only custom endnotes found. Window convert to native? 'only custom endnotes found. Window convert to native?
runEndnotesCustomToNativeDialog(foundEndNotes(1))
Exit Sub Exit Sub
EndIf EndIf
'both custom and native endnotes found 'both custom and native endnotes found
'convert to custom all or 'convert to custom all or
'convert to native 'convert to native
runDualEndnotesDialog(foundEndNotes(0),foundEndNotes(1))
End Sub End Sub
Sub runDualEndnotesDialog(nativeEndNotes() As Object,customEndnotes() As Object)
Dim dialog As Object
waitingForDialog = true
dialog = notModalDialog("EndnotesConversion")
dialog.getControl("found").SetText(getTranslation("EndnotesNativeDialogFound") & CStr(UBound(nativeEndNotes)+1))
dialog.getControl("found2").SetText(getTranslation("EndnotesCustomDialogFound") & CStr(UBound(customEndnotes)+1))
dialog.getControl("found2").Model.EnableVisible = TRUE
dialog.getControl("description").SetText(getTranslation("EndnotesConversionTwoOptions"))
dialog.getControl("cancel").Label = getTranslation("buttonCancel")
dialog.getControl("start").Label = getTranslation("toNativeEndnotes")
dialog.getControl("option2").Label = getTranslation("toCustomEndnotes")
dialog.getControl("option2").Model.EnableVisible = TRUE
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
convertCustomEndnotesToNative(customEndnotes)
exit Do
EndIf
If dialog.getControl("option2").model.state = 1 then
convertEndnotesToCustom(nativeEndNotes)
exit Do
EndIf
wait (100)
Loop
dialog.dispose
End Sub
Sub runEndnotesCustomToNativeDialog(customEndnotes() As Object)
Dim dialog As Object
waitingForDialog = true
dialog = notModalDialog("EndnotesConversion")
dialog.getControl("found").SetText(getTranslation("EndnotesCustomDialogFound") & CStr(UBound(customEndnotes)+1))
dialog.getControl("description").SetText(getTranslation("EndnotesCustomConversionOption"))
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
convertCustomEndnotesToNative(customEndnotes)
exit Do
EndIf
wait (100)
Loop
dialog.dispose
End Sub
Sub convertCustomEndnotesToNative(foundEndnotes() As Object)
Dim i As Long
Dim bodyAnchorName As String
Dim textAnchorName As String
Dim bookmarksName As String
Dim bookmarks As Object
bookmarksName = ThisComponent.Links.ElementNames(6)
bookmarks = ThisComponent.Links.getByName(bookmarksName)
For i = LBound(foundEndnotes) To UBound(foundEndnotes)
bodyAnchorName = getBodyAnchorName(foundEndnotes(i))
textAnchorName = getTextAnchorName(bodyAnchorName)
If bookmarks.hasByName(bodyAnchorName) And bookmarks.hasByName(textAnchorName) Then
convertLinksToEndnote(bodyAnchorName,textAnchorName)
EndIf
Next i
End Sub
Function getBodyAnchorName(textRange As Object) As String
getBodyAnchorName = ""
If (Len(textRange.HyperLinkURL) > 0) Then
getBodyAnchorName = Right(textRange.HyperLinkURL,Len(textRange.HyperLinkURL)-1)
EndIf
End Function
Function getTextAnchorName(bodyAnchorName As String) As String
getTextAnchorName = ""
If Len(bodyAnchorName) > Len(endnoteInBodyAnchorSuffix) Then
getTextAnchorName = Left(bodyAnchorName,Len(bodyAnchorName)-Len(endnoteInBodyAnchorSuffix)) & endnoteInTextAnchorSuffix
EndIf
End Function
Sub convertLinksToEndnote(forwardLink As String,backwardLink As String)
Dim bookMarkName As String
bookmarkName = ThisComponent.Links.ElementNames(6)
Dim bookmarks As Object
bookmarks = ThisComponent.Links.getByName(bookmarkName)
Dim forward As Object
Dim backward As Object
Dim oViewCursor As Object
Dim footNoteSign As String
oViewCursor = ThisComponent.CurrentController.getViewCursor()
Dim oTextCursor As Object
If NOT bookmarks.hasByName(forwardLink) OR NOT bookmarks.hasByName(backwardLink) Then
exit sub
EndIf
forward = bookmarks.getByName(forwardLink)
backward = bookmarks.getByName(backwardLink)
footNoteSign = forward.Anchor.String
oViewCursor.goToRange(forward.Anchor,false)
SendRM
SendRM
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
goToEndOfEndnoteBody(oTextCursor)
oTextCursor.goToRange(oViewCursor,true)
oViewCursor.goToRange(oTextCursor,true)
unoCut()
SendRM
oViewCursor.goToRange(backward.Anchor,false)
removeEndnoteSignInText()
createEndnote
unoPaste()
oViewCursor.getText.setLabel(footNoteSign)
forward.dispose()
backward.dispose()
End Sub
Sub goToEndOfEndnoteBody(oTextCursor As Object)
Dim position As Object
position = oTextCursor.End
oTextCursor.goToEndOfParagraph(false)
oTextCursor.goRight(1,false)
If oTextCursor.ParaStyleName <> "Endnote" OR oTextCursor.CharStyleName = "Endnote Symbol" Then
oTextCursor.goLeft(1,false)
Exit Sub
EndIf
'Got to the end of the document
If oTextCursor.Text.compareRegionEnds(position,oTextCursor.End) = 0 Then
Exit Sub
EndIf
goToEndOfEndnoteBody(oTextCursor)
End Sub
Sub removeEndnoteSignInText()
Dim oViewCursor As Object
Dim character As String
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oViewCursor.String = ""
oViewCursor.HyperLinkURL=""
End Sub
sub createEndnote
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:InsertEndnote", "", 0, Array())
end Sub
Sub runEndnotesConversionDialog(foundEndNotes As Variant) Sub runEndnotesConversionDialog(foundEndNotes As Variant)
Dim dialog As Object Dim dialog As Object
waitingForDialog = true waitingForDialog = true
@ -62,6 +221,7 @@ Sub runEndnotesConversionDialog(foundEndNotes As Variant)
dialog.getControl("description").SetText(getTranslation("EndnotesNativeDialogDescriptionSelect")) dialog.getControl("description").SetText(getTranslation("EndnotesNativeDialogDescriptionSelect"))
dialog.getControl("cancel").Label = getTranslation("buttonCancel") dialog.getControl("cancel").Label = getTranslation("buttonCancel")
dialog.getControl("start").Label = getTranslation("buttonOk") dialog.getControl("start").Label = getTranslation("buttonOk")
Thiscomponent.CurrentController.select(ThisComponent.Text)
dialog.setvisible(true) dialog.setvisible(true)
Do While waitingForDialog Do While waitingForDialog
If dialog.getControl("cancel").model.state = 1 then If dialog.getControl("cancel").model.state = 1 then
@ -95,16 +255,14 @@ End Sub
Function createEndnoteFieldPrefix As String Function createEndnoteFieldPrefix As String
Dim names() As String Dim names() As String
Dim i As Integer
Dim prefix As String Dim prefix As String
names = ThisComponent.getTextFieldMasters().getElementNames() names = ThisComponent.getTextFieldMasters().getElementNames()
For i = 0 To 10000 prefix = endnoteFieldPrefix & RND_String() & "_"
prefix = endnoteFieldPrefix & i & "_"
If NOT startsWithInArray(prefix, names) Then If NOT startsWithInArray(prefix, names) Then
createEndnoteFieldPrefix = prefix createEndnoteFieldPrefix = prefix
Exit Function Exit Function
EndIf EndIf
Next i
createEndnoteFieldPrefix = prefix createEndnoteFieldPrefix = prefix
End Function End Function
@ -278,6 +436,7 @@ Sub findEndNotesInParagraph(enum1Element As Object,nativeEndNotes As Variant, cu
Dim footnoteText As Object Dim footnoteText As Object
Dim label As String Dim label As String
Dim labelNum As Long Dim labelNum As Long
Dim bookmarkName As String
If enum1Element.OutlineLevel = level Then If enum1Element.OutlineLevel = level Then
curNum = 1 curNum = 1
EndIf EndIf
@ -286,9 +445,20 @@ Sub findEndNotesInParagraph(enum1Element As Object,nativeEndNotes As Variant, cu
thisPortion = textPortions.nextElement thisPortion = textPortions.nextElement
If isTargetNote(thisPortion,1) Then If isTargetNote(thisPortion,1) Then
AddToArray(nativeEndNotes, thisPortion) AddToArray(nativeEndNotes, thisPortion)
' ElseIf isCustomEndnote(thisPortion) ElseIf isCustomEndnote(thisPortion) Then
' AddToArray(customEndNotesd, thisPortion) AddToArray(customEndNotes, thisPortion)
EndIf EndIf
Wend Wend
End Sub End Sub
Function isCustomEndnote(portion As Object) As Boolean
If InStr(portion.HyperLinkURL, "#" & endnoteFieldPrefix) = 1 And portion.String <> "" Then
If InStr(portion.HyperLinkURL, endnoteInBodyAnchorSuffix) > 0 Then
isCustomEndnote = true
Exit Function
EndIf
EndIf
isCustomEndnote = false
End Function
</script:module> </script:module>

View file

@ -1,10 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd"> <!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: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="160" dlg:height="84" dlg:closeable="true" dlg:moveable="true">
<dlg:bulletinboard> <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="description" dlg:tab-index="0" dlg:left="8" dlg:top="28" dlg:width="147" dlg:height="36" dlg:value="Для вывода концевых сносок установите курсор в целевом параграфе и нажмите Конвертация" dlg:align="center" 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:text dlg:id="found" dlg:tab-index="1" dlg:left="8" dlg:top="3" dlg:width="145" dlg:height="8" dlg:value="Найдено концевых сносок" dlg:align="center"/>
<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="cancel" dlg:tab-index="2" dlg:left="2" dlg:top="69" dlg:width="50" 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:button dlg:id="start" dlg:tab-index="3" dlg:left="107" dlg:top="69" dlg:width="50" dlg:height="13" dlg:value="Конвертация" dlg:toggled="1"/>
<dlg:button dlg:id="option2" dlg:tab-index="4" dlg:visible="false" dlg:left="55" dlg:top="69" dlg:width="50" dlg:height="13" dlg:value="Вариант2" dlg:toggled="1"/>
<dlg:text dlg:id="found2" dlg:tab-index="5" dlg:visible="false" dlg:left="8" dlg:top="14" dlg:width="145" dlg:height="8" dlg:value="Найдено концевых сносок" dlg:align="center"/>
</dlg:bulletinboard> </dlg:bulletinboard>
</dlg:window> </dlg:window>

View file

@ -280,6 +280,21 @@ Function getRussian(identifier As String) As String
Case &quot;EndnotesNotFound&quot; Case &quot;EndnotesNotFound&quot;
getRussian = &quot;В текущем выделении концевых сносок не найдено. Выделите текст с концевыми сносками.&quot; getRussian = &quot;В текущем выделении концевых сносок не найдено. Выделите текст с концевыми сносками.&quot;
Exit Function Exit Function
Case &quot;EndnotesCustomDialogFound&quot;
getRussian = &quot;Найдено ручных концевых сносок: &quot;
Exit Function
Case &quot;EndnotesCustomConversionOption&quot;
getRussian = &quot;Для конвертации ручных концевых сносок в стандартные нажмите кнопку Применить&quot;
Exit Function
Case &quot;toNativeEndnotes&quot;
getRussian = &quot;В стандартные&quot;
Exit Function
Case &quot;toCustomEndnotes&quot;
getRussian = &quot;В ручные&quot;
Exit Function
Case &quot;EndnotesConversionTwoOptions&quot;
getRussian = &quot;Найдены и стандартные и ручные концевые сноски. Можно сконвертировать стандартные в ручные (установите курсор в нужном параграфе) или ручные в стандартные&quot;
Exit Function
Case Else Case Else
getRussian = &quot;Перевод не найден&quot; getRussian = &quot;Перевод не найден&quot;
End Select End Select
@ -531,6 +546,30 @@ Function getEnglish(identifier As String) As String
Case &quot;FootnotesConfigDialogNotesPerPageRangeLabel&quot; Case &quot;FootnotesConfigDialogNotesPerPageRangeLabel&quot;
getEnglish = &quot;Enter the page range &quot; getEnglish = &quot;Enter the page range &quot;
Exit Function Exit Function
Case &quot;EndnotesNativeDialogFound&quot;
getEnglish = &quot;Endnotes found:&quot;
Exit Function
Case &quot;EndnotesNativeDialogDescriptionSelect&quot;
getEnglish = &quot;To list endnote bodies, position the cursor in the desired paragraph and click the Apply button.&quot;
Exit Function
Case &quot;EndnotesNotFound&quot;
getEnglish = &quot;No endnotes found in the current selection. Select text with endnotes.&quot;
Exit Function
Case &quot;EndnotesCustomDialogFound&quot;
getEnglish = &quot;Found custom endnotes: &quot;
Exit Function
Case &quot;EndnotesCustomConversionOption&quot;
getEnglish = &quot;To convert manual endnotes to standard, click the Apply button&quot;
Exit Function
Case &quot;toNativeEndnotes&quot;
getEnglish = &quot;To standard&quot;
Exit Function
Case &quot;toCustomEndnotes&quot;
getEnglish = &quot;To custom&quot;
Exit Function
Case &quot;EndnotesConversionTwoOptions&quot;
getEnglish = &quot;Both standard and manual endnotes are found. You can convert standard to manual (place the cursor in the desired paragraph) or manual to standard&quot;
Exit Function
Case Else Case Else
getEnglish = &quot;No translation&quot; getEnglish = &quot;No translation&quot;
End Select End Select
@ -781,6 +820,30 @@ Function getFrench(identifier As String) As String
Case &quot;FootnotesConfigDialogNotesPerPageRangeLabel&quot; Case &quot;FootnotesConfigDialogNotesPerPageRangeLabel&quot;
getFrench = &quot;Entrez la plage de pages &quot; getFrench = &quot;Entrez la plage de pages &quot;
Exit Function Exit Function
Case &quot;EndnotesNativeDialogFound&quot;
getFrench = &quot;Notes trouvées :&quot;
Exit Function
Case &quot;EndnotesNativeDialogDescriptionSelect&quot;
getFrench = &quot;Pour afficher les notes de fin, positionnez le curseur dans le paragraphe souhaité et cliquez sur le bouton Appliquer.&quot;
Exit Function
Case &quot;EndnotesNotFound&quot;
getFrench = &quot;Aucune note de fin trouvée dans la sélection actuelle. Sélectionnez du texte avec des notes de fin.&quot;
Exit Function
Case &quot;EndnotesCustomDialogFound&quot;
getFrench = &quot;Notes de fin de main trouvées :&quot;
Exit Function
Case &quot;EndnotesCustomConversionOption&quot;
getFrench = &quot;Pour convertir les notes de fin manuelles en notes standard, cliquez sur le bouton Appliquer&quot;
Exit Function
Case &quot;toNativeEndnotes&quot;
getFrench = &quot;À la norme&quot;
Exit Function
Case &quot;toCustomEndnotes&quot;
getFrench = &quot;Sur mesure&quot;
Exit Function
Case &quot;EndnotesConversionTwoOptions&quot;
getFrench = &quot;Des notes de fin standard et manuelles sont trouvées. Vous pouvez convertir standard en manuel (placez le curseur dans le paragraphe souhaité) ou manuel en standard&quot;
Exit Function
Case Else Case Else
getFrench = &quot;No translation&quot; getFrench = &quot;No translation&quot;
End Select End Select
@ -1031,6 +1094,30 @@ Function getCroatian(identifier As String) As String
Case &quot;FootnotesConfigDialogNotesPerPageRangeLabel&quot; Case &quot;FootnotesConfigDialogNotesPerPageRangeLabel&quot;
getCroatian = &quot;Unesite raspon stranica &quot; getCroatian = &quot;Unesite raspon stranica &quot;
Exit Function Exit Function
Case &quot;EndnotesNativeDialogFound&quot;
getCroatian = &quot;Pronađene krajnje bilješke:&quot;
Exit Function
Case &quot;EndnotesNativeDialogDescriptionSelect&quot;
getCroatian = &quot;Za prikaz krajnjih bilješki postavite kursor u željeni odlomak i kliknite gumb Primijeni.&quot;
Exit Function
Case &quot;EndnotesNotFound&quot;
getCroatian = &quot;U trenutnom odabiru nisu pronađene nikakve bilješke. Odaberite tekst s krajnjim bilješkama.&quot;
Exit Function
Case &quot;EndnotesCustomDialogFound&quot;
getCroatian = &quot;Pronađene ručne bilješke:&quot;
Exit Function
Case &quot;EndnotesCustomConversionOption&quot;
getCroatian = &quot;Da biste ručne bilješke pretvorili u standardne, kliknite gumb Primijeni&quot;
Exit Function
Case &quot;toNativeEndnotes&quot;
getCroatian = &quot;Standardno&quot;
Exit Function
Case &quot;toCustomEndnotes&quot;
getCroatian = &quot;Na običaj&quot;
Exit Function
Case &quot;EndnotesConversionTwoOptions&quot;
getCroatian = &quot;Pronađene su i standardne i ručne bilješke. Možete pretvoriti standardni u ručni (postavite kursor u željeni odlomak) ili ručni u standardni&quot;
Exit Function
Case Else Case Else
getCroatian = &quot;No translation&quot; getCroatian = &quot;No translation&quot;
End Select End Select
@ -1281,6 +1368,30 @@ Function getSerbian(identifier As String) As String
Case &quot;FootnotesConfigDialogNotesPerPageRangeLabel&quot; Case &quot;FootnotesConfigDialogNotesPerPageRangeLabel&quot;
getSerbian = &quot;Унесите опсег страница &quot; getSerbian = &quot;Унесите опсег страница &quot;
Exit Function Exit Function
Case &quot;EndnotesNativeDialogFound&quot;
getSerbian = &quot;Пронађене крајње белешке:&quot;
Exit Function
Case &quot;EndnotesNativeDialogDescriptionSelect&quot;
getSerbian = &quot;Да бисте приказали крајње белешке, поставите курсор у жељени пасус и кликните на дугме Примени.&quot;
Exit Function
Case &quot;EndnotesNotFound&quot;
getSerbian = &quot;У тренутном избору нису пронађене белешке. Изаберите текст са крајњим белешкама.&quot;
Exit Function
Case &quot;EndnotesCustomDialogFound&quot;
getSerbian = &quot;Пронађене ручне белешке:&quot;
Exit Function
Case &quot;EndnotesCustomConversionOption&quot;
getSerbian = &quot;Да бисте ручне белешке претворили у стандардне, кликните на дугме Примени&quot;
Exit Function
Case &quot;toNativeEndnotes&quot;
getSerbian = &quot;Стандардно&quot;
Exit Function
Case &quot;toCustomEndnotes&quot;
getSerbian = &quot;По мери&quot;
Exit Function
Case &quot;EndnotesConversionTwoOptions&quot;
getSerbian = &quot;Пронађене су и стандардне и ручне белешке. Можете претворити стандардни у ручни (поставите курсор у жељени одломак) или ручни у стандардни&quot;
Exit Function
Case Else Case Else
getSerbian = &quot;No translation&quot; getSerbian = &quot;No translation&quot;
End Select End Select
@ -1531,6 +1642,30 @@ Function getBosnian(identifier As String) As String
Case &quot;FootnotesConfigDialogNotesPerPageRangeLabel&quot; Case &quot;FootnotesConfigDialogNotesPerPageRangeLabel&quot;
getBosnian = &quot;Unesite raspon stranica &quot; getBosnian = &quot;Unesite raspon stranica &quot;
Exit Function Exit Function
Case &quot;EndnotesNativeDialogFound&quot;
getBosnian = &quot;Pronađene krajnje bilješke:&quot;
Exit Function
Case &quot;EndnotesNativeDialogDescriptionSelect&quot;
getBosnian = &quot;Za prikaz krajnjih bilješki postavite kursor u željeni odlomak i kliknite gumb Primijeni.&quot;
Exit Function
Case &quot;EndnotesNotFound&quot;
getBosnian = &quot;U trenutnom odabiru nisu pronađene nikakve bilješke. Odaberite tekst s krajnjim bilješkama.&quot;
Exit Function
Case &quot;EndnotesCustomDialogFound&quot;
getBosnian = &quot;Pronađene ručne bilješke:&quot;
Exit Function
Case &quot;EndnotesCustomConversionOption&quot;
getBosnian = &quot;Da biste ručne bilješke pretvorili u standardne, kliknite gumb Primijeni&quot;
Exit Function
Case &quot;toNativeEndnotes&quot;
getBosnian = &quot;Standardno&quot;
Exit Function
Case &quot;toCustomEndnotes&quot;
getBosnian = &quot;Na običaj&quot;
Exit Function
Case &quot;EndnotesConversionTwoOptions&quot;
getBosnian = &quot;Pronađene su i standardne i ručne bilješke. Možete pretvoriti standardni u ručni (postavite kursor u željeni odlomak) ili ručni u standardni&quot;
Exit Function
Case Else Case Else
getBosnian = &quot;No translation&quot; getBosnian = &quot;No translation&quot;
End Select End Select

Binary file not shown.