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(&quot;Tools&quot;)
12*cdf0e10cSrcweir	myOpenDialog = LoadDialog(&quot;Tutorials&quot;,&quot;TutorialOpenDialog&quot;)
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 = &quot;Tutorials&quot;
20*cdf0e10cSrcweir		oListBox = myOpenDialog.GetControl(&quot;ListBox&quot;)
21*cdf0e10cSrcweir		templatePath = GetPathSettings(&quot;Template&quot;,false, 0)
22*cdf0e10cSrcweir		Dim tutorialPath As String
23*cdf0e10cSrcweir		iPos = InStr(templatePath,&quot;/&quot;)
24*cdf0e10cSrcweir		if(iPos &gt; 0) Then
25*cdf0e10cSrcweir			tutorialPath = templatePath &amp; &quot;/tutorials&quot;
26*cdf0e10cSrcweir		Else
27*cdf0e10cSrcweir			tutorialPath = templatePath &amp; &quot;\tutorials&quot;
28*cdf0e10cSrcweir		End If
29*cdf0e10cSrcweir		oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
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(&quot;com.sun.star.document.DocumentProperties&quot;)
37*cdf0e10cSrcweir			oDocInfo.Read(completPath)
38*cdf0e10cSrcweir			sDocTitle = oDocInfo.Title
39*cdf0e10cSrcweir			if(not isNull(sDocTitle) And len(sDocTitle) &gt; 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		&apos;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 &lt;&gt; 0 Then
55*cdf0e10cSrcweir		Msgbox &quot;No file found error!&quot; &amp; CHR(13) &amp; &quot;Path: ...\share\template\...\tutorials\&quot;
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(&quot;Label&quot;) &apos;TextField
64*cdf0e10cSrcweir		oTextField.setText(&quot;&quot;)
65*cdf0e10cSrcweir		Dim NoArgs() as new com.sun.star.beans.PropertyValue
66*cdf0e10cSrcweir		oDocInfo = CreateUnoService(&quot;com.sun.star.document.DocumentProperties&quot;)
67*cdf0e10cSrcweir		oDocInfo.Read(completPath)
68*cdf0e10cSrcweir		sDocDescription = oDocInfo.Description
69*cdf0e10cSrcweir		if(not isNull(sDocTitle) And len(sDocDescription) &gt; 0) Then
70*cdf0e10cSrcweir			oTextField.setText(sDocDescription)
71*cdf0e10cSrcweir		Else
72*cdf0e10cSrcweir			oTextField.setText(&quot;Not Description!!!.&quot;)
73*cdf0e10cSrcweir		End If
74*cdf0e10cSrcweir	Exit Sub
75*cdf0e10cSrcweir	NOFILE:
76*cdf0e10cSrcweir	If Err &lt;&gt; 0 Then
77*cdf0e10cSrcweir		Msgbox &quot;Open file error!&quot;
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 = &quot;MacroExecutionMode&quot;
85*cdf0e10cSrcweir	Args(1).Value = com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE
86*cdf0e10cSrcweir	Args(2).Name = &quot;AsTemplate&quot;
87*cdf0e10cSrcweir	Args(2).Value = true
88*cdf0e10cSrcweir
89*cdf0e10cSrcweir	StarDesktop.LoadComponentFromURL(completPath,&quot;_default&quot;,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>