diff --git a/ePublishing/Endnotes.xba b/ePublishing/Endnotes.xba index e74867e..a85fbee 100644 --- a/ePublishing/Endnotes.xba +++ b/ePublishing/Endnotes.xba @@ -45,15 +45,174 @@ Sub convertEndnotesExecution EndIf If (nativeEndnotesCounter = -1 ) Then 'only custom endnotes found. Window convert to native? + runEndnotesCustomToNativeDialog(foundEndNotes(1)) Exit Sub EndIf 'both custom and native endnotes found 'convert to custom all or 'convert to native - + runDualEndnotesDialog(foundEndNotes(0),foundEndNotes(1)) 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) Dim dialog As Object waitingForDialog = true @@ -62,6 +221,7 @@ Sub runEndnotesConversionDialog(foundEndNotes As Variant) dialog.getControl("description").SetText(getTranslation("EndnotesNativeDialogDescriptionSelect")) dialog.getControl("cancel").Label = getTranslation("buttonCancel") dialog.getControl("start").Label = getTranslation("buttonOk") + Thiscomponent.CurrentController.select(ThisComponent.Text) dialog.setvisible(true) Do While waitingForDialog If dialog.getControl("cancel").model.state = 1 then @@ -95,16 +255,14 @@ 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 + prefix = endnoteFieldPrefix & RND_String() & "_" + If NOT startsWithInArray(prefix, names) Then + createEndnoteFieldPrefix = prefix + Exit Function + EndIf + createEndnoteFieldPrefix = prefix End Function @@ -278,6 +436,7 @@ Sub findEndNotesInParagraph(enum1Element As Object,nativeEndNotes As Variant, cu Dim footnoteText As Object Dim label As String Dim labelNum As Long + Dim bookmarkName As String If enum1Element.OutlineLevel = level Then curNum = 1 EndIf @@ -286,9 +445,20 @@ Sub findEndNotesInParagraph(enum1Element As Object,nativeEndNotes As Variant, cu thisPortion = textPortions.nextElement If isTargetNote(thisPortion,1) Then AddToArray(nativeEndNotes, thisPortion) -' ElseIf isCustomEndnote(thisPortion) -' AddToArray(customEndNotesd, thisPortion) + ElseIf isCustomEndnote(thisPortion) Then + AddToArray(customEndNotes, thisPortion) EndIf Wend 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 + \ No newline at end of file diff --git a/ePublishing/EndnotesConversion.xdl b/ePublishing/EndnotesConversion.xdl index 4105650..65fda95 100644 --- a/ePublishing/EndnotesConversion.xdl +++ b/ePublishing/EndnotesConversion.xdl @@ -1,10 +1,12 @@ - + - - - - + + + + + + \ No newline at end of file diff --git a/ePublishing/Translations.xba b/ePublishing/Translations.xba index 0f86bfa..a47b9e3 100644 --- a/ePublishing/Translations.xba +++ b/ePublishing/Translations.xba @@ -245,14 +245,14 @@ Function getRussian(identifier As String) As String getRussian = "Отступ от текста до линии сноски" Exit Function Case "PageConfigMM" - getRussian = "мм" - Exit Function + getRussian = "мм" + Exit Function Case "allPagesHaveUniqPageStyle" - getRussian = "Каждой странице в документе назначен уникальный стиль" - Exit Function + getRussian = "Каждой странице в документе назначен уникальный стиль" + Exit Function Case "OutlineLinksFinished" - getRussian = "Создание ссылок в оглавлении завершено. Если этому сообщению предшествовали предупреждения об ошибках, то после исправления ошибок запустите создание ссылок заново." - Exit Function + getRussian = "Создание ссылок в оглавлении завершено. Если этому сообщению предшествовали предупреждения об ошибках, то после исправления ошибок запустите создание ссылок заново." + Exit Function Case "FootnotesConfigDialogFootnotesName" getRussian = "Обычные сноски" Exit Function @@ -280,6 +280,21 @@ Function getRussian(identifier As String) As String Case "EndnotesNotFound" getRussian = "В текущем выделении концевых сносок не найдено. Выделите текст с концевыми сносками." Exit Function + Case "EndnotesCustomDialogFound" + getRussian = "Найдено ручных концевых сносок: " + Exit Function + Case "EndnotesCustomConversionOption" + getRussian = "Для конвертации ручных концевых сносок в стандартные нажмите кнопку Применить" + Exit Function + Case "toNativeEndnotes" + getRussian = "В стандартные" + Exit Function + Case "toCustomEndnotes" + getRussian = "В ручные" + Exit Function + Case "EndnotesConversionTwoOptions" + getRussian = "Найдены и стандартные и ручные концевые сноски. Можно сконвертировать стандартные в ручные (установите курсор в нужном параграфе) или ручные в стандартные" + Exit Function Case Else getRussian = "Перевод не найден" End Select @@ -505,14 +520,14 @@ Function getEnglish(identifier As String) As String getEnglish = "Indent from text to footnote line" Exit Function Case "PageConfigMM" - getEnglish = "mm" - Exit Function + getEnglish = "mm" + Exit Function Case "allPagesHaveUniqPageStyle" - getEnglish = "Every page in document now have unique page style" - Exit Function - Case "OutlineLinksFinished" - getEnglish = "Creating links in the table of contents is complete. If this message was preceded by error warnings, then after correcting the errors, restart creating links in table of contents." - Exit Function + getEnglish = "Every page in document now have unique page style" + Exit Function + Case "OutlineLinksFinished" + getEnglish = "Creating links in the table of contents is complete. If this message was preceded by error warnings, then after correcting the errors, restart creating links in table of contents." + Exit Function Case "FootnotesConfigDialogFootnotesName" getEnglish = "Footnotes" Exit Function @@ -531,6 +546,30 @@ Function getEnglish(identifier As String) As String Case "FootnotesConfigDialogNotesPerPageRangeLabel" getEnglish = "Enter the page range " Exit Function + Case "EndnotesNativeDialogFound" + getEnglish = "Endnotes found:" + Exit Function + Case "EndnotesNativeDialogDescriptionSelect" + getEnglish = "To list endnote bodies, position the cursor in the desired paragraph and click the Apply button." + Exit Function + Case "EndnotesNotFound" + getEnglish = "No endnotes found in the current selection. Select text with endnotes." + Exit Function + Case "EndnotesCustomDialogFound" + getEnglish = "Found custom endnotes: " + Exit Function + Case "EndnotesCustomConversionOption" + getEnglish = "To convert manual endnotes to standard, click the Apply button" + Exit Function + Case "toNativeEndnotes" + getEnglish = "To standard" + Exit Function + Case "toCustomEndnotes" + getEnglish = "To custom" + Exit Function + Case "EndnotesConversionTwoOptions" + getEnglish = "Both standard and manual endnotes are found. You can convert standard to manual (place the cursor in the desired paragraph) or manual to standard" + Exit Function Case Else getEnglish = "No translation" End Select @@ -761,8 +800,8 @@ Function getFrench(identifier As String) As String getFrench = "Un style unique est attribué à chaque page du document" Exit Function Case "OutlineLinksFinished" - getFrench = "La création de liens dans la table des matières est terminée. Si ce message a été précédé d'avertissements d'erreur, après avoir corrigé les erreurs, recommencez à créer des liens." - Exit Function + getFrench = "La création de liens dans la table des matières est terminée. Si ce message a été précédé d'avertissements d'erreur, après avoir corrigé les erreurs, recommencez à créer des liens." + Exit Function Case "FootnotesConfigDialogFootnotesName" getFrench = "Notes de bas de page " Exit Function @@ -781,6 +820,30 @@ Function getFrench(identifier As String) As String Case "FootnotesConfigDialogNotesPerPageRangeLabel" getFrench = "Entrez la plage de pages " Exit Function + Case "EndnotesNativeDialogFound" + getFrench = "Notes trouvées :" + Exit Function + Case "EndnotesNativeDialogDescriptionSelect" + getFrench = "Pour afficher les notes de fin, positionnez le curseur dans le paragraphe souhaité et cliquez sur le bouton Appliquer." + Exit Function + Case "EndnotesNotFound" + getFrench = "Aucune note de fin trouvée dans la sélection actuelle. Sélectionnez du texte avec des notes de fin." + Exit Function + Case "EndnotesCustomDialogFound" + getFrench = "Notes de fin de main trouvées :" + Exit Function + Case "EndnotesCustomConversionOption" + getFrench = "Pour convertir les notes de fin manuelles en notes standard, cliquez sur le bouton Appliquer" + Exit Function + Case "toNativeEndnotes" + getFrench = "À la norme" + Exit Function + Case "toCustomEndnotes" + getFrench = "Sur mesure" + Exit Function + Case "EndnotesConversionTwoOptions" + getFrench = "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" + Exit Function Case Else getFrench = "No translation" End Select @@ -1011,8 +1074,8 @@ Function getCroatian(identifier As String) As String getCroatian = "Svakoj stranici u dokumentu dodeljen je jedinstveni stil." Exit Function Case "OutlineLinksFinished" - getCroatian = "Stvaranje veza u sadržaju je završeno. Ako su ovoj poruci prethodila upozorenja o pogrešci, počnite stvarati veze nakon ispravljanja pogrešaka." - Exit Function + getCroatian = "Stvaranje veza u sadržaju je završeno. Ako su ovoj poruci prethodila upozorenja o pogrešci, počnite stvarati veze nakon ispravljanja pogrešaka." + Exit Function Case "FootnotesConfigDialogFootnotesName" getCroatian = "Fusnote " Exit Function @@ -1031,6 +1094,30 @@ Function getCroatian(identifier As String) As String Case "FootnotesConfigDialogNotesPerPageRangeLabel" getCroatian = "Unesite raspon stranica " Exit Function + Case "EndnotesNativeDialogFound" + getCroatian = "Pronađene krajnje bilješke:" + Exit Function + Case "EndnotesNativeDialogDescriptionSelect" + getCroatian = "Za prikaz krajnjih bilješki postavite kursor u željeni odlomak i kliknite gumb Primijeni." + Exit Function + Case "EndnotesNotFound" + getCroatian = "U trenutnom odabiru nisu pronađene nikakve bilješke. Odaberite tekst s krajnjim bilješkama." + Exit Function + Case "EndnotesCustomDialogFound" + getCroatian = "Pronađene ručne bilješke:" + Exit Function + Case "EndnotesCustomConversionOption" + getCroatian = "Da biste ručne bilješke pretvorili u standardne, kliknite gumb Primijeni" + Exit Function + Case "toNativeEndnotes" + getCroatian = "Standardno" + Exit Function + Case "toCustomEndnotes" + getCroatian = "Na običaj" + Exit Function + Case "EndnotesConversionTwoOptions" + getCroatian = "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" + Exit Function Case Else getCroatian = "No translation" End Select @@ -1261,8 +1348,8 @@ Function getSerbian(identifier As String) As String getSerbian = "Свакој страници у документу додељен је јединствени стил." Exit Function Case "OutlineLinksFinished" - getSerbian = "Стварање веза у табели садржаја је завршено. Ако су овој поруци претходила упозорења о грешци, након исправљања грешака поново почните стварати везе." - Exit Function + getSerbian = "Стварање веза у табели садржаја је завршено. Ако су овој поруци претходила упозорења о грешци, након исправљања грешака поново почните стварати везе." + Exit Function Case "FootnotesConfigDialogFootnotesName" getSerbian = "Фусноте" Exit Function @@ -1281,6 +1368,30 @@ Function getSerbian(identifier As String) As String Case "FootnotesConfigDialogNotesPerPageRangeLabel" getSerbian = "Унесите опсег страница " Exit Function + Case "EndnotesNativeDialogFound" + getSerbian = "Пронађене крајње белешке:" + Exit Function + Case "EndnotesNativeDialogDescriptionSelect" + getSerbian = "Да бисте приказали крајње белешке, поставите курсор у жељени пасус и кликните на дугме Примени." + Exit Function + Case "EndnotesNotFound" + getSerbian = "У тренутном избору нису пронађене белешке. Изаберите текст са крајњим белешкама." + Exit Function + Case "EndnotesCustomDialogFound" + getSerbian = "Пронађене ручне белешке:" + Exit Function + Case "EndnotesCustomConversionOption" + getSerbian = "Да бисте ручне белешке претворили у стандардне, кликните на дугме Примени" + Exit Function + Case "toNativeEndnotes" + getSerbian = "Стандардно" + Exit Function + Case "toCustomEndnotes" + getSerbian = "По мери" + Exit Function + Case "EndnotesConversionTwoOptions" + getSerbian = "Пронађене су и стандардне и ручне белешке. Можете претворити стандардни у ручни (поставите курсор у жељени одломак) или ручни у стандардни" + Exit Function Case Else getSerbian = "No translation" End Select @@ -1511,8 +1622,8 @@ Function getBosnian(identifier As String) As String getBosnian = "Svakoj stranici u dokumentu dodeljen je jedinstveni stil." Exit Function Case "OutlineLinksFinished" - getBosnian = "Stvaranje veza u sadržaju je završeno. Ako su ovoj poruci prethodila upozorenja o pogrešci, počnite stvarati veze nakon ispravljanja pogrešaka." - Exit Function + getBosnian = "Stvaranje veza u sadržaju je završeno. Ako su ovoj poruci prethodila upozorenja o pogrešci, počnite stvarati veze nakon ispravljanja pogrešaka." + Exit Function Case "FootnotesConfigDialogFootnotesName" getBosnian = "Fusnote " Exit Function @@ -1531,6 +1642,30 @@ Function getBosnian(identifier As String) As String Case "FootnotesConfigDialogNotesPerPageRangeLabel" getBosnian = "Unesite raspon stranica " Exit Function + Case "EndnotesNativeDialogFound" + getBosnian = "Pronađene krajnje bilješke:" + Exit Function + Case "EndnotesNativeDialogDescriptionSelect" + getBosnian = "Za prikaz krajnjih bilješki postavite kursor u željeni odlomak i kliknite gumb Primijeni." + Exit Function + Case "EndnotesNotFound" + getBosnian = "U trenutnom odabiru nisu pronađene nikakve bilješke. Odaberite tekst s krajnjim bilješkama." + Exit Function + Case "EndnotesCustomDialogFound" + getBosnian = "Pronađene ručne bilješke:" + Exit Function + Case "EndnotesCustomConversionOption" + getBosnian = "Da biste ručne bilješke pretvorili u standardne, kliknite gumb Primijeni" + Exit Function + Case "toNativeEndnotes" + getBosnian = "Standardno" + Exit Function + Case "toCustomEndnotes" + getBosnian = "Na običaj" + Exit Function + Case "EndnotesConversionTwoOptions" + getBosnian = "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" + Exit Function Case Else getBosnian = "No translation" End Select diff --git a/translations.ods b/translations.ods index 379967c..b7b2ce0 100644 Binary files a/translations.ods and b/translations.ods differ