gtk+ r19728 - in branches/gtk-2-12: . gtk



Author: federico
Date: Fri Mar  7 03:58:32 2008
New Revision: 19728
URL: http://svn.gnome.org/viewvc/gtk+?rev=19728&view=rev

Log:
bgo505857 - GtkFileChooserDialog ensures its default response
2008-03-06  Federico Mena Quintero  <federico novell com>

	Merged from trunk:

	Fix http://bugzilla.gnome.org/show_bug.cgi?id=505857 -
	GtkFileChooserDialog should set a default response button if the
	app doesn't set it.  Based on a patch by Chris Wang <chris wang sun com>.

	* gtk/gtkfilechooserdialog.c (is_stock_accept_response_id): New
	function, refactor from where there was duplicated code.
	(gtk_file_chooser_dialog_new_valist): If the response ID for the
	button is one of the stock ones, make it the default response
	button.

Signed-off-by: Federico Mena Quintero <federico gnu org>


Modified:
   branches/gtk-2-12/ChangeLog
   branches/gtk-2-12/gtk/gtkfilechooserdialog.c

Modified: branches/gtk-2-12/gtk/gtkfilechooserdialog.c
==============================================================================
--- branches/gtk-2-12/gtk/gtkfilechooserdialog.c	(original)
+++ branches/gtk-2-12/gtk/gtkfilechooserdialog.c	Fri Mar  7 03:58:32 2008
@@ -112,6 +112,15 @@
   G_OBJECT_CLASS (gtk_file_chooser_dialog_parent_class)->finalize (object);  
 }
 
+static gboolean
+is_stock_accept_response_id (int response_id)
+{
+  return (response_id == GTK_RESPONSE_ACCEPT
+	  || response_id == GTK_RESPONSE_OK
+	  || response_id == GTK_RESPONSE_YES
+	  || response_id == GTK_RESPONSE_APPLY);
+}
+
 /* Callback used when the user activates a file in the file chooser widget */
 static void
 file_chooser_widget_file_activated (GtkFileChooser       *chooser,
@@ -135,10 +144,7 @@
 
       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)
+      if (is_stock_accept_response_id (response_id))
 	{
 	  gtk_widget_activate (widget); /* Should we gtk_dialog_response (dialog, response_id) instead? */
 	  break;
@@ -244,10 +250,7 @@
 
       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)
+      if (is_stock_accept_response_id (response_id))
 	{
 	  dialog->priv->response_requested = TRUE;
 	  gtk_widget_activate (widget); /* Should we gtk_dialog_response (dialog, response_id) instead? */
@@ -383,6 +386,26 @@
 }
 #endif
 
+static void
+foreach_ensure_default_response_cb (GtkWidget *widget,
+				    gpointer   data)
+{
+  GtkFileChooserDialog *dialog = GTK_FILE_CHOOSER_DIALOG (data);
+  int response_id;
+
+  response_id = gtk_dialog_get_response_for_widget (GTK_DIALOG (dialog), widget);
+  if (is_stock_accept_response_id (response_id))
+    gtk_dialog_set_default_response (GTK_DIALOG (dialog), response_id);
+}
+
+static void
+ensure_default_response (GtkFileChooserDialog *dialog)
+{
+  gtk_container_foreach (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area),
+			 foreach_ensure_default_response_cb,
+			 dialog);
+}
+
 /* GtkWidget::map handler */
 static void
 gtk_file_chooser_dialog_map (GtkWidget *widget)
@@ -390,6 +413,8 @@
   GtkFileChooserDialog *dialog = GTK_FILE_CHOOSER_DIALOG (widget);
   GtkFileChooserDialogPrivate *priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
 
+  ensure_default_response (dialog);
+
   if (!GTK_WIDGET_MAPPED (priv->widget))
     gtk_widget_map (priv->widget);
 
@@ -427,12 +452,9 @@
   priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
 
   /* 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) &&
-      !priv->response_requested &&
-      !_gtk_file_chooser_embed_should_respond (GTK_FILE_CHOOSER_EMBED (priv->widget)))
+  if (is_stock_accept_response_id (response_id)
+      && !priv->response_requested
+      && !_gtk_file_chooser_embed_should_respond (GTK_FILE_CHOOSER_EMBED (priv->widget)))
     {
       g_signal_stop_emission_by_name (dialog, "response");
     }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]