From b6bf9112ad0316b0746f03e7458d8559eafb8481 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Thu, 24 Feb 2011 14:53:09 -0600 Subject: [PATCH] [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 https://bugzilla.gnome.org/show_bug.cgi?id=643170 --- gtk/gtkfilechooserdefault.c | 43 ++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index ccf205f6b1..8d29f9fbc9 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -6345,20 +6345,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; @@ -6366,21 +6371,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)) { gtk_tree_selection_select_iter (selection, &iter);