cleanandvalidate/Redaction/Configuration.xba
2021-09-13 19:51:11 +02:00

370 lines
No EOL
16 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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="Configuration" script:language="StarBasic" script:moduleType="normal">Public Const redactionExtensionName = &quot;cleanAndValidate&quot;
Public Const redactionExtensionVersion = &quot;0.10.3&quot;
Public Const template_name_monography = &quot;Монография&quot;
Public Const template_name_pj = &quot;Философский журнал&quot;
Public Const template_name_pq = &quot;Вопросы философии&quot;
Public Const template_name_hp = &quot;История философии&quot;
Public Const template_name_hpe = &quot;Историко-философский ежегодник&quot;
Public Const template_name_pr = &quot;Философия религии&quot;
Public Const template_name_fnit = &quot;Философия науки и техники&quot;
Public Const template_name_pa = &quot;Философская антропология&quot;
Public Const template_name_pcr = &quot;Путь цивилизационного развития&quot;
Public Const template_name_eifn = &quot;Эпистемология и философия науки&quot;
Public Const template_name_et = &quot;Этическая мысль&quot;
Public Const template_name_iph_big = &quot;Большой формат издания&quot;
Public Const template_manual = &quot;custom_selected_template&quot;
Function initRedactionConfiguration()
On Error Goto exceptionHandler
Dim regFactory As Object
Dim reg As Object
Dim redactionProps As Object
Dim props(2) As New com.sun.star.beans.PropertyValue
Dim propSetInfo As Object
regFactory = CreateUnoService(&quot;com.sun.star.ucb.Store&quot;)
reg = regFactory.createPropertySetRegistry(redactionExtensionName)
redactionProps = reg.openPropertySet(redactionExtensionName, TRUE)
propSetInfo = redactionProps.getPropertySetInfo()
If Not propSetInfo.hasPropertyByName(&quot;superscript_max_length&quot;) Then
redactionProps.addProperty(&quot;superscript_max_length&quot;, 128, &quot;10&quot;)
EndIf
If Not propSetInfo.hasPropertyByName(&quot;subscript_max_length&quot;) Then
redactionProps.addProperty(&quot;subscript_max_length&quot;, 128, &quot;10&quot;)
EndIf
If Not propSetInfo.hasPropertyByName(&quot;fixes_russian_iph&quot;) Then
redactionProps.addProperty(&quot;fixes_russian_iph&quot;, 128, &quot;true&quot;)
EndIf
If Not propSetInfo.hasPropertyByName(&quot;predefined_template&quot;) Then
redactionProps.addProperty(&quot;predefined_template&quot;, 128, &quot;false&quot;)
EndIf
If Not propSetInfo.hasPropertyByName(&quot;complexity&quot;) Then
redactionProps.addProperty(&quot;complexity&quot;, 128, &quot;user&quot;)
EndIf
exceptionHandler:
Resume Next
On Error Goto exceptionHandler2
If Not propSetInfo.hasPropertyByName(&quot;defaultTemplate&quot;) Then
redactionProps.addProperty(&quot;defaultTemplate&quot;, 128, &quot;Статья.ott&quot;)
EndIf
If Not propSetInfo.hasPropertyByName(&quot;predefined_template&quot;) Then
redactionProps.addProperty(&quot;predefined_template&quot;, 128, &quot;false&quot;)
EndIf
exceptionHandler2:
Resume Next
initRedactionConfiguration = redactionProps
End Function
Private Sub setConfigFromDialog(dialog As Object)
Dim config As Object
config = initRedactionConfiguration()
If dialog.getControl(&quot;CB_complexity&quot;).state = 1 Then
config.setPropertyValue(&quot;complexity&quot;, &quot;makerUp&quot;)
Else
config.setPropertyValue(&quot;complexity&quot;, &quot;user&quot;)
EndIf
If dialog.getControl(&quot;cb_russian_fixes_iph&quot;).state = 1 Then
config.setPropertyValue(&quot;fixes_russian_iph&quot;, &quot;true&quot;)
Else
config.setPropertyValue(&quot;fixes_russian_iph&quot;, &quot;false&quot;)
EndIf
config.setPropertyValue(&quot;superscript_max_length&quot;, dialog.getControl(&quot;tf_max_superscript&quot;).getText())
config.setPropertyValue(&quot;subscript_max_length&quot;, dialog.getControl(&quot;tf_max_subscript&quot;).getText())
End Sub
Private Sub loadConfigToDialog(dialog As Object)
Dim config As Object
config = initRedactionConfiguration()
If config.getPropertyValue(&quot;complexity&quot;) = &quot;makerUp&quot; Then
dialog.getControl(&quot;CB_complexity&quot;).state = 1
Else
dialog.getControl(&quot;CB_complexity&quot;).state = 0
EndIf
If config.getPropertyValue(&quot;fixes_russian_iph&quot;) = &quot;true&quot; Then
dialog.getControl(&quot;cb_russian_fixes_iph&quot;).state = 1
Else
dialog.getControl(&quot;cb_russian_fixes_iph&quot;).state = 0
EndIf
dialog.getControl(&quot;tf_max_superscript&quot;).setText(config.getPropertyValue(&quot;superscript_max_length&quot;))
dialog.getControl(&quot;tf_max_subscript&quot;).setText(config.getPropertyValue(&quot;subscript_max_length&quot;))
End Sub
Private Sub configurationDialog
Dim dialog As Object
DialogLibraries.LoadLibrary(&quot;Redaction&quot;)
dialog = CreateUnoDialog(DialogLibraries.Redaction.ConfigDialog)
loadConfigToDialog(dialog)
dialog.getControl(&quot;CB_complexity&quot;).Label = getTranslation(&quot;dialogConfigComplexity&quot;)
dialog.getControl(&quot;cb_russian_fixes_iph&quot;).Label = getTranslation(&quot;dialogRussianFixesIPH&quot;)
dialog.getControl(&quot;label_max_superscript&quot;).setText(getTranslation(&quot;dialogConfigMaxSuperscript&quot;))
dialog.getControl(&quot;label_max_subscript&quot;).setText(getTranslation(&quot;dialogConfigMaxSubscript&quot;))
dialog.Title = getTranslation(&quot;dialogConfigTitle&quot;)
dialog.getControl(&quot;OK&quot;).Label = getTranslation(&quot;buttonYes&quot;)
dialog.getControl(&quot;CANCEL&quot;).Label = getTranslation(&quot;buttonStop&quot;)
dialog.setVisible(true)
Select Case dialog.Execute()
Case 1
setConfigFromDialog(dialog)
Case 0
End Select
dialog.setVisible(false)
dialog.dispose()
Exit sub
End Sub
Dim queitCleaningDialog As Object
Private Sub quietStartDialog
DialogLibraries.LoadLibrary(&quot;Redaction&quot;)
queitCleaningDialog = CreateUnoDialog(DialogLibraries.Redaction.StartQuietCleaning)
Dim buttonNameOk As String
Dim buttonNameStop As String
Dim buttonNameLoad As String
Dim dialogTitle As String
buttonNameOk = getTranslation(&quot;buttonYes&quot;)
buttonNameStop = getTranslation(&quot;buttonStop&quot;)
buttonNameLoad = getTranslation(&quot;buttonLoad&quot;)
dialogTitle = getTranslation(&quot;quietStartCleaningTitle&quot;)
queitCleaningDialog.Title = dialogTitle
setQuietDialogDescription()
queitCleaningDialog.getControl(&quot;buttonOk&quot;).Label = buttonNameOk
queitCleaningDialog.getControl(&quot;buttonStop&quot;).Label = buttonNameStop
queitCleaningDialog.getControl(&quot;buttonLoad&quot;).Label = buttonNameLoad
queitCleaningDialog.setVisible(true)
Select Case queitCleaningDialog.Execute()
Case 1
queitCleaningDialog.setVisible(false)
queitCleaningDialog.dispose()
quietCleaning
Case 0
queitCleaningDialog.setVisible(false)
queitCleaningDialog.dispose()
End Select
Exit sub
End Sub
Function setAdvancedDialogDescription()
If IsNull(advancedCleaningDialog) Then
Exit Function
EndIf
Dim config As Object
Dim description As String
Dim predefined As String
Dim customFile As String
config = initRedactionConfiguration()
predefined = config.getPropertyValue(&quot;predefined_template&quot;)
customFile = config.getPropertyValue(&quot;defaultTemplate&quot;)
If predefined = &quot;false&quot; Then
description = getTranslation(&quot;templateNotSelected&quot;)
ElseIf predefined = template_manual Then
description = getTranslation(&quot;templateChosen&quot;) &amp; &quot; «&quot; &amp; customFile &amp; &quot;»&quot;
Else
description = getTranslation(&quot;templateChosen&quot;) &amp; &quot; «&quot; &amp; predefined &amp; &quot;»&quot;
EndIf
advancedCleaningDialog.getControl(&quot;description&quot;).setText(description)
End Function
Function setQuietDialogDescription()
If IsNull(queitCleaningDialog) Then
Exit Function
EndIf
Dim config As Object
Dim description As String
Dim predefined As String
Dim customFile As String
config = initRedactionConfiguration()
predefined = config.getPropertyValue(&quot;predefined_template&quot;)
customFile = config.getPropertyValue(&quot;defaultTemplate&quot;)
If predefined = &quot;false&quot; Then
description = getTranslation(&quot;startQuietCleaningDescription1&quot;) &amp; &quot; &quot; &amp; getTranslation(&quot;startQuietCleaningDescription2&quot;)
ElseIf predefined = template_manual Then
description = getTranslation(&quot;startQuietCleaningDescription1&quot;) &amp; &quot; «&quot; &amp; customFile &amp; &quot;» &quot; &amp; getTranslation(&quot;startQuietCleaningDescription2&quot;)
Else
description = getTranslation(&quot;startQuietCleaningDescription1&quot;) &amp; &quot; «&quot; &amp; predefined &amp; &quot;» &quot; &amp; getTranslation(&quot;startQuietCleaningDescription2&quot;)
EndIf
queitCleaningDialog.getControl(&quot;Description&quot;).setText(description)
End Function
Dim styleFileDialog As Object
Private Sub configureStyleFileDialog
&apos;Globalscope.BasicLibraries.LoadLibrary( &quot;MRILib&quot; )
Dim config As Object
Dim dialog As Object
Dim predefined As String
Dim description As String
Dim customFile As String
DialogLibraries.LoadLibrary(&quot;Redaction&quot;)
styleFileDialog = CreateUnoDialog(DialogLibraries.Redaction.NoStyleFile)
config = initRedactionConfiguration()
predefined = config.getPropertyValue(&quot;predefined_template&quot;)
customFile = config.getPropertyValue(&quot;defaultTemplate&quot;)
If predefined = &quot;false&quot; Then
description = getTranslation(&quot;noFileWithStylesFound&quot;)
ElseIf predefined = template_manual Then
description = getTranslation(&quot;manualStyleFileSet&quot;) &amp; &quot; «&quot; &amp; customFile &amp; &quot;»&quot;
Else
description = getTranslation(&quot;predefiendTemplateSelected&quot;) &amp; &quot; «&quot; &amp; predefined &amp; &quot;»&quot;
EndIf
styleFileDialog.Title = getTranslation(&quot;noStylesFileDialogTitle&quot;)
styleFileDialog.getControl(&quot;Description&quot;).setText(description)
styleFileDialog.getControl(&quot;FileSelection&quot;).Label = getTranslation(&quot;buttonNameToSelectFileWithStyles&quot;)
styleFileDialog.getControl(&quot;buttonOk&quot;).Label = getTranslation(&quot;buttonTemplateNotFoundSkip&quot;)
styleFileDialog.setVisible(true)
Select Case styleFileDialog.Execute()
Case 0
End Select
setQuietDialogDescription()
setAdvancedDialogDescription()
styleFileDialog.setVisible(false)
styleFileDialog.dispose()
End Sub
Sub selectTemplateDialog()
Dim config As Object
Dim description As String
Dim templateName As String
Dim templateNames() As String
Dim i As Integer
Dim listComponent As Object
config = initRedactionConfiguration()
Dim dialog As Object
DialogLibraries.LoadLibrary(&quot;Redaction&quot;)
dialog = CreateUnoDialog(DialogLibraries.Redaction.SelectTemplate)
listComponent = dialog.getControl(&quot;ListBox&quot;)
dialog.getControl(&quot;buttonOk&quot;).Label = getTranslation(&quot;buttonYes&quot;)
dialog.getControl(&quot;buttonStop&quot;).Label = getTranslation(&quot;buttonStop&quot;)
dialog.Title = getTranslation(&quot;selectTemplateDialogTitle&quot;)
templateNames = getTemplateNames()
listComponent.addItems(templateNames , 0)
dialog.setVisible(true)
Select Case dialog.Execute()
Case 1
templateName = listComponent.SelectedItem
If NOT (templateName=&quot;0&quot; or templateName=&quot;&quot;) Then
config.setPropertyValue(&quot;predefined_template&quot;, templateName)
description = getTranslation(&quot;predefiendTemplateSelected&quot;) &amp; &quot; «&quot; &amp; templateName &amp; &quot;»&quot;
styleFileDialog.getControl(&quot;Description&quot;).setText(description)
EndIf
Case 0
End Select
dialog.setVisible(false)
dialog.dispose()
End Sub
Sub setManualTemplate()
Dim description As String
Dim selectedTemplate As String
selectedTemplate = getFileURLDialog()
oSimpleFileAccess = CreateUnoService( &quot;com.sun.star.ucb.SimpleFileAccess&quot; )
If NOT (oSimpleFileAccess.exists( selectedTemplate ) AND NOT oSimpleFileAccess.isFolder( selectedTemplate ) ) Then
Exit sub
End If
Dim fileName As String
Dim config As Object
config = initRedactionConfiguration()
fileName = Dir(selectedTemplate)
config.setPropertyValue(&quot;defaultTemplate&quot;,fileName)
config.setPropertyValue(&quot;predefined_template&quot;, template_manual)
Dim templatePath As String
templatePath = getTemplatePath()
MkDir(templatePath)
FileCopy(selectedTemplate, templatePath &amp; &quot;/&quot; &amp; fileName)
description = getTranslation(&quot;manualStyleFileSet&quot;) &amp; &quot; «&quot; &amp; fileName &amp; &quot;»&quot;
styleFileDialog.getControl(&quot;Description&quot;).setText(description)
End Sub
Function getFileURLDialog() As String
Dim oFilePicker As Object, oSimpleFileAccess As Object
Dim oSettings As Object, oPathSettings As Object
Dim oTextField As Object, oTextFieldModel As Object
Dim sFileURL As String
Dim sFiles As Variant
oFilePicker = CreateUnoService( &quot;com.sun.star.ui.dialogs.FilePicker&quot; )
oFilePicker.AppendFilter( &quot;All files (*.*)&quot;, &quot;*.*&quot; )
oFilePicker.AppendFilter( &quot;Open Document Text&quot;, &quot;*.odt;*.ott&quot; )
oFilePicker.SetCurrentFilter( &quot;Open Document Text&quot; )
If sFileURL = &quot;&quot; Then
oPathSettings = CreateUnoService( &quot;com.sun.star.util.PathSettings&quot; )
sFileURL = oPathSettings.Work
End If
REM set display directory
oSimpleFileAccess = CreateUnoService( &quot;com.sun.star.ucb.SimpleFileAccess&quot; )
If oSimpleFileAccess.exists( sFileURL ) And oSimpleFileAccess.isFolder( sFileURL ) Then
oFilePicker.setDisplayDirectory( sFileURL )
End If
If oFilePicker.execute() Then
sFiles = oFilePicker.getFiles()
sFileURL = sFiles(0)
If oSimpleFileAccess.exists( sFileURL ) Then
getFileURLDialog = sFileURL
Exit Function
End If
End If
getFileURLDialog = &quot;&quot;
End Function
Function getTemplateNames() As Variant
Dim names() As String
AddToArray(names, template_name_monography)
AddToArray(names, template_name_pq)
AddToArray(names, template_name_hp)
AddToArray(names, template_name_hpe)
AddToArray(names, template_name_pr)
AddToArray(names, template_name_fnit)
AddToArray(names, template_name_pa)
AddToArray(names, template_name_pcr)
AddToArray(names, template_name_eifn)
AddToArray(names, template_name_et)
AddToArray(names, template_name_iph_big)
getTemplateNames = names
End Function
Function extensionPath() As String
Dim oPackageInfoProvider As Object
oPackageInfoProvider = GetDefaultContext.getByName(&quot;/singletons/com.sun.star.deployment.PackageInformationProvider&quot;)
extensionPath = oPackageInfoProvider.getPackageLocation(&quot;pro.litvinovg.Redaction&quot;)
End Function
Function getTemplateFile(templateName As String) As String
Dim config As Object
Dim fileName As String
Select Case templateName
Case template_manual
config = initRedactionConfiguration()
fileName = config.getPropertyValue(&quot;defaultTemplate&quot;)
getTemplateFile = getTemplatePath() &amp; &quot;/&quot; &amp; fileName
Exit Function
Case template_name_eifn
getTemplateFile = extensionPath() &amp; &quot;/templates/articles/статья_журнала_ЭиФН.ott&quot;
Exit Function
Case template_name_et
getTemplateFile = extensionPath() &amp; &quot;/templates/articles/статья_этическая_мысль.ott&quot;
Exit Function
Case template_name_iph_big
getTemplateFile = extensionPath() &amp; &quot;/templates/books/большой_формат_для_архива.ott&quot;
Exit Function
Case Else
getTemplateFile = extensionPath() &amp; &quot;/templates/articles/default_article_template_ru.ott&quot;
Exit Function
End Select
End Function
</script:module>