From: Owen Taylor Date: Sat, 14 Dec 2002 00:14:54 +0000 (+0000) Subject: Change the Escape key binding to only close if the dialog contains a X-Git-Url: http://pileus.org/git/?p=~andy%2Fgtk;a=commitdiff_plain;h=59f712ad5f622d40ebd854dfa8d0882730adf106 Change the Escape key binding to only close if the dialog contains a Fri Dec 13 18:57:20 2002 Owen Taylor * gtk/gtkdialog.c: Change the Escape key binding to only close if the dialog contains a cancel button. (Patch from James Willcox, #74221) --- diff --git a/ChangeLog b/ChangeLog index 056898de3..7af59c513 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Dec 13 18:57:20 2002 Owen Taylor + + * gtk/gtkdialog.c: Change the Escape key binding to only close + if the dialog contains a cancel button. (Patch from + James Willcox, #74221) + Fri Dec 13 18:22:21 2002 Owen Taylor * gtk/gtkfilesel.c (compare_cmpl_dir): Use diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 056898de3..7af59c513 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,9 @@ +Fri Dec 13 18:57:20 2002 Owen Taylor + + * gtk/gtkdialog.c: Change the Escape key binding to only close + if the dialog contains a cancel button. (Patch from + James Willcox, #74221) + Fri Dec 13 18:22:21 2002 Owen Taylor * gtk/gtkfilesel.c (compare_cmpl_dir): Use diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 056898de3..7af59c513 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,9 @@ +Fri Dec 13 18:57:20 2002 Owen Taylor + + * gtk/gtkdialog.c: Change the Escape key binding to only close + if the dialog contains a cancel button. (Patch from + James Willcox, #74221) + Fri Dec 13 18:22:21 2002 Owen Taylor * gtk/gtkfilesel.c (compare_cmpl_dir): Use diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 056898de3..7af59c513 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,9 @@ +Fri Dec 13 18:57:20 2002 Owen Taylor + + * gtk/gtkdialog.c: Change the Escape key binding to only close + if the dialog contains a cancel button. (Patch from + James Willcox, #74221) + Fri Dec 13 18:22:21 2002 Owen Taylor * gtk/gtkfilesel.c (compare_cmpl_dir): Use diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 056898de3..7af59c513 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,9 @@ +Fri Dec 13 18:57:20 2002 Owen Taylor + + * gtk/gtkdialog.c: Change the Escape key binding to only close + if the dialog contains a cancel button. (Patch from + James Willcox, #74221) + Fri Dec 13 18:22:21 2002 Owen Taylor * gtk/gtkfilesel.c (compare_cmpl_dir): Use diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 056898de3..7af59c513 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,9 @@ +Fri Dec 13 18:57:20 2002 Owen Taylor + + * gtk/gtkdialog.c: Change the Escape key binding to only close + if the dialog contains a cancel button. (Patch from + James Willcox, #74221) + Fri Dec 13 18:22:21 2002 Owen Taylor * gtk/gtkfilesel.c (compare_cmpl_dir): Use diff --git a/gtk/gtkdialog.c b/gtk/gtkdialog.c index a2379aa19..c70b1541b 100644 --- a/gtk/gtkdialog.c +++ b/gtk/gtkdialog.c @@ -35,6 +35,13 @@ #include "gtkintl.h" #include "gtkbindings.h" +typedef struct _ResponseData ResponseData; + +struct _ResponseData +{ + gint response_id; +}; + static void gtk_dialog_class_init (GtkDialogClass *klass); static void gtk_dialog_init (GtkDialog *dialog); @@ -60,6 +67,8 @@ static void gtk_dialog_map (GtkWidget *widget); static void gtk_dialog_close (GtkDialog *dialog); +static ResponseData* get_response_data (GtkWidget *widget); + enum { PROP_0, PROP_HAS_SEPARATOR @@ -345,15 +354,42 @@ gtk_dialog_style_set (GtkWidget *widget, update_spacings (GTK_DIALOG (widget)); } +static gboolean +dialog_has_cancel (GtkDialog *dialog) +{ + GList *children, *tmp_list; + gboolean ret = FALSE; + + children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area)); + + for (tmp_list = children; tmp_list; tmp_list = tmp_list->next) + { + ResponseData *rd = get_response_data (tmp_list->data); + + if (rd && rd->response_id == GTK_RESPONSE_CANCEL) + { + ret = TRUE; + break; + } + } + + g_list_free (children); + + return ret; +} + static void gtk_dialog_close (GtkDialog *dialog) { /* Synthesize delete_event to close dialog. */ - GdkEvent *event = gdk_event_new (GDK_DELETE); - GtkWidget *widget; + GtkWidget *widget = GTK_WIDGET (dialog); + GdkEvent *event; - widget = GTK_WIDGET (dialog); + if (!dialog_has_cancel (dialog)) + return; + + event = gdk_event_new (GDK_DELETE); event->any.window = g_object_ref (widget->window); event->any.send_event = TRUE; @@ -459,13 +495,6 @@ gtk_dialog_new_with_buttons (const gchar *title, return GTK_WIDGET (dialog); } -typedef struct _ResponseData ResponseData; - -struct _ResponseData -{ - gint response_id; -}; - static ResponseData* get_response_data (GtkWidget *widget) {