After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 497491 - On TreeView, GDK_Left and GDK_Right should be binded by default. *Patch included*
On TreeView, GDK_Left and GDK_Right should be binded by default. *Patch inclu...
Status: RESOLVED DUPLICATE of bug 105895
Product: gtk+
Classification: Platform
Component: Widget: GtkTreeView
2.12.x
Other All
: Normal enhancement
: ---
Assigned To: gtktreeview-bugs
gtktreeview-bugs
Depends on:
Blocks:
 
 
Reported: 2007-11-16 21:34 UTC by Marcos Diez
Modified: 2007-11-18 17:45 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement



Description Marcos Diez 2007-11-16 21:34:10 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;
}
Comment 1 Kristian Rietveld 2007-11-18 17:45:28 UTC

*** This bug has been marked as a duplicate of 105895 ***