From 1535e540179f93825fefd46854a725b3979b2e5a Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Mon, 16 Mar 2020 14:53:17 +0100 Subject: [PATCH] Added button to replace paragraph style --- Addons.xcu | 62 ++++++++++++++ description.xml | 2 +- ePublishing/Archive.xba | 138 ++++++++++++++++++++++++++++++- ePublishing/dialog.xlb | 3 +- ePublishing/replaceParaStyle.xdl | 9 ++ 5 files changed, 208 insertions(+), 6 deletions(-) create mode 100644 ePublishing/replaceParaStyle.xdl diff --git a/Addons.xcu b/Addons.xcu index 8dedae6..7269070 100644 --- a/Addons.xcu +++ b/Addons.xcu @@ -1,6 +1,68 @@  + + + + ePublishing panel + Панель ePublishing + + + true + + false + false + + + + com.sun.star.text.TextDocument,com.sun.star.text.WebDocument + + + ePublishing panel + Панель ePublishing + + + macro:///ePublishing.Archive.replaceParaStyle + + + _self + + + + + + com.sun.star.text.TextDocument,com.sun.star.text.WebDocument + + + ЗаменитьСтильПараграфа + ReplaceParaStyle + + + macro:///ePublishing.Archive.replaceParaStyle + + + _self + + + + + + + + macro:///ePublishing.Archive.replaceParaStyle + + + + %origin%/icons/validate.png + + + + + + + + + diff --git a/description.xml b/description.xml index cf6fcc0..a522dc6 100644 --- a/description.xml +++ b/description.xml @@ -3,7 +3,7 @@ xmlns:dep="http://openoffice.org/extensions/description/2006" xmlns:xlink="http://www.w3.org/1999/xlink"> - + Инструменты для создания электронных изданий diff --git a/ePublishing/Archive.xba b/ePublishing/Archive.xba index 8aaba1d..f414455 100644 --- a/ePublishing/Archive.xba +++ b/ePublishing/Archive.xba @@ -1,6 +1,6 @@ -Sub archMark2 +Sub archMark7 End Sub @@ -123,7 +123,11 @@ End Function sub convertIndesignPageBreaks - + Dim description As String + description = "Запустить восстановление разрывов страниц?" + If NOT confirm(description) Then + Exit Sub + EndIf document = ThisComponent.CurrentController.Frame dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") oViewCursor = thisComponent.getCurrentController.getViewCursor @@ -183,7 +187,7 @@ sub convertIndesignPageBreaks End If oFound = ThisComponent.findNext(oFound.End, oSearch) Loop - + MsgBox "Восстановление разрывов страниц завершено." end Sub Sub adjustLastLine(oTextCursor) @@ -297,6 +301,12 @@ End Sub Sub convertBookmarksToFootnotes() + Dim description As String + description = "Запустить восстановление сносок из текста?" + If NOT confirm(description) Then + Exit Sub + EndIf + Dim bookmarks as Object Dim bookmarkName as String Dim strStart As Integer @@ -331,7 +341,7 @@ Sub convertBookmarksToFootnotes() Next i resetNotesStyle - + MsgBox "Восстановление сносок завершено." End Sub Sub convertLinkToFootnote(forwardLink,backwardLink) @@ -398,4 +408,124 @@ sub createFootnote dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") dispatcher.executeDispatch(document, ".uno:InsertFootnote", "", 0, Array()) end Sub + + +Dim oDialog + +Sub onSelectMenuItem(oEvent) + oDialog.endExecute() + oDialog.model.Tag = oEvent.ActionCommand +End Sub + +Sub replaceParaStyle + + dim oldStyleName As String + dim oldStyle As Object + dim newStyleName As String + dim paragraphStyles As Object + dim userInput As Integer + Dim listBox As Object + Dim paraStyle As Object + Dim oViewCursor As Object + Dim enum1 As Object + Dim oTextCursor As Object + + oStyles = ThisComponent.StyleFamilies + paraStyles = oStyles.getByName(oStyles.elementNames(1)) + oViewCursor = ThisComponent.CurrentController.getViewCursor() + oldStyleName = oViewCursor.ParaStyleName + + paraStyleNames = paraStyles.ElementNames + Dim displayParaStyleNames(Ubound(paraStyleNames)) + Dim sortedDPSN(Ubound(paraStyleNames)) + displayParaStyleNames = paraStyleNames + Redim Preserve displayParaStyleNames(Ubound(paraStyleNames)) + For i = LBound(displayParaStyleNames) To Ubound(displayParaStyleNames) + paraStyle = paraStyles.getByName(displayParaStyleNames(i)) + displayParaStyleNames(i) = paraStyle.displayName + Next i + sortedDPSN = displayParaStyleNames + Redim Preserve sortedDPSN(Ubound(paraStyleNames)) + subShellSort(sortedDPSN) + DialogLibraries.LoadLibrary("ePublishing") + oDialog = CreateUnoDialog( DialogLibraries.ePublishing.replaceParaStyle ) + listBox = oDialog.getControl("ListBox1") + listBox.addItems(sortedDPSN , 0) + oDialog.Execute() + newStyleName = oDialog.model.Tag + If newStyleName="0" or newStyleName="" Then + Exit sub + EndIf + foundIndex = getIndex(displayParaStyleNames, newStyleName) + 'set style system name instead of display name + newStyleName = paraStyleNames(foundIndex) + + If newStyleName = oldStyleName Then + MsgBox "Стили не различаются" + Exit sub + EndIf + If oldStyleName <> "" Then + oldStyle = paraStyles.getByName(oldStyleName) + oldStyle.ParentStyle = newStyleName + paraStyles.removeByName(oldStyleName) + EndIf + oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor) + enum1 = oTextCursor.createEnumeration() + While enum1.hasMoreElements + enum1Element = enum1.nextElement + If enum1Element.supportsService("com.sun.star.text.Paragraph") Then + If enum1Element.ParaStyleName <> newStyleName Then + oldStyle = paraStyles.getByName(enum1Element.ParaStyleName) + oldStyle.ParentStyle = newStyleName + paraStyles.removeByName(enum1Element.ParaStyleName) + EndIf + EndIf + Wend + + +End Sub + +function getIndex(a, v) + id = 0 + nRight = uBound(a) + nLen = len(v) + while id <= nRight + if a(id) = v then + getIndex = id + exit Function + Else + id = id + 1 + end if + wend + getIndex = -1 +end function + +sub subShellSort(mArray) + + dim n as integer, h as integer, i as integer, j as integer, t as string, Ub as integer, LB as Integer + Lb = lBound(mArray) + Ub = uBound(mArray) + + ' compute largest increment + n = Ub - Lb + 1 + h = 1 + if n > 14 then + do while h < n + h = 3 * h + 1 + loop + h = h \ 3 + h = h \ 3 + end if + do while h > 0 + for i = Lb + h to Ub + t = mArray(i) + for j = i - h to Lb step -h + if strComp(mArray(j), t, 0) < 1 then exit for + mArray(j + h) = mArray(j) + next j + mArray(j + h) = t + next i + h = h \ 3 + loop +end sub \ No newline at end of file diff --git a/ePublishing/dialog.xlb b/ePublishing/dialog.xlb index 2024bb0..6f7d005 100644 --- a/ePublishing/dialog.xlb +++ b/ePublishing/dialog.xlb @@ -2,4 +2,5 @@ - \ No newline at end of file + + diff --git a/ePublishing/replaceParaStyle.xdl b/ePublishing/replaceParaStyle.xdl new file mode 100644 index 0000000..2b50613 --- /dev/null +++ b/ePublishing/replaceParaStyle.xdl @@ -0,0 +1,9 @@ + + + + + + + + +