1<?xml version="1.0" encoding="UTF-8"?>
2<!--***********************************************************
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements.  See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership.  The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License.  You may obtain a copy of the License at
11 *
12 *   http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied.  See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 *
21 ***********************************************************-->
22<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="FileDialog" script:language="StarBasic">REM  *****  BASIC  *****
24
25Dim oDialog As Object
26
27Sub Main()
28
29	Dim oLibContainer As Object, oLib As Object
30	Dim oInputStreamProvider As Object
31
32	Const sLibName = &quot;ToolkitControls&quot;
33	Const sDialogName = &quot;FileDialogDlg&quot;
34
35	REM load/get library and input stream provider
36	oLibContainer = DialogLibraries
37	oLibContainer.loadLibrary( sLibName )
38	oLib = oLibContainer.getByName( sLibName )
39	oInputStreamProvider = oLib.getByName( sDialogName )
40
41	REM create dialog control
42	oDialog = CreateUnoDialog( oInputStreamProvider )
43
44	REM show the dialog
45	oDialog.execute()
46
47End Sub
48
49Sub OpenFileDialog()
50
51	Dim oFilePicker As Object, oSimpleFileAccess As Object
52	Dim oPathSettings As Object
53	Dim oTextField As Object, oTextFieldModel As Object
54	Dim sFileURL As String
55	Dim sFiles As Variant
56
57	REM file dialog
58	oFilePicker = CreateUnoService( &quot;com.sun.star.ui.dialogs.FilePicker&quot; )
59
60	REM set filter
61	oFilePicker.AppendFilter( &quot;All files (*.*)&quot;, &quot;*.*&quot; )
62	oFilePicker.AppendFilter( &quot;StarOffice 6.0 Text Text Document&quot;, &quot;*.sxw&quot; )
63	oFilePicker.AppendFilter( &quot;StarOffice 6.0 Spreadsheet&quot;, &quot;*.sxc&quot; )
64	oFilePicker.SetCurrentFilter( &quot;All files (*.*)&quot; )
65
66	REM if no file URL is set, get path settings from configuration
67	oTextFieldModel = oDialog.Model.TextField1
68	sFileURL = ConvertToURL( oTextFieldModel.Text )
69	If sFileURL = &quot;&quot; Then
70		oSettings = CreateUnoService( &quot;com.sun.star.frame.Settings&quot; )
71		oPathSettings = CreateUnoService( &quot;com.sun.star.util.PathSettings&quot; )
72	 	sFileURL = oPathSettings.getPropertyValue( &quot;Work&quot; )
73	End If
74
75	REM set display directory
76	oSimpleFileAccess = CreateUnoService( &quot;com.sun.star.ucb.SimpleFileAccess&quot; )
77	If oSimpleFileAccess.exists( sFileURL ) And oSimpleFileAccess.isFolder( sFileURL ) Then
78		oFilePicker.setDisplayDirectory( sFileURL )
79	End If
80
81	REM execute file dialog
82	If oFilePicker.execute() Then
83		sFiles = oFilePicker.getFiles()
84		sFileURL = sFiles(0)
85		If oSimpleFileAccess.exists( sFileURL ) Then
86			REM set file path in text field
87			oTextField = oDialog.GetControl(&quot;TextField1&quot;)
88			oTextField.SetText( ConvertFromURL( sFileURL ) )
89		End If
90	End If
91
92End Sub
93</script:module>