[gtk+] filechooserbutton: Restore to an empty previous selection properly



commit cf921c353b074a5ba17a1b823e7ac673c1226735
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Feb 13 11:01:50 2013 -0600

    filechooserbutton: Restore to an empty previous selection properly
    
    If no file was originally selected in the GtkFileChooserButton, then its
    internal dialog is brought up and cancelled, then we need to restore the
    selection back to none.  GtkFileChooser, though, doesn't like to
    select a NULL file, so call _unselect_all() in that condition.
    
    Signed-off-by: Federico Mena Quintero <federico gnome org>

 gtk/gtkfilechooserbutton.c |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c
index ba2a445..4604cdd 100644
--- a/gtk/gtkfilechooserbutton.c
+++ b/gtk/gtkfilechooserbutton.c
@@ -2555,6 +2555,17 @@ fs_bookmarks_changed_cb (GtkFileSystem *fs,
   update_combo_box (user_data);
 }
 
+static void
+restore_inactive_selection (GtkFileChooserButton *button)
+{
+  GtkFileChooserButtonPrivate *priv = button->priv;
+
+  if (priv->selection_while_inactive)
+    gtk_file_chooser_select_file (GTK_FILE_CHOOSER (priv->dialog), priv->selection_while_inactive, NULL);
+  else
+    gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (priv->dialog));
+}
+
 /* Dialog */
 static void
 open_dialog (GtkFileChooserButton *button)
@@ -2589,7 +2600,7 @@ open_dialog (GtkFileChooserButton *button)
       g_signal_handler_block (priv->dialog,
                              priv->dialog_selection_changed_id);
 
-      gtk_file_chooser_select_file (GTK_FILE_CHOOSER (priv->dialog), priv->selection_while_inactive, NULL);
+      restore_inactive_selection (button);
 
       priv->active = TRUE;
     }
@@ -2772,12 +2783,10 @@ dialog_response_cb (GtkDialog *dialog,
       update_label_and_image (button);
       update_combo_box (button);
     }
-  else if (priv->selection_while_inactive)
+  else
     {
-      gtk_file_chooser_select_file (GTK_FILE_CHOOSER (dialog), priv->selection_while_inactive, NULL);
+      restore_inactive_selection (button);
     }
-  else
-    gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (dialog));
 
   if (priv->active)
     {


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