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