]> Pileus Git - ~andy/gtk/commitdiff
treeview: Properly change cursor when row is collapsed
authorBenjamin Otte <otte@redhat.com>
Sat, 26 Nov 2011 23:06:53 +0000 (00:06 +0100)
committerBenjamin Otte <otte@redhat.com>
Tue, 29 Nov 2011 19:44:57 +0000 (20:44 +0100)
Previously, when the cursor was a descendant of the collapsed row,
the cursor path was set to the collapsed row, but this was not
communicated via cursor-changed events.

gtk/gtktreeview.c

index 698052c7d2ae1c17f1dc099d1ef41f5f35115c1c..4ea20bb848d20d7711286877e811ae97c32c40f4 100644 (file)
@@ -12807,7 +12807,7 @@ gtk_tree_view_real_collapse_row (GtkTreeView *tree_view,
   gint x, y;
   GList *list;
   GdkWindow *child;
-  gboolean selection_changed;
+  gboolean selection_changed, cursor_changed;
 
   if (animate)
     g_object_get (gtk_widget_get_settings (GTK_WIDGET (tree_view)),
@@ -12875,13 +12875,8 @@ gtk_tree_view_real_collapse_row (GtkTreeView *tree_view,
     {
       GtkTreePath *cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
 
-      if (gtk_tree_path_is_ancestor (path, cursor_path))
-       {
-         gtk_tree_row_reference_free (tree_view->priv->cursor);
-         tree_view->priv->cursor = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
-                                                                     tree_view->priv->model,
-                                                                     path);
-       }
+      cursor_changed = gtk_tree_path_is_ancestor (path, cursor_path);
+
       gtk_tree_path_free (cursor_path);
     }
 
@@ -12906,8 +12901,12 @@ gtk_tree_view_real_collapse_row (GtkTreeView *tree_view,
 
   _gtk_rbtree_remove (node->children);
 
-  if (selection_changed)
-      g_signal_emit_by_name (tree_view->priv->selection, "changed");
+  /* if we change the cursor, we also change the selection,
+   * so no need to emit selection-changed. */
+  if (cursor_changed)
+    gtk_tree_view_real_set_cursor (tree_view, path, TRUE, FALSE);
+  else if (selection_changed)
+    g_signal_emit_by_name (tree_view->priv->selection, "changed");
 
   if (animate)
     {