Added archives menu

This commit is contained in:
Georgy Litvinov 2020-03-16 13:53:48 +01:00
parent dbf6d1d49e
commit 03789e78c7
4 changed files with 442 additions and 1 deletions

View file

@ -70,6 +70,42 @@
</node> </node>
</node> </node>
</node> </node>
<node oor:name="Submenu">
<node oor:name="archiveMenu" oor:op="replace">
<prop oor:name="Title" oor:type="xs:string">
<value xml:lang="en">Archive</value>
<value xml:lang="ru">Архив</value>
</prop>
<node oor:name="Submenu">
<node oor:name="footnotesRecovery" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>macro:///ePublishing.Archive.convertBookmarksToFootnotes</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value/>
<value xml:lang="en">Recovery footnotes from text</value>
<value xml:lang="ru">Восстановление сносок из текста</value>
</prop>
</node>
<node oor:name="pageBreaksRecovery" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>macro:///ePublishing.Archive.convertIndesignPageBreaks</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value/>
<value xml:lang="en">PageBreaks recovery</value>
<value xml:lang="ru">Восстановление разрывов страниц</value>
</prop>
</node>
</node>
</node>
</node>
<node oor:name="Submenu"> <node oor:name="Submenu">
<node oor:name="cleanConfigure" oor:op="replace"> <node oor:name="cleanConfigure" oor:op="replace">
<prop oor:name="Context" oor:type="xs:string"> <prop oor:name="Context" oor:type="xs:string">

401
ePublishing/Archive.xba Normal file
View file

@ -0,0 +1,401 @@
<?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="Archive" script:language="StarBasic" script:moduleType="normal">Sub archMark2
End Sub
Sub resetNotesStyle
Dim oDescriptor &apos;The search descriptor
dim dispatcher as Object
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dim document as Object
document = ThisComponent.CurrentController.Frame
Dim oViewCursor As Object &apos;View cursor
oViewCursor = ThisComponent.CurrentController.getViewCursor()
allNotes= thisComponent.FootNotes
for x = 0 to allNotes.Count -1
aNote = allNotes.getByIndex(x)
aNote.Anchor.CharStyleName=&quot;Footnote anchor&quot;
oEnum = aNote.Text.createEnumeration()
Do While oEnum.hasMoreElements()
oCurPar = oEnum.nextElement()
oCurPar.ParaStyleName = &quot;Footnote&quot;
Loop
Next
End Sub
Sub createBidirectLink
Dim oSelections &apos;Contains all of the selections
Dim oAnchor1
Dim oAnchor2
If IsNull(ThisComponent) Then
MsgBox &quot;Ничего не выбрано&quot;
Exit Sub
End If
oSelections = ThisComponent.getCurrentSelection()
If IsNull(oSelections) Then
MsgBox &quot;Ничего не выбрано&quot;
Exit Sub
End If
objectsCount = oSelections.getCount() - 1
If oSelections.getCount() = 0 Then
MsgBox &quot;Ничего не выбрано&quot;
Exit Sub
End If
If oSelections.getCount() &lt;= 2 Then
MsgBox &quot;Нужно выделить два объекта, а не &quot; + objectsCount
Exit Sub
End If
If oSelections.getCount() &gt; 3 Then
MsgBox &quot;Нужно выделить только два объекта, а не &quot; + objectsCount
Exit Sub
End If
oAnchor1 = oSelections.getByIndex(1)
oAnchor2 = oSelections.getByIndex(2)
oAnchor1Name = RND_String()
oAnchor2Name = RND_String()
createAnchor(oAnchor1,oAnchor1Name)
createAnchor(oAnchor2,oAnchor2Name)
createLink(oAnchor1,oAnchor1.String,oAnchor2Name)
createLink(oAnchor2,oAnchor2.String,oAnchor1Name)
End Sub
Sub createAnchor(targetRange as Object,anchorName as String)
dim oViewCursor as object
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oViewCursor.gotoRange(targetRange,false)
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = &quot;Bookmark&quot;
args1(0).Value = anchorName
dispatcher.executeDispatch(document, &quot;.uno:InsertBookmark&quot;, &quot;&quot;, 0, args1())
End Sub
Sub createLink(targetRange as Object,linkName as String,linkURL as String)
dim oViewCursor as object
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
oViewCursor = ThisComponent.CurrentController.getViewCursor()
oViewCursor.gotoRange(targetRange,false)
dim args2(4) as new com.sun.star.beans.PropertyValue
args2(0).Name = &quot;Hyperlink.Text&quot;
args2(0).Value = linkName
args2(1).Name = &quot;Hyperlink.URL&quot;
args2(1).Value = &quot;#&quot;+linkURL
args2(2).Name = &quot;Hyperlink.Target&quot;
args2(2).Value = &quot;&quot;
args2(3).Name = &quot;Hyperlink.Name&quot;
args2(3).Value = linkName
args2(4).Name = &quot;Hyperlink.Type&quot;
args2(4).Value = 1
dispatcher.executeDispatch(document, &quot;.uno:SetHyperlink&quot;, &quot;&quot;, 0, args2())
End Sub
Function RND_String
Dim OutputString As String
Dim TempString As String
Dim i as Long
OutputString=&quot;&quot;
randomize
for i = 1 to 20
Select Case i
Case 5, 8, 11, 14
OutputString=OutputString+&quot;-&quot;
Case Else
TempString=Hex(int(rnd*256))
if len(TempString)&lt;2 then TempString=TempString+&quot;0&quot;
OutputString=OutputString+TempString
End Select
next i
RND_String = OutputString
End Function
sub convertIndesignPageBreaks
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
oViewCursor = thisComponent.getCurrentController.getViewCursor
oViewCursor.jumpToFirstPage
Dim args(0) as new com.sun.star.beans.PropertyValue
rem Turn off tracking changes to prevent infinite
args(0).Name = &quot;TrackChanges&quot;
args(0).Value = false
dispatcher.executeDispatch(document, &quot;.uno:TrackChanges&quot;, &quot;&quot;, 0, args())
Dim oSearch
Dim oTextCursor
Dim lineIndent
Dim firstLowercase As Boolean
Dim charNum As Long
Dim character As String
firstLowercase = false
oSearch = ThisComponent.createSearchDescriptor()
oSearch.SearchString = &quot;---XYXYX---&quot;
oSearch.SearchRegularExpression=True
oSearch.searchAll=True
oFound = ThisComponent.findFirst(oSearch)
Do While Not IsNull(oFound)
oTextCursor = oFound.Text.createTextCursor()
oTextCursor.gotoRange(oFound,false)
oTextCursor.gotoStartOfParagraph(false)
oTextCursor.gotoEndOfParagraph(true)
oTextCursor.goRight(1,true)
oTextCursor.String = &quot;&quot;
oTextCursor.BreakType = com.sun.star.style.BreakType.PAGE_BEFORE
&apos;check first character
oTextCursor.goRight(1,true)
If (isLowerCase(oTextCursor.getString())) Then
oTextCursor.ParaFirstLineIndent = 0
firstLowercase = true
End If
&apos;check last character
oTextCursor.goLeft(2,false)
oTextCursor.goLeft(1,true)
character = oTextCursor.getString()
If (character = &quot; &quot;) Then
oTextCursor.String=&quot;&quot;
adjustLastLine(oTextCursor)
adjustFirstLine(oTextCursor)
EndIf
If (isLowerCase(character)) Then
If firstLowercase Then
oTextCursor.collapseToEnd()
oTextCursor.setString(&quot;-&quot;)
oTextCursor.collapseToEnd()
adjustLastLine(oTextCursor)
adjustFirstLine(oTextCursor)
EndIf
End If
oFound = ThisComponent.findNext(oFound.End, oSearch)
Loop
end Sub
Sub adjustLastLine(oTextCursor)
oTextCursor.ParaAdjust = 2
oTextCursor.ParaLastLineAdjust = 2
balancePara(oTextCursor)
End Sub
Sub adjustFirstLine(oTextCursor)
oTextCursor.goRight(1,false)
oTextCursor.ParaFirstLineIndent = 0
End Sub
Function isLowerCase(character)
If (character = &quot;&quot;) Then
charNum = ASC(&quot;&quot;+0)
Else
charNum = ASC(character)
End If
If ((charNum &gt; 1071 AND charNum &lt; 1104) Or (charNum &gt; 60 AND charNum &lt; 123)) Then
isLowerCase = true
Exit Function
EndIf
isLowerCase = false
End Function
Sub balancePara(Optional targetPara As Object)
&apos; Globalscope.BasicLibraries.LoadLibrary( &quot;MRILib&quot; )
Dim oViewCursor As Object
Dim oTextCursor As Object
Dim oPara As Object
Dim oParaStart As Object
Dim oParaEnd As Object
Dim paraLen As Integer
Dim lineCount As Integer
Dim initialLineCount As Integer
Dim lineLen As Integer
Dim mathExpect As Integer
Dim minLastLineLength As Integer
paraLen = 0
lineLen = 0
minLastLineLength = 0
initialLineCount = 0
oViewCursor = ThisComponent.CurrentController.getViewCursor()
If NOT IsMissing(targetPara) Then
oViewCursor.goToRange(targetPara, false)
EndIf
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
oPara = oViewCursor.Text.createTextCursorByRange(oViewCursor)
&apos;Go to start of para
oTextCursor.gotoStartOfParagraph(false)
&apos;Get start position
oParaStart = oTextCursor.getStart()
&apos;Go to end of para
oTextCursor.gotoEndOfParagraph(false)
&apos;Get end position
oParaEnd = oTextCursor.getEnd()
&apos;return Text cursor to start
oTextCursor.goToRange(oParaStart,false)
&apos;oPara is full para cursor
oPara.goToRange(oParaStart,false)
oPara.goToRange(oParaEnd,true)
Do
&apos;Not first iteration
If minLastLineLength &lt;&gt; 0 Then
If oPara.CharKerning &lt; 30 Then
If(IsEmpty(oPara.CharKerning)) Then
oPara.CharKerning = 0
Else
oPara.CharKerning = oPara.CharKerning + 2
End If
Else
&apos;Failed to balance para
Exit Sub
EndIf
EndIf
oViewCursor.goToRange(oParaStart,false)
oTextCursor.goToRange(oParaStart,false)
lineCount = 0
While NOT oTextCursor.isEndOfParagraph()
oViewCursor.gotoEndOfLine(true)
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
lineLen = Len(oTextCursor.getString())
paraLen = paraLen + lineLen
lineCount = lineCount + 1
oViewCursor.collapseToEnd()
Wend
&apos;set initial line count
If initialLineCount = 0 Then
initialLineCount = lineCount
ElseIf lineCount &gt; initialLineCount Then
&apos;Undo last iteration as line overflow happened.
&apos;And exit
If(IsEmpty(oPara.CharKerning)) Then
oPara.CharKerning = 0
Else
oPara.CharKerning = oPara.CharKerning - 2
End If
Exit sub
EndIf
mathExpect = paraLen / lineCount
minLastLineLength = mathExpect * 0.9
Loop Until minLastLineLength &lt; lineLen
End Sub
Sub convertBookmarksToFootnotes()
Dim bookmarks as Object
Dim bookmarkName as String
Dim strStart As Integer
Dim linkPrefix As String
Dim backLinkSuffix As String
Dim backwardLink As String
Dim forwardLink As String
Dim forward As Object
Dim backward As Object
linkPrefix = &quot;footnote-&quot;
backLinkSuffix = &quot;-backlink&quot;
bookmarkName = ThisComponent.Links.ElementNames(6)
bookmarks = ThisComponent.Links.getByName(bookmarkName)
&apos; Mri bookmarks
bookmarkNames = bookmarks.getElementNames()
For i = LBound(bookmarkNames) To Ubound(bookmarkNames)
bookmarkName = bookmarkNames(i)
If InStr(bookmarkName, linkPrefix) = 1 Then
forwardLink = &quot;&quot;
backwardLink = &quot;&quot;
If InStr(bookmarkName, backLinkSuffix) &gt; 0 Then
forwardLink = Left(bookmarkName,Len(bookmarkName) - Len(backLinkSuffix))
backwardLink = bookmarkName
Else
forwardLink = bookmarkName
backwardLink = bookmarkName + backLinkSuffix
EndIf
convertLinkToFootnote(forwardLink,backwardLink)
EndIf
Next i
resetNotesStyle
End Sub
Sub convertLinkToFootnote(forwardLink,backwardLink)
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
&apos;If msgbox( &quot;NO SuCH LINK&quot;, 36 ) = 6 Then Stop
EndIf
forward = bookmarks.getByName(forwardLink)
backward = bookmarks.getByName(backwardLink)
oViewCursor.goToRange(forward.Anchor,false)
footNoteSign = oViewCursor.getString()
backspace
backspace
SendRM
oTextCursor = oViewCursor.Text.createTextCursorByRange(oViewCursor)
oTextCursor.gotoEndOfParagraph(false)
oTextCursor.gotoStartOfParagraph(true)
oViewCursor.goToRange(oTextCursor,true)
unoCut()
SendRM
oViewCursor.goToRange(backward.Anchor,false)
backspace
createFootnote
unoPaste()
oViewCursor.getText.setLabel(footNoteSign)
forward.dispose()
backward.dispose()
End sub
sub unoCut
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dispatcher.executeDispatch(document, &quot;.uno:Cut&quot;, &quot;&quot;, 0, Array())
end sub
sub unoPaste
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dispatcher.executeDispatch(document, &quot;.uno:Paste&quot;, &quot;&quot;, 0, Array())
end sub
sub createFootnote
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dispatcher.executeDispatch(document, &quot;.uno:InsertFootnote&quot;, &quot;&quot;, 0, Array())
end Sub
</script:module>

View file

@ -419,4 +419,7 @@ Private Function confirm(description)
EndIf EndIf
End Function End Function
</script:module>
Sub Macro1
End Sub</script:module>

View file

@ -7,4 +7,5 @@
<library:element library:name="Footnotes"/> <library:element library:name="Footnotes"/>
<library:element library:name="TOCLinks"/> <library:element library:name="TOCLinks"/>
<library:element library:name="Album"/> <library:element library:name="Album"/>
<library:element library:name="Archive"/>
</library:library> </library:library>