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(&quot;Tools&quot;)
32	myOpenDialog = LoadDialog(&quot;Tutorials&quot;,&quot;TutorialOpenDialog&quot;)
33	init()
34	myOpenDialog.Execute()
35End Sub
36
37Sub Init
38	On Local Error Goto NOFILE
39		myOpenDialog.Title = &quot;Tutorials&quot;
40		oListBox = myOpenDialog.GetControl(&quot;ListBox&quot;)
41		templatePath = GetPathSettings(&quot;Template&quot;,false, 0)
42		Dim tutorialPath As String
43		iPos = InStr(templatePath,&quot;/&quot;)
44		if(iPos &gt; 0) Then
45			tutorialPath = templatePath &amp; &quot;/tutorials&quot;
46		Else
47			tutorialPath = templatePath &amp; &quot;\tutorials&quot;
48		End If
49		oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
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(&quot;com.sun.star.document.DocumentProperties&quot;)
57			oDocInfo.Read(completPath)
58			sDocTitle = oDocInfo.Title
59			if(not isNull(sDocTitle) And len(sDocTitle) &gt; 0) Then
60				oListbox.additem(sDocTitle,0)
61				tempFiles(tempCount) = completPath
62				tempCount = tempCount + 1
63			End If
64		Next iCount
65		&apos;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 &lt;&gt; 0 Then
75		Msgbox &quot;No file found error!&quot; &amp; CHR(13) &amp; &quot;Path: ...\share\template\...\tutorials\&quot;
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(&quot;Label&quot;) &apos;TextField
84		oTextField.setText(&quot;&quot;)
85		Dim NoArgs() as new com.sun.star.beans.PropertyValue
86		oDocInfo = CreateUnoService(&quot;com.sun.star.document.DocumentProperties&quot;)
87		oDocInfo.Read(completPath)
88		sDocDescription = oDocInfo.Description
89		if(not isNull(sDocTitle) And len(sDocDescription) &gt; 0) Then
90			oTextField.setText(sDocDescription)
91		Else
92			oTextField.setText(&quot;Not Description!!!.&quot;)
93		End If
94	Exit Sub
95	NOFILE:
96	If Err &lt;&gt; 0 Then
97		Msgbox &quot;Open file error!&quot;
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 = &quot;MacroExecutionMode&quot;
105	Args(1).Value = com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE
106	Args(2).Name = &quot;AsTemplate&quot;
107	Args(2).Value = true
108
109	StarDesktop.LoadComponentFromURL(completPath,&quot;_default&quot;,0, Args())
110	myOpenDialog.endExecute()
111End Sub
112
113Sub Cancel(aEvent)
114	myOpenDialog.endExecute()
115End Sub
116</script:module>
117