[JW Lua] Modeless dialog implementation

Robert Patterson robert at robertgpatterson.com
Sat Nov 27 15:41:57 CET 2021


I am interested in comments on a proposed implementation of modeless
dialogs for lua scripts. A modeless dialog means that the plugin for
Finale-embedded Lua (RGP Lua in this case) has to exit back to Finale
leaving the Lua state intact and runnable. This implies the following
requirements.

1. The script has to manage its own Undo blocks.
2. The script has to be able to notify the RGP Lua plugin when it
terminates.
3. All useful processing has to be done by callbacks to lua functions in
the script.

To this end I am proposing the following enhancements to the RGP Lua
scripting environment.

1. Add finaleplugin.HandlesUndo = true to notify RGP Lua that a script will
manage its own undo block(s).
2. Add finenv.RegisterModelessDialog(customluawindow) to allow a script to
register one (and only one) FCCustomLuaWindow instance with RGP Lua as a
modeless dialog window. When this window closes, RGP Lua terminates the Lua
state for the script.
3. Add finenv.EndUndoBlock(success) to allow a script to end the current
undo block without starting another.
4. Add ShowModeless() method to FCCustomLuaWindow. If you have registered
the instance, it opens the window modelessly and returns true. If you have
not registered it, the method returns false and does nothing.

Here is a brief Hello World example. This example is currently working in
my dev environment. I am polling this list to find out if anyone can think
of anything else that we need.

function plugindef()
    finaleplugin.IsModeless = true
end

-- scratch FCString
local str = finale.FCString()
-- create a new dialog
local dialog = finale.FCCustomLuaWindow()
-- add a button to say "Hello World"
local helloWorldButton = dialog:CreateButton(0, 0)
str.LuaString = "Hello World"
helloWorldButton:SetWidth(100)
helloWorldButton:SetText(str)
dialog:RegisterHandleControlEvent (
    helloWorldButton,
    function(control)
        -- if this modifies the Finale document, call
finenv.StartNewUndoBlock("My Undo Text")
        finenv.UI():AlertInfo("Hello World", "")
        -- if updates were successful, call finenv.EndUndoBlock(true)
        -- if updates were not successful, call finenv.EndUndoBlock(false)
    end
)
dialog:CreateOkButton()
finenv.RegisterModelessDialog(dialog) -- must register, or ShowModeless
does nothing
dialog:ShowModeless()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20211127/33767dba/attachment.html>


More information about the JWLua mailing list