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