diff options
author | Simon Steinbeiss <simon.steinbeiss@elfenbeinturm.at> | 2019-12-29 00:25:11 +0100 |
---|---|---|
committer | Simon Steinbeiss <simon.steinbeiss@elfenbeinturm.at> | 2020-01-09 23:31:37 +0100 |
commit | aeedd3d763cad1962150b60464c88123d46b0ed0 (patch) | |
tree | 24a99f7884f3228eff535abf52857e5da9442b1f /libxfce4ui/xfce-titled-dialog.c | |
parent | be30e8d224ffc699179780556afea17f2c2d83bf (diff) | |
download | libxfce4ui-aeedd3d763cad1962150b60464c88123d46b0ed0.tar.gz |
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.
Diffstat (limited to 'libxfce4ui/xfce-titled-dialog.c')
-rw-r--r-- | libxfce4ui/xfce-titled-dialog.c | 83 |
1 files changed, 83 insertions, 0 deletions
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: |