Todd Sabin <tas@xxxxxxxxxxx> writes:
> Does anyone know how to make it so that hitting return in the proto
> tree view expands/collapses the current node? I'd much appreciate it.
I have a working patch for this. It's something I hacked together
during the last two weeks I was off from work.
The good thing about the patch is that it works, the bad thing is that
it accesses GtkCTree directly, not through the API. I did not have all
the documentation available when I did the patch, but I think the API
does not provide a method for accessing the selected row.
The patch also changes the place where tree-expand and tree-collapse
signals are connected. The old place (gtk/proto_draw.c:proto_draw)
connected the signal every time the tree was redrawn which caused
redundant calls to expand_tree/collapse_tree
Index: gtk/proto_draw.c
===================================================================
RCS file: /cvsroot/ethereal/gtk/proto_draw.c,v
retrieving revision 1.35
diff -u -r1.35 proto_draw.c
--- proto_draw.c 2001/06/05 07:38:37 1.35
+++ proto_draw.c 2001/07/09 13:29:33
@@ -37,6 +37,7 @@
#include <stdarg.h>
#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
#ifdef NEED_SNPRINTF_H
# include "snprintf.h"
@@ -184,6 +185,15 @@
*val = FALSE;
}
+static void
+toggle_tree(GtkCTree *ctree, GdkEventKey *event, gpointer user_data)
+{
+ GtkCTreeNode *node;
+
+ if (event->keyval != GDK_Return) return;
+ gtk_ctree_toggle_expansion(ctree, GTK_CTREE_NODE(ctree->clist.selection->data));
+}
+
/* Which byte the offset is referring to. Associates
* whitespace with the preceding digits. */
static int
@@ -822,6 +832,12 @@
gtk_widget_show(tv_scrollw);
tree_view = gtk_ctree_new(1, 0);
+ gtk_signal_connect( GTK_OBJECT(tree_view), "key-press-event",
+ (GtkSignalFunc) toggle_tree, NULL );
+ gtk_signal_connect( GTK_OBJECT(tree_view), "tree-expand",
+ (GtkSignalFunc) expand_tree, NULL );
+ gtk_signal_connect( GTK_OBJECT(tree_view), "tree-collapse",
+ (GtkSignalFunc) collapse_tree, NULL );
/* I need this next line to make the widget work correctly with hidden
* column titles and GTK_SELECTION_BROWSE */
gtk_clist_set_column_auto_resize( GTK_CLIST(tree_view), 0, TRUE );
@@ -873,11 +889,6 @@
g_node_children_foreach((GNode*) protocol_tree, G_TRAVERSE_ALL,
proto_tree_draw_node, &info);
-
- gtk_signal_connect( GTK_OBJECT(info.ctree), "tree-expand",
- (GtkSignalFunc) expand_tree, NULL );
- gtk_signal_connect( GTK_OBJECT(info.ctree), "tree-collapse",
- (GtkSignalFunc) collapse_tree, NULL );
gtk_clist_thaw ( GTK_CLIST(tree_view) );
}
--
Heikki Vatiainen * hessu@xxxxxxxxx
Tampere University of Technology * Tampere, Finland