From acefba187aeb2ceacdf145cb541a816d59087e87 Mon Sep 17 00:00:00 2001 From: Ulf Lamping Date: Thu, 8 Mar 2007 23:37:55 +0000 Subject: [PATCH] from Sake Blok: I have changed the patch according to your suggestions and also changed the doc[book] files accordingly. I tested the patch and it does seem to work fine on my test-system. ULFL: In addition, I've added the en-/disabling to the other (already existing) Copy menu items - some just did nothing, some crashed if nothing was selected. I've also sligthly changed the menu seperators and made both context menus look a bit more identical. svn path=/trunk/; revision=21005 --- doc/wireshark.pod | 31 ++++++++++----- docbook/wsug_src/WSUG_chapter_use.xml | 14 +++++++ docbook/wsug_src/WSUG_chapter_work.xml | 21 ++++++++++ gtk/main.c | 28 +++++++++---- gtk/main.h | 3 ++ gtk/menu.c | 55 ++++++++++++++++---------- 6 files changed, 113 insertions(+), 39 deletions(-) diff --git a/doc/wireshark.pod b/doc/wireshark.pod index 1119af6571..4f8aacb3ea 100644 --- a/doc/wireshark.pod +++ b/doc/wireshark.pod @@ -731,6 +731,17 @@ dialog box popped up by this menu item. Exit the application. +=item Edit:Copy:As Filter + +Create a display filter based on the data currently highlighted in the +packet details and copy that filter to the clipboard. + +If that data is a field that can be tested in a display filter +expression, the display filter will test that field; otherwise, the +display filter will be based on the absolute offset within the packet. +Therefore it could be unreliable if the packet contains protocols with +variable-length headers, such as a source-routed token-ring packet. + =item Edit:Find Packet Search forward or backward, starting with the currently selected packet @@ -972,28 +983,27 @@ changed, or deleted. =item Analyze:Apply as Filter -Create a display filter, or add to the display filter strip at the -bottom, a display filter based on the data currently highlighted in the -packe details, and apply the filter. +Create a display filter based on the data currently highlighted in the +packet details and apply the filter. If that data is a field that can be tested in a display filter expression, the display filter will test that field; otherwise, the -display filter will be based on absolute offset within the packet, and -so could be unreliable if the packet contains protocols with +display filter will be based on the absolute offset within the packet. +Therefore it could be unreliable if the packet contains protocols with variable-length headers, such as a source-routed token-ring packet. The B option creates a display filter that tests for a match of the data; the B option creates a display filter that tests for a non-match of the data. The B, B, B, and B options add to the end of -the display filter in the strip at the bottom an AND or OR operator -followed by the new display filter expression. +the display filter in the strip at the top (or bottom) an AND or OR +operator followed by the new display filter expression. =item Analyze:Prepare a Filter -Create a display filter, or add to the display filter strip at the -bottom, a display filter based on the data currently highlighted in the -packet details, but don't apply the filter. +Create a display filter based on the data currently highlighted in the +packet details. The filter strip at the top (or bottom) is updated but +it is not yet applied. =item Analyze:Enabled Protocols @@ -2227,3 +2237,4 @@ L. =head1 AUTHORS + diff --git a/docbook/wsug_src/WSUG_chapter_use.xml b/docbook/wsug_src/WSUG_chapter_use.xml index d5c22252df..411f9b19f9 100644 --- a/docbook/wsug_src/WSUG_chapter_use.xml +++ b/docbook/wsug_src/WSUG_chapter_use.xml @@ -573,6 +573,20 @@ + + Copy > As Filter + + + This menu item will use the selected item in the detail view to + create a display filter. This display filter is then copied to + the clipboard. + + + + ------ + + + Find Packet... Ctrl+F diff --git a/docbook/wsug_src/WSUG_chapter_work.xml b/docbook/wsug_src/WSUG_chapter_work.xml index 1935eac844..0b559579df 100644 --- a/docbook/wsug_src/WSUG_chapter_work.xml +++ b/docbook/wsug_src/WSUG_chapter_work.xml @@ -184,6 +184,16 @@ + + Copy as Filter + Analyze + + + Prepare a display filter based on the currently selected item + and copy that filter to the clipboard. + + + Copy/ Bytes (Offset Hex Text) - @@ -350,6 +360,16 @@ Copy the displayed text of the selected field to the system clipboard. + + + + + Copy/ As Filter + - + + + Prepare a display filter based on the currently selected item + and copy it to the clipboard. @@ -1485,3 +1505,4 @@ eth.src[1-2] == 00:83 + diff --git a/gtk/main.c b/gtk/main.c index 3c3e4d32ab..8f848be76e 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -247,8 +247,11 @@ match_selected_cb_do(gpointer data, int action, gchar *text) GtkWidget *filter_te; char *cur_filter, *new_filter; - if (!text) + if ((!text) || (0 == strlen(text))) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not acquire information to build a filter!\nTry expanding or choosing another item."); return; + } + g_assert(data); filter_te = OBJECT_GET_DATA(data, E_DFILTER_TE_KEY); g_assert(filter_te); @@ -302,12 +305,20 @@ match_selected_cb_do(gpointer data, int action, gchar *text) /* Free up the copy we got of the old filter text. */ g_free(cur_filter); - /* create a new one and set the display filter entry accordingly */ - gtk_entry_set_text(GTK_ENTRY(filter_te), new_filter); + /* Don't change the current display filter if we only want to copy the filter */ + if (action&MATCH_SELECTED_COPY_ONLY) { + GString *gtk_text_str = g_string_new(""); + g_string_sprintfa(gtk_text_str, "%s", new_filter); + copy_to_clipboard(gtk_text_str); + g_string_free(gtk_text_str, TRUE); + } else { + /* create a new one and set the display filter entry accordingly */ + gtk_entry_set_text(GTK_ENTRY(filter_te), new_filter); - /* Run the display filter so it goes in effect. */ - if (action&MATCH_SELECTED_APPLY_NOW) - main_filter_packets(&cfile, new_filter, FALSE); + /* Run the display filter so it goes in effect. */ + if (action&MATCH_SELECTED_APPLY_NOW) + main_filter_packets(&cfile, new_filter, FALSE); + } /* Free up the new filter text. */ g_free(new_filter); @@ -321,8 +332,7 @@ match_selected_ptree_cb(GtkWidget *w, gpointer data, MATCH_SELECTED_E action) if (cfile.finfo_selected) { filter = proto_construct_match_selected_string(cfile.finfo_selected, cfile.edt); - if (filter != NULL) - match_selected_cb_do((data ? data : w), action, filter); + match_selected_cb_do((data ? data : w), action, filter); } } @@ -4638,6 +4648,8 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs) * of any widget that ends up calling a callback which needs * that text entry pointer */ set_menu_object_data("/File/Open...", E_DFILTER_TE_KEY, filter_te); + set_menu_object_data("/Edit/Copy/As Filter", E_DFILTER_TE_KEY, + filter_te); set_menu_object_data("/Analyze/Display Filters...", E_FILT_TE_PTR_KEY, filter_te); set_menu_object_data("/Analyze/Follow TCP Stream", E_DFILTER_TE_KEY, diff --git a/gtk/main.h b/gtk/main.h index 5cfb272f4e..fcb341f69a 100644 --- a/gtk/main.h +++ b/gtk/main.h @@ -126,6 +126,9 @@ typedef enum { /** "bitwise or" this with MATCH_SELECTED_E value for instant apply instead of prepare only */ #define MATCH_SELECTED_APPLY_NOW 0x100 +/** "bitwise or" this with MATCH_SELECTED_E value for copy to clipboard instead of prepare only */ +#define MATCH_SELECTED_COPY_ONLY 0x200 + /** User highlited item in details window and then right clicked and selected the copy option * * @param widget parent widget diff --git a/gtk/menu.c b/gtk/menu.c index eac203358d..7266b9e098 100644 --- a/gtk/menu.c +++ b/gtk/menu.c @@ -432,6 +432,9 @@ static GtkItemFactoryEntry menu_items[] = ITEM_FACTORY_STOCK_ENTRY("/File/_Quit", "Q", file_quit_cmd_cb, 0, GTK_STOCK_QUIT), ITEM_FACTORY_ENTRY("/_Edit", NULL, NULL, 0, "", NULL), + ITEM_FACTORY_ENTRY("/Edit/Copy", NULL, NULL, 0, "", NULL), + ITEM_FACTORY_ENTRY("/Edit/Copy/As Filter", NULL, match_selected_ptree_cb, + MATCH_SELECTED_REPLACE|MATCH_SELECTED_COPY_ONLY, NULL, NULL), #if 0 /* Un-#if this when we actually implement Cut/Copy/Paste. */ ITEM_FACTORY_STOCK_ENTRY("/Edit/Cut", "X", NULL, @@ -440,8 +443,8 @@ static GtkItemFactoryEntry menu_items[] = 0, GTK_STOCK_COPY), ITEM_FACTORY_STOCK_ENTRY("/Edit/Paste", "V", NULL, 0, GTK_STOCK_PASTE), - ITEM_FACTORY_ENTRY("/Edit/", NULL, NULL, 0, ""), #endif + ITEM_FACTORY_ENTRY("/Edit/", NULL, NULL, 0, "", NULL), ITEM_FACTORY_STOCK_ENTRY("/Edit/_Find Packet...", "F", find_frame_cb, 0, GTK_STOCK_FIND), ITEM_FACTORY_ENTRY("/Edit/Find Ne_xt", "N", find_next_cb, 0, NULL, NULL), @@ -721,6 +724,9 @@ static GtkItemFactoryEntry packet_list_menu_items[] = ITEM_FACTORY_ENTRY("/Copy/Summary (Text)", NULL, packet_list_copy_summary_cb, CS_TEXT, NULL, NULL), ITEM_FACTORY_ENTRY("/Copy/Summary (CSV)", NULL, packet_list_copy_summary_cb, CS_CSV, NULL, NULL), ITEM_FACTORY_ENTRY("/Copy/", NULL, NULL, 0, "", NULL), + ITEM_FACTORY_ENTRY("/Copy/As Filter", NULL, match_selected_plist_cb, + MATCH_SELECTED_REPLACE|MATCH_SELECTED_COPY_ONLY, NULL, NULL), + ITEM_FACTORY_ENTRY("/Copy/", NULL, NULL, 0, "", NULL), ITEM_FACTORY_ENTRY("/Copy/Bytes (Offset Hex Text)", NULL, copy_hex_cb, CD_ALLINFO, NULL, NULL), ITEM_FACTORY_ENTRY("/Copy/Bytes (Offset Hex)", NULL, copy_hex_cb, CD_HEXCOLUMNS, NULL, NULL), ITEM_FACTORY_ENTRY("/Copy/Bytes (Printable Text Only)", NULL, copy_hex_cb, CD_TEXTONLY, NULL, NULL), @@ -730,8 +736,6 @@ static GtkItemFactoryEntry packet_list_menu_items[] = ITEM_FACTORY_ENTRY("/Copy/Bytes (Binary Stream)", NULL, copy_hex_cb, CD_BINARY, NULL, NULL), #endif - ITEM_FACTORY_ENTRY("/", NULL, NULL, 0, "", NULL), - ITEM_FACTORY_ENTRY("/Export Selected Packet Bytes...", NULL, savehex_cb, 0, NULL, NULL), @@ -752,24 +756,6 @@ static GtkItemFactoryEntry tree_view_menu_items[] = ITEM_FACTORY_ENTRY("/", NULL, NULL, 0, "", NULL), - ITEM_FACTORY_ENTRY("/Copy", NULL, NULL, 0, "", NULL), - ITEM_FACTORY_ENTRY("/Copy/Description", NULL, copy_selected_plist_cb, 0, NULL, NULL), - ITEM_FACTORY_ENTRY("/Copy/Bytes (Offset Hex Text)", NULL, copy_hex_cb, CD_ALLINFO | CD_FLAGS_SELECTEDONLY, NULL, NULL), - ITEM_FACTORY_ENTRY("/Copy/Bytes (Offset Hex)", NULL, copy_hex_cb, CD_HEXCOLUMNS | CD_FLAGS_SELECTEDONLY, NULL, NULL), - ITEM_FACTORY_ENTRY("/Copy/Bytes (Printable Text Only)", NULL, copy_hex_cb, CD_TEXTONLY | CD_FLAGS_SELECTEDONLY, NULL, NULL), - ITEM_FACTORY_ENTRY("/Copy/", NULL, NULL, 0, "", NULL), - ITEM_FACTORY_ENTRY("/Copy/Bytes (Hex Stream)", NULL, copy_hex_cb, CD_HEX | CD_FLAGS_SELECTEDONLY, NULL, NULL), -#if GTK_MAJOR_VERSION >= 2 - ITEM_FACTORY_ENTRY("/Copy/Bytes (Binary Stream)", NULL, copy_hex_cb, CD_BINARY | CD_FLAGS_SELECTEDONLY, NULL, NULL), -#endif - - ITEM_FACTORY_ENTRY("/", NULL, NULL, 0, "", NULL), - - ITEM_FACTORY_ENTRY("/Export Selected Packet Bytes...", NULL, savehex_cb, - 0, NULL, NULL), - - ITEM_FACTORY_ENTRY("/", NULL, NULL, 0, "", NULL), - ITEM_FACTORY_ENTRY("/Apply as Filter", NULL, NULL, 0, "", NULL), ITEM_FACTORY_ENTRY("/Apply as Filter/_Selected", NULL, match_selected_ptree_cb, MATCH_SELECTED_REPLACE|MATCH_SELECTED_APPLY_NOW, NULL, NULL), @@ -805,6 +791,25 @@ static GtkItemFactoryEntry tree_view_menu_items[] = ITEM_FACTORY_ENTRY("/", NULL, NULL, 0, "", NULL), + ITEM_FACTORY_ENTRY("/Copy", NULL, NULL, 0, "", NULL), + ITEM_FACTORY_ENTRY("/Copy/Description", NULL, copy_selected_plist_cb, 0, NULL, NULL), + ITEM_FACTORY_ENTRY("/Copy/", NULL, NULL, 0, "", NULL), + ITEM_FACTORY_ENTRY("/Copy/As Filter", NULL, match_selected_ptree_cb, MATCH_SELECTED_REPLACE|MATCH_SELECTED_COPY_ONLY, NULL, NULL), + ITEM_FACTORY_ENTRY("/Copy/", NULL, NULL, 0, "", NULL), + ITEM_FACTORY_ENTRY("/Copy/Bytes (Offset Hex Text)", NULL, copy_hex_cb, CD_ALLINFO | CD_FLAGS_SELECTEDONLY, NULL, NULL), + ITEM_FACTORY_ENTRY("/Copy/Bytes (Offset Hex)", NULL, copy_hex_cb, CD_HEXCOLUMNS | CD_FLAGS_SELECTEDONLY, NULL, NULL), + ITEM_FACTORY_ENTRY("/Copy/Bytes (Printable Text Only)", NULL, copy_hex_cb, CD_TEXTONLY | CD_FLAGS_SELECTEDONLY, NULL, NULL), + ITEM_FACTORY_ENTRY("/Copy/", NULL, NULL, 0, "", NULL), + ITEM_FACTORY_ENTRY("/Copy/Bytes (Hex Stream)", NULL, copy_hex_cb, CD_HEX | CD_FLAGS_SELECTEDONLY, NULL, NULL), +#if GTK_MAJOR_VERSION >= 2 + ITEM_FACTORY_ENTRY("/Copy/Bytes (Binary Stream)", NULL, copy_hex_cb, CD_BINARY | CD_FLAGS_SELECTEDONLY, NULL, NULL), +#endif + + ITEM_FACTORY_ENTRY("/Export Selected Packet Bytes...", NULL, savehex_cb, + 0, NULL, NULL), + + ITEM_FACTORY_ENTRY("/", NULL, NULL, 0, "", NULL), + ITEM_FACTORY_STOCK_ENTRY("/Wiki Protocol Page", NULL, selected_ptree_info_cb, 0, WIRESHARK_STOCK_WIKI), ITEM_FACTORY_STOCK_ENTRY("/Filter Field Reference", NULL, selected_ptree_ref_cb, @@ -2395,6 +2400,8 @@ set_menus_for_selected_packet(capture_file *cf) cf->current_frame != NULL && (g_resolv_flags & RESOLV_ALL_ADDRS) != RESOLV_ALL_ADDRS); set_menu_sensitivity(tree_view_menu_factory, "/Resolve Name", cf->current_frame != NULL && (g_resolv_flags & RESOLV_ALL_ADDRS) != RESOLV_ALL_ADDRS); + set_menu_sensitivity(packet_list_menu_factory, "/Copy", + cf->current_frame != NULL); set_menu_sensitivity(packet_list_menu_factory, "/Apply as Filter", cf->current_frame != NULL); set_menu_sensitivity(packet_list_menu_factory, "/Prepare a Filter", @@ -2482,6 +2489,10 @@ set_menus_for_selected_tree_row(capture_file *cf) "/Go/Go to Corresponding Packet", hfinfo->type == FT_FRAMENUM); set_menu_sensitivity(tree_view_menu_factory, "/Go to Corresponding Packet", hfinfo->type == FT_FRAMENUM); + set_menu_sensitivity(main_menu_factory, "/Edit/Copy", + proto_can_match_selected(cf->finfo_selected, cf->edt)); + set_menu_sensitivity(tree_view_menu_factory, "/Copy", + proto_can_match_selected(cf->finfo_selected, cf->edt)); set_menu_sensitivity(main_menu_factory, "/Analyze/Apply as Filter", proto_can_match_selected(cf->finfo_selected, cf->edt)); set_menu_sensitivity(tree_view_menu_factory, "/Apply as Filter", @@ -2503,6 +2514,8 @@ set_menus_for_selected_tree_row(capture_file *cf) "/Go/Go to Corresponding Packet", FALSE); set_menu_sensitivity(tree_view_menu_factory, "/Go to Corresponding Packet", FALSE); + set_menu_sensitivity(main_menu_factory, "/Edit/Copy", FALSE); + set_menu_sensitivity(tree_view_menu_factory, "/Copy", FALSE); set_menu_sensitivity(main_menu_factory, "/Analyze/Apply as Filter", FALSE); set_menu_sensitivity(tree_view_menu_factory, "/Apply as Filter", FALSE); set_menu_sensitivity(main_menu_factory, "/Analyze/Prepare a Filter", FALSE);