cleanandvalidate/Redaction/Configuration.xba

370 lines
16 KiB
Text
Raw Normal View History

2020-03-05 20:23:54 +01:00
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
2021-07-29 11:43:13 +02:00
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Configuration" script:language="StarBasic" script:moduleType="normal">Public Const redactionExtensionName = &quot;cleanAndValidate&quot;
2021-08-29 17:01:22 +02:00
Public Const redactionExtensionVersion = &quot;0.10.2&quot;
2021-07-29 11:43:13 +02:00
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;
2021-08-29 17:01:22 +02:00
Public Const template_name_iph_big = &quot;Большой формат издания&quot;
2021-07-29 11:43:13 +02:00
Public Const template_manual = &quot;custom_selected_template&quot;
2020-03-05 20:23:54 +01:00
Function initRedactionConfiguration()
On Error Goto exceptionHandler
Dim regFactory As Object
Dim reg As Object
2020-03-21 11:55:13 +01:00
Dim redactionProps As Object
2020-03-05 20:23:54 +01:00
Dim props(2) As New com.sun.star.beans.PropertyValue
Dim propSetInfo As Object
2020-03-05 20:23:54 +01:00
regFactory = CreateUnoService(&quot;com.sun.star.ucb.Store&quot;)
2020-03-05 20:55:14 +01:00
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;)
2021-07-29 11:43:13 +02:00
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
2020-04-23 14:15:18 +02:00
exceptionHandler:
2020-03-21 12:37:32 +01:00
Resume Next
2020-04-23 14:15:18 +02:00
On Error Goto exceptionHandler2
2021-01-14 12:09:53 +01:00
If Not propSetInfo.hasPropertyByName(&quot;defaultTemplate&quot;) Then
redactionProps.addProperty(&quot;defaultTemplate&quot;, 128, &quot;Статья.ott&quot;)
2021-07-29 11:43:13 +02:00
EndIf
If Not propSetInfo.hasPropertyByName(&quot;predefined_template&quot;) Then
redactionProps.addProperty(&quot;predefined_template&quot;, 128, &quot;false&quot;)
EndIf
2020-04-23 14:15:18 +02:00
exceptionHandler2:
Resume Next
2020-03-05 20:23:54 +01:00
initRedactionConfiguration = redactionProps
End Function
2020-03-21 11:55:13 +01:00
Private Sub setConfigFromDialog(dialog As Object)
2020-03-05 20:23:54 +01:00
Dim config As Object
config = initRedactionConfiguration()
2020-05-18 17:16:20 +02:00
2020-03-05 20:55:14 +01:00
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
2020-05-18 17:16:20 +02:00
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())
2020-03-05 20:55:14 +01:00
End Sub
2020-03-21 11:55:13 +01:00
Private Sub loadConfigToDialog(dialog As Object)
2020-03-05 20:55:14 +01:00
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
2020-05-18 17:16:20 +02:00
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;))
2020-03-05 20:55:14 +01:00
End Sub
Private Sub configurationDialog
Dim dialog As Object
DialogLibraries.LoadLibrary(&quot;Redaction&quot;)
dialog = CreateUnoDialog(DialogLibraries.Redaction.ConfigDialog)
2020-05-04 14:28:39 +02:00
loadConfigToDialog(dialog)
2020-05-04 16:43:15 +02:00
dialog.getControl(&quot;CB_complexity&quot;).Label = getTranslation(&quot;dialogConfigComplexity&quot;)
2020-05-18 17:16:20 +02:00
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;))
2020-05-04 16:43:15 +02:00
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;)
2020-03-05 20:55:14 +01:00
dialog.setVisible(true)
Select Case dialog.Execute()
Case 1
setConfigFromDialog(dialog)
Case 0
End Select
dialog.setVisible(false)
dialog.dispose()
Exit sub
2020-03-05 20:23:54 +01:00
End Sub
2020-04-23 14:15:18 +02:00
Dim queitCleaningDialog As Object
2020-04-23 14:15:18 +02:00
Private Sub quietStartDialog
DialogLibraries.LoadLibrary(&quot;Redaction&quot;)
queitCleaningDialog = CreateUnoDialog(DialogLibraries.Redaction.StartQuietCleaning)
2020-04-23 14:15:18 +02:00
Dim buttonNameOk As String
Dim buttonNameStop As String
Dim buttonNameLoad As String
2020-04-23 14:33:18 +02:00
Dim dialogTitle As String
2020-05-04 14:28:39 +02:00
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()
2020-04-23 14:15:18 +02:00
Case 1
queitCleaningDialog.setVisible(false)
queitCleaningDialog.dispose()
2020-04-23 14:15:18 +02:00
quietCleaning
Case 0
queitCleaningDialog.setVisible(false)
queitCleaningDialog.dispose()
2020-04-23 14:15:18 +02:00
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
2021-07-29 11:43:13 +02:00
Dim styleFileDialog As Object
Private Sub configureStyleFileDialog
2020-04-23 14:15:18 +02:00
&apos;Globalscope.BasicLibraries.LoadLibrary( &quot;MRILib&quot; )
2021-07-29 11:43:13 +02:00
Dim config As Object
2020-04-23 14:15:18 +02:00
Dim dialog As Object
2021-07-29 11:43:13 +02:00
Dim predefined As String
Dim description As String
Dim customFile As String
2020-04-23 14:15:18 +02:00
DialogLibraries.LoadLibrary(&quot;Redaction&quot;)
2021-07-29 11:43:13 +02:00
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()
2020-04-23 14:15:18 +02:00
Case 0
End Select
setQuietDialogDescription()
setAdvancedDialogDescription()
2021-07-29 11:43:13 +02:00
styleFileDialog.setVisible(false)
styleFileDialog.dispose()
2020-04-23 14:15:18 +02:00
End Sub
2021-07-29 11:43:13 +02:00
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;)
2021-07-29 11:43:13 +02:00
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
2020-04-23 14:15:18 +02:00
2021-07-29 11:43:13 +02:00
Sub setManualTemplate()
Dim description As String
2020-04-23 14:15:18 +02:00
Dim selectedTemplate As String
selectedTemplate = getFileURLDialog()
2020-04-23 14:33:18 +02:00
oSimpleFileAccess = CreateUnoService( &quot;com.sun.star.ucb.SimpleFileAccess&quot; )
If NOT (oSimpleFileAccess.exists( selectedTemplate ) AND NOT oSimpleFileAccess.isFolder( selectedTemplate ) ) Then
Exit sub
End If
2020-04-23 14:15:18 +02:00
Dim fileName As String
Dim config As Object
config = initRedactionConfiguration()
fileName = Dir(selectedTemplate)
config.setPropertyValue(&quot;defaultTemplate&quot;,fileName)
2021-07-29 11:43:13 +02:00
config.setPropertyValue(&quot;predefined_template&quot;, template_manual)
2020-04-23 14:15:18 +02:00
Dim templatePath As String
templatePath = getTemplatePath()
2021-01-14 12:09:53 +01:00
MkDir(templatePath)
2021-07-29 11:43:13 +02:00
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)
2020-04-23 14:15:18 +02:00
End Sub
2021-07-29 11:43:13 +02:00
Function getFileURLDialog() As String
2020-04-23 14:15:18 +02:00
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;
2021-07-29 11:43:13 +02:00
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)
2021-07-29 11:43:13 +02:00
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
2021-08-29 17:01:22 +02:00
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
2021-07-29 11:43:13 +02:00
Case Else
getTemplateFile = extensionPath() &amp; &quot;/templates/articles/default_article_template_ru.ott&quot;
Exit Function
End Select
End Function
</script:module>