1.3 <AdwAlertDialog>

Class: <AdwAlertDialog>

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);

Async API

<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 as GtkBuildable

<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>

Fields

parent-instance

Properties

Property: alert-dialog:body self

The body text of the dialog.

Its value is a string, or #f.

Set it with (set! (alert-dialog:body self) value).

Property: alert-dialog:body-use-markup self

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).

Property: alert-dialog:close-response self

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).

Property: alert-dialog:default-response self

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).

Property: alert-dialog:extra-child self

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).

Property: alert-dialog:heading self

The heading of the dialog.

Its value is a string, or #f.

Set it with (set! (alert-dialog:heading self) value).

Property: alert-dialog:heading-use-markup self

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).

Property: alert-dialog:prefer-wide-layout self

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).

Procedures

Method: alert-dialog:add-response self id label
Method: add-response self id label

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.

self

Passed: a <AdwAlertDialog>.

an alert dialog

id

Passed: a string.

the response ID

label

Passed: a string.

the response label

Method: alert-dialog:choose self [parent] [cancellable] [callback]
Method: choose self [parent] [cancellable] [callback]

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.

self

Passed: a <AdwAlertDialog>.

an alert dialog

parent

Passed, or left out: a <GtkWidget>, or #f.

the parent widget

cancellable

Passed, or left out: a <GCancellable>, or #f.

a <GCancellable> to cancel the operation

callback

Passed, or left out: a procedure, or #f.

a callback to call when the operation is complete

See GAsyncReadyCallback for how it is called.

user-data

Not passed: guile-gi supplies it.

data to pass to callback

Method: alert-dialog:choose-finish self result ⇒ %return
Method: choose-finish self result ⇒ %return

Finishes the AlertDialog.choose call and returns the response ID.

self

Passed: a <AdwAlertDialog>.

an alert dialog

result

Passed: a <GAsyncResult>.

a <GAsyncResult>

%return

Returned: a string.

the ID of the response that was selected, or AlertDialog:close-response if the call was cancelled.

Method: alert-dialog:get-body self ⇒ %return
Method: get-body self ⇒ %return

Gets the body text of self.

self

Passed: a <AdwAlertDialog>.

an alert dialog

%return

Returned: a string.

the body of self.

Method: alert-dialog:get-body-use-markup? self ⇒ %return
Method: get-body-use-markup? self ⇒ %return

Gets whether the body text of self includes Pango markup.

self

Passed: a <AdwAlertDialog>.

an alert dialog

%return

Returned: a boolean.

whether self uses markup for body text

Method: alert-dialog:get-close-response self ⇒ %return
Method: get-close-response self ⇒ %return

Gets the ID of the close response of self.

self

Passed: a <AdwAlertDialog>.

an alert dialog

%return

Returned: a string.

the close response ID

Method: alert-dialog:get-default-response self ⇒ %return
Method: get-default-response self ⇒ %return

Gets the ID of the default response of self.

self

Passed: a <AdwAlertDialog>.

an alert dialog

%return

Returned: a string, or #f.

the default response ID

Method: alert-dialog:get-extra-child self ⇒ %return
Method: get-extra-child self ⇒ %return

Gets the child widget of self.

self

Passed: a <AdwAlertDialog>.

an alert dialog

%return

Returned: a <GtkWidget>, or #f.

the child widget of self.

Method: alert-dialog:get-heading self ⇒ %return
Method: get-heading self ⇒ %return

Gets the heading of self.

self

Passed: a <AdwAlertDialog>.

an alert dialog

%return

Returned: a string, or #f.

the heading of self.

Method: alert-dialog:get-heading-use-markup? self ⇒ %return
Method: get-heading-use-markup? self ⇒ %return

Gets whether the heading of self includes Pango markup.

self

Passed: a <AdwAlertDialog>.

an alert dialog

%return

Returned: a boolean.

whether self uses markup for heading

Method: alert-dialog:get-prefer-wide-layout? self ⇒ %return
Method: get-prefer-wide-layout? self ⇒ %return

Gets whether self prefers horizontal button layout.

self

Passed: a <AdwAlertDialog>.

an alert dialog

%return

Returned: a boolean.

whether to prefer wide layout

Method: alert-dialog:get-response-appearance self response ⇒ %return
Method: get-response-appearance self response ⇒ %return

Gets the appearance of response.

See AlertDialog.set_response_appearance.

self

Passed: a <AdwAlertDialog>.

an alert dialog

response

Passed: a string.

a response ID

%return

Returned: a <AdwResponseAppearance>.

the appearance of response

Method: alert-dialog:get-response-enabled? self response ⇒ %return
Method: get-response-enabled? self response ⇒ %return

Gets whether response is enabled.

See AlertDialog.set_response_enabled.

self

Passed: a <AdwAlertDialog>.

an alert dialog

response

Passed: a string.

a response ID

%return

Returned: a boolean.

whether response is enabled

Method: alert-dialog:get-response-label self response ⇒ %return
Method: get-response-label self response ⇒ %return

Gets the label of response.

See AlertDialog.set_response_label.

self

Passed: a <AdwAlertDialog>.

an alert dialog

response

Passed: a string.

a response ID

%return

Returned: a string.

the label of response

Method: alert-dialog:has-response? self response ⇒ %return
Method: has-response? self response ⇒ %return

Gets whether self has a response with the ID response.

self

Passed: a <AdwAlertDialog>.

an alert dialog

response

Passed: a string.

response ID

%return

Returned: a boolean.

whether self has a response with the ID response.

Procedure: alert-dialog:new [heading] [body] ⇒ %return

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);
heading

Passed, or left out: a string, or #f.

the heading

body

Passed, or left out: a string, or #f.

the body text

%return

Returned: a <AdwDialog>.

the newly created <AdwAlertDialog>

Method: alert-dialog:remove-response self id
Method: remove-response self id

Removes a response from self.

self

Passed: a <AdwAlertDialog>.

an alert dialog

id

Passed: a string.

the response ID

Method: alert-dialog:set-body self body
Method: set-body self body

Sets the body text of self.

self

Passed: a <AdwAlertDialog>.

an alert dialog

body

Passed: a string.

the body of self

Method: alert-dialog:set-body-use-markup self use-markup
Method: set-body-use-markup self use-markup

Sets whether the body text of self includes Pango markup.

See parse-markup.

self

Passed: a <AdwAlertDialog>.

an alert dialog

use-markup

Passed: a boolean.

whether to use markup for body text

Method: alert-dialog:set-close-response self response
Method: set-close-response self response

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.

self

Passed: a <AdwAlertDialog>.

an alert dialog

response

Passed: a string.

the close response ID

Method: alert-dialog:set-default-response self [response]
Method: set-default-response self [response]

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.

self

Passed: a <AdwAlertDialog>.

an alert dialog

response

Passed, or left out: a string, or #f.

the default response ID

Method: alert-dialog:set-extra-child self [child]
Method: set-extra-child self [child]

Sets the child widget of self.

The child widget is displayed below the heading and body.

self

Passed: a <AdwAlertDialog>.

an alert dialog

child

Passed, or left out: a <GtkWidget>, or #f.

the child widget

Method: alert-dialog:set-heading self [heading]
Method: set-heading self [heading]

Sets the heading of self.

self

Passed: a <AdwAlertDialog>.

an alert dialog

heading

Passed, or left out: a string, or #f.

the heading of self

Method: alert-dialog:set-heading-use-markup self use-markup
Method: set-heading-use-markup self use-markup

Sets whether the heading of self includes Pango markup.

See parse-markup.

self

Passed: a <AdwAlertDialog>.

an alert dialog

use-markup

Passed: a boolean.

whether to use markup for heading

Method: alert-dialog:set-prefer-wide-layout self prefer-wide-layout
Method: set-prefer-wide-layout self prefer-wide-layout

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.

self

Passed: a <AdwAlertDialog>.

an alert dialog

prefer-wide-layout

Passed: a boolean.

whether to prefer wide layout

Method: alert-dialog:set-response-appearance self response appearance
Method: set-response-appearance self response appearance

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.

self

Passed: a <AdwAlertDialog>.

an alert dialog

response

Passed: a string.

a response ID

appearance

Passed: a <AdwResponseAppearance>, or one of its symbols.

appearance for response

Method: alert-dialog:set-response-enabled self response enabled
Method: set-response-enabled self response enabled

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.

self

Passed: a <AdwAlertDialog>.

an alert dialog

response

Passed: a string.

a response ID

enabled

Passed: a boolean.

whether to enable response

Method: alert-dialog:set-response-label self response label
Method: set-response-label self response label

Sets the label of response to label.

Labels are displayed on the dialog buttons. An embedded underline in label indicates a mnemonic.

self

Passed: a <AdwAlertDialog>.

an alert dialog

response

Passed: a string.

a response ID

label

Passed: a string.

the label of response

Signals

Signal: alert-dialog: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.

self

Passed: a <AdwAlertDialog>.

response

Passed: a string.

the response ID

Virtual methods

Virtual method: alert-dialog:do-response implementor self response

To override it in a new class, give register-type #:vfuncs `((response . ,procedure)). The procedure is called as (procedure self response).

implementor

Passed: the class whose implementation to call: <AdwAlertDialog>, or a class that derives from it, or its GType number.

self

Passed: a <AdwAlertDialog>.

response

Passed: a string.