It derives from <AdwDialog>.
A dialog presenting a message or a question.
Alert dialogs have a heading, a body, an optional child widget, and one or multiple responses, each presented as a button.
Each response has a unique string ID, and a button label. Additionally, each response can be enabled or disabled, and can have a suggested or destructive appearance.
When one of the responses is activated, or the dialog is closed, the
"response" signal will be emitted. This signal is detailed, and
the detail, as well as the response parameter will be set to the
ID of the activated response, or to the value of the
AlertDialog:close-response property if the dialog had been closed
without activating any of the responses.
Response buttons can be presented horizontally or vertically depending on available space.
When a response is activated, <AdwAlertDialog>
is closed automatically.
An example of using an alert dialog:
AdwDialog *dialog;
dialog = adw_alert_dialog_new (_("Replace File?"), NULL);
adw_alert_dialog_format_body (ADW_ALERT_DIALOG (dialog),
_("A file named “%s” already exists. Do you want to replace it?"),
filename);
adw_alert_dialog_add_responses (ADW_ALERT_DIALOG (dialog),
"cancel", _("_Cancel"),
"replace", _("_Replace"),
NULL);
adw_alert_dialog_set_response_appearance (ADW_ALERT_DIALOG (dialog),
"replace",
ADW_RESPONSE_DESTRUCTIVE);
adw_alert_dialog_set_default_response (ADW_ALERT_DIALOG (dialog), "cancel");
adw_alert_dialog_set_close_response (ADW_ALERT_DIALOG (dialog), "cancel");
g_signal_connect (dialog, "response", G_CALLBACK (response_cb), self);
adw_dialog_present (dialog, parent);
<AdwAlertDialog> can also be used via the
AlertDialog.choose method. This API follows the GIO async
pattern, for example:
static void
dialog_cb (AdwAlertDialog *dialog,
GAsyncResult *result,
MyWindow *self)
{
const char *response = adw_alert_dialog_choose_finish (dialog, result);
// ...
}
static void
show_dialog (MyWindow *self)
{
AdwDialog *dialog;
dialog = adw_alert_dialog_new (_("Replace File?"), NULL);
adw_alert_dialog_format_body (ADW_ALERT_DIALOG (dialog),
_("A file named “%s” already exists. Do you want to replace it?"),
filename);
adw_alert_dialog_add_responses (ADW_ALERT_DIALOG (dialog),
"cancel", _("_Cancel"),
"replace", _("_Replace"),
NULL);
adw_alert_dialog_set_response_appearance (ADW_ALERT_DIALOG (dialog),
"replace",
ADW_RESPONSE_DESTRUCTIVE);
adw_alert_dialog_set_default_response (ADW_ALERT_DIALOG (dialog), "cancel");
adw_alert_dialog_set_close_response (ADW_ALERT_DIALOG (dialog), "cancel");
adw_alert_dialog_choose (ADW_ALERT_DIALOG (dialog), GTK_WIDGET (self),
NULL, (GAsyncReadyCallback) dialog_cb, self);
}
<AdwAlertDialog> supports adding responses in
UI definitions by via the <responses> element that may contain
multiple <response> elements, each representing a response.
Each of the <response> elements must have the id attribute
specifying the response ID. The contents of the element are used as the
response label.
Response labels can be translated with the usual translatable,
context and comments attributes.
The <response> elements can also have enabled and/or
appearance attributes. See
AlertDialog.set_response_enabled and
AlertDialog.set_response_appearance for details.
Example of an <AdwAlertDialog> UI definition:
<object class="AdwAlertDialog" id="dialog">
<property name="heading" translatable="yes">Save Changes?</property>
<property name="body" translatable="yes">Open documents contain unsaved changes. Changes which are not saved will be permanently lost.</property>
<property name="default-response">save</property>
<property name="close-response">cancel</property>
<signal name="response" handler="response_cb"/>
<responses>
<response id="cancel" translatable="yes">_Cancel</response>
<response id="discard" translatable="yes" appearance="destructive">_Discard</response>
<response id="save" translatable="yes" appearance="suggested" enabled="false">_Save</response>
</responses>
</object>
parent-instanceThe body text of the dialog.
Its value is a string, or #f.
Set it with (set! (alert-dialog:body self) value).
Whether the body text includes Pango markup.
See parse-markup.
Its value is a boolean.
Set it with (set! (alert-dialog:body-use-markup self) value).
The ID of the close response.
It will be passed to "response" if the dialog is closed by
pressing Escape or with a system action.
It doesn’t have to correspond to any of the responses in the dialog.
The default close response is close.
Its value is a string, or #f.
Set it with (set! (alert-dialog:close-response self) value).
The response ID of the default response.
The button corresponding to this response will be set as the default widget of the dialog.
If not set, the default widget will not be set, and the last added response will be focused by default.
See Dialog:default-widget.
Its value is a string, or #f.
Set it with (set! (alert-dialog:default-response self) value).
The child widget.
Displayed below the heading and body.
Its value is a <GtkWidget>, or #f.
Set it with (set! (alert-dialog:extra-child self) value).
The heading of the dialog.
Its value is a string, or #f.
Set it with (set! (alert-dialog:heading self) value).
Whether the heading includes Pango markup.
See parse-markup.
Its value is a boolean.
Set it with (set! (alert-dialog:heading-use-markup self) value).
Whether to prefer horizontal button layout.
<AdwAlertDialog> can present buttons
horizontally or vertically depending on available space, how many
buttons there are and how wide they are.
By default it will prefer to stack buttons vertically at medium sizes.
Set to TRUE to prefer horizontal layout in these cases instead.
This will make the dialog slightly wider as well.
Vertical layout may still be used if the dialog would get too wide otherwise.
Does nothing with just one button, or when the buttons are already horizontal.
Its value is a boolean.
Set it with (set! (alert-dialog:prefer-wide-layout self) value).
Adds a response with id and label to self.
Responses are represented as buttons in the dialog.
Response ID must be unique. It will be used in "response" to
tell which response had been activated, as well as to inspect and modify
the response later.
An embedded underline in label indicates a mnemonic.
AlertDialog.set_response_label can be used to change the response
label after it had been added.
AlertDialog.set_response_enabled and
AlertDialog.set_response_appearance can be used to customize the
responses further.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed: a string.
the response ID
Passed: a string.
the response label
This function shows self to the user.
If the window is an Window or ApplicationWindow, the
dialog will be shown within it. Otherwise, it will be a separate
window.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed, or left out: a <GtkWidget>, or
#f.
the parent widget
Passed, or left out: a <GCancellable>, or
#f.
a <GCancellable> to cancel the operation
Passed, or left out: a procedure, or #f.
a callback to call when the operation is complete
See GAsyncReadyCallback for how it
is called.
Not passed: guile-gi supplies it.
data to pass to callback
Finishes the AlertDialog.choose call and returns the response ID.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed: a <GAsyncResult>.
Returned: a string.
the ID of the response that was selected, or
AlertDialog:close-response if the call was cancelled.
Gets the body text of self.
Passed: a <AdwAlertDialog>.
an alert dialog
Returned: a string.
the body of self.
Gets whether the body text of self includes Pango markup.
Passed: a <AdwAlertDialog>.
an alert dialog
Returned: a boolean.
whether self uses markup for body text
Gets the ID of the close response of self.
Passed: a <AdwAlertDialog>.
an alert dialog
Returned: a string.
the close response ID
Gets the ID of the default response of self.
Passed: a <AdwAlertDialog>.
an alert dialog
Returned: a string, or #f.
the default response ID
Gets the child widget of self.
Passed: a <AdwAlertDialog>.
an alert dialog
Returned: a <GtkWidget>, or #f.
the child widget of self.
Gets the heading of self.
Passed: a <AdwAlertDialog>.
an alert dialog
Returned: a string, or #f.
the heading of self.
Gets whether the heading of self includes Pango markup.
Passed: a <AdwAlertDialog>.
an alert dialog
Returned: a boolean.
whether self uses markup for heading
Gets whether self prefers horizontal button layout.
Passed: a <AdwAlertDialog>.
an alert dialog
Returned: a boolean.
whether to prefer wide layout
Gets the appearance of response.
See AlertDialog.set_response_appearance.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed: a string.
a response ID
Returned: a <AdwResponseAppearance>.
the appearance of response
Gets whether response is enabled.
See AlertDialog.set_response_enabled.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed: a string.
a response ID
Returned: a boolean.
whether response is enabled
Gets the label of response.
See AlertDialog.set_response_label.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed: a string.
a response ID
Returned: a string.
the label of response
Gets whether self has a response with the ID response.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed: a string.
response ID
Returned: a boolean.
whether self has a response with the ID response.
Creates a new <AdwAlertDialog>.
heading and body can be set to NULL. This can be
useful if they need to be formatted or use markup. In that case, set
them to NULL and call AlertDialog.format_body or similar
methods afterwards:
AdwDialog *dialog;
dialog = adw_alert_dialog_new (_("Replace File?"), NULL);
adw_alert_dialog_format_body (ADW_ALERT_DIALOG (dialog),
_("A file named “%s” already exists. Do you want to replace it?"),
filename);
Passed, or left out: a string, or #f.
the heading
Passed, or left out: a string, or #f.
the body text
Returned: a <AdwDialog>.
the newly created <AdwAlertDialog>
Removes a response from self.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed: a string.
the response ID
Sets the body text of self.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed: a string.
the body of self
Sets whether the body text of self includes Pango markup.
See parse-markup.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed: a boolean.
whether to use markup for body text
Sets the ID of the close response of self.
It will be passed to "response" if the dialog is closed by
pressing Escape or with a system action.
It doesn’t have to correspond to any of the responses in the dialog.
The default close response is close.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed: a string.
the close response ID
Sets the ID of the default response of self.
The button corresponding to this response will be set as the default widget of self.
If not set, the default widget will not be set, and the last added response will be focused by default.
See Dialog:default-widget.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed, or left out: a string, or #f.
the default response ID
Sets the child widget of self.
The child widget is displayed below the heading and body.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed, or left out: a <GtkWidget>, or
#f.
the child widget
Sets the heading of self.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed, or left out: a string, or #f.
the heading of self
Sets whether the heading of self includes Pango markup.
See parse-markup.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed: a boolean.
whether to use markup for heading
Whether to prefer horizontal button layout.
<AdwAlertDialog> can present buttons
horizontally or vertically depending on available space, how many
buttons there are and how wide they are.
By default it will prefer to stack buttons vertically at medium sizes.
Set to TRUE to prefer horizontal layout in these cases instead.
This will make the dialog slightly wider as well.
Vertical layout may still be used if the dialog would get too wide otherwise.
Does nothing with just one button, or when the buttons are already horizontal.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed: a boolean.
whether to prefer wide layout
Sets the appearance for response.
Use Adw.ResponseAppearance.suggested to mark important responses
such as the affirmative action, like the Save button in the example.
Use Adw.ResponseAppearance.destructive to draw attention to the
potentially damaging consequences of using response. This
appearance acts as a warning to the user. The Discard button in the
example is using this appearance.
The default appearance is Adw.ResponseAppearance.default.
Negative responses like Cancel or Close should use the default appearance.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed: a string.
a response ID
Passed: a <AdwResponseAppearance>, or
one of its symbols.
appearance for response
Sets whether response is enabled.
If response is not enabled, the corresponding button will have
widget:sensitive set to
FALSE and it can’t be activated as a default response.
response can still be used as AlertDialog:close-response
while it’s not enabled.
Responses are enabled by default.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed: a string.
a response ID
Passed: a boolean.
whether to enable response
Sets the label of response to label.
Labels are displayed on the dialog buttons. An embedded underline in label indicates a mnemonic.
Passed: a <AdwAlertDialog>.
an alert dialog
Passed: a string.
a response ID
Passed: a string.
the label of response
Connect a handler with (connect object alert-dialog:response
handler). It is called as (handler self response).
This signal is emitted when the dialog is closed.
response will be set to the response ID of the button that had been activated.
if the dialog was closed by pressing Escape or with a system
action, response will be set to the value of
AlertDialog:close-response.
Passed: a <AdwAlertDialog>.
Passed: a string.
the response ID
To override it in a new class, give register-type #:vfuncs
`((response . ,procedure)). The procedure is called as
(procedure self response).
Passed: the class whose implementation to call:
<AdwAlertDialog>, or a class that derives from
it, or its GType number.
Passed: a <AdwAlertDialog>.
Passed: a string.