Bug 161946 - ScriptForge's CreateMenu method does not accept integer value for the Before argument
Summary: ScriptForge's CreateMenu method does not accept integer value for the Before ...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
24.2.4.2 release
Hardware: All All
: medium normal
Assignee: Jean-Pierre Ledure
URL:
Whiteboard: target:25.2.0 target:24.8.0.2 target:...
Keywords:
Depends on:
Blocks: ScriptForge
  Show dependency treegraph
 
Reported: 2024-07-08 08:56 UTC by Jerzy Moruś
Modified: 2024-07-10 09:52 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
Error reported by CreateMenu (27.66 KB, image/jpeg)
2024-07-08 08:56 UTC, Jerzy Moruś
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jerzy Moruś 2024-07-08 08:56:54 UTC
Created attachment 195160 [details]
Error reported by CreateMenu

The issue involves the Document service's CreateMenu method and the "before" parameter.
As described in the help:
before: The name (as a string) or position (as an integer starting at 1) of an existing menu before which the new menu will be placed. If no value is defined for this argument, the menu will be created at the last position in the menu bar.

Well, inserting an integer generates an execution error as in the attached image.
Form of this parameter is important when the macro is to be executed in different language versions of the installed LibreOffice application.
Comment 1 Rafael Lima 2024-07-08 11:22:31 UTC
Can you provide a sample code where the bug happens?
Comment 2 Rafael Lima 2024-07-08 11:34:37 UTC
Indeed, the following macro results in the reported error message:

Sub MenuMacro
    GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
    oDoc = CreateScriptService("Document", ThisComponent)
    oMenu = oDoc.CreateMenu("My Menu", Before := 3)
    With oMenu
        oMenu.AddItem("Item A")
        oMenu.AddItem("Item B")
    End With
End Sub

As per documentation, it should work. Changing the CreateMenu call to:

oMenu = oDoc.CreateMenu("My Menu", Before := "Insert")

Makes it work.

@JPL what is your opinion?
Comment 3 Jean-Pierre Ledure 2024-07-08 13:41:24 UTC
I confirm the bug.

The validity check of the Before argument is too strict.
Line 573 in the SF_Document module (library SFDocuments)

   If Not ScriptForge.SF_Utils._Validate(Before, "Before", V_STRING) Then GoTo Finally

must contain:

   If Not ScriptForge.SF_Utils._Validate(Before, "Before", Array(V_STRING, ScriptForge.V_NUMERIC)) Then GoTo Finally

I will prepare a patch.

NB: a manual change in the Basic install file can be a temporary workaround.

Thanks for reporting the bug.
Comment 4 Commit Notification 2024-07-09 13:57:17 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "master":

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

ScriptForge (Document) tdf#161946 Fix CreateMenu() / Before

It will be available in 25.2.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 5 Commit Notification 2024-07-09 16:00:38 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "libreoffice-24-8":

https://git.libreoffice.org/core/commit/42e3bb7cde89db579d5a42a18b7a7a93c6aad059

ScriptForge (Document) tdf#161946 Fix CreateMenu() / Before

It will be available in 24.8.0.2.

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 6 Commit Notification 2024-07-09 20:28:11 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "libreoffice-24-2":

https://git.libreoffice.org/core/commit/161a6e1b2f946ee8f756874d240da738668ccbba

ScriptForge (Document) tdf#161946 Fix CreateMenu() / Before

It will be available in 24.2.6.

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 7 Commit Notification 2024-07-10 09:52:09 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "libreoffice-24-2-5":

https://git.libreoffice.org/core/commit/647e35f54a9c41d6840bf191fcc97de56c6578a8

ScriptForge (Document) tdf#161946 Fix CreateMenu() / Before

It will be available in 24.2.5.

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.