Thread

Index > Scribe > Scripting API changes.
Author/Date Scripting API changes.
fret
18/03/2023 1:47pm
So with the event of the Haiku branch being merged back in. There is no valid way of doing dialogs without having a callback. This affects the API of scripting functions that open dialogs and return values to the calling script. No longer can the dialog wait and then return the value in the normal way. It must use a callback function.

The functions affected are: GetInputDlg, SelectFiles and SelectFolder.

In rewriting this I used the following script to test each function and make sure it works correctly. This also forms a nice tutorial on how to use the new API:

////////////////////////////////////////////////////////////////////////////////
function OnGetInputDlgResult(str)
{
    Print("OnGetInputDlgResult=" + str + "\n");
}

function TestGetInputDlg(App, Thing, CallbackId)
{
    GetInputDlg(App, "init", "Enter a string:", "TestGetInputDlg", false, "OnGetInputDlgResult");
}

////////////////////////////////////////////////////////////////////////////////
function OnSelectFiles(files)
{
    Print("Files: ", files, "\n");
}

function TestSelectFiles(App, Thing, CallbackId)
{
    SelectFiles(App, "OnSelectFiles", "*.png", "C:\\Users\\matthew\\Desktop", 1);
}

////////////////////////////////////////////////////////////////////////////////
function OnSelectFolder(path)
{
    Print("OnSelectFolder: ", path, "\n");
}

function TestSelectFolder(App, Thing, CallbackId)
{
    SelectFolder(App, "OnSelectFolder", "*.png", "C:\\Users\\matthew\\Desktop", 1);
}

////////////////////////////////////////////////////////////////////////////////
function OnMenu(Application, Thing, Menu)
{
    MenuAddItem(Menu, -1, "Test GetInputDlg",  -1, "TestGetInputDlg", 55);
    MenuAddItem(Menu, -1, "Test SelectFiles",  -1, "TestSelectFiles", 56);
    MenuAddItem(Menu, -1, "Test SelectFolder", -1, "TestSelectFolder", 57);
}

function Main(App)
{
    if (!AddCallback("OnThingContextMenu", "OnMenu"))
        MsgBox(App, "Couldn't add hook for OnMenu");
    return 1;
}


I've updated the help files to match. Please rewrite any scripts that use these methods when installing v3.2.
fret
18/03/2023 2:14pm
I've also added a nice script exception if the scripting callback is not found. It'll pull up the debugger at the line referring to the missing callback.

Even thought the original LVirtualMachine object is long gone. It saves it's state in a context object and then restores it later in a new instance of the VM.
Reply