Difference between revisions of "Documentation/DevGuide/Basic/File Control"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (1 revision(s))
m (Robot: Changing Category:Basic and Dialogs)
Line 57: Line 57:
[[Category: Basic and Dialogs]]
[[Category:Documentation/Developers Guide/Basic and Dialogs]]

Revision as of 12:09, 4 June 2008

The file control com.sun.star.awt.UnoControlFileControl has all the properties of a text field control, with the additional feature of a built-in command button. When the button is clicked, the file dialog shows up. The directory that the file dialog initially displays is set by the Text property.

The directory must be given as a system path, file URLs do not work at the moment. In Basic you can use the runtime function ConvertToURL() to convert system paths to URLs.

 oFileControl = oDialog.Model.FileControl1
 oFileControl.Text = "D:\Programme\Office60"

Filters for the file dialog can not be set or appended for the file control. An alternative way is to use a text field and a command button instead of a file control and assign a macro to the button which instantiates the file dialog com.sun.star.ui.dialogs.FilePicker at runtime. An example is provided below.

 Sub OpenFileDialog()
     Dim oFilePicker As Object, oSimpleFileAccess As Object
     Dim oSettings As Object, oPathSettings As Object
     Dim oTextField As Object, oTextFieldModel As Object
     Dim sFileURL As String
     Dim sFiles As Variant
     REM file dialog
     oFilePicker = CreateUnoService( "com.sun.star.ui.dialogs.FilePicker" )
     REM set filter
     oFilePicker.AppendFilter( "All files (*.*)", "*.*" )
     oFilePicker.AppendFilter( "StarOffice 6.0 Text Text Document", "*.sxw" )
     oFilePicker.AppendFilter( "StarOffice 6.0 Spreadsheet", "*.sxc" )
     oFilePicker.SetCurrentFilter( "All files (*.*)" )
     REM if no file URL is set, get path settings from configuration
     oTextFieldModel = oDialog.Model.TextField1
     sFileURL = ConvertToURL( oTextFieldModel.Text )
     If sFileURL = "" Then
         oSettings = CreateUnoService( "com.sun.star.frame.Settings" )
         oPathSettings = oSettings.getByName( "PathSettings" )
         sFileURL = oPathSettings.getPropertyValue( "Work" )
     End If
     REM set display directory
     oSimpleFileAccess = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" )
     If oSimpleFileAccess.exists( sFileURL ) And oSimpleFileAccess.isFolder( sFileURL ) Then
         oFilePicker.setDisplayDirectory( sFileURL )
     End If
     REM execute file dialog
     If oFilePicker.execute() Then
         sFiles = oFilePicker.getFiles()
         sFileURL = sFiles(0)
         If oSimpleFileAccess.exists( sFileURL ) Then
             REM set file path in text field
             oTextField = oDialog.GetControl("TextField1")
             oTextField.SetText( ConvertFromURL( sFileURL ) )
         End If
     End If
 End Sub
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools