Difference between revisions of "Lua:messageDialog"
Jump to navigation
Jump to search
(Major overhaul of the post.) |
|||
| (7 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
[[Category:Lua]] | [[Category:Lua]] | ||
| − | '''function''' messageDialog('' | + | {{CodeBox|'''function''' messageDialog(''text'') ''':''' integer}} |
| − | + | {{CodeBox|'''function''' messageDialog(''text'', ''type'', ''buttons''...) ''':''' integer}} | |
| − | + | {{CodeBox|'''function''' messageDialog(''title'', ''text'', ''type'', ''buttons''...) ''':''' integer}} | |
| + | |||
| + | Shows a message dialog. | ||
| + | |||
| + | messageDialog can show a simple information dialog, or a dialog with a specific icon/sound and custom buttons. The overload with title allows setting a custom dialog title. | ||
===Function Parameters=== | ===Function Parameters=== | ||
| − | {|width="85%" cellpadding="10 | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" |
!align="left"|Parameter | !align="left"|Parameter | ||
!align="left"|Type | !align="left"|Type | ||
!style="width: 80%;background-color:white;" align="left"|Description | !style="width: 80%;background-color:white;" align="left"|Description | ||
|- | |- | ||
| − | | | + | |title |
| + | |String OPTIONAL | ||
| + | |The custom title shown in the dialog caption. | ||
| + | |- | ||
| + | |text | ||
|String | |String | ||
| − | |The message | + | |The message text shown in the dialog. |
| + | |- | ||
| + | |type | ||
| + | |MessageType | ||
| + | |The dialog type. This controls the icon and sound. | ||
| + | |- | ||
| + | |buttons | ||
| + | |MessageButton ... | ||
| + | |One or more button constants, such as mbOK, mbYes, or mbNo. | ||
| + | |} | ||
| + | |||
| + | ===Returns=== | ||
| + | Integer — The modal result of the button that was pressed. | ||
| + | |||
| + | ===Message Types=== | ||
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Constant | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |mtWarning | ||
| + | |Shows a warning dialog. | ||
| + | |- | ||
| + | |mtError | ||
| + | |Shows an error dialog. | ||
| + | |- | ||
| + | |mtInformation | ||
| + | |Shows an information dialog. | ||
|- | |- | ||
| − | | | + | |mtConfirmation |
| − | | | + | |Shows a confirmation dialog. |
| − | |||
|- | |- | ||
| − | | | + | |mtCustom |
| − | | | + | |Shows a custom dialog type. |
| − | |||
|} | |} | ||
| + | ===Button Constants=== | ||
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Constant | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |mbOK | ||
| + | |Adds an OK button. | ||
| + | |- | ||
| + | |mbCancel | ||
| + | |Adds a Cancel button. | ||
| + | |- | ||
| + | |mbYes | ||
| + | |Adds a Yes button. | ||
| + | |- | ||
| + | |mbNo | ||
| + | |Adds a No button. | ||
| + | |- | ||
| + | |mbAbort | ||
| + | |Adds an Abort button. | ||
| + | |- | ||
| + | |mbRetry | ||
| + | |Adds a Retry button. | ||
| + | |- | ||
| + | |mbIgnore | ||
| + | |Adds an Ignore button. | ||
| + | |- | ||
| + | |mbAll | ||
| + | |Adds an All button. | ||
| + | |- | ||
| + | |mbNoToAll | ||
| + | |Adds a No to All button. | ||
| + | |- | ||
| + | |mbYesToAll | ||
| + | |Adds a Yes to All button. | ||
| + | |- | ||
| + | |mbHelp | ||
| + | |Adds a Help button. | ||
| + | |- | ||
| + | |mbClose | ||
| + | |Adds a Close button. | ||
| + | |} | ||
| + | |||
| + | ===Common Modal Results=== | ||
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Constant | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |mrOK | ||
| + | |The OK button was pressed. | ||
| + | |- | ||
| + | |mrCancel | ||
| + | |The Cancel button was pressed. | ||
| + | |- | ||
| + | |mrYes | ||
| + | |The Yes button was pressed. | ||
| + | |- | ||
| + | |mrNo | ||
| + | |The No button was pressed. | ||
| + | |- | ||
| + | |mrAbort | ||
| + | |The Abort button was pressed. | ||
| + | |- | ||
| + | |mrRetry | ||
| + | |The Retry button was pressed. | ||
| + | |- | ||
| + | |mrIgnore | ||
| + | |The Ignore button was pressed. | ||
| + | |- | ||
| + | |mrAll | ||
| + | |The All button was pressed. | ||
| + | |- | ||
| + | |mrNoToAll | ||
| + | |The No to All button was pressed. | ||
| + | |- | ||
| + | |mrYesToAll | ||
| + | |The Yes to All button was pressed. | ||
| + | |- | ||
| + | |mrClose | ||
| + | |The Close button was pressed. | ||
| + | |} | ||
| + | |||
| + | ===Examples=== | ||
| + | |||
| + | ====Show a simple information dialog==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | messageDialog("Operation completed") | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ====Show an information dialog with an OK button==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | messageDialog("Operation completed", mtInformation, mbOK) | ||
| + | </syntaxhighlight> | ||
| − | == | + | ====Show a warning dialog==== |
| − | + | <syntaxhighlight lang="lua" line highlight="1"> | |
| + | messageDialog("This action may be unsafe", mtWarning, mbOK) | ||
| + | </syntaxhighlight> | ||
| + | ====Show an error dialog==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | messageDialog("The operation failed", mtError, mbOK) | ||
| + | </syntaxhighlight> | ||
| + | ====Show a confirmation dialog==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local result = messageDialog("Do you want to continue?", mtConfirmation, mbYes, mbNo) | ||
| + | if result == mrYes then | ||
| + | print("User selected Yes") | ||
| + | else | ||
| + | print("User selected No") | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | ====Use a custom dialog title==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local result = messageDialog("Confirm Action", "Apply the selected changes?", mtConfirmation, mbYes, mbNo, mbCancel) | ||
| − | == | + | if result == mrYes then |
| + | print("Applying changes") | ||
| + | elseif result == mrNo then | ||
| + | print("Changes skipped") | ||
| + | else | ||
| + | print("Action cancelled") | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| + | ====Ask before deleting records==== | ||
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local result = messageDialog("Delete selected records?", mtConfirmation, mbYes, mbNo) | ||
| − | + | if result == mrYes then | |
| + | AddressList.deleteSelected() | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| − | + | ====Ask before disabling records==== | |
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local result = messageDialog("Disable all records without executing disable sections?", mtWarning, mbYes, mbNo) | ||
| − | + | if result == mrYes then | |
| + | AddressList.disableAllWithoutExecute() | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| − | messageDialog(" | + | ====Use Retry and Cancel==== |
| + | <syntaxhighlight lang="lua" line highlight="1"> | ||
| + | local result = messageDialog("Could not open the process", mtError, mbRetry, mbCancel) | ||
| − | + | if result == mrRetry then | |
| + | print("Retrying") | ||
| + | else | ||
| + | print("Cancelled") | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| − | messageDialog( | + | ====Wrap messageDialog in a helper function==== |
| + | <syntaxhighlight lang="lua" line highlight="2"> | ||
| + | local function confirm(text) | ||
| + | return messageDialog(text, mtConfirmation, mbYes, mbNo) == mrYes | ||
| + | end | ||
| − | + | if confirm("Enable this script?") then | |
| + | print("Confirmed") | ||
| + | end | ||
| + | </syntaxhighlight> | ||
| − | + | {{LuaSeeAlso}} | |
| − | |||
Latest revision as of 20:22, 25 June 2026
Shows a message dialog.
messageDialog can show a simple information dialog, or a dialog with a specific icon/sound and custom buttons. The overload with title allows setting a custom dialog title.
Contents
- 1 Function Parameters
- 2 Returns
- 3 Message Types
- 4 Button Constants
- 5 Common Modal Results
- 6 Examples
- 6.1 Show a simple information dialog
- 6.2 Show an information dialog with an OK button
- 6.3 Show a warning dialog
- 6.4 Show an error dialog
- 6.5 Show a confirmation dialog
- 6.6 Use a custom dialog title
- 6.7 Ask before deleting records
- 6.8 Ask before disabling records
- 6.9 Use Retry and Cancel
- 6.10 Wrap messageDialog in a helper function
Function Parameters[edit]
| Parameter | Type | Description |
|---|---|---|
| title | String OPTIONAL | The custom title shown in the dialog caption. |
| text | String | The message text shown in the dialog. |
| type | MessageType | The dialog type. This controls the icon and sound. |
| buttons | MessageButton ... | One or more button constants, such as mbOK, mbYes, or mbNo. |
Returns[edit]
Integer — The modal result of the button that was pressed.
Message Types[edit]
| Constant | Description |
|---|---|
| mtWarning | Shows a warning dialog. |
| mtError | Shows an error dialog. |
| mtInformation | Shows an information dialog. |
| mtConfirmation | Shows a confirmation dialog. |
| mtCustom | Shows a custom dialog type. |
Button Constants[edit]
| Constant | Description |
|---|---|
| mbOK | Adds an OK button. |
| mbCancel | Adds a Cancel button. |
| mbYes | Adds a Yes button. |
| mbNo | Adds a No button. |
| mbAbort | Adds an Abort button. |
| mbRetry | Adds a Retry button. |
| mbIgnore | Adds an Ignore button. |
| mbAll | Adds an All button. |
| mbNoToAll | Adds a No to All button. |
| mbYesToAll | Adds a Yes to All button. |
| mbHelp | Adds a Help button. |
| mbClose | Adds a Close button. |
Common Modal Results[edit]
| Constant | Description |
|---|---|
| mrOK | The OK button was pressed. |
| mrCancel | The Cancel button was pressed. |
| mrYes | The Yes button was pressed. |
| mrNo | The No button was pressed. |
| mrAbort | The Abort button was pressed. |
| mrRetry | The Retry button was pressed. |
| mrIgnore | The Ignore button was pressed. |
| mrAll | The All button was pressed. |
| mrNoToAll | The No to All button was pressed. |
| mrYesToAll | The Yes to All button was pressed. |
| mrClose | The Close button was pressed. |
Examples[edit]
Show a simple information dialog[edit]
1 messageDialog("Operation completed")
Show an information dialog with an OK button[edit]
1 messageDialog("Operation completed", mtInformation, mbOK)
Show a warning dialog[edit]
1 messageDialog("This action may be unsafe", mtWarning, mbOK)
Show an error dialog[edit]
1 messageDialog("The operation failed", mtError, mbOK)
Show a confirmation dialog[edit]
1 local result = messageDialog("Do you want to continue?", mtConfirmation, mbYes, mbNo)
2
3 if result == mrYes then
4 print("User selected Yes")
5 else
6 print("User selected No")
7 end
Use a custom dialog title[edit]
1 local result = messageDialog("Confirm Action", "Apply the selected changes?", mtConfirmation, mbYes, mbNo, mbCancel)
2
3 if result == mrYes then
4 print("Applying changes")
5 elseif result == mrNo then
6 print("Changes skipped")
7 else
8 print("Action cancelled")
9 end
Ask before deleting records[edit]
1 local result = messageDialog("Delete selected records?", mtConfirmation, mbYes, mbNo)
2
3 if result == mrYes then
4 AddressList.deleteSelected()
5 end
Ask before disabling records[edit]
1 local result = messageDialog("Disable all records without executing disable sections?", mtWarning, mbYes, mbNo)
2
3 if result == mrYes then
4 AddressList.disableAllWithoutExecute()
5 end
Use Retry and Cancel[edit]
1 local result = messageDialog("Could not open the process", mtError, mbRetry, mbCancel)
2
3 if result == mrRetry then
4 print("Retrying")
5 else
6 print("Cancelled")
7 end
Wrap messageDialog in a helper function[edit]
1 local function confirm(text)
2 return messageDialog(text, mtConfirmation, mbYes, mbNo) == mrYes
3 end
4
5 if confirm("Enable this script?") then
6 print("Confirmed")
7 end