1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
<?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="Config_Dlg" script:language="StarBasic">Option Explicit
Private oDlgConfig As Object
Sub ApplyConfig
' Set the configuration variables...
sLilyPondExecutable = oDlgConfig.getControl("LilyPondExecutable").getText()
sTemplatePath = AddSlash(ConvertToURL(oDlgConfig.getControl("TemplatePath").getText()))
sFormat = oDlgConfig.getControl("Format").getText()
iGraphicDPI = oDlgConfig.getControl("GraphicDPI").getValue()
sWriterTemplate = oDlgConfig.getControl("WriterTemplate").getText()
sImageMagicExecutable = oDlgConfig.getControl("ImageMagicExecutable").getText()
if oDlgConfig.getControl("WriterAnchorAsCharacter").getState() then iWriterAnchor = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
if oDlgConfig.getControl("WriterAnchorToParagraph").getState() then iWriterAnchor = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
if oDlgConfig.getControl("WriterAnchorToPage").getState() then iWriterAnchor = com.sun.star.text.TextContentAnchorType.AT_PAGE
if oDlgConfig.getControl("WriterNoWrap").getState() then iWriterWrap = com.sun.star.text.WrapTextMode.NONE
if oDlgConfig.getControl("WriterOptimalPageWrap").getState() then iWriterWrap = com.sun.star.text.WrapTextMode.DYNAMIC
if oDlgConfig.getControl("WriterWrapThrough").getState() then iWriterWrap = com.sun.star.text.WrapTextMode.THROUGHT
sImpressTemplate = oDlgConfig.getControl("ImpressTemplate").getText()
End Sub
' Hejsan hoppsan
' Lingonskog...
Sub ConfigDialog( )
' Load the library OOoLilyPond...
DialogLibraries.LoadLibrary( "OOoLilyPond" )
' Create the dialog object
oDlgConfig = createUnoDialog( DialogLibraries.GetByName("OOoLilyPond").GetByName("Config_GUI") )
'Set the contents of the combo box only one time, thus not in SetDialogConfigValues
oDlgConfig.getControl("Format").addItems(Array("png","eps"),0)
ListOfTemplates(oDlgConfig.getControl("WriterTemplate"), True)
ListOfTemplates(oDlgConfig.getControl("ImpressTemplate"), True)
SetDialogConfigValues()
' Display the dialog.
' This routine call does not return until the dialog is dismissed.
oDlgConfig.Execute()
End Sub
Sub DefaultConfig()
sOSType=GetOSType()
If sOSType="Unix" Then
sConfigFile = ConvertToURL(Environ("HOME")) & "/.ooolilypond"
sTmpPath = ConvertToURL(Environ("HOME")) & "/.ooolilypond-tmp/"
If Not FileExists(ConvertFromURL(sTmpPath)) Then MkDir(ConvertFromURL(sTmpPath))
' LilyPond Executable (not an URL)
sLilyPondExecutable = "lilypond"
sTemplatePath = ConvertToURL(Environ("HOME")) & "/OOoLilyPond/templates/2.10/"
Else
'Operating System is Windows
sConfigFile = ConvertToURL(Environ("APPDATA")) & "/ooolilypond"
' The following tmp path usually contains spaces and does not work with OOo 2.0
' for calling batch files:
sTmpPath = ConvertToURL(Environ("temp")) & "/"
' For OOo 2.0 the following path works when the user has administrative rights
' sTmpPath = ConvertToURL(Environ("SystemRoot")) & "/Temp/"
sLilyPondExecutable = Environ("ProgramFiles") & "\LilyPond\usr\bin\lilypond.exe"
sTemplatePath = ConvertToURL(Environ("ProgramFiles") & "/OOoLilyPond/templates/2.10/")
End If
sWriterTemplate = "a4"
sImpressTemplate = "a4_big"
iWriterAnchor = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
iWriterWrap = com.sun.star.text.WrapTextMode.NONE
sFormat = "png"
iGraphicDPI = 300
End sub
Sub DefaultConfigButton_Clicked()
' load default configuration...
DefaultConfig()
SetDialogConfigValues()
End Sub
Sub ReadConfigFile()
'MsgBox("ReadConfigFile")
Dim iNumber As Integer
Dim sLine,sArguments(2) As String
iNumber = Freefile
Open sConfigFile For Input As iNumber
While not eof(iNumber)
Line Input #iNumber, sLine
if sLine <> "" then
sArguments() = Split(sLine,"=")
Select Case sArguments(0)
Case "LilyPondExecutable"
sLilyPondExecutable = sArguments(1)
Case "ImageMagicExecutable"
sImageMagicExecutable = sArguments(1)
Case "TemplatePath"
sTemplatePath = AddSlash(ConvertToURL(sArguments(1)))
Case "GraphicDPI"
iGraphicDPI = sArguments(1)
Case "FileFormat"
sFormat = sArguments(1)
Case "WriterTemplate"
sWriterTemplate = sArguments(1)
Case "WriterAnchor"
iWriterAnchor = CInt(sArguments(1))
Case "WriterWrap"
iWriterWrap = CInt(sArguments(1))
Case "ImpressTemplate"
sImpressTemplate = sArguments(1)
End Select
end if
wend
Close #iNumber
End Sub
Sub SaveConfig
'MsgBox("SaveConfig")
'MsgBox(sImageMagicExecutable)
Dim oFileAccess, oTextStream As Object
' Open service file and an output stream...
oFileAccess = createUnoService("com.sun.star.ucb.SimpleFileAccess")
oTextStream = createUnoService("com.sun.star.io.TextOutputStream")
' Save the general options
If oFileAccess.exists( sConfigFile ) Then oFileAccess.kill( sConfigFile )
oTextStream.setOutputStream(oFileAccess.openFileWrite(sConfigFile))
oTextStream.writeString("*** Configuration file of OOoLilyPond ***" & chr(10) )
oTextStream.writeString("LilyPondExecutable=" & ConvertFromURL(sLilyPondExecutable)& chr(10) )
oTextStream.writeString("ImageMagicExecutable=" & ConvertFromURL(sImageMagicExecutable)& chr(10) )
oTextStream.writeString("TemplatePath=" & ConvertFromURL(sTemplatePath)& chr(10) )
oTextStream.writeString("GraphicDPI=" & iGraphicDPI & chr(10))
oTextStream.writeString("FileFormat=" & sFormat & chr(10))
oTextStream.writeString("WriterTemplate=" & sWriterTemplate & chr(10))
oTextStream.writeString("WriterAnchor=" & CStr(iWriterAnchor) & chr(10))
oTextStream.writeString("WriterWrap=" & CStr(iWriterWrap) & chr(10))
oTextStream.writeString("ImpressTemplate=" & sImpressTemplate & chr(10))
oTextStream.closeOutput()
End Sub
Sub SaveConfigButton_Clicked
Dim sCommand As String
'Read the values from the form
ApplyConfig()
'Check wheter LilyPond can be executed and get version
CleanUp()
If sOSType = "Unix" Then
'sCommand="cd " & Chr(34) & ConvertFromURL(sTmpPath) & Chr(34) & "; " _
'& Chr(34) & sLilyPondExecutable & Chr(34) & " --version >LilyPond-version.out || touch LilyPond-cannot_execute"
'BashCommand(sCommand)
ElseIf sOSType = "Windows" Then
'sCommand="cd /d " & Chr(34) & ConvertFromURL(sTmpPath) & Chr(34) & Chr(10) _
'& Chr(34) & sLilyPondExecutable & Chr(34) & " --version >LilyPond-version.out" & Chr(10) _
'& "if errorlevel 9009 echo cannot execute >LilyPond-cannot_execute" 'ToDo: 9009 OK? Other errors? Wrong Permissions?
'WindowsCommand(sCommand)
End If
If FileExists(ConvertFromURL(sTmpPath) & "LilyPond-cannot_execute") then
MsgBox "LilyPond cannot be executed." & Chr(10) _
& "Check the path specified for the lilypond executable in the configuration dialog," & Chr(10) _
& "your LilyPond installation and permissions."
EndIf
'ToDo: evaluate LilyPond version
'Save the values to file and close dialog
SaveConfig()
oDlgConfig.endExecute()
End Sub
Sub SetDialogConfigValues()
' System...
oDlgConfig.getControl("TemplatePath").setText(ConvertFromURL(sTemplatePath))
oDlgConfig.getControl("LilyPondExecutable").setText(ConvertFromURL(sLilyPondExecutable))
oDlgConfig.getControl("ImageMagicExecutable").setText(ConvertFromURL(sImageMagicExecutable))
' Image...
oDlgConfig.getControl("Format").setText(sFormat)
oDlgConfig.getControl("GraphicDPI").setValue(iGraphicDPI)
' Writer configuration
oDlgConfig.getControl("WriterTemplate").setText(sWriterTemplate)
If iWriterAnchor = com.sun.star.text.TextContentAnchorType.AS_CHARACTER Then oDlgConfig.getControl("WriterAnchorAsCharacter").setState(true)
If iWriterAnchor = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH Then oDlgConfig.getControl("WriterAnchorToParagraph").setState(true)
If iWriterAnchor = com.sun.star.text.TextContentAnchorType.AT_PAGE Then oDlgConfig.getControl("WriterAnchorToPage").setState(true)
If iWriterWrap = com.sun.star.text.WrapTextMode.NONE Then oDlgConfig.getControl("WriterNoWrap").setState(true)
If iWriterWrap = com.sun.star.text.WrapTextMode.DYNAMIC Then oDlgConfig.getControl("WriterOptimalPageWrap").setState(true)
If iWriterWrap = com.sun.star.text.WrapTextMode.THROUGHT Then oDlgConfig.getControl("WriterWrapThrough").setState(true)
' Impress configuration
oDlgConfig.getControl("ImpressTemplate").setText(sImpressTemplate)
End Sub
</script:module>
|