Difference between revisions of "Documentation/DevGuide/Basic/File Control"
OOoWikiBot (Talk | contribs) m (Robot: Changing Category:Basic and Dialogs) |
|||
(4 intermediate revisions by 2 users not shown) | |||
Line 6: | Line 6: | ||
|NextPage=Documentation/DevGuide/Basic/Creating Dialogs at Runtime | |NextPage=Documentation/DevGuide/Basic/Creating Dialogs at Runtime | ||
}} | }} | ||
− | {{DISPLAYTITLE:File Control}} | + | {{Documentation/DevGuideLanguages|Documentation/DevGuide/Basic/{{SUBPAGENAME}}}} |
+ | {{DISPLAYTITLE:File Control}} | ||
The file control <idl>com.sun.star.awt.UnoControlFileControl</idl> 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 file control <idl>com.sun.star.awt.UnoControlFileControl</idl> 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. | ||
<!--[BUG641+]--> | <!--[BUG641+]--> | ||
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 <code>ConvertToURL()</code> to convert system paths to URLs. | 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 <code>ConvertToURL()</code> to convert system paths to URLs. | ||
− | + | <syntaxhighlight lang="oobas"> | |
oFileControl = oDialog.Model.FileControl1 | oFileControl = oDialog.Model.FileControl1 | ||
oFileControl.Text = "D:\Programme\Office60" | oFileControl.Text = "D:\Programme\Office60" | ||
+ | </syntaxhighlight> | ||
+ | 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 <idl>com.sun.star.ui.dialogs.FilePicker</idl> at runtime. An example is provided below. | ||
− | + | Once the dialog is open, the user may write a directory address in the text field. Then he/she clicks the button. The file dialog will display the file names in that directory, or by default in the work directory. The selected file name is stored in the text field. | |
<!--[SOURCE:BasicAndDialogs/ToolkitControls/FileDialog.xba]--> | <!--[SOURCE:BasicAndDialogs/ToolkitControls/FileDialog.xba]--> | ||
− | + | <syntaxhighlight lang="oobas"> | |
Sub OpenFileDialog() | Sub OpenFileDialog() | ||
Dim oFilePicker As Object, oSimpleFileAccess As Object | Dim oFilePicker As Object, oSimpleFileAccess As Object | ||
Line 35: | Line 38: | ||
sFileURL = ConvertToURL( oTextFieldModel.Text ) | sFileURL = ConvertToURL( oTextFieldModel.Text ) | ||
If sFileURL = "" Then | If sFileURL = "" Then | ||
− | + | oPathSettings = CreateUnoService( "com.sun.star.util.PathSettings" ) | |
− | + | sFileURL = oPathSettings.Work | |
− | sFileURL = oPathSettings. | + | |
End If | End If | ||
REM set display directory | REM set display directory | ||
Line 55: | Line 57: | ||
End If | End If | ||
End Sub | End Sub | ||
− | + | </syntaxhighlight> | |
{{PDL1}} | {{PDL1}} | ||
− | [[Category:Documentation/ | + | [[Category:Documentation/Developer's Guide/Basic and Dialogs]] |
Latest revision as of 13:05, 21 December 2020
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.
Once the dialog is open, the user may write a directory address in the text field. Then he/she clicks the button. The file dialog will display the file names in that directory, or by default in the work directory. The selected file name is stored in the text field.
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 oPathSettings = CreateUnoService( "com.sun.star.util.PathSettings" ) sFileURL = oPathSettings.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). |