1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?> 2*cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3*cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="TutorialOpen" script:language="StarBasic">REM ***** BASIC ***** 4*cdf0e10cSrcweirDim myOpenDialog As Object 5*cdf0e10cSrcweirDim oListBox As Object 6*cdf0e10cSrcweirDim files As Object 7*cdf0e10cSrcweirDim oUcb As Object 8*cdf0e10cSrcweirDim oListener As Object 9*cdf0e10cSrcweir 10*cdf0e10cSrcweirSub TutorialOpenMain 11*cdf0e10cSrcweir GlobalScope.BasicLibraries.LoadLibrary("Tools") 12*cdf0e10cSrcweir myOpenDialog = LoadDialog("Tutorials","TutorialOpenDialog") 13*cdf0e10cSrcweir init() 14*cdf0e10cSrcweir myOpenDialog.Execute() 15*cdf0e10cSrcweirEnd Sub 16*cdf0e10cSrcweir 17*cdf0e10cSrcweirSub Init 18*cdf0e10cSrcweir On Local Error Goto NOFILE 19*cdf0e10cSrcweir myOpenDialog.Title = "Tutorials" 20*cdf0e10cSrcweir oListBox = myOpenDialog.GetControl("ListBox") 21*cdf0e10cSrcweir templatePath = GetPathSettings("Template",false, 0) 22*cdf0e10cSrcweir Dim tutorialPath As String 23*cdf0e10cSrcweir iPos = InStr(templatePath,"/") 24*cdf0e10cSrcweir if(iPos > 0) Then 25*cdf0e10cSrcweir tutorialPath = templatePath & "/tutorials" 26*cdf0e10cSrcweir Else 27*cdf0e10cSrcweir tutorialPath = templatePath & "\tutorials" 28*cdf0e10cSrcweir End If 29*cdf0e10cSrcweir oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess") 30*cdf0e10cSrcweir files = oUcb.getFolderContents(tutorialPath,true) 31*cdf0e10cSrcweir size = Ubound( files() ) 32*cdf0e10cSrcweir Dim tempFiles(size) As String 33*cdf0e10cSrcweir tempCount = 0 34*cdf0e10cSrcweir For iCount = 0 To size 35*cdf0e10cSrcweir completPath = files(iCount) 36*cdf0e10cSrcweir oDocInfo = CreateUnoService("com.sun.star.document.DocumentProperties") 37*cdf0e10cSrcweir oDocInfo.Read(completPath) 38*cdf0e10cSrcweir sDocTitle = oDocInfo.Title 39*cdf0e10cSrcweir if(not isNull(sDocTitle) And len(sDocTitle) > 0) Then 40*cdf0e10cSrcweir oListbox.additem(sDocTitle,0) 41*cdf0e10cSrcweir tempFiles(tempCount) = completPath 42*cdf0e10cSrcweir tempCount = tempCount + 1 43*cdf0e10cSrcweir End If 44*cdf0e10cSrcweir Next iCount 45*cdf0e10cSrcweir 'printdbgInfo oListbox 46*cdf0e10cSrcweir size = oListbox.ItemCount - 1 47*cdf0e10cSrcweir Dim tempFiles2(size) As String 48*cdf0e10cSrcweir For iCount = 0 To size 49*cdf0e10cSrcweir tempFiles2(iCount) = tempFiles(iCount) 50*cdf0e10cSrcweir Next iCount 51*cdf0e10cSrcweir files() = tempFiles2() 52*cdf0e10cSrcweir Exit Sub 53*cdf0e10cSrcweir NOFILE: 54*cdf0e10cSrcweir If Err <> 0 Then 55*cdf0e10cSrcweir Msgbox "No file found error!" & CHR(13) & "Path: ...\share\template\...\tutorials\" 56*cdf0e10cSrcweir myOpenDialog.model.Open.enabled = False 57*cdf0e10cSrcweir End If 58*cdf0e10cSrcweirEnd Sub 59*cdf0e10cSrcweir 60*cdf0e10cSrcweirSub ItemSelected(oEvent) 61*cdf0e10cSrcweir On Local Error Goto NOFILE 62*cdf0e10cSrcweir completPath = files(Ubound(files()) - oEvent.Selected) 63*cdf0e10cSrcweir oTextField = myOpenDialog.GetControl("Label") 'TextField 64*cdf0e10cSrcweir oTextField.setText("") 65*cdf0e10cSrcweir Dim NoArgs() as new com.sun.star.beans.PropertyValue 66*cdf0e10cSrcweir oDocInfo = CreateUnoService("com.sun.star.document.DocumentProperties") 67*cdf0e10cSrcweir oDocInfo.Read(completPath) 68*cdf0e10cSrcweir sDocDescription = oDocInfo.Description 69*cdf0e10cSrcweir if(not isNull(sDocTitle) And len(sDocDescription) > 0) Then 70*cdf0e10cSrcweir oTextField.setText(sDocDescription) 71*cdf0e10cSrcweir Else 72*cdf0e10cSrcweir oTextField.setText("Not Description!!!.") 73*cdf0e10cSrcweir End If 74*cdf0e10cSrcweir Exit Sub 75*cdf0e10cSrcweir NOFILE: 76*cdf0e10cSrcweir If Err <> 0 Then 77*cdf0e10cSrcweir Msgbox "Open file error!" 78*cdf0e10cSrcweir End If 79*cdf0e10cSrcweirEnd Sub 80*cdf0e10cSrcweir 81*cdf0e10cSrcweirSub OpenTutorial(aEvent) 82*cdf0e10cSrcweir completPath = files(Ubound(files()) - oListBox.getSelectedItemPos()) 83*cdf0e10cSrcweir Dim Args(2) as new com.sun.star.beans.PropertyValue 84*cdf0e10cSrcweir Args(1).Name = "MacroExecutionMode" 85*cdf0e10cSrcweir Args(1).Value = com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE 86*cdf0e10cSrcweir Args(2).Name = "AsTemplate" 87*cdf0e10cSrcweir Args(2).Value = true 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir StarDesktop.LoadComponentFromURL(completPath,"_default",0, Args()) 90*cdf0e10cSrcweir myOpenDialog.endExecute() 91*cdf0e10cSrcweirEnd Sub 92*cdf0e10cSrcweir 93*cdf0e10cSrcweirSub Cancel(aEvent) 94*cdf0e10cSrcweir myOpenDialog.endExecute() 95*cdf0e10cSrcweirEnd Sub 96*cdf0e10cSrcweir</script:module>