Class MessageDialog

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Native, Root, ShortcutManager, Proxy

@Generated("org.javagi.JavaGI") @Deprecated public class MessageDialog extends Window implements Accessible, Buildable, ConstraintTarget, Native, Root, ShortcutManager
Deprecated.

A dialog presenting a message or a question.

message-dialog

Message 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 MessageDialog::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 MessageDialog: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, AdwMessageDialog is closed automatically.

An example of using a message dialog:

GtkWidget *dialog;

dialog = adw_message_dialog_new (parent, _("Replace File?"), NULL);

adw_message_dialog_format_body (ADW_MESSAGE_DIALOG (dialog),
                                _("A file named “%s” already exists. Do you want to replace it?"),
                                filename);

adw_message_dialog_add_responses (ADW_MESSAGE_DIALOG (dialog),
                                  "cancel",  _("_Cancel"),
                                  "replace", _("_Replace"),
                                  NULL);

adw_message_dialog_set_response_appearance (ADW_MESSAGE_DIALOG (dialog), "replace", ADW_RESPONSE_DESTRUCTIVE);

adw_message_dialog_set_default_response (ADW_MESSAGE_DIALOG (dialog), "cancel");
adw_message_dialog_set_close_response (ADW_MESSAGE_DIALOG (dialog), "cancel");

g_signal_connect (dialog, "response", G_CALLBACK (response_cb), self);

gtk_window_present (GTK_WINDOW (dialog));

Async API

AdwMessageDialog can also be used via the choose(Cancellable, AsyncReadyCallback) method. This API follows the GIO async pattern, for example:

static void
dialog_cb (AdwMessageDialog *dialog,
           GAsyncResult     *result,
           MyWindow         *self)
{
  const char *response = adw_message_dialog_choose_finish (dialog, result);

  // ...
}

static void
show_dialog (MyWindow *self)
{
  GtkWidget *dialog;

  dialog = adw_message_dialog_new (GTK_WINDOW (self), _("Replace File?"), NULL);

  adw_message_dialog_format_body (ADW_MESSAGE_DIALOG (dialog),
                                  _("A file named “%s” already exists. Do you want to replace it?"),
                                  filename);

  adw_message_dialog_add_responses (ADW_MESSAGE_DIALOG (dialog),
                                    "cancel",  _("_Cancel"),
                                    "replace", _("_Replace"),
                                    NULL);

  adw_message_dialog_set_response_appearance (ADW_MESSAGE_DIALOG (dialog), "replace", ADW_RESPONSE_DESTRUCTIVE);

  adw_message_dialog_set_default_response (ADW_MESSAGE_DIALOG (dialog), "cancel");
  adw_message_dialog_set_close_response (ADW_MESSAGE_DIALOG (dialog), "cancel");

  adw_message_dialog_choose (ADW_MESSAGE_DIALOG (dialog), NULL, (GAsyncReadyCallback) dialog_cb, self);
}

AdwMessageDialog as GtkBuildable

AdwMessageDialog 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 setResponseEnabled(String, boolean) and setResponseAppearance(String, ResponseAppearance) for details.

Example of an AdwMessageDialog UI definition:

<object class="AdwMessageDialog" 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>

Accessibility

AdwMessageDialog uses the Gtk.AccessibleRole.dialog role.

Since:
1.2
  • Constructor Details

    • MessageDialog

      public MessageDialog(MemorySegment address)
      Deprecated.
      Create a MessageDialog instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • MessageDialog

      @Deprecated public MessageDialog(@Nullable Window parent, @Nullable String heading, @Nullable String body)
      Deprecated.

      Creates a new AdwMessageDialog.

      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 formatBody(String, Object...) or similar methods afterwards:

      GtkWidget *dialog;
      
      dialog = adw_message_dialog_new (parent, _("Replace File?"), NULL);
      adw_message_dialog_format_body (ADW_MESSAGE_DIALOG (dialog),
                                      _("A file named “%s” already exists.  Do you want to replace it?"),
                                      filename);
      
      Parameters:
      parent - transient parent
      heading - the heading
      body - the body text
      Since:
      1.2
    • MessageDialog

      public MessageDialog()
      Deprecated.
      Create a new MessageDialog.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Deprecated.
      Get the GType of the MessageDialog class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      Deprecated.
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected MessageDialog asParent()
      Deprecated.
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class Window
      Returns:
      the instance as if it were its parent type
    • addResponse

      @Deprecated public void addResponse(String id, String label)
      Deprecated.

      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 MessageDialog::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.

      setResponseLabel(String, String) can be used to change the response label after it had been added.

      setResponseEnabled(String, boolean) and setResponseAppearance(String, ResponseAppearance) can be used to customize the responses further.

      Parameters:
      id - the response ID
      label - the response label
      Since:
      1.2
    • addResponses

      @Deprecated public void addResponses(String firstId, Object... varargs)
      Deprecated.

      Adds multiple responses to self.

      This is the same as calling addResponse(String, String) repeatedly. The variable argument list should be NULL-terminated list of response IDs and labels.

      Example:

      adw_message_dialog_add_responses (dialog,
                                        "cancel",  _("_Cancel"),
                                        "discard", _("_Discard"),
                                        "save",    _("_Save"),
                                        NULL);
      
      Parameters:
      firstId - response id
      varargs - label for first response, then more id-label pairs
      Since:
      1.2
    • choose

      @Deprecated public void choose(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)
      Deprecated.
      This function shows this MessageDialog to the user.
      Parameters:
      cancellable - a GCancellable to cancel the operation
      callback - a callback to call when the operation is complete
      Since:
      1.3
    • chooseFinish

      @Deprecated public String chooseFinish(AsyncResult result)
      Deprecated.
      Finishes the choose(Cancellable, AsyncReadyCallback) call and returns the response ID.
      Parameters:
      result - a GAsyncResult
      Returns:
      the ID of the response that was selected, or MessageDialog:close-response if the call was cancelled.
      Since:
      1.3
    • formatBody

      @Deprecated public void formatBody(String format, Object... varargs)
      Deprecated.

      Sets the formatted body text of self.

      See MessageDialog:body.

      Parameters:
      format - the formatted string for the body text
      varargs - the parameters to insert into format
      Since:
      1.2
    • formatBodyMarkup

      @Deprecated public void formatBodyMarkup(String format, Object... varargs)
      Deprecated.

      Sets the formatted body text of this MessageDialog with Pango markup.

      The format is assumed to contain Pango markup.

      Special XML characters in the printf() arguments passed to this function will automatically be escaped as necessary, see GLib#markupPrintfEscaped.

      See MessageDialog:body.

      Parameters:
      format - the formatted string for the body text with Pango markup
      varargs - the parameters to insert into format
      Since:
      1.2
    • formatHeading

      @Deprecated public void formatHeading(String format, Object... varargs)
      Deprecated.

      Sets the formatted heading of self.

      See MessageDialog:heading.

      Parameters:
      format - the formatted string for the heading
      varargs - the parameters to insert into format
      Since:
      1.2
    • formatHeadingMarkup

      @Deprecated public void formatHeadingMarkup(String format, Object... varargs)
      Deprecated.

      Sets the formatted heading of this MessageDialog with Pango markup.

      The format is assumed to contain Pango markup.

      Special XML characters in the printf() arguments passed to this function will automatically be escaped as necessary, see GLib#markupPrintfEscaped.

      See MessageDialog:heading.

      Parameters:
      format - the formatted string for the heading with Pango markup
      varargs - the parameters to insert into format
      Since:
      1.2
    • getBody

      @Deprecated public String getBody()
      Deprecated.
      Gets the body text of self.
      Returns:
      the body of self.
      Since:
      1.2
    • getBodyUseMarkup

      @Deprecated public boolean getBodyUseMarkup()
      Deprecated.
      Gets whether the body text of this MessageDialog includes Pango markup.
      Returns:
      whether this MessageDialog uses markup for body text
      Since:
      1.2
    • getCloseResponse

      @Deprecated public String getCloseResponse()
      Deprecated.
      Gets the ID of the close response of self.
      Returns:
      the close response ID
      Since:
      1.2
    • getDefaultResponse

      @Deprecated public @Nullable String getDefaultResponse()
      Deprecated.
      Gets the ID of the default response of self.
      Returns:
      the default response ID
      Since:
      1.2
    • getExtraChild

      @Deprecated public @Nullable Widget getExtraChild()
      Deprecated.
      Gets the child widget of self.
      Returns:
      the child widget of self.
      Since:
      1.2
    • getHeading

      @Deprecated public @Nullable String getHeading()
      Deprecated.
      Gets the heading of self.
      Returns:
      the heading of self.
      Since:
      1.2
    • getHeadingUseMarkup

      @Deprecated public boolean getHeadingUseMarkup()
      Deprecated.
      Gets whether the heading of this MessageDialog includes Pango markup.
      Returns:
      whether this MessageDialog uses markup for heading
      Since:
      1.2
    • getResponseAppearance

      @Deprecated public ResponseAppearance getResponseAppearance(String response)
      Deprecated.

      Gets the appearance of response.

      See setResponseAppearance(String, ResponseAppearance).

      Parameters:
      response - a response ID
      Returns:
      the appearance of response
      Since:
      1.2
    • getResponseEnabled

      @Deprecated public boolean getResponseEnabled(String response)
      Deprecated.

      Gets whether response is enabled.

      See setResponseEnabled(String, boolean).

      Parameters:
      response - a response ID
      Returns:
      whether response is enabled
      Since:
      1.2
    • getResponseLabel

      @Deprecated public String getResponseLabel(String response)
      Deprecated.

      Gets the label of response.

      See setResponseLabel(String, String).

      Parameters:
      response - a response ID
      Returns:
      the label of response
      Since:
      1.2
    • hasResponse

      @Deprecated public boolean hasResponse(String response)
      Deprecated.
      Gets whether this MessageDialog has a response with the ID response.
      Parameters:
      response - response ID
      Returns:
      whether this MessageDialog has a response with the ID response.
      Since:
      1.2
    • removeResponse

      @Deprecated public void removeResponse(String id)
      Deprecated.
      Removes a response from self.
      Parameters:
      id - the response ID
      Since:
      1.5
    • response

      @Deprecated public void response(String response)
      Deprecated.

      Emits the MessageDialog::response signal with the given response ID.

      Used to indicate that the user has responded to the dialog in some way.

      Parameters:
      response - response ID
      Since:
      1.2
    • setBody

      @Deprecated public void setBody(String body)
      Deprecated.
      Sets the body text of self.
      Parameters:
      body - the body of this MessageDialog
      Since:
      1.2
    • setBodyUseMarkup

      @Deprecated public void setBodyUseMarkup(boolean useMarkup)
      Deprecated.

      Sets whether the body text of this MessageDialog includes Pango markup.

      See Pango#parseMarkup.

      Parameters:
      useMarkup - whether to use markup for body text
      Since:
      1.2
    • setCloseResponse

      @Deprecated public void setCloseResponse(String response)
      Deprecated.

      Sets the ID of the close response of self.

      It will be passed to MessageDialog::response if the window 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.

      Parameters:
      response - the close response ID
      Since:
      1.2
    • setDefaultResponse

      @Deprecated public void setDefaultResponse(@Nullable String response)
      Deprecated.

      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 Gtk.Window:default-widget.

      Parameters:
      response - the default response ID
      Since:
      1.2
    • setExtraChild

      @Deprecated public void setExtraChild(@Nullable Widget child)
      Deprecated.

      Sets the child widget of self.

      The child widget is displayed below the heading and body.

      Parameters:
      child - the child widget
      Since:
      1.2
    • setHeading

      @Deprecated public void setHeading(@Nullable String heading)
      Deprecated.
      Sets the heading of self.
      Parameters:
      heading - the heading of this MessageDialog
      Since:
      1.2
    • setHeadingUseMarkup

      @Deprecated public void setHeadingUseMarkup(boolean useMarkup)
      Deprecated.

      Sets whether the heading of this MessageDialog includes Pango markup.

      See Pango#parseMarkup.

      Parameters:
      useMarkup - whether to use markup for heading
      Since:
      1.2
    • setResponseAppearance

      @Deprecated public void setResponseAppearance(String response, ResponseAppearance appearance)
      Deprecated.

      Sets the appearance for response.

      message-dialog-appearance

      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.

      Parameters:
      response - a response ID
      appearance - appearance for response
      Since:
      1.2
    • setResponseEnabled

      @Deprecated public void setResponseEnabled(String response, boolean enabled)
      Deprecated.

      Sets whether response is enabled.

      If response is not enabled, the corresponding button will have Gtk.Widget:sensitive set to FALSE and it can't be activated as a default response.

      response can still be used as MessageDialog:close-response while it's not enabled.

      Responses are enabled by default.

      Parameters:
      response - a response ID
      enabled - whether to enable response
      Since:
      1.2
    • setResponseLabel

      @Deprecated public void setResponseLabel(String response, String label)
      Deprecated.

      Sets the label of response to label.

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

      Parameters:
      response - a response ID
      label - the label of response
      Since:
      1.2
    • onResponse

      Deprecated.

      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 MessageDialog:close-response.

      Parameters:
      detail - the signal detail
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      Since:
      1.2
      See Also:
    • emitResponse

      @Deprecated public void emitResponse(@Nullable String detail, String response)
      Deprecated.
      Emits the "response" signal. See onResponse(String, MessageDialog.ResponseCallback).
    • builder

      public static MessageDialog.Builder<? extends MessageDialog.Builder> builder()
      Deprecated.
      A MessageDialog.Builder object constructs a MessageDialog with the specified properties. Use the various set...() methods to set properties, and finish construction with MessageDialog.Builder.build().
      Returns:
      the builder object