`msg_ok_cancel()` creates an OK/Cancel message dialog object.
Use it when the user must confirm or cancel an action.
`msg_ok_cancel` is not cloneable because it represents dialog configuration, result state, and optional asynchronous callback state.
Creates an OK/Cancel message dialog.
| Item | Description |
|---|---|
| Syntax | `msg_ok_cancel()` |
| Arguments | none |
| Returns | msg_ok_cancel object |
Example:
dlg = msg_ok_cancel();
| Property | Type | Description |
|---|---|---|
| `title` | string | Dialog title. |
| `message` | string | Dialog message text. |
| `buttons` | boolean | Whether dialog buttons are shown. |
| `has_result` | boolean | `true` after the dialog has produced a result. |
| `action` | string | Result action: `ok`, `cancel`, or `none`. |
| `ok` | boolean | `true` when OK was selected. |
| `cancel` | boolean | `true` when Cancel was selected. |
| `save` | boolean | Save flag in the result map. Usually `false` for `msg_ok_cancel`. |
Properties are read-only. Use methods such as `title(text)` and `message(text)` to change dialog configuration.
Returns a display string for the object.
| Item | Description |
|---|---|
| Syntax | `value.to_string()` |
| Arguments | none |
| Returns | string |
Example:
text = value.to_string();
`clone()` is not supported for `msg_ok_cancel`.
Sets the dialog title.
| Argument | Type | Description |
|---|---|---|
| `text` | string | Title text. |
Returns: msg_ok_cancel object.
Sets the message text.
| Argument | Type | Description |
|---|---|---|
| `text` | string | Message text. |
Returns: msg_ok_cancel object.
Shows or hides dialog buttons.
| Argument | Type | Description |
|---|---|---|
| `enabled` | boolean | Button visibility state. |
Returns: msg_ok_cancel object.
Sets a callback for asynchronous result handling.
| Argument | Type | Description |
|---|---|---|
| `callback` | callable object | Function reference, method reference, or other object that implements `call(result)`. |
Returns: msg_ok_cancel object.
When `on_result()` is used, `show()` displays the dialog and returns the dialog object immediately. The callback receives one argument: a result `map`.
Shows the dialog.
| Item | Description |
|---|---|
| Syntax | `msg_ok_cancel.show()` |
| Arguments | none |
| Returns | map or msg_ok_cancel object |
Without `on_result()`, `show()` blocks until the dialog is closed and returns a result `map`.
With `on_result(callback)`, `show()` returns the dialog object immediately.
Example:
result = msg_ok_cancel() .title('Confirm') .message('Start probing?') .show(); if (result.ok) { print('start'); } else { print('cancelled'); }
Clicks OK on an active asynchronous dialog.
| Item | Description |
|---|---|
| Syntax | `msg_ok_cancel.click_ok()` |
| Arguments | none |
| Returns | boolean-style number |
Returns `true` when the click was accepted.
Clicks Close on an active asynchronous dialog.
| Item | Description |
|---|---|
| Syntax | `msg_ok_cancel.click_close()` |
| Arguments | none |
| Returns | boolean-style number |
Returns `true` when the click was accepted.
Synchronous `show()` returns a result `map`. Asynchronous `on_result(callback)` callbacks receive the same kind of result map.
| Key | Type | Description |
|---|---|---|
| `action` | string | `ok`, `cancel`, or `none`. For Yes/No dialogs, Yes is reported as `ok` and No/Close as `cancel`. |
| `action_code` | number | Numeric host action code. |
| `ok` | boolean | `true` when the result action is OK/Yes. |
| `cancel` | boolean | `true` when the result action is Cancel/No/Close. |
| `affirmative` | boolean | `true` for affirmative choices such as OK or Yes. |
| `save` | boolean | Save flag from the host dialog result. |
| `password` | string | Password text. Empty for non-password dialogs. |
Previous: msg_ok
Next: msg_yes_no