Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Closing dialogs

Adobe Community Professional ,
Jul 01, 2009 Jul 01, 2009

Copy link to clipboard

Copied

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

TOPICS
SDK

Views

3.2K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 07, 2009 Jul 07, 2009

Copy link to clipboard

Copied

The 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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 07, 2009 Jul 07, 2009

Copy link to clipboard

Copied

Hm, still no go. This is a cut down test script (attached or via link)

John

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 07, 2009 Jul 07, 2009

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 08, 2009 Jul 08, 2009

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 08, 2009 Jul 08, 2009

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 08, 2009 Jul 08, 2009

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 08, 2009 Jul 08, 2009

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 08, 2009 Jul 08, 2009

Copy link to clipboard

Copied

That's the clairvoyance, as mediated by Gypsy Jeffrey. It can be anything you want.

John

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 08, 2009 Jul 08, 2009

Copy link to clipboard

Copied

Oh...of course.  Why didn't I realise that from the docs?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 08, 2009 Jul 08, 2009

Copy link to clipboard

Copied

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 {                                                       
     f:push_button {
             title = 'I should close the dialog too!',
          action = function()
               LrDialogs.message( MainDialog, 'The button is doing something....' )     
               LrDialogs.stopModalWithResult( MainDialog, 'ok' )     
          end,
     },                                                                           
}
     
MainDialog = LrDialogs.presentModalDialog(
     {
          contents = c
     }
)

end) -- end main function

(Hopefully that formatting works)
Or you could also do as suggested by using the first parameter to the action() method which is a reference to the button LrView. This is only briefly mentioned in the docs.
The first parameter to stopModalWithResult() can be the dialog or any view within the dialog.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 08, 2009 Jul 08, 2009

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 08, 2009 Jul 08, 2009

Copy link to clipboard

Copied

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:

The first parameter to stopModalWithResult() can be the dialog or any view within the dialog.

Have you got any examples of how to pass a dialog or other view within the dialog?  I have tried many different things and failed to get anything to work - the only thing I have seen working is the method passed on by John above.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 08, 2009 Jul 08, 2009

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 08, 2009 Jul 08, 2009

Copy link to clipboard

Copied

jsteinme wrote:

You could use the upvalue c instead of MainDialog but using the first parameter to action is probably the most flexible.

The more I think about it, the more I think Jeffrey's magic_sauce is the only way to deal with this issue.

Given in lua you can do things like:

a, b = b, a

to swap values between variables, I'm pretty sure John's c variable will still be nil if we use that as the input to the stopDialog... function.  That is because it is being accessed as part of setting the c variable.

magic_sauce is guaranteed to be set with a valid, non-nil value at the time the button is pressed.  So you will have a correct reference to an element in the correct LrView dialog.  I can't really think of any other way to do that, short of explicitly setting one of the elements as a separate variable (e.g. set d = a static_text element) then reference d as an entry in table c.  That seems a bit of a kludge.  magic_sauce seems more natural way to achieve this.

So I think "correct answer" needs to go to Jeffrey.  How to we assign those forum points to someone in their absence?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 08, 2009 Jul 08, 2009

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 20, 2021 Oct 20, 2021

Copy link to clipboard

Copied

Hello folks, i have read your comments seems like i still not able to close my dialog on button click, can anyone help me out with my below example.

 

local LrFunctionContext = import 'LrFunctionContext'
local LrDialogs = import 'LrDialogs'
local LrView = import 'LrView'

MyCode = {}

function MyCode.MyDialog()

	LrFunctionContext.callWithContext("MyDialog", function(context)
        local MainDialog 
	local f = LrView.osFactory()
	
		local c = f:column {											
			f:push_button {
					title = 'I should close the dialog too!',
					action = function()
						LrDialogs.stopModalWithResult(MainDialog, 'ok' )	
					end,
			},															
		}
	
	MainDialog = LrDialogs.presentModalDialog(
		{
			contents = c
		}
	)

	end) -- end main function

end

-- Now display the dialogs
MyCode.MyDialog()

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 20, 2021 Oct 20, 2021

Copy link to clipboard

Copied

LATEST

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines