Copy link to clipboard
Copied
As it stands, the dialog box requires you to have an "OK" button, and a "Cancel" button (names can be changed...) - both of which will dismiss the dialog box. More buttons than that and you have to define an accessory view or put buttons in the views - all of which is fine, except when a dialog box is used more like an application frame, in which case it would be preferrable if only one button dismissed the dialog box (e.g. 'Done').
Rob
Here's an undocumented way to create a dialog with just a single "Done" button. Not sure you want to rely on this though :-;
local LrDialogs = import 'LrDialogs'
local LrFunctionContext = import 'LrFunctionContext'
local LrTasks = import 'LrTasks'
local LrView = import 'LrView'
local function findButton (x, label, visited)
if visited == nil then visited = {} end
if type (x) ~= "table" or visited
visited
if x._WinClassName == "AgViewWinPushButton" and
...
Copy link to clipboard
Copied
Here's an undocumented way to create a dialog with just a single "Done" button. Not sure you want to rely on this though :-;
local LrDialogs = import 'LrDialogs'
local LrFunctionContext = import 'LrFunctionContext'
local LrTasks = import 'LrTasks'
local LrView = import 'LrView'
local function findButton (x, label, visited)
if visited == nil then visited = {} end
if type (x) ~= "table" or visited
visited
if x._WinClassName == "AgViewWinPushButton" and
x.title == label then
return x;
end
for k, v in pairs (x) do
local result = findButton (v, label, visited)
if result then return result end
end
return nil
end
local f = LrView.osFactory()
local controls = f:column {
f:static_text {title = "Look Ma! No OK or Cancel!"},
f:edit_field {value = "fields"},
f:push_button {title = "Do It"}}
LrTasks.startAsyncTask (function ()
while true do
local okButton = findButton (controls, "OK")
if okButton then
okButton.enabled = false
okButton.visible = false
return
end
LrTasks.sleep (0.1)
end
end)
LrDialogs.presentModalDialog {
title = "Test", contents = controls, cancelVerb = "Done"}
Copy link to clipboard
Copied
John - You are so "the man"!
PS - To the Adobe SDK workers - I still would like direct support in the SDK/API. The present work-around gets me through the day, but its klugy and leaves a dead-zone next to the "Cancel" button where the invisible "OK" button is hiding.
Thanks,
Rob
Copy link to clipboard
Copied
Seconded.
Copy link to clipboard
Copied
Yeah, I've been using a slightly enhanced version of John Ellis solution for a while, but it just stopped working on the Mac (some Macs?). I guess something changed under the hood - needs to be re-engineered.
Official documented support would be better indeed.
PS - Another gotcha of the above approach: edited text values are not commited before exiting when 'Cancel' button is used as 'OK' button. (on Windows that is, they are not commited anyway on Mac, even if 'OK' button is used, so you have to set immediate to true if you want them commited on both platforms.).
Copy link to clipboard
Copied
On the Mac you can catch the button via "_NSClass". Modify John's code as follows and it works on both plattforms:
if WIN_ENV then
if x._WinClassName == "AgViewWinPushButton" and x.title == label then
return x
end
elseif MAC_ENV then
if x._NSClass == "NSButton" and x.title == label then
return x
end
else
return nil
end
HTH someone
cb
Copy link to clipboard
Copied
johnbeardy's solution described above has been documented in both the LR 4 and 5 SDKs. Does it not work for you?
Copy link to clipboard
Copied
I have not seen that. Where is it documented?
Copy link to clipboard
Copied
In the LR 4/5 SDK documentation under LrDialogs.presentModalDialog.
Copy link to clipboard
Copied
I want to enable/disable the default button depending on the users input instead of hiding a button.
Copy link to clipboard
Copied
I want to enable/disable the default button depending on the users input instead of hiding a button.
I don't think you'll be able to do that with the documented method of "< exclude >".
Copy link to clipboard
Copied
John R. Ellis schrieb:
I want to enable/disable the default button depending on the users input instead of hiding a button.
I don't think you'll be able to do that with the documented method of "< exclude >".
You're right and my mistake: I mean not Johns code, I mean Rob Coles code in the first answer (findButton function).
Copy link to clipboard
Copied
Rob
Try this currently undocumented / unsupported value:
cancelVerb = "< exclude >", -- Must be exact including the spaces
I only learnt about it recently but apparently it's been lurking there since LR1 and may get documented in LR4.
John