Clicking 'Open' button without selecting a file, there is no problem for the dialog remains unchanged.
But clicking 'Close' button or 'Cancel' button, there is an error.
What is the way to handle these 2 button?
[Solved] Clicking Close or Cancel on dialogs.FilePicker
[Solved] Clicking Close or Cancel on dialogs.FilePicker
Last edited by oonk on Sun Nov 03, 2019 2:14 am, edited 1 time in total.
| Fedora 31 Workstation Cinnamon of Fedora from Spins | LibreOffice 6.2.8.2-2 | Base with embedded Firebird |
Re: Event of clicking Close or Cancel on dialogs.FilePicker
Please upload a real ODF type document file (together the embedded macro code) here, instead of the pictures.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: Event of clicking Close or Cancel on dialogs.FilePicker
Your variable s is declared as string. Declare it as variant and test which type of value is assigned to that variable.
https://api.libreoffice.org/docs/idl/re ... d93556a60d
P.P.S.
With LO I would get a single selected file like this
or like this:
If the code needs to be compatible with AOO, you can use the deprecated getFiles() in the exact same ways as long as LO supports this method and as long as you don't need the result of a multiple file selection. In this case AOO returns one element more than the selected files. First element is the path URL, subsequent elements are the file names without path.
Edit: getFiles is deprecated. For now it returns an empty array or an array with one string element. |
P.P.S.
With LO I would get a single selected file like this
Code: Select all
x = oDialog.execute()
if x = 0 then
REM Cancel
else
s = oDialog.getSelectedFiles()(0)
endif
Code: Select all
oDialog.execute()
a() = oDialog.getSelectedFiles()
if uBound(a())=-1 then
REM Cancel
elseif uBound(a())=0 then
s = a(0)
else
REM multi-selection
endif
Last edited by Villeroy on Sat Nov 02, 2019 12:06 pm, edited 1 time in total.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Event of clicking Close or Cancel on dialogs.FilePicker
This works for me in LibO and in AOO 4.1.5 as well:
See also https://xkcd.com/2116/
Code: Select all
Function pickedCsvUrl()
pickedCsvUrl = ""
filePicker = createUnoService("com.sun.star.ui.dialogs.FilePicker")
With filePicker
.MultiSelectionMode = False
.AppendFilter("CSV files (.csv)", "*.csv")
returned = .Execute
If returned=1 Then
pickedUrl = .Files(0)
splitUrl = Split(pickedUrl, ".")
u = Ubound(splitUrl)
extension = splitUrl(u)
If extension="csv" Then pickedCsvUrl = url
End If
End With
End Function
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München
Re: Event of clicking Close or Cancel on dialogs.FilePicker
c.s.s.ui.dialogs.FilePicker supports all the options that are availlable in the complex file picker that appears when you hit Ctrl+O, i.e. extra check boxes and grouped file type filters.
This is a simplified file picker for one file with a simple pattern filter:
Takes the window title, the start path, the displayed filter name and one or more file name patterns separated by semicolon.
It is compatible with both office suites as long as LibreOffice supports getFiles(). With LO only you should use the new method getSelectedFiles().
Example call:
Window title: TEST
If the init path is "", the picker starts in the default document directory.
Name of file type: "Blah Text"
Displayed files: *.txt and *.csv
This is a simplified file picker for one file with a simple pattern filter:
Code: Select all
Function pickFile(sTitle$, sInit$, sFilterLabel$, sPattern$)
REM dialog starts at office default directory if sInit = ""
Dim oPicker, x()
oPicker = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
oPicker.setTitle(sTitle)
oPicker.setDisplayDirectory(sInit)
oPicker.setMultiSelectionMode(False)
oPicker.appendFilter(sFilterLabel, sPattern)
if oPicker.execute()<>0 then
x = oPicker.getFiles()
pickFile = x(0)
endif
End Function
It is compatible with both office suites as long as LibreOffice supports getFiles(). With LO only you should use the new method getSelectedFiles().
Example call:
Code: Select all
f = pickFile("TEST", "", "Blah Text", "*.txt;*.csv"
If the init path is "", the picker starts in the default document directory.
Name of file type: "Blah Text"
Displayed files: *.txt and *.csv
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice