« MBS Plugin Advent cal… | Home | MBS Plugin Advent cal… »

MBS Plugin Advent calendar: 17 - Dialog

Door 17 - Dialogs

Fact of the day
Did you know that you can also influence FileMaker's own dialogs a little?
Take a look at the DialogModifications component in the plugin.

The dialog box for displaying information to the user is essential and can be found in almost every application. But sometimes you want more design options for the dialog box and this is where the plugin comes into play, because with this you can build your dialog box according to your wishes. I will show you how this works in this door.

Such a dialog is valid for the entire application, which means that you can make the settings for a dialog in one script and call the dialog in another script. However, this also means that we have to get rid of old settings at the beginning. To do this, we use the Dialog.Reset function, which resets all dialog settings to their original state.

Set Variable [ $r ; Value: MBS( "Dialog.Reset" ) ]

Now we can start making our settings. We can set the text to be displayed in the dialog. We use the function Dialog.SetMessage for this. If we also want to display an additional information text (a text in a smaller font), this can be specified with Dialog.SetInformativeText. Icons can be very practical so that you can see at first glance what the dialog might be about. You can use the Dialog.SetIcon function to bring this icon into your dialog from a container, for example. Would you like to display your text in the dialog right-aligned? No problem Dialog.SetTextAlignment makes it possible. All you have to do is select the appropriate alignment in the parameters.

Set Variable [ $r ; Value: MBS( "Dialog.SetMessage"; DoorSevenTeen::Text ) ] 
Set Variable [ $r ; Value: MBS( "Dialog.SetInformativeText"; DoorSevenTeen::Infotext ) ] 
Set Variable [ $r ; Value: MBS( "Dialog.SetIcon"; DoorSevenTeen::Icon ) ] 
Set Variable [ $r ; Value: MBS( "Dialog.SetTextAlignment"; "right") ] 

Would you like to have several options for the buttons? That's no problem at all to have up to 10 more buttons in addition to the default button. First of all, we can change the title of the default button if we don't like the default OK. To do this, we use the function Dialog.SetDefaultButton and enter the new name in the parameters. If we now want more buttons, we can use the function Dialog.SetButton to set the titles of the buttons that then appear. In the parameters, we specify the index to say which button we want to add now, followed by the title.

…
Set Variable [ $r ; Value: MBS( "Dialog.SetDefaultButton"; "DefaultButton" ) ] 
Set Variable [ $r ; Value: MBS( "Dialog.SetButton"; 1; "Santa Clause" ) ] 
…

But we can not only add buttons, for example, if you need information from your user, you can also use fields under Mac in the dialog. The Dialog.AddField function is available for this purpose. Here we have many optional options in addition to the label title of the field.

MBS( "Dialog.AddField"; Label { ; Text; Placeholder; Password; TextViewHeight } )  

After the title, we can place a text that has already been entered in the field. This is useful, for example, if the data has already been entered in the database and you want to check it again so that the user can make changes if necessary.
With the Placeholder parameter, you can display a text in the field that tells you what should be entered in the field. The Password parameter expects a 0 or 1 as a value and determines whether only dots are displayed in the field instead of the plain text, as we know it from password entries. Last but not least, we can also influence the height of the text field. With a higher text field, we can specify a list, for example. If the value we specify in this parameter, is higher than 20, the field changes from a standard field to a text view. This text view behaves a little differently to a normal field, as we cannot create a placeholder text or use a password option. The values that are set in this way are simply ignored, but we can already enter text in this field. The following configuration creates this dialog

# Fields
Set Variable [ $r ; Value: MBS( "Dialog.AddField"; "Name" ) ] 
Set Variable [ $r ; Value: MBS( "Dialog.AddField"; "FirstName" ; ""; " Write your name" ) ] 
Set Variable [ $r ; Value: MBS( "Dialog.AddField"; "Do you like gingerbread" ; "Yes"; "Type 'Yes' or 'No'" ) ] 
Set Variable [ $r ; Value: MBS( "Dialog.AddField"; "Your Secret Santa" ; ""; ""; 1 ) ] 
Set Variable [ $r ; Value: MBS( "Dialog.AddField"; "Your special wish" ; ""; "What do you want for Christmas"; 0; 50 ) ] 

We can also determine the position of the dialog on the screen. To do this, we can specify the coordinates of the upper left corner of the dialog.

# Position 
Set Variable [ $r ; Value: MBS( "Dialog.SetTop"; 100 ) ] 
Set Variable [ $r ; Value: MBS( "Dialog.SetLeft"; 100 ) ] 

Under windows the dialog looks a little different. Here the dialog also has a title bar. We can set this title with Dialog.SetWindowTitle.

If we now run the script, we don't see anything yet, because we first have to give the program the command that the dialog should be displayed. We do this with Dialog.Run.

# Show Dialog
Set Variable [ $r ; Value: MBS( "Dialog.Run" ) ] 

At this point, our script is stopped and we are shown the dialog. We can now enter our values. By clicking on one of the buttons, the dialog disappears. Now, of course, we want to know what the user has clicked or what is in the fields. We can find out which button was clicked with the Dialog.GetButtonPressed function. This provides us with the index of the button that was pressed. We can then use the Dialog.GetButton function to find out the title of the button. We have to be careful here. If we have previously omitted an index when creating the button, an mistake will occur here and we will get back the wrong title of the button. It is therefore important to ensure that sequential indexes are used when creating the button.

# Results
# Button
Set Variable [ $Button ; Value: MBS( "Dialog.GetButtonPressed" ) ] 
Set Variable [ $TitelOfButton ; Value: MBS("Dialog.GetButton"; $Button) ] 
Set Field [ DoorSevenTeen::Button Result ; $TitelOfButton ] 

For each field that we have in our dialog, we query the value individually. This is where the Dialog.GetFieldText function comes into play. We enter the index of the field we want to query and get the content back.

Set Variable [ $F1 ; Value: MBS("Dialog.GetFieldText"; 0) ] 
Set Variable [ $F2 ; Value: MBS("Dialog.GetFieldText"; 1) ] 
Set Variable [ $F3 ; Value: MBS("Dialog.GetFieldText"; 2) ] 
Set Variable [ $F4 ; Value: MBS("Dialog.GetFieldText"; 3) ] 
Set Variable [ $F5 ; Value: MBS("Dialog.GetFieldText"; 4) ] 
Set Field [ DoorSevenTeen::Fields Result ; "Name:" & $F1 & "¶¶First name:" & $F2 & "¶¶Gingerbread:" & $F3 & "¶¶Your Secret Santa:" & $F4 & "¶¶Wish:" & $F5 ] 

If we have now entered the information in our dialog, a return can look like this, for example:

I hope you enjoyed this insight into the dialogs.


Monkeybread Software Logo with Monkey with Santa hat
16 👈 17 of 24 👉 18
17 12 23 - 09:38