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