Skip to main content
Inspiring
February 26, 2025
Answered

SDK LrDialogs.presentModalDialog with table: how to add a new row

  • February 26, 2025
  • 1 reply
  • 653 views

I managed to display a table with rows and column using the LrDialogs.presentModalDialog.

All the values from the orginal table I converted to a flat property table.

 

propertyTable = LrBinding.makePropertyTable(context)

 

 

Before adding the new row I display the table. This works fine
Ofcourse variable "c" contains all groups, rows and columns.

 

 

dialogValue = LrDialogs.presentModalDialog(
	{
		title = "My table",
		contents = c,
	}

 

 

Having my original table and a flattened projection of it as property table, below the table rows I added a button.

The button calls a function which performs the steps below:

  1. Adding a row to my original table
  2. Updating the property table with these new values
  3. Added a row to the contents in variable "c"
  4. After these steps I tried to stop and show the dialog again, however that doesn't work.

 

LrDialogs.stopModalWithResult(dialogValue)

dialogValue = LrDialogs.presentModalDialog(
	{
		title = LOC "$$$/LightroomStatistics/Dialogs/Translations=Translations",
		contents = c,
	}
)

 

Question

How can I redraw / redisplay  the modal form.

Correct answer johnrellis

Here's an example of how to change the controls displayed dynamically (see the attached screen recording):

 

local LrDialogs = import "LrDialogs"
local LrView = import "LrView"
local f = LrView.osFactory ()

local nRows = 1
while true do 
    local rows = {spacing = f:control_spacing ()}
    for i = 1, nRows do 
        table.insert (rows, f:static_text {title = "Row " .. i})
        end

    table.insert (rows, f:push_button {title = "Add row", 
        action = function (button) 
            nRows = nRows + 1
            LrDialogs.stopModalWithResult (button, "refresh")
            end})

    local result = LrDialogs.presentModalDialog {title = "Test", 
        contents = f:column (rows)}
    if result ~= "refresh" then break end 
    end

 

1 reply

johnrellis
johnrellisCorrect answer
Legend
February 28, 2025

Here's an example of how to change the controls displayed dynamically (see the attached screen recording):

 

local LrDialogs = import "LrDialogs"
local LrView = import "LrView"
local f = LrView.osFactory ()

local nRows = 1
while true do 
    local rows = {spacing = f:control_spacing ()}
    for i = 1, nRows do 
        table.insert (rows, f:static_text {title = "Row " .. i})
        end

    table.insert (rows, f:push_button {title = "Add row", 
        action = function (button) 
            nRows = nRows + 1
            LrDialogs.stopModalWithResult (button, "refresh")
            end})

    local result = LrDialogs.presentModalDialog {title = "Test", 
        contents = f:column (rows)}
    if result ~= "refresh" then break end 
    end

 

Inspiring
March 1, 2025

This works great, you put me on track again.

 

Since I work with scrolled_view, I modified the code a little and now works also.
Simply replacing f:columns(rows) by f:scrolled_view(rows) didn't work.

while true do
	local outerRows = {}
	local rows = {}
	outerRows = { spacing = f:control_spacing() }
	for i = 1, nRows do
		table.insert(rows, f:static_text { title = "Row " .. i })
	end
	table.insert(outerRows, f:scrolled_view(rows))
	table.insert(outerRows, f:push_button { title = "Add row",
		action = function(button)
			nRows = nRows + 1
			LrDialogs.stopModalWithResult(button, "refresh")
		end })

	local result = LrDialogs.presentModalDialog { title = "Test",
		contents = f:column(outerRows) }
	if result ~= "refresh" then break end
end