Code cleaning

This commit is contained in:
Georgy Litvinov 2020-03-21 11:55:13 +01:00
parent bf58089cf1
commit 21d1d274bd
4 changed files with 73 additions and 76 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Clean" script:language="StarBasic">Sub mark33 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Clean" script:language="StarBasic">Sub mark34
End Sub End Sub
@ -28,7 +28,7 @@ Private Sub makerUpMenu
Exit sub Exit sub
End Sub End Sub
Private Sub cleanAccordingTo(dialog) Private Sub cleanAccordingTo(dialog As Object)
Dim statusIndicator as Object Dim statusIndicator as Object
statusIndicator = ThisComponent.getCurrentController.statusIndicator statusIndicator = ThisComponent.getCurrentController.statusIndicator
dialog.setVisible(false) dialog.setVisible(false)
@ -141,6 +141,8 @@ Private Sub quietCleaning
End Sub End Sub
Private Sub removeFirstElementPageBreak Private Sub removeFirstElementPageBreak
Dim enum1 As Object
Dim enum1Element As Object
enum1 = ThisComponent.Text.createEnumeration enum1 = ThisComponent.Text.createEnumeration
If enum1.hasMoreElements Then If enum1.hasMoreElements Then
enum1Element = enum1.nextElement enum1Element = enum1.nextElement
@ -163,12 +165,14 @@ Private Sub replaceStyleFonts
replaceFontsInStyles(&quot;Palatino Linotype Greek&quot;,&quot;Tinos&quot;) replaceFontsInStyles(&quot;Palatino Linotype Greek&quot;,&quot;Tinos&quot;)
End Sub End Sub
Private Sub replaceFontsInStyles(oldFontStart,newFontName) Private Sub replaceFontsInStyles(oldFontStart As String,newFontName As String)
&apos; Substitutes font names starts with oldFont value with newFont value
Dim oDoc as Object
Dim propertySetInfo As Object Dim propertySetInfo As Object
Dim oPositionOfMatch As Long Dim oPositionOfMatch As Long
oDoc = ThisComponent Dim oFamilies As Object
Dim sElements As Object
Dim oFamily As Object
Dim oStyle As Object
Dim fontName As String
oFamilies = Thiscomponent.StyleFamilies oFamilies = Thiscomponent.StyleFamilies
sElements() = oFamilies.getElementNames() sElements() = oFamilies.getElementNames()
For i = 0 to oFamilies.count -1 For i = 0 to oFamilies.count -1
@ -183,10 +187,10 @@ Private Sub replaceFontsInStyles(oldFontStart,newFontName)
oStyle.CharFontName = newFontName oStyle.CharFontName = newFontName
If propertySetInfo.hasPropertyByName(&quot;CharFontNameComplex&quot;) Then If propertySetInfo.hasPropertyByName(&quot;CharFontNameComplex&quot;) Then
oStyle.CharFontNameComplex = newFontName oStyle.CharFontNameComplex = newFontName
ENdIf EndIf
If propertySetInfo.hasPropertyByName(&quot;CharFontNameAsian&quot;) Then If propertySetInfo.hasPropertyByName(&quot;CharFontNameAsian&quot;) Then
oStyle.CharFontNameAsian = newFontName oStyle.CharFontNameAsian = newFontName
ENdIf EndIf
EndIf EndIf
EndIf EndIf
@ -248,18 +252,19 @@ Private Sub unicodeSymbolsConversion
End Sub End Sub
Private Sub unicodeConversionEverywhere(searchPattern,rAtts) Private Sub unicodeConversionEverywhere(searchPattern As String,rAtts)
&apos;in text
setAttributesBySearchPattern(searchPattern,RAtts) setAttributesBySearchPattern(searchPattern,RAtts)
End Sub End Sub
&apos;Replaces manual formatting text with font into character style with assigned font &apos;Replaces manual formatting text with font into character style with assigned font
Private Sub convertFontsToCharStyles Private Sub convertFontsToCharStyles
Dim oDoc Dim oDoc As Object
oDoc = Thiscomponent Dim SDesc As Object
Dim founds As Object
Dim curFont As String
Dim srch(0) as new com.sun.star.beans.PropertyValue Dim srch(0) as new com.sun.star.beans.PropertyValue
oDoc = Thiscomponent
SDesc = Thiscomponent.createSearchDescriptor() SDesc = Thiscomponent.createSearchDescriptor()
SDesc.SearchAll = true SDesc.SearchAll = true
SDesc.ValueSearch = false SDesc.ValueSearch = false
@ -294,9 +299,11 @@ End Sub
Private Sub removeUserPageStyles Private Sub removeUserPageStyles
Dim oStyles As Object Dim oStyles As Object
Dim oStyle As Object Dim oStyle As Object
oStyles = ThisComponent.StyleFamilies.getByName(&quot;PageStyles&quot;)
Dim count As Long Dim count As Long
Dim i As Long
oStyles = ThisComponent.StyleFamilies.getByName(&quot;PageStyles&quot;)
count = oStyles.count - 1 count = oStyles.count - 1
For i = 0 to count For i = 0 to count
oStyle = oStyles.getByIndex(i) oStyle = oStyles.getByIndex(i)
If oStyle.isUserDefined Then If oStyle.isUserDefined Then
@ -366,8 +373,8 @@ Private Sub fixFrequentMistakes
End Sub End Sub
Private Sub loadArticleStyles Private Sub loadArticleStyles
Dim dispatcher as object Dim dispatcher As Object
Dim fileePath As String Dim filePath As String
Dim fileTest As Object Dim fileTest As Object
Dim fileName As String Dim fileName As String
Dim aArgs(0) As New com.sun.star.beans.PropertyValue Dim aArgs(0) As New com.sun.star.beans.PropertyValue
@ -384,11 +391,11 @@ Private Sub loadArticleStyles
ThisComponent.StyleFamilies.loadStylesFromURL( filePath, aArgs() ) ThisComponent.StyleFamilies.loadStylesFromURL( filePath, aArgs() )
End Sub End Sub
Private Sub CreateCharacterStyle(sStyleName$, oProps()) Private Sub CreateCharacterStyle(sStyleName As String, oProps())
Dim i% Dim i As Integer
Dim oFamilies Dim oFamilies As Object
Dim oStyle Dim oStyle As Object
Dim oStyles Dim oStyles As Object
oFamilies = ThisComponent.StyleFamilies oFamilies = ThisComponent.StyleFamilies
oStyles = oFamilies.getByName(&quot;CharacterStyles&quot;) oStyles = oFamilies.getByName(&quot;CharacterStyles&quot;)
If oStyles.HasByName(sStyleName) Then If oStyles.HasByName(sStyleName) Then
@ -412,21 +419,20 @@ Private Function CreateProperty( Optional cName As String, Optional uValue ) As
CreateProperty() = oPropertyValue CreateProperty() = oPropertyValue
End Function End Function
Private Sub AskAndReplace(SearchString, oReplaceString) Private Sub AskAndReplace(SearchString As String, oReplaceString As String)
Dim SrchAttributes(0) as new com.sun.star.beans.PropertyValue Dim SrchAttributes(0) as new com.sun.star.beans.PropertyValue
Dim ReplAttributes(0) as new com.sun.star.beans.PropertyValue Dim ReplAttributes(0) as new com.sun.star.beans.PropertyValue
ReplaceFormatting(SearchString,oReplaceString,SrchAttributes,ReplAttributes, true) ReplaceFormatting(SearchString,oReplaceString,SrchAttributes,ReplAttributes, true)
End Sub End Sub
Private Function DocHasCharStyle(oDoc, sName$) As Boolean Private Function DocHasCharStyle(oDoc, sName$) As Boolean
Dim oStyles Dim oStyles As Object
oStyles = oDoc.StyleFamilies.getByName(&quot;CharacterStyles&quot;) oStyles = oDoc.StyleFamilies.getByName(&quot;CharacterStyles&quot;)
DocHasCharStyle() = oStyles.hasByName(sName) DocHasCharStyle() = oStyles.hasByName(sName)
End Function End Function
Private Function getTemplatePath() as String Private Function getTemplatePath() as String
Dim ath as String Dim path as String
Dim settings As Object Dim settings As Object
Dim configProvider As Object Dim configProvider As Object
Dim params(0) As new com.sun.star.beans.PropertyValue Dim params(0) As new com.sun.star.beans.PropertyValue
@ -448,20 +454,17 @@ End Function
Private Sub removeHyperlinks() Private Sub removeHyperlinks()
Dim aNote As Object Dim aNote As Object
Dim i As Long
removeHLInText(ThisComponent.Text) removeHLInText(ThisComponent.Text)
For x = 0 to ThisComponent.FootNotes.Count -1 For i = 0 to ThisComponent.FootNotes.Count -1
aNote = ThisComponent.FootNotes.getByIndex(x) aNote = ThisComponent.FootNotes.getByIndex(x)
removeHLInText(aNote.Text) removeHLInText(aNote.Text)
Next Next
For x = 0 to ThisComponent.EndNotes.Count -1 For i = 0 to ThisComponent.EndNotes.Count -1
aNote = ThisComponent.EndNotes.getByIndex(x) aNote = ThisComponent.EndNotes.getByIndex(x)
removeHLInText(aNote.Text) removeHLInText(aNote.Text)
Next Next
End Sub End Sub
Private Sub removeHLInText(textElement) Private Sub removeHLInText(textElement)
@ -513,6 +516,9 @@ End Sub
Private Sub removeManualPageBreaks Private Sub removeManualPageBreaks
Dim oTextCursor As Object
Dim enum1 As Object
Dim enum1Element As Object
oTextCursor = ThisComponent.Text.CreateTextCursor() oTextCursor = ThisComponent.Text.CreateTextCursor()
enum1 = ThisComponent.Text.createEnumeration enum1 = ThisComponent.Text.createEnumeration
While enum1.hasMoreElements While enum1.hasMoreElements
@ -538,12 +544,15 @@ Sub setAttributesBySearchPattern(searchPattern As String,ReplAttributes, Optiona
doNotTrack doNotTrack
dim stringValue1 As String dim stringValue1 As String
dim stringValue2 As String dim stringValue2 As String
Dim oSearch Dim oSearch As Object
Dim oTextCursor As Object Dim oTextCursor As Object
Dim oViewCursor As Object Dim oViewCursor As Object
Dim replace As Boolean Dim replace As Boolean
Dim attrName As string Dim attrName As string
Dim attrValue As String Dim attrValue As String
Dim oFound As Object
Dim i As Long
Dim j As Long
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;) dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
oSearch = ThisComponent.createSearchDescriptor() oSearch = ThisComponent.createSearchDescriptor()
oSearch.SearchString = searchPattern oSearch.SearchString = searchPattern
@ -585,9 +594,8 @@ Sub setAttributesBySearchPattern(searchPattern As String,ReplAttributes, Optiona
End Sub End Sub
Private Sub saveAndreload() Private Sub saveAndreload()
Dim document As Object
dim document as object Dim dispatcher As Object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;) dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dispatcher.executeDispatch(document, &quot;.uno:Save&quot;, &quot;&quot;, 0, Array()) dispatcher.executeDispatch(document, &quot;.uno:Save&quot;, &quot;&quot;, 0, Array())
@ -596,9 +604,8 @@ Private Sub saveAndreload()
End Sub End Sub
Private Sub saveDocument() Private Sub saveDocument()
Dim document As Object
dim document as object Dim dispatcher As Object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;) dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dispatcher.executeDispatch(document, &quot;.uno:Save&quot;, &quot;&quot;, 0, Array()) dispatcher.executeDispatch(document, &quot;.uno:Save&quot;, &quot;&quot;, 0, Array())
@ -616,19 +623,15 @@ Private Sub cleanFormatting
&apos;Не должно быть пустых абзацев &apos;Не должно быть пустых абзацев
AskAndReplace(&quot;^$&quot;,&quot;&quot;) AskAndReplace(&quot;^$&quot;,&quot;&quot;)
convertFormattingToText convertFormattingToText()
convertFontsToCharStyles
replaceBaseWithStandard
removeDirectFormatting
convertFormattingFromText
convertFontsToCharStyles()
replaceBaseWithStandard()
removeDirectFormatting()
convertFormattingFromText()
End Sub End Sub
@ -637,6 +640,7 @@ Private Sub fixTableWidth()
Dim tables As Object Dim tables As Object
tables = ThisComponent.TextTables tables = ThisComponent.TextTables
Dim count As Long Dim count As Long
Dim i As Long
count = ThisComponent.TextTables.getCount() count = ThisComponent.TextTables.getCount()
For i = 0 To count - 1 For i = 0 To count - 1
table = tables.getByIndex(i) table = tables.getByIndex(i)
@ -654,6 +658,7 @@ Private Sub fixDrawingAnchors()
Dim drawings As Object Dim drawings As Object
drawings = ThisComponent.DrawPage drawings = ThisComponent.DrawPage
Dim count As Long Dim count As Long
Dim i As Long
count = drawings.getCount() count = drawings.getCount()
For i = 0 To count - 1 For i = 0 To count - 1
drawing = drawings.getByIndex(i) drawing = drawings.getByIndex(i)

View file

@ -6,6 +6,7 @@ Function initRedactionConfiguration()
On Error Goto exceptionHandler On Error Goto exceptionHandler
Dim regFactory As Object Dim regFactory As Object
Dim reg As Object Dim reg As Object
Dim redactionProps As Object
Dim props(2) As New com.sun.star.beans.PropertyValue Dim props(2) As New com.sun.star.beans.PropertyValue
regFactory = CreateUnoService(&quot;com.sun.star.ucb.Store&quot;) regFactory = CreateUnoService(&quot;com.sun.star.ucb.Store&quot;)
@ -19,7 +20,7 @@ Function initRedactionConfiguration()
initRedactionConfiguration = redactionProps initRedactionConfiguration = redactionProps
End Function End Function
Private Sub setConfigFromDialog(dialog) Private Sub setConfigFromDialog(dialog As Object)
Dim config As Object Dim config As Object
config = initRedactionConfiguration() config = initRedactionConfiguration()
If dialog.getControl(&quot;CB_complexity&quot;).state = 1 Then If dialog.getControl(&quot;CB_complexity&quot;).state = 1 Then
@ -29,7 +30,7 @@ Private Sub setConfigFromDialog(dialog)
EndIf EndIf
End Sub End Sub
Private Sub loadConfigToDialog(dialog) Private Sub loadConfigToDialog(dialog As Object)
Dim config As Object Dim config As Object
config = initRedactionConfiguration() config = initRedactionConfiguration()
If config.getPropertyValue(&quot;complexity&quot;) = &quot;makerUp&quot; Then If config.getPropertyValue(&quot;complexity&quot;) = &quot;makerUp&quot; Then
@ -51,11 +52,8 @@ Private Sub configurationDialog
setConfigFromDialog(dialog) setConfigFromDialog(dialog)
Case 0 Case 0
End Select End Select
dialog.setVisible(false) dialog.setVisible(false)
dialog.dispose() dialog.dispose()
Exit sub Exit sub
End Sub End Sub
</script:module> </script:module>

View file

@ -4,7 +4,7 @@
End Sub End Sub
Private Function isInDoc(searchString As String) Private Function isInDoc(searchString As String) As Boolean
Dim founds As Object Dim founds As Object
Dim sDesc As Object Dim sDesc As Object
Dim srch(0) as new com.sun.star.beans.PropertyValue Dim srch(0) as new com.sun.star.beans.PropertyValue
@ -71,12 +71,7 @@ Sub validateButton
EndIf EndIf
End Sub End Sub
Private Function checkGraphics() As String
Sub testcheckGraphics
checkGraphics
End Sub
Private Function checkGraphics
Dim drawPages As Object Dim drawPages As Object
Dim count as Integer Dim count as Integer
Dim draw As Object Dim draw As Object
@ -128,12 +123,11 @@ End Function
Private Sub removeBadCharacters Private Sub removeBadCharacters
StartTracking StartTracking
AskAndReplace(&quot;[\uE000-\uF8FF]+&quot;,&quot;&quot;) AskAndReplace(&quot;[\uE000-\uF8FF]+&quot;,&quot;&quot;)
StopTracking StopTracking
showTrackedChanges showTrackedChanges
End Sub End Sub
Private Function checkAllFootnotes() Private Function checkAllFootnotes() As String
Dim footnotes As Object Dim footnotes As Object
Dim count as Integer Dim count as Integer
Dim charNum as Long Dim charNum as Long

View file

@ -3,7 +3,7 @@
xmlns:dep="http://openoffice.org/extensions/description/2006" xmlns:dep="http://openoffice.org/extensions/description/2006"
xmlns:xlink="http://www.w3.org/1999/xlink"> xmlns:xlink="http://www.w3.org/1999/xlink">
<identifier value="pro.litvinovg.Redaction" /> <identifier value="pro.litvinovg.Redaction" />
<version value="0.5.8" /> <version value="0.5.9" />
<platform value="all" /> <platform value="all" />
<display-name> <display-name>
<name lang="en">Cleaning and validation documents for publishing in html and epub with pagination</name> <name lang="en">Cleaning and validation documents for publishing in html and epub with pagination</name>