+ } else {
+ if (priv->autoselect_reference != NULL) {
+ gboolean moved_selection = FALSE;
+ GtkTreePath * last_path;
+ if (gtk_tree_selection_count_selected_rows (sel) != 1) {
+ moved_selection = TRUE;
+ } else {
+ GList *rows;
+
+ rows = gtk_tree_selection_get_selected_rows (sel, NULL);
+ last_path = gtk_tree_row_reference_get_path (priv->autoselect_reference);
+ if (gtk_tree_path_compare (last_path, (GtkTreePath *) rows->data) != 0)
+ moved_selection = TRUE;
+ g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
+ g_list_free (rows);
+ gtk_tree_path_free (last_path);
+ }
+ if (moved_selection) {
+ gtk_tree_row_reference_free (priv->autoselect_reference);
+ priv->autoselect_reference = NULL;
+ } else {
+
+ if (gtk_tree_model_get_iter_first (model, &tree_iter)) {
+ GtkTreePath *current_path;
+ current_path = gtk_tree_model_get_path (model, &tree_iter);
+ last_path = gtk_tree_row_reference_get_path (priv->autoselect_reference);
+ if (gtk_tree_path_compare (current_path, last_path) != 0) {
+ g_object_set(header_view, "can-focus", FALSE, NULL);
+ gtk_tree_selection_unselect_all (sel);
+ gtk_tree_selection_select_iter(sel, &tree_iter);
+ gtk_tree_view_set_cursor (header_view, current_path, NULL, FALSE);
+ g_object_set(header_view, "can-focus", TRUE, NULL);
+ gtk_tree_row_reference_free (priv->autoselect_reference);
+ priv->autoselect_reference = gtk_tree_row_reference_new (model, current_path);
+ }
+ gtk_tree_path_free (current_path);
+ gtk_tree_path_free (last_path);
+ }
+ }
+ }
+ }