[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
This commit is contained in:
Federico Mena Quintero 2011-02-24 14:53:09 -06:00
parent e158b9b13a
commit b6bf9112ad

View File

@ -6345,20 +6345,25 @@ show_and_select_files (GtkFileChooserDefault *impl,
{ {
GtkTreeSelection *selection; GtkTreeSelection *selection;
GtkFileSystemModel *fsmodel; GtkFileSystemModel *fsmodel;
gboolean can_have_hidden, can_have_filtered, selected_a_file; gboolean enabled_hidden, removed_filters;
gboolean selected_a_file;
GSList *walk; GSList *walk;
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view)); 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))); 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; 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; GFile *file = walk->data;
GtkTreeIter iter; GtkTreeIter iter;
/* Is it a hidden file? */
if (!_gtk_file_system_model_get_iter_for_file (fsmodel, &iter, file)) if (!_gtk_file_system_model_get_iter_for_file (fsmodel, &iter, file))
continue; continue;
@ -6366,21 +6371,35 @@ show_and_select_files (GtkFileChooserDefault *impl,
{ {
GFileInfo *info = _gtk_file_system_model_get_info (fsmodel, &iter); 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_hidden (info) ||
g_file_info_get_is_backup (info))) g_file_info_get_is_backup (info)))
{ {
g_object_set (impl, "show-hidden", TRUE, NULL); g_object_set (impl, "show-hidden", TRUE, NULL);
can_have_hidden = FALSE; enabled_hidden = TRUE;
}
if (can_have_filtered)
{
set_current_filter (impl, NULL);
can_have_filtered = FALSE;
} }
} }
/* 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)) if (_gtk_file_system_model_iter_is_visible (fsmodel, &iter))
{ {
gtk_tree_selection_select_iter (selection, &iter); gtk_tree_selection_select_iter (selection, &iter);