Bug 154462 - BASIC The ScriptForge.SF_FileSystem.pickfile macro runs once and fails on a second call (gtk3/gen)
Summary: BASIC The ScriptForge.SF_FileSystem.pickfile macro runs once and fails on a s...
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.3.7.2 release
Hardware: All Linux (All)
: medium normal
Assignee: Jean-Pierre Ledure
URL:
Whiteboard: target:7.6.0 target:7.5.3
Keywords:
Depends on:
Blocks: ScriptForge
  Show dependency treegraph
 
Reported: 2023-03-29 22:19 UTC by gellid
Modified: 2024-02-08 12:22 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
error message generated by ScriptForge.SF_FileSystem.pickfile() (36.09 KB, image/png)
2023-03-29 22:19 UTC, gellid
Details

Note You need to log in before you can comment on or make changes to this bug.
Description gellid 2023-03-29 22:19:26 UTC
Created attachment 186304 [details]
error message generated by ScriptForge.SF_FileSystem.pickfile()

This code evinces the error:-

sub pickafile()
	f = ScriptForge.SF_FileSystem.pickfile()
	print(f)

End Sub
Comment 1 Xisco Faulí 2023-03-30 08:33:44 UTC
Thank you for reporting the bug. Please attach a sample document, as this makes it easier for us to verify the bug. 
I have set the bug's status to 'NEEDINFO'. Please change it back to 'UNCONFIRMED' once the requested document is provided.
(Please note that the attachment will be public, remove any sensitive information before attaching it. 
See https://wiki.documentfoundation.org/QA/FAQ#How_can_I_eliminate_confidential_data_from_a_sample_document.3F for help on how to do so.)
Comment 2 Rafael Lima 2023-03-30 17:54:55 UTC
I can reproduce this issue in "gtk3" and "gen". The first call works fine, but if you run it a second time, we get an error.

Running the macro in kf5 works fine.

If anyone else wants to test, do not forget to load the ScriptForge library first. For that, use the following:

sub pickafile()
    GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
    f = ScriptForge.SF_FileSystem.pickfile()
    print(f)
End Sub
Comment 3 gellid 2023-03-31 01:15:49 UTC
Xisco asks for a sample document. 

I tried to attach PickAFile.ods  but this message appears

"The content type ods file is invalid. Valid types must be of the form foo/bar where foo is one of application, audio, image, message, model, multipart, text, video and bar must not contain any special characters (such as "=", "?", ...)."

and I don't understand what is required to submit a sample document
Comment 4 Rafael Lima 2023-03-31 18:24:44 UTC
(In reply to gellid from comment #3)
> Xisco asks for a sample document. 

I was already able to reproduce the problem. So no need of an attachment for now.
Comment 5 Jean-Pierre Ledure 2023-04-10 10:08:20 UTC
I confirm the error under Linux Mint:
Version: 7.5.2.2 (X86_64) / LibreOffice Community
Build ID: 50(Build:2)
CPU threads: 12; OS: Linux 5.4; UI render: default; VCL: gtk3
Locale: fr-BE (fr_BE.UTF-8); UI: fr-FR
Ubuntu package version: 4:7.5.2~rc2-0ubuntu0.20.04.1~lo1
Calc: threaded

in next code:
sub pickafile()
    GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
    f = ScriptForge.SF_FileSystem.pickfile()
    print(f)
    g = ScriptForge.SF_FileSystem.pickfile()
    print(g)
End Sub

on line:
    g = ScriptForge.SF_FileSystem.pickfile()

The execution is normal under Windows:
Version: 7.5.2.2 (X86_64) / LibreOffice Community
Build ID: 53bb9681a964705cf672590721dbc85eb4d0c3a2
CPU threads: 6; OS: Windows 10.0 Build 19044; UI render: Skia/Raster; VCL: win
Locale: en-US (en_BE); UI: en-US
Calc: threaded
Comment 6 Jean-Pierre Ledure 2023-04-10 10:19:11 UTC
The root cause is:

when running next Basic code:
Sub pickafile()
	a = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
	a.appendFilter("*.*", "*.*")
	a.appendFilter("*.*", "*.*")
End Sub

the error occurs on the 2nd occurrence of line:
	a.appendFilter("*.*", "*.*")

in the same graphical environments as described above:
   gen, gtk3: error
   kf5, win: no error

The error does not happen in next code:
Sub pickafile2()
	a = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
	a.appendFilter("*.*", "*.*")
	a = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
	a.appendFilter("*.*", "*.*")
End Sub
Comment 7 Jean-Pierre Ledure 2023-04-10 10:27:46 UTC
Possible workarounds are:

(1) in the user script, insert a statement, like in next code:

sub pickafile()
    GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
    Set _SF_.FilePicker = Nothing
    f = ScriptForge.SF_FileSystem.pickfile()
    print(f)
End Sub

(2) in the sources of ScriptForge, force next re-execution where appropriate:

    ... = CreateScriptService("com.sun.star.ui.dialogs.FilePicker")

WHAT SHOULD BE DONE ?

(1) is an immediate solution to help the user
(2) does not solve the root cause but avoids error in the ScriptForge context

Please recommendation is requested here. If implementation of (2) is requested, current bug report may be assigned to myself.
Comment 8 Jean-Pierre Ledure 2023-04-11 15:05:37 UTC
Reading
https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1ui_1_1dialogs_1_1XFilterManager.html#ae6c608a77c755b24972d5d8abbddc1d4

it appears that an exception is raised on appendFilter() when a filter with the specified title already exists (even if not all contexts implement that exception).

=> The correction of the bug should be done in the ScriptForge code.
Comment 9 Commit Notification 2023-04-11 17:00:08 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/9c60996fc2a536803d016d6f60f879f8a1e49a54

ScriptForge - (SF_FileSystem) tdf#154462 2nd call of PickFile() fails

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 10 Commit Notification 2023-04-13 07:44:55 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "libreoffice-7-5":

https://git.libreoffice.org/core/commit/ffbe4d480802a351a13ec70777e68e37c3c019eb

ScriptForge (SF_FileSystem) tdf#154462 2nd call of PickFile() fails

It will be available in 7.5.3.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 11 Rafael Lima 2023-07-18 22:04:11 UTC
Fixed and verified with

Version: 24.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: a4af5432753408c4eea8a8d56c2f48202160c5fe
CPU threads: 16; OS: Linux 6.2; UI render: default; VCL: kf5 (cairo+xcb)
Locale: pt-BR (pt_BR.UTF-8); UI: en-US
Calc: CL threaded