[Xfce4-commits] [xfce/libxfce4ui] 04/28: Introduce xfce_titled_dialog_set_default_response

noreply at xfce.org noreply at xfce.org
Thu Jan 9 23:31:47 CET 2020


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/libxfce4ui.

commit aeedd3d763cad1962150b60464c88123d46b0ed0
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Sun Dec 29 00:25:11 2019 +0100

    Introduce xfce_titled_dialog_set_default_response
    
    This function works as a drop-in replacement for
    gtk_dialog_set_default_response and also relies on good portions of the
    original upstream code.
---
 docs/libxfce4ui-sections.txt    |  1 +
 libxfce4ui/xfce-titled-dialog.c | 83 +++++++++++++++++++++++++++++++++++++++++
 libxfce4ui/xfce-titled-dialog.h |  8 ++--
 3 files changed, 89 insertions(+), 3 deletions(-)

diff --git a/docs/libxfce4ui-sections.txt b/docs/libxfce4ui-sections.txt
index 74871fb..fa45b36 100644
--- a/docs/libxfce4ui-sections.txt
+++ b/docs/libxfce4ui-sections.txt
@@ -58,6 +58,7 @@ XfceTitledDialog
 xfce_titled_dialog_new
 xfce_titled_dialog_new_with_buttons
 xfce_titled_dialog_new_with_mixed_buttons
+xfce_titled_dialog_set_default_response
 xfce_titled_dialog_get_subtitle
 xfce_titled_dialog_set_subtitle
 <SUBSECTION Standard>
diff --git a/libxfce4ui/xfce-titled-dialog.c b/libxfce4ui/xfce-titled-dialog.c
index 5cc5027..9bd9c42 100644
--- a/libxfce4ui/xfce-titled-dialog.c
+++ b/libxfce4ui/xfce-titled-dialog.c
@@ -80,6 +80,13 @@ struct _XfceTitledDialogPrivate
   gchar     *subtitle;
 };
 
+typedef struct _ResponseData ResponseData;
+
+struct _ResponseData
+{
+  gint response_id;
+};
+
 
 
 G_DEFINE_TYPE (XfceTitledDialog, xfce_titled_dialog, GTK_TYPE_DIALOG)
@@ -257,6 +264,36 @@ xfce_titled_dialog_update_icon (XfceTitledDialog *titled_dialog)
 
 
 
+static void
+response_data_free (gpointer data)
+{
+  g_slice_free (ResponseData, data);
+}
+
+
+
+static ResponseData *
+get_response_data (GtkWidget *widget,
+                   gboolean   create)
+{
+  ResponseData *ad = g_object_get_data (G_OBJECT (widget),
+                                        "gtk-dialog-response-data");
+
+  if (ad == NULL && create)
+    {
+      ad = g_slice_new (ResponseData);
+
+      g_object_set_data_full (G_OBJECT (widget),
+                              I_("gtk-dialog-response-data"),
+                              ad,
+      response_data_free);
+    }
+
+  return ad;
+}
+
+
+
 /**
  * xfce_titled_dialog_new:
  *
@@ -418,6 +455,52 @@ G_GNUC_END_IGNORE_DEPRECATIONS
 
 
 
+/**
+ * xfce_titled_dialog_set_default_response:
+ * @titled_dialog : a #XfceTitledDialog.
+ * @response_id: a response ID
+ *
+ * Sets the last widget in the dialog’s action area with the given @response_id
+ * as the default widget for the dialog. Pressing “Enter” normally activates
+ * the default widget.
+ *
+ * This function is a replacement for #gtk_dialog_set_default_response, which does
+ * not work with #XfceTitledDialog.
+ *
+ * Since: 4.16
+ *
+ **/
+void
+xfce_titled_dialog_set_default_response (XfceTitledDialog *titled_dialog,
+                                         gint              response_id)
+{
+  GtkWidget *action_area;
+  GList     *children;
+  GList     *tmp_list;
+
+  g_return_if_fail (XFCE_IS_TITLED_DIALOG (titled_dialog));
+
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+  action_area = gtk_dialog_get_action_area (GTK_DIALOG (titled_dialog));
+G_GNUC_END_IGNORE_DEPRECATIONS
+
+  children = gtk_container_get_children (GTK_CONTAINER (action_area));
+  tmp_list = children;
+  while (tmp_list != NULL)
+    {
+      GtkWidget *widget = tmp_list->data;
+      ResponseData *rd = get_response_data (widget, FALSE);
+
+      if (rd && rd->response_id == response_id)
+        gtk_window_set_default (GTK_WINDOW (titled_dialog), widget);
+
+      tmp_list = tmp_list->next;
+    }
+
+  g_list_free (children);
+}
+
+
 
 /**
  * xfce_titled_dialog_get_subtitle:
diff --git a/libxfce4ui/xfce-titled-dialog.h b/libxfce4ui/xfce-titled-dialog.h
index edd61b8..5f99e2d 100644
--- a/libxfce4ui/xfce-titled-dialog.h
+++ b/libxfce4ui/xfce-titled-dialog.h
@@ -81,9 +81,11 @@ GtkWidget            *xfce_titled_dialog_new_with_mixed_buttons (const gchar
                                                                  const gchar    *first_button_text,
                                                                  ...) G_GNUC_MALLOC;
 
-const gchar          *xfce_titled_dialog_get_subtitle     (XfceTitledDialog *titled_dialog);
-void                  xfce_titled_dialog_set_subtitle     (XfceTitledDialog *titled_dialog,
-                                                           const gchar      *subtitle);
+void                  xfce_titled_dialog_set_default_response (XfceTitledDialog *titled_dialog,
+                                                               gint              response_id);
+const gchar          *xfce_titled_dialog_get_subtitle         (XfceTitledDialog *titled_dialog);
+void                  xfce_titled_dialog_set_subtitle         (XfceTitledDialog *titled_dialog,
+                                                               const gchar      *subtitle);
 
 G_END_DECLS
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list