0

I am trying to create a Lightroom Classic Export Service Provider plugin that has a Browse... button in the sectionsForTopOfDialog to allow the user to choose a Folder related to the plugin. The open dialog is attached to the action of the viewFactory:push_button, and the dialog opens successfully, but it seems like the rest of the push button's action is never executed, as if the runOpenPanel function never returned.

How can I create a Browse button to allow the user to select a folder and get the result? (I want to store the result in the propertyTable, this part is omitted from the code.)

Complete plugin code to reproduce the issue below. (Create a folder named runOpenDialogMCVE.lrdevplugin folder, add these files, load it as a Lightroom plugin.)

-- Info.lua

return {
    LrSdkVersion = 3.0,
    LrSdkMinimumVersion = 1.3, -- minimum SDK version required by this plugin

    LrPluginName = "RunOpenPanel MCVE",
    LrToolkitIdentifier = 'com.example.lightroom.runopenpanelmcve',
    
    LrExportServiceProvider = {
        title = "LrDialogs.runOpenPanel MCVE",
        file = 'ExportServiceProvider.lua',
    },

    VERSION = { major=0, minor=1, revision=0 },
}
-- ExportServiceProvider.lua

local LrDialogs = import 'LrDialogs'
local LrLogger = import 'LrLogger'
local LrView = import 'LrView'

local logger = LrLogger("LrDialogs.runOpenDialogMCVE")
local viewFactory = LrView.osFactory()

logger:enable("print")
local ExportServiceProvider = {}

function ExportServiceProvider.sectionsForTopOfDialog( propertyTable )
    
    return {
        {
            title = "LrDialogs.runOpenDialog MCVE",
            viewFactory:row {
                viewFactory:push_button {
                    title = "Browse...",
                    action = function ()
                        logger:trace("Opening dialog...")
                        LrDialogs.message("Will open dialog after this.")
                        local result = LrDialogs.runOpenPanel( {
                            title = "Location",
                            prompt = "Choose",
                            canChooseDirectories = true,
                            canChooseFiles = false,
                            allowsMultipleSelection = false,
                        } )
                        -- I would expect the code below to execute, but it never does.
                        -- No trace is printed and none of the dialogs below are shown.
                        logger.trace("Closing dialog. "..tostring(result))
                        if result ~= nil then
                            logger:trace("Chosen folder: "..result[1])
                            LrDialogs.message("Choseen folder: "..result[1])
                        else
                            logger:trace("Cancelled")
                            LrDialogs.message("Cancelled")
                        end
                    end,
                },
            },
        },
    }
end

return ExportServiceProvider

I'm using Lightroom version 12.0 on MacOS.

palotasb
  • 4,108
  • 3
  • 24
  • 32

0 Answers0