[gtk+] [GtkFileChooser] Fix initial selection when hidden files are shown



commit 6c4196e9e4b66aef4054cca0597f9799654ae43a
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Feb 24 14:53:09 2011 -0600

    [GtkFileChooser] Fix initial selection when hidden files are shown
    
    We were breaking prematurely out of the loop that goes through
    each file that is pending selection; not only does that loop
    disable filtering and show hidden files if needed, but it also
    selects the files themselves.  So we need to walk the whole
    list of files.
    
    Signed-off-by: Federico Mena Quintero <federico gnome org>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=643170

 gtk/gtkfilechooserdefault.c |   43 +++++++++++++++++++++++++++++++------------
 1 files changed, 31 insertions(+), 12 deletions(-)
---
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index e86175f..034c232 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -6229,20 +6229,25 @@ show_and_select_files (GtkFileChooserDefault *impl,
 {
   GtkTreeSelection *selection;
   GtkFileSystemModel *fsmodel;
-  gboolean can_have_hidden, can_have_filtered, selected_a_file;
+  gboolean enabled_hidden, removed_filters;
+  gboolean selected_a_file;
   GSList *walk;
 
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
   fsmodel = GTK_FILE_SYSTEM_MODEL (gtk_tree_view_get_model (GTK_TREE_VIEW (impl->browse_files_tree_view)));
-  can_have_hidden = !impl->show_hidden;
-  can_have_filtered = impl->current_filter != NULL;
+
+  enabled_hidden = impl->show_hidden;
+  removed_filters = (impl->current_filter == NULL);
+
   selected_a_file = FALSE;
 
-  for (walk = files; walk && (can_have_hidden || can_have_filtered); walk = walk->next)
+  for (walk = files; walk; walk = walk->next)
     {
       GFile *file = walk->data;
       GtkTreeIter iter;
 
+      /* Is it a hidden file? */
+
       if (!_gtk_file_system_model_get_iter_for_file (fsmodel, &iter, file))
         continue;
 
@@ -6250,21 +6255,35 @@ show_and_select_files (GtkFileChooserDefault *impl,
         {
           GFileInfo *info = _gtk_file_system_model_get_info (fsmodel, &iter);
 
-          if (can_have_hidden &&
+          if (!enabled_hidden &&
               (g_file_info_get_is_hidden (info) ||
                g_file_info_get_is_backup (info)))
             {
               g_object_set (impl, "show-hidden", TRUE, NULL);
-              can_have_hidden = FALSE;
-            }
-
-          if (can_have_filtered)
-            {
-              set_current_filter (impl, NULL);
-              can_have_filtered = FALSE;
+              enabled_hidden = TRUE;
             }
         }
+
+      /* Is it a filtered file? */
+
+      if (!_gtk_file_system_model_get_iter_for_file (fsmodel, &iter, file))
+        continue; /* re-get the iter as it may change when the model refilters */
+
+      if (!_gtk_file_system_model_iter_is_visible (fsmodel, &iter))
+        {
+	  /* Maybe we should have a way to ask the fsmodel if it had filtered a file */
+	  if (!removed_filters)
+	    {
+	      set_current_filter (impl, NULL);
+	      removed_filters = TRUE;
+	    }
+	}
+
+      /* Okay, can we select the file now? */
           
+      if (!_gtk_file_system_model_get_iter_for_file (fsmodel, &iter, file))
+        continue;
+
       if (_gtk_file_system_model_iter_is_visible (fsmodel, &iter))
         {
           GtkTreePath *path;



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