Jump to content

How to create a default button in a dialog window


This topic is 2909 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I have a dialog window with buttons. I open the window in a script, and when I click on any button a script runs with a single parameter containing text identifying which button was clicked. The button is set up to resume the original calling script. On resuming, the calling script closes the dialog window and acts on the text message, which is stored in a global field called message. My question is, how can one in effect create a default button? I want carriage return to cause the appropriate message to be added to the message field and then resume the calling script. Typing carriage return should be equivalent to clicking the default button. The layout trigger OnLayoutKeystroke can certainly invoke a script that will set the global message field to the default, but the trigger doesn't allow one to resume the calling script.

Is there a simple way to accomplish what I'm after?

Link to comment
Share on other sites

are you using the "show custom dialog" script step or have you built your own dialog?

If the latter, you could make your new window modal and let the original script stop after spawning the window.  The scripts triggered by the user action or the layoutkeystroke for enter can just run the script it needs instead of trying to resume the paused script.

Link to comment
Share on other sites

If your main script is paused, than hitting Return will resume it. You just need to populate the global field with the default value in the main script itself, and make the default button do Resume Script (without performing the subscript).

 

Edited by comment
Link to comment
Share on other sites

Thanks, both. Yes, I am talking about creating my own dialog. Wim, I can see how your solution will do the job. I assume this does mean, then, that if one wants to make a general practice of allowing users in each window with button choices to always have one default action and to be able to close the window using escape, one ends up with a profusion of scripts, many of them left hanging. So I take it that such a general practice would not be considered a best practice? I think I would generally stick with the convention of using dialog boxes for simple dialogs and have users rely solely on buttons for taking actions.

Consultant, when you say that hitting return will resume the main script if it's paused, are you talking about the case of "show custom dialog"?

 

Link to comment
Share on other sites

13 minutes ago, jjjjp said:

 I assume this does mean, then, that if one wants to make a general practice of allowing users in each window with button choices to always have one default action and to be able to close the window using escape, one ends up with a profusion of scripts, many of them left hanging. So I take it that such a general practice would not be considered a best practice?

I don't really follow how you come to this conclusion about the profusion of scripts.  There is no best practice around showing dialogs; it's all fairly straightforward coding.

 

Link to comment
Share on other sites

23 minutes ago, jjjjp said:

Consultant, when you say that hitting return will resume the main script if it's paused, are you talking about the case of "show custom dialog"?

No. I am talking about resuming your "original calling script", which is paused:

On 08/07/2016 at 11:11 PM, jjjjp said:

The button is set up to resume the original calling script. On resuming, the calling script closes the dialog window and acts on the text message, which is stored in a global field called message.

Even with your current arrangement, if the user does not click any of the buttons in the dialog window but presses Return or Enter instead, the original script resumes, does it not?

 

Link to comment
Share on other sites

Yes, you are right, Consultant. I see now that hitting return does resume the script, so populating the global variable with the default will work, whether or not the window is modal.

But I guess I don't understand what you are suggesting Wim, or at least how I can keep from adding a new script every time I want a dialog box. You yourself speak of spawning a new script. Maybe I'm missing something obvious.

I've created a simple script (attached) that has three buttons, one a default and one cancel. Clicking on a button saves a message to a global variable and then displays it. Clicking return does print the message corresponding to the default button. There is an enclosing loop. The loop exits when the user clicks on the cancel button. Start by clicking Test Dialog. Can you say how I can implement this so that clicking the escape key gets you out of the loop just as clicking the cancel button does?

TestDialog.fmp12.zip

Link to comment
Share on other sites

This topic is 2909 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.