GTKTreeView navigation improvement



Hi gtk-devel-list,

First time submitting a patch to gnome, so bear with me.
I've included a patch that should greatly enhance the usability of GTKTreeView.
Currently the keyboard navigation of GTKTreeView is a bit cumbersome,
collapsing nodes is frustrating because the user has to either click
on the collapse arrow or select the parent node and <Shift>+<Left> on
it.
This patch only modifies the <Shift>+<Left> behavior and I have tested
it on with great success on Ubuntu 9.10 x86.
Current behavior of <Shift>+<Left> on the treeview widget:
If node has children, collapse node
else do nothing
Patch:
If node has children, collapse node
else if node has parent, select parent row
else do nothing

Cheers,
-Andrey
-------------------------------------------------------------------------------------------------------------
--- gtk+2.0-2.18.3/gtk/gtktreeview.c	2009-10-08 22:00:44.000000000 -0700
+++ gtktreeview.c	2009-11-22 19:43:44.792600790 -0800
@@ -10102,14 +10102,30 @@ gtk_tree_view_real_expand_collapse_curso
   if (_gtk_tree_view_find_node (tree_view, cursor_path, &tree, &node))
     return FALSE;

-  /* Don't handle the event if we aren't an expander */
-  if (!((node->flags & GTK_RBNODE_IS_PARENT) == GTK_RBNODE_IS_PARENT))
-    return FALSE;
-
   if (!logical
       && gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL)
     expand = !expand;

+  /* On a keyboard accelerator for collapse, this code should move the cursor
+   * to the parent, if the node has no children or is collapsed
+   * notes:
+   * a node is expanded if node->children != null
+   */
+  if(!expand && (node->children == NULL))
+  {
+    //get parent path or return false
+    if(!gtk_tree_path_up(cursor_path))
+      return FALSE;
+
+    //do the parent select
+    gtk_tree_view_set_cursor(tree_view,cursor_path,NULL,FALSE);
+    return TRUE;
+  }
+
+  /* Don't handle the event if we aren't an expander */
+  if (!((node->flags & GTK_RBNODE_IS_PARENT) == GTK_RBNODE_IS_PARENT))
+    return FALSE;
+
   if (expand)
     gtk_tree_view_real_expand_row (tree_view, cursor_path, tree,
node, open_all, TRUE);
   else
--- gtk+2.0-2.18.3/gtk/gtktreeview.c	2009-10-08 22:00:44.000000000 -0700
+++ gtktreeview.c	2009-11-22 19:43:44.792600790 -0800
@@ -10102,14 +10102,30 @@ gtk_tree_view_real_expand_collapse_curso
   if (_gtk_tree_view_find_node (tree_view, cursor_path, &tree, &node))
     return FALSE;
 
-  /* Don't handle the event if we aren't an expander */
-  if (!((node->flags & GTK_RBNODE_IS_PARENT) == GTK_RBNODE_IS_PARENT))
-    return FALSE;
-
   if (!logical
       && gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL)
     expand = !expand;
 
+  /* On a keyboard accelerator for collapse, this code should move the cursor
+   * to the parent, if the node has no children or is collapsed
+   * notes:
+   * a node is expanded if node->children != null
+   */
+  if(!expand && (node->children == NULL))
+  {
+    //get parent path or return false
+    if(!gtk_tree_path_up(cursor_path))
+      return FALSE;
+
+    //do the parent select
+    gtk_tree_view_set_cursor(tree_view,cursor_path,NULL,FALSE);
+    return TRUE;
+  }
+
+  /* Don't handle the event if we aren't an expander */
+  if (!((node->flags & GTK_RBNODE_IS_PARENT) == GTK_RBNODE_IS_PARENT))
+    return FALSE;
+
   if (expand)
     gtk_tree_view_real_expand_row (tree_view, cursor_path, tree, node, open_all, TRUE);
   else


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