From Kovarththanan Rajaratnam:
authorAnders Broman <anders.broman@ericsson.com>
Sat, 25 Jul 2009 07:50:53 +0000 (07:50 -0000)
committerAnders Broman <anders.broman@ericsson.com>
Sat, 25 Jul 2009 07:50:53 +0000 (07:50 -0000)
New packet list: enable goto first/last packet (Optimized)

svn path=/trunk/; revision=29190

file.c
gtk/menus.c
gtk/new_packet_list.c
ui_util.h

diff --git a/file.c b/file.c
index fb205268461f4df562813665a0fe7967ebcb6153..21e3554df35a21b0f28c713d1ccf73d339db27c6 100644 (file)
--- a/file.c
+++ b/file.c
@@ -3398,6 +3398,10 @@ cf_goto_frame(capture_file *cf, guint fnumber)
 gboolean
 cf_goto_top_frame(capture_file *cf)
 {
+#ifdef NEW_PACKET_LIST
+  /* Find and select */
+  new_packet_list_select_first_row();
+#else
   frame_data *fdata;
   int row;
   frame_data *lowest_fdata = NULL;
@@ -3413,10 +3417,6 @@ cf_goto_top_frame(capture_file *cf)
       return FALSE;
   }
 
-#ifdef NEW_PACKET_LIST
-  /* Find and select */
-  row = new_packet_list_find_row_from_data(fdata, TRUE);
-#else
   /* We found that packet, and it's currently being displayed.
      Find what row it's in. */
   row = packet_list_find_row_from_data(lowest_fdata);
@@ -3431,6 +3431,10 @@ cf_goto_top_frame(capture_file *cf)
 gboolean
 cf_goto_bottom_frame(capture_file *cf)
 {
+#ifdef NEW_PACKET_LIST
+  /* Find and select */
+  new_packet_list_select_last_row();
+#else
   frame_data *fdata;
   int row;
   frame_data *highest_fdata = NULL;
@@ -3445,10 +3449,6 @@ cf_goto_bottom_frame(capture_file *cf)
       return FALSE;
   }
 
-#ifdef NEW_PACKET_LIST
-  /* Find and select */
-  row = new_packet_list_find_row_from_data(fdata, TRUE);
-#else
   /* We found that packet, and it's currently being displayed.
      Find what row it's in. */
   row = packet_list_find_row_from_data(highest_fdata);
index 4ca981eb0c6c0628b58004d75feb55a813427e42..8fbd0adf73fd2d9451e5a49bfe5f4a8846ceb7a6 100644 (file)
@@ -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",
index 5f559bc7ca592c29a99d7beefc510a03be2fed45..ac8a576fc9ede03b1749670848aad1bc0bd6f7a0 100644 (file)
@@ -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));
index ec659c5c609f825adf20354189e05e9c0bc446d0..bccb967cf973d94e1f2e0f163b42da3866af6d12 100644 (file)
--- a/ui_util.h
+++ b/ui_util.h
@@ -63,6 +63,7 @@ guint new_packet_list_append(column_info *cinfo, frame_data *fdata);
 frame_data * new_packet_list_get_row_data(gint row);
 void new_packet_list_enable_color(gboolean enable);
 void new_packet_list_select_first_row(void);
+void new_packet_list_select_last_row(void);
 gint new_packet_list_find_row_from_data(gpointer data, gboolean select);
 #else
 /* packet list related functions */