1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<!--*********************************************************** 4 * 5 * Licensed to the Apache Software Foundation (ASF) under one 6 * or more contributor license agreements. See the NOTICE file 7 * distributed with this work for additional information 8 * regarding copyright ownership. The ASF licenses this file 9 * to you under the Apache License, Version 2.0 (the 10 * "License"); you may not use this file except in compliance 11 * with the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, 16 * software distributed under the License is distributed on an 17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 * KIND, either express or implied. See the License for the 19 * specific language governing permissions and limitations 20 * under the License. 21 * 22 ***********************************************************--> 23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="TutorialOpen" script:language="StarBasic">REM ***** BASIC ***** 24Dim myOpenDialog As Object 25Dim oListBox As Object 26Dim files As Object 27Dim oUcb As Object 28Dim oListener As Object 29 30Sub TutorialOpenMain 31 GlobalScope.BasicLibraries.LoadLibrary("Tools") 32 myOpenDialog = LoadDialog("Tutorials","TutorialOpenDialog") 33 init() 34 myOpenDialog.Execute() 35End Sub 36 37Sub Init 38 On Local Error Goto NOFILE 39 myOpenDialog.Title = "Tutorials" 40 oListBox = myOpenDialog.GetControl("ListBox") 41 templatePath = GetPathSettings("Template",false, 0) 42 Dim tutorialPath As String 43 iPos = InStr(templatePath,"/") 44 if(iPos > 0) Then 45 tutorialPath = templatePath & "/tutorials" 46 Else 47 tutorialPath = templatePath & "\tutorials" 48 End If 49 oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess") 50 files = oUcb.getFolderContents(tutorialPath,true) 51 size = Ubound( files() ) 52 Dim tempFiles(size) As String 53 tempCount = 0 54 For iCount = 0 To size 55 completPath = files(iCount) 56 oDocInfo = CreateUnoService("com.sun.star.document.DocumentProperties") 57 oDocInfo.Read(completPath) 58 sDocTitle = oDocInfo.Title 59 if(not isNull(sDocTitle) And len(sDocTitle) > 0) Then 60 oListbox.additem(sDocTitle,0) 61 tempFiles(tempCount) = completPath 62 tempCount = tempCount + 1 63 End If 64 Next iCount 65 'printdbgInfo oListbox 66 size = oListbox.ItemCount - 1 67 Dim tempFiles2(size) As String 68 For iCount = 0 To size 69 tempFiles2(iCount) = tempFiles(iCount) 70 Next iCount 71 files() = tempFiles2() 72 Exit Sub 73 NOFILE: 74 If Err <> 0 Then 75 Msgbox "No file found error!" & CHR(13) & "Path: ...\share\template\...\tutorials\" 76 myOpenDialog.model.Open.enabled = False 77 End If 78End Sub 79 80Sub ItemSelected(oEvent) 81 On Local Error Goto NOFILE 82 completPath = files(Ubound(files()) - oEvent.Selected) 83 oTextField = myOpenDialog.GetControl("Label") 'TextField 84 oTextField.setText("") 85 Dim NoArgs() as new com.sun.star.beans.PropertyValue 86 oDocInfo = CreateUnoService("com.sun.star.document.DocumentProperties") 87 oDocInfo.Read(completPath) 88 sDocDescription = oDocInfo.Description 89 if(not isNull(sDocTitle) And len(sDocDescription) > 0) Then 90 oTextField.setText(sDocDescription) 91 Else 92 oTextField.setText("Not Description!!!.") 93 End If 94 Exit Sub 95 NOFILE: 96 If Err <> 0 Then 97 Msgbox "Open file error!" 98 End If 99End Sub 100 101Sub OpenTutorial(aEvent) 102 completPath = files(Ubound(files()) - oListBox.getSelectedItemPos()) 103 Dim Args(2) as new com.sun.star.beans.PropertyValue 104 Args(1).Name = "MacroExecutionMode" 105 Args(1).Value = com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE 106 Args(2).Name = "AsTemplate" 107 Args(2).Value = true 108 109 StarDesktop.LoadComponentFromURL(completPath,"_default",0, Args()) 110 myOpenDialog.endExecute() 111End Sub 112 113Sub Cancel(aEvent) 114 myOpenDialog.endExecute() 115End Sub 116</script:module> 117