Can't quite figure out how to get stopModalWithResult working.
I'm calling a dialog using MainDialog = LrDialogs.presentModalDialog.... This dialog has a number of buttons which ''do something'' and it would be cool if they also dismissed the dialog. So I'm including a stopModalWithResult in the button's action. However, the dialog isn't closing.
f:push_button {
?title = 'do owt',
?enabled = true,
?action = function()
DoSomething(editEditor1.value)
LrDialogs.stopModalWithResult( MainDialog, true )
?end,
},
I suspect it's a matter of getting the correct name for the dialog. I've tried a range from MainDialog, 'MainDialog '.
Anyone done this? Clues?
John
Closing dialogsThe second parameter to stopModalWithResult() needs to be a string and not the value true. Try replacing true with string like ''foo''. Hopefully that should fix this issue.
Closing dialogsHm, still no go. This is a cut down test script (attached or via link)
John
Hi,
Haven't used this function before, but the reference doco on the first parameter is:
(LrView
) The dialog to dismiss, or any element of that dialog.
So try changing the first parameter to c (your LrView local variable) rather than a text string.?Failing that try aligning your first parameter with the dialog title, or the context's name, but these last two suggestions are unlikely to work because they don't align with the reference doco.
The current value ('MainDialog') doesn't match up with anything suitable.?The local variable MainDialog will hold a string when it eventually gets set (after the stopModalwithResult does its thing), so couldn't help identify the dialog to close.
Matt
Thanks Matt
I had read the same passage (seems to make sense now) and had tried 'c', c. 'f', f. I've tried them all.... As the second parameter I've tried things like 'ok'. Man, this one has me stumped.
John
I think Jeffrey uses it in his geotagging plug-in (there is a check-box option to close the dialog when you press the main button), so may be worth dropping him an email.
Thanks to Jeffrey. Hopefully you will love this one as much as I do....
Apparently clairvoyance is helpful:
?action = function(magic_sauce)
?LrDialogs.stopModalWithResult(magic_sauce, 'FOO' )
?end,
In this snippet, this would set local MainDialog to 'FOO' and closes the dialog.
I think this really emphasises a point I've made before, that for every documented function, specimen code needs to be available.
John
Thanks for sharing that John.?The second parameter behaves as I expected from the documentation (i.e. it sets the return value for the dialog, just as if you pressed the typical OK or Cancel buttons) - it was the first parameter that didn't make any sense to me.?In your example, where do you get the magic_sauce to pass it to the function?
That's the clairvoyance, as mediated by Gypsy Jeffrey. It can be anything you want.
John
Oh...of course.?Why didn't I realise that from the docs?
Sorry, I did not notice until you posted the whole code snippet that it looks like MainDialog is probably nil since it looks like it is declared after its use as an up value. You could move the definition up:
LrFunctionContext.callWithContext(''MyDialog'', function(context)
local f = LrView.osFactory()
local MainDialog
local c = f:column { %26amp;n bsp; %26amp;nbs p;
f:push_button {
title = 'I should close the dialog too!',
action = function()
%26amp; nbsp; LrDialogs.message( MainDialog, 'The button is doing something....' )
%26amp; nbsp; LrDialogs.stopModalWithResult( MainDialog, 'ok' )
end,
}, %26amp;nbsp ; %26amp; nbsp; %26amp;nb sp; %26amp;nbsp ; %26amp; nbsp; %26amp;nb sp;
}
MainDialog = LrDialogs.presentModalDialog(
{
?contents = c
}
)
end) -- end main function
You sure about that? I wouldn't be surprised if it is lurking there in an unsuspected form, but AFAICS stopModalWithResult isn't even mentioned in the SDK PDF and in only one spot in the API reference HTML content.
Equally, declaring MainDialog early doesn't seem to work. I still have to put the first parameter in the function.
But I've got what I need working now (and had my whinge) !
John
Not sure I follow that - I thought presentModalDialog returned the value of the button pressed (e.g. ''ok'').?How does defining MainDialog earlier in the function make it work as the LrView dialog to pass to stopModalWithResult?
jsteinme wrote:
Sorry, you are correct. Our internal versions of these act a little different. You could use the upvalue c instead of MainDialog but using the first parameter to action is probably the most flexible.
The current versions of the docs in the internal source tree mention button as the first parameter to the action method, but that does not mean it is clear in any way. There should be some documentation improvements coming with the next version.
Glad things are working now.
jsteinme wrote:
You could use the upvalue c instead of MainDialog but using the first parameter to action is probably the most flexible.
Sorry, in case it is not clear I am a member of the Lightroom team. So I can say that by looking at the internal source code that the first parameter can be either the dialog or a view in the dialog. I would recommend changing the name of the action parameter to 'button' from 'secret_sauce'.
For 'c' to be a valid up value you would probably need to declare it earlier on but that is academic. I agree that the better answer is to use the button parameter.
Taking a quick look through LR source reveals that that is what we use most commonly as well.
No comments:
Post a Comment