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