GNOME Bugzilla – Bug 497491
On TreeView, GDK_Left and GDK_Right should be binded by default. *Patch included*
Last modified: 2007-11-18 17:45:28 UTC
It would be interesting if GDK_Left and GDK_Right were binded by default in the TreeView. GDK_Left should either close the current selection or select the parent node. GDK_Right should either open the current selection or select the first child node or do nothing. Microsoft Windows works like this and it is pretty intuitive to the user. The code below is used on all my GTK+ applications, but should be included in the main tree. Thanks. ----------------------- gboolean on_TVtreeView_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data) { switch(event->keyval) { case GDK_Left: case GDK_KP_Left: case GDK_Right: case GDK_KP_Right: { GtkTreeView *treeView = (GtkTreeView *) widget; GtkTreeSelection *selection= gtk_tree_view_get_selection( treeView ); GtkTreeIter iter; GtkTreeModel *model=0; gboolean isSomethingSelected = gtk_tree_selection_get_selected( selection , &model , &iter ); if( ! isSomethingSelected ) return TRUE; GtkTreePath* treePath = gtk_tree_model_get_path( model , &iter ); gboolean rowIsExpanded=gtk_tree_view_row_expanded( treeView , treePath ); if( event->keyval == GDK_Left || event->keyval == GDK_KP_Left ){ if( rowIsExpanded ){ gtk_tree_view_collapse_row ( treeView , treePath ); }else{ gtk_tree_path_up ( treePath ); gtk_tree_view_set_cursor( treeView , treePath , 0 , FALSE ); } }else{ // GDK_Right or KP_Right if( rowIsExpanded ){ gtk_tree_path_down ( treePath ); gtk_tree_view_set_cursor( treeView , treePath , 0 , FALSE ); }else{ gtk_tree_view_expand_row ( treeView , treePath , 0 ); } } gtk_tree_path_free( treePath ); return TRUE; } default: break; }; return FALSE; }
*** This bug has been marked as a duplicate of 105895 ***