Don't ignore the return value of gtk_widget_activate().

2004-03-12  Federico Mena Quintero  <federico@ximian.com>

	* gtk/gtkwindow.c (gtk_window_activate_focus): Don't ignore the
	return value of gtk_widget_activate().
	(gtk_window_activate_default): Likewise.  Fixes #137008.

	* gtk/gtkfilechooserdialog.c (response_cb): Act on positive
	response IDs we recognize, rather than bailing out on cancellation
	ones.  Fixes #136237; patch by Olivier Andrieu
	<oliv__a@users.sourceforge.net>.
	(file_chooser_widget_file_activated): If the dialog doesn't have a
	default widget, try to find a suitable response widget on our own.
	People should *really* be using gtk_dialog_set_default_response(),
	but this is to help lazy programmers.

	* gtk/gtkdialog.c (_gtk_dialog_get_response_for_widget): New
	internal function.
	(get_response_data): Add a "create" argument so that we don't
	unconditionally create the response data.
This commit is contained in:
Federico Mena Quintero 2004-03-12 20:38:54 +00:00 committed by Federico Mena Quintero
parent c2ddd0e23c
commit edf8e6f580
9 changed files with 162 additions and 31 deletions

View File

@ -1,3 +1,23 @@
2004-03-12 Federico Mena Quintero <federico@ximian.com>
* gtk/gtkwindow.c (gtk_window_activate_focus): Don't ignore the
return value of gtk_widget_activate().
(gtk_window_activate_default): Likewise. Fixes #137008.
* gtk/gtkfilechooserdialog.c (response_cb): Act on positive
response IDs we recognize, rather than bailing out on cancellation
ones. Fixes #136237; patch by Olivier Andrieu
<oliv__a@users.sourceforge.net>.
(file_chooser_widget_file_activated): If the dialog doesn't have a
default widget, try to find a suitable response widget on our own.
People should *really* be using gtk_dialog_set_default_response(),
but this is to help lazy programmers.
* gtk/gtkdialog.c (_gtk_dialog_get_response_for_widget): New
internal function.
(get_response_data): Add a "create" argument so that we don't
unconditionally create the response data.
2004-03-12 Morten Welinder <terra@gnome.org>
* tests/Makefile.am: Add new testspinbutton.c

View File

@ -1,3 +1,23 @@
2004-03-12 Federico Mena Quintero <federico@ximian.com>
* gtk/gtkwindow.c (gtk_window_activate_focus): Don't ignore the
return value of gtk_widget_activate().
(gtk_window_activate_default): Likewise. Fixes #137008.
* gtk/gtkfilechooserdialog.c (response_cb): Act on positive
response IDs we recognize, rather than bailing out on cancellation
ones. Fixes #136237; patch by Olivier Andrieu
<oliv__a@users.sourceforge.net>.
(file_chooser_widget_file_activated): If the dialog doesn't have a
default widget, try to find a suitable response widget on our own.
People should *really* be using gtk_dialog_set_default_response(),
but this is to help lazy programmers.
* gtk/gtkdialog.c (_gtk_dialog_get_response_for_widget): New
internal function.
(get_response_data): Add a "create" argument so that we don't
unconditionally create the response data.
2004-03-12 Morten Welinder <terra@gnome.org>
* tests/Makefile.am: Add new testspinbutton.c

View File

@ -1,3 +1,23 @@
2004-03-12 Federico Mena Quintero <federico@ximian.com>
* gtk/gtkwindow.c (gtk_window_activate_focus): Don't ignore the
return value of gtk_widget_activate().
(gtk_window_activate_default): Likewise. Fixes #137008.
* gtk/gtkfilechooserdialog.c (response_cb): Act on positive
response IDs we recognize, rather than bailing out on cancellation
ones. Fixes #136237; patch by Olivier Andrieu
<oliv__a@users.sourceforge.net>.
(file_chooser_widget_file_activated): If the dialog doesn't have a
default widget, try to find a suitable response widget on our own.
People should *really* be using gtk_dialog_set_default_response(),
but this is to help lazy programmers.
* gtk/gtkdialog.c (_gtk_dialog_get_response_for_widget): New
internal function.
(get_response_data): Add a "create" argument so that we don't
unconditionally create the response data.
2004-03-12 Morten Welinder <terra@gnome.org>
* tests/Makefile.am: Add new testspinbutton.c

View File

@ -1,3 +1,23 @@
2004-03-12 Federico Mena Quintero <federico@ximian.com>
* gtk/gtkwindow.c (gtk_window_activate_focus): Don't ignore the
return value of gtk_widget_activate().
(gtk_window_activate_default): Likewise. Fixes #137008.
* gtk/gtkfilechooserdialog.c (response_cb): Act on positive
response IDs we recognize, rather than bailing out on cancellation
ones. Fixes #136237; patch by Olivier Andrieu
<oliv__a@users.sourceforge.net>.
(file_chooser_widget_file_activated): If the dialog doesn't have a
default widget, try to find a suitable response widget on our own.
People should *really* be using gtk_dialog_set_default_response(),
but this is to help lazy programmers.
* gtk/gtkdialog.c (_gtk_dialog_get_response_for_widget): New
internal function.
(get_response_data): Add a "create" argument so that we don't
unconditionally create the response data.
2004-03-12 Morten Welinder <terra@gnome.org>
* tests/Makefile.am: Add new testspinbutton.c

View File

@ -1,3 +1,23 @@
2004-03-12 Federico Mena Quintero <federico@ximian.com>
* gtk/gtkwindow.c (gtk_window_activate_focus): Don't ignore the
return value of gtk_widget_activate().
(gtk_window_activate_default): Likewise. Fixes #137008.
* gtk/gtkfilechooserdialog.c (response_cb): Act on positive
response IDs we recognize, rather than bailing out on cancellation
ones. Fixes #136237; patch by Olivier Andrieu
<oliv__a@users.sourceforge.net>.
(file_chooser_widget_file_activated): If the dialog doesn't have a
default widget, try to find a suitable response widget on our own.
People should *really* be using gtk_dialog_set_default_response(),
but this is to help lazy programmers.
* gtk/gtkdialog.c (_gtk_dialog_get_response_for_widget): New
internal function.
(get_response_data): Add a "create" argument so that we don't
unconditionally create the response data.
2004-03-12 Morten Welinder <terra@gnome.org>
* tests/Makefile.am: Add new testspinbutton.c

View File

@ -74,7 +74,8 @@ static void gtk_dialog_map (GtkWidget *widget);
static void gtk_dialog_close (GtkDialog *dialog);
static ResponseData* get_response_data (GtkWidget *widget);
static ResponseData* get_response_data (GtkWidget *widget,
gboolean create);
enum {
PROP_0,
@ -378,7 +379,7 @@ dialog_has_cancel (GtkDialog *dialog)
for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
{
ResponseData *rd = get_response_data (tmp_list->data);
ResponseData *rd = get_response_data (tmp_list->data, FALSE);
if (rd && rd->response_id == GTK_RESPONSE_CANCEL)
{
@ -510,12 +511,13 @@ gtk_dialog_new_with_buttons (const gchar *title,
}
static ResponseData*
get_response_data (GtkWidget *widget)
get_response_data (GtkWidget *widget,
gboolean create)
{
ResponseData *ad = g_object_get_data (G_OBJECT (widget),
"gtk-dialog-response-data");
if (ad == NULL)
if (ad == NULL && create)
{
ad = g_new (ResponseData, 1);
@ -538,7 +540,7 @@ action_widget_activated (GtkWidget *widget, GtkDialog *dialog)
response_id = GTK_RESPONSE_NONE;
ad = get_response_data (widget);
ad = get_response_data (widget, TRUE);
g_assert (ad != NULL);
@ -571,7 +573,7 @@ gtk_dialog_add_action_widget (GtkDialog *dialog,
g_return_if_fail (GTK_IS_DIALOG (dialog));
g_return_if_fail (GTK_IS_WIDGET (child));
ad = get_response_data (child);
ad = get_response_data (child, TRUE);
ad->response_id = response_id;
@ -1035,3 +1037,16 @@ _gtk_dialog_set_ignore_separator (GtkDialog *dialog,
priv = GET_PRIVATE (dialog);
priv->ignore_separator = ignore_separator;
}
gint
_gtk_dialog_get_response_for_widget (GtkDialog *dialog,
GtkWidget *widget)
{
ResponseData *rd;
rd = get_response_data (widget, FALSE);
if (!rd)
return GTK_RESPONSE_NONE;
else
return rd->response_id;
}

View File

@ -163,6 +163,8 @@ gint gtk_dialog_run (GtkDialog *dialog);
/* For private use only */
void _gtk_dialog_set_ignore_separator (GtkDialog *dialog,
gboolean ignore_separator);
gint _gtk_dialog_get_response_for_widget (GtkDialog *dialog,
GtkWidget *widget);
#ifdef __cplusplus
}

View File

@ -162,7 +162,35 @@ static void
file_chooser_widget_file_activated (GtkFileChooser *chooser,
GtkFileChooserDialog *dialog)
{
gtk_window_activate_default (GTK_WINDOW (dialog));
GList *children, *l;
if (gtk_window_activate_default (GTK_WINDOW (dialog)))
return;
/* There probably isn't a default widget, so make things easier for the
* programmer by looking for a reasonable button on our own.
*/
children = gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area));
for (l = children; l; l = l->next)
{
GtkWidget *widget;
int response_id;
widget = GTK_WIDGET (l->data);
response_id = _gtk_dialog_get_response_for_widget (GTK_DIALOG (dialog), widget);
if (response_id == GTK_RESPONSE_ACCEPT
|| response_id == GTK_RESPONSE_OK
|| response_id == GTK_RESPONSE_YES
|| response_id == GTK_RESPONSE_APPLY)
{
gtk_widget_activate (widget); /* Should we gtk_dialog_response (dialog, response_id) instead? */
break;
}
}
g_list_free (children);
}
static void
@ -465,14 +493,11 @@ response_cb (GtkDialog *dialog,
priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
/* Ugh, try to filter out cancel-type responses */
if (response_id == GTK_RESPONSE_NONE
|| response_id == GTK_RESPONSE_REJECT
|| response_id == GTK_RESPONSE_DELETE_EVENT
|| response_id == GTK_RESPONSE_CANCEL
|| response_id == GTK_RESPONSE_CLOSE
|| response_id == GTK_RESPONSE_NO
|| response_id == GTK_RESPONSE_HELP)
/* Act only on response IDs we recognize */
if (!(response_id == GTK_RESPONSE_ACCEPT
|| response_id == GTK_RESPONSE_OK
|| response_id == GTK_RESPONSE_YES
|| response_id == GTK_RESPONSE_APPLY))
return;
if (!_gtk_file_chooser_embed_should_respond (GTK_FILE_CHOOSER_EMBED (priv->widget)))

View File

@ -1571,12 +1571,8 @@ gtk_window_activate_focus (GtkWindow *window)
{
g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
if (window->focus_widget)
{
if (GTK_WIDGET_IS_SENSITIVE (window->focus_widget))
gtk_widget_activate (window->focus_widget);
return TRUE;
}
if (window->focus_widget && GTK_WIDGET_IS_SENSITIVE (window->focus_widget))
return gtk_widget_activate (window->focus_widget);
return FALSE;
}
@ -1619,16 +1615,9 @@ gtk_window_activate_default (GtkWindow *window)
if (window->default_widget && GTK_WIDGET_IS_SENSITIVE (window->default_widget) &&
(!window->focus_widget || !GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget)))
{
gtk_widget_activate (window->default_widget);
return TRUE;
}
else if (window->focus_widget)
{
if (GTK_WIDGET_IS_SENSITIVE (window->focus_widget))
gtk_widget_activate (window->focus_widget);
return TRUE;
}
return gtk_widget_activate (window->default_widget);
else if (window->focus_widget && GTK_WIDGET_IS_SENSITIVE (window->focus_widget))
return gtk_widget_activate (window->focus_widget);
return FALSE;
}