aboutsummaryrefslogtreecommitdiffstats
path: root/gtk
diff options
context:
space:
mode:
authorAnders Broman <anders.broman@ericsson.com>2009-07-25 07:50:53 +0000
committerAnders Broman <anders.broman@ericsson.com>2009-07-25 07:50:53 +0000
commitbe084ae799ff0866f15679db480a9c42aa072322 (patch)
tree1c1a4e4b2eb59fe3fbaab0ce2c1c7cea5cd70384 /gtk
parent14852c1384595005fd02a5e081a02ae80380c377 (diff)
From Kovarththanan Rajaratnam:
New packet list: enable goto first/last packet (Optimized) svn path=/trunk/; revision=29190
Diffstat (limited to 'gtk')
-rw-r--r--gtk/menus.c2
-rw-r--r--gtk/new_packet_list.c69
2 files changed, 48 insertions, 23 deletions
diff --git a/gtk/menus.c b/gtk/menus.c
index 4ca981eb0c..8fbd0adf73 100644
--- a/gtk/menus.c
+++ b/gtk/menus.c
@@ -632,11 +632,11 @@ static GtkItemFactoryEntry menu_items[] =
GTK_MENU_FUNC(packet_list_prev), 0, "<StockItem>", GTK_STOCK_GO_UP,},
{"/Go/Next Packet", "<control>Down",
GTK_MENU_FUNC(packet_list_next), 0, "<StockItem>", GTK_STOCK_GO_DOWN,},
+#endif /* NEW_PACKET_LIST */
{"/Go/F_irst Packet", "<control>Home",
GTK_MENU_FUNC(goto_top_frame_cb), 0, "<StockItem>", GTK_STOCK_GOTO_TOP,},
{"/Go/_Last Packet", "<control>End",
GTK_MENU_FUNC(goto_bottom_frame_cb), 0, "<StockItem>", GTK_STOCK_GOTO_BOTTOM,},
-#endif /* NEW_PACKET_LIST */
#ifdef HAVE_LIBPCAP
{"/_Capture", NULL, NULL, 0, "<Branch>", NULL,},
{"/Capture/_Interfaces...", "<control>I",
diff --git a/gtk/new_packet_list.c b/gtk/new_packet_list.c
index 5f559bc7ca..ac8a576fc9 100644
--- a/gtk/new_packet_list.c
+++ b/gtk/new_packet_list.c
@@ -207,27 +207,64 @@ new_packet_list_prev(void)
{
g_warning("*** new_packet_list_prev() not yet implemented.");
}
+
+static void scroll_to_and_select_iter(GtkTreeIter *iter)
+{
+ GtkTreeModel *model = GTK_TREE_MODEL(packetlist);
+ GtkTreeSelection *selection;
+ GtkTreePath *path;
+
+ /* Select the row */
+ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(packetlist->view));
+ gtk_tree_selection_select_iter (selection, iter);
+ path = gtk_tree_model_get_path(model, iter);
+ gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(packetlist->view),
+ path,
+ NULL,
+ TRUE, /* use_align */
+ 0.5, /* row_align determines where the row is placed, 0.5 means center */
+ 0); /* The horizontal alignment of the column */
+ gtk_tree_view_set_cursor(GTK_TREE_VIEW(packetlist->view),
+ path,
+ NULL,
+ FALSE); /* start_editing */
+
+ /* Needed to get the middle and bottom panes updated */
+ new_packet_list_select_cb(GTK_TREE_VIEW(packetlist->view), NULL);
+}
+
void
new_packet_list_select_first_row(void)
{
GtkTreeModel *model = GTK_TREE_MODEL(packetlist);
- GtkTreeSelection *selection;
GtkTreeIter iter;
if(!gtk_tree_model_get_iter_first(model, &iter))
return;
- selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(packetlist->view));
- gtk_tree_selection_select_iter (selection, &iter);
- new_packet_list_select_cb(GTK_TREE_VIEW(packetlist->view), NULL);
+ scroll_to_and_select_iter(&iter);
+}
+
+void
+new_packet_list_select_last_row(void)
+{
+ GtkTreeModel *model = GTK_TREE_MODEL(packetlist);
+ GtkTreeIter iter;
+ gint children;
+
+ if((children = gtk_tree_model_iter_n_children(model, NULL)) == 0)
+ return;
+
+ if(!gtk_tree_model_iter_nth_child(model, &iter, NULL, children-1))
+ return;
+
+ scroll_to_and_select_iter(&iter);
}
gint
new_packet_list_find_row_from_data(gpointer data, gboolean select)
{
GtkTreeModel *model = GTK_TREE_MODEL(packetlist);
- GtkTreeSelection *selection;
- GtkTreePath *path;
GtkTreeIter iter;
frame_data *fdata;
gint row;
@@ -241,23 +278,11 @@ new_packet_list_find_row_from_data(gpointer data, gboolean select)
do {
row = row_from_iter(&iter);
fdata = new_packet_list_get_row_data(row);
-
+
if(fdata == (frame_data*)data){
- if(select){
- /* Select the row */
- selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(packetlist->view));
- gtk_tree_selection_select_iter (selection, &iter);
- path = gtk_tree_model_get_path(model, &iter);
- gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(packetlist->view),
- path,
- NULL,
- TRUE, /* use_align */
- 0.5, /* row_align determines where the row is placed, 0.5 means center */
- 0); /* The horizontal alignment of the column */
-
- /* Needed to get the middle and bottom panes updated? */
- new_packet_list_select_cb(GTK_TREE_VIEW(packetlist->view),data);
- }
+ if(select)
+ scroll_to_and_select_iter(&iter);
+
return row;
}
} while (gtk_tree_model_iter_next (model,&iter));