[gtk+/gtk-2-24] filechooserbutton: Simplify the code to preserve the selection while the dialog is running



commit 69bf331c980c576ad474e2388c6a7d4be8dd19f0
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Feb 11 19:33:17 2013 -0600

    filechooserbutton: Simplify the code to preserve the selection while the dialog is running
    
    It used to fetch a possibly multiple selection from the GtkFileChooserDialog, and then
    pick just the first item from the selection list.  But since GtkFileChooserButton
    operates in single-selection mode only, it can simply use gtk_file_chooser_get_file()
    instead.
    
    Also, the right way to reset the selection for GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
    is with gtk_file_chooser_select_file(), not with _set_current_folder_file().
    
    Signed-off-by: Federico Mena Quintero <federico gnome org>

 gtk/gtkfilechooserbutton.c |   30 +++---------------------------
 1 files changed, 3 insertions(+), 27 deletions(-)
---
diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c
index ddc54ee..efb346a3 100644
--- a/gtk/gtkfilechooserbutton.c
+++ b/gtk/gtkfilechooserbutton.c
@@ -633,7 +633,6 @@ gtk_file_chooser_button_constructor (GType                  type,
   GtkFileChooserButton *button;
   GtkFileChooserButtonPrivate *priv;
   GSList *list;
-  char *current_folder;
 
   object = G_OBJECT_CLASS (gtk_file_chooser_button_parent_class)->constructor (type,
 									       n_params,
@@ -1141,8 +1140,6 @@ gtk_file_chooser_button_hide (GtkWidget *widget)
 static void
 gtk_file_chooser_button_map (GtkWidget *widget)
 {
-  GtkFileChooserButton *button = GTK_FILE_CHOOSER_BUTTON (widget);
-
   GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->map (widget);
 }
 
@@ -2447,23 +2444,15 @@ open_dialog (GtkFileChooserButton *button)
 
   if (!priv->active)
     {
-      GSList *files;
-
       g_signal_handler_block (priv->dialog,
 			      priv->dialog_folder_changed_id);
       g_signal_handler_block (priv->dialog,
 			      priv->dialog_file_activated_id);
       g_signal_handler_block (priv->dialog,
 			      priv->dialog_selection_changed_id);
-      files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (priv->dialog));
-      if (files)
-	{
-	  if (files->data)
-	    priv->old_file = g_object_ref (files->data);
 
-	  g_slist_foreach (files, (GFunc) g_object_unref, NULL);
-	  g_slist_free (files);
-	}
+      g_assert (priv->old_file == NULL);
+      priv->old_file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (priv->dialog));
 
       priv->active = TRUE;
     }
@@ -2643,20 +2632,7 @@ dialog_response_cb (GtkDialog *dialog,
     }
   else if (priv->old_file)
     {
-      switch (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)))
-	{
-	case GTK_FILE_CHOOSER_ACTION_OPEN:
-	  gtk_file_chooser_select_file (GTK_FILE_CHOOSER (dialog), priv->old_file,
-					NULL);
-	  break;
-	case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
-	  gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog),
-						    priv->old_file, NULL);
-	  break;
-	default:
-	  g_assert_not_reached ();
-	  break;
-	}
+      gtk_file_chooser_select_file (GTK_FILE_CHOOSER (dialog), priv->old_file, NULL);
     }
   else
     gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (dialog));


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