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