From 2ef301bcf670d6bbb309f83d8838687e0a46c37f Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 3 Jan 2000 03:57:04 +0000 Subject: Have "gtk/menu.c" (and, in the future, code for other UIs) export a set of routines to enable and disable various sets of menu items; call only those routines, not routines to enable or disable particular menu items, from files in the top-level directory, as other UIs may not refer to menu items with path strings of the sort used in GTK+, and as this buries knowledge of the menu items available in "gtk/menu.c" rather than requiring stuff outside of "gtk/menu.c" to know what menu items exist. svn path=/trunk/; revision=1410 --- Makefile.am | 3 +- capture.c | 3 +- file.c | 93 +++++++++++++++---------------------------------------------- gtk/menu.c | 72 ++++++++++++++++++++++++++++++++++++----------- gtk/menu.h | 8 +++--- menu.h | 60 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 146 insertions(+), 93 deletions(-) create mode 100644 menu.h diff --git a/Makefile.am b/Makefile.am index bcb2748a8e..c952ffc81f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ # Makefile.am # Automake file for Ethereal # -# $Id: Makefile.am,v 1.140 1999/12/29 05:19:58 guy Exp $ +# $Id: Makefile.am,v 1.141 2000/01/03 03:56:53 guy Exp $ # # Ethereal - Network traffic analyzer # By Gerald Combs @@ -206,6 +206,7 @@ ethereal_SOURCES = \ ipproto.c \ ipv4.c \ ipv4.h \ + menu.h \ oui.h \ packet.c \ packet.h \ diff --git a/capture.c b/capture.c index e8133c4225..c06f896f9d 100644 --- a/capture.c +++ b/capture.c @@ -1,7 +1,7 @@ /* capture.c * Routines for packet capture windows * - * $Id: capture.c,v 1.86 1999/12/09 07:19:02 guy Exp $ + * $Id: capture.c,v 1.87 2000/01/03 03:56:53 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -87,7 +87,6 @@ #include "gtk/gtkglobals.h" #include "packet.h" #include "file.h" -#include "gtk/menu.h" #include "capture.h" #include "util.h" #include "ui_util.h" diff --git a/file.c b/file.c index a063858bdb..54b5327eba 100644 --- a/file.c +++ b/file.c @@ -1,7 +1,7 @@ /* file.c * File I/O routines * - * $Id: file.c,v 1.144 2000/01/03 03:46:36 guy Exp $ + * $Id: file.c,v 1.145 2000/01/03 03:56:54 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -71,10 +71,10 @@ #include "gtk/main.h" #include "column.h" -#include "gtk/menu.h" #include "packet.h" #include "print.h" #include "file.h" +#include "menu.h" #include "util.h" #include "ui_util.h" #include "gtk/proto_draw.h" @@ -225,21 +225,10 @@ close_cap_file(capture_file *cf, void *w) set_main_window_name("The Ethereal Network Analyzer"); /* Disable all menu items that make sense only if you have a capture. */ - set_menu_sensitivity("/File/Save", FALSE); - set_menu_sensitivity("/File/Save As...", FALSE); - set_menu_sensitivity("/File/Close", FALSE); - set_menu_sensitivity("/File/Reload", FALSE); - set_menu_sensitivity("/File/Print...", FALSE); - set_menu_sensitivity("/Display/Options...", FALSE); - set_menu_sensitivity("/Display/Match Selected", FALSE); - set_menu_sensitivity("/Display/Colorize Display...", FALSE); - set_menu_sensitivity("/Display/Find Frame...", FALSE); - set_menu_sensitivity("/Display/Go To Frame...", FALSE); - set_menu_sensitivity("/Display/Collapse All", FALSE); - set_menu_sensitivity("/Display/Expand All", FALSE); - set_menu_sensitivity("/Tools/Follow TCP Stream", FALSE); - set_menu_sensitivity("/Tools/Graph", FALSE); - set_menu_sensitivity("/Tools/Summary", FALSE); + set_menus_for_capture_file(FALSE); + set_menus_for_unsaved_capture_file(FALSE); + set_menus_for_captured_packets(FALSE); + set_menus_for_selected_packet(FALSE); } /* Set the file name in the status line, in the name for the main window, @@ -335,20 +324,11 @@ read_cap_file(capture_file *cf) /* Enable menu items that make sense if you have a capture file you've finished reading. */ - set_menu_sensitivity("/File/Save", !cf->user_saved); - set_menu_sensitivity("/File/Save As...", TRUE); - set_menu_sensitivity("/File/Close", TRUE); - set_menu_sensitivity("/File/Reload", TRUE); - set_menu_sensitivity("/File/Print...", TRUE); + set_menus_for_capture_file(TRUE); + set_menus_for_unsaved_capture_file(!cf->user_saved); /* Enable menu items that make sense if you have some captured packets. */ - set_menu_sensitivity("/Display/Options...", TRUE); - set_menu_sensitivity("/Display/Match Selected", TRUE); - set_menu_sensitivity("/Display/Colorize Display...", TRUE); - set_menu_sensitivity("/Display/Find Frame...", TRUE); - set_menu_sensitivity("/Display/Go To Frame...", TRUE); - set_menu_sensitivity("/Tools/Graph", TRUE); - set_menu_sensitivity("/Tools/Summary", TRUE); + set_menus_for_captured_packets(TRUE); if (!success) { /* Put up a message box noting that the read failed somewhere along @@ -392,23 +372,13 @@ start_tail_cap_file(char *fname, gboolean is_tempfile, capture_file *cf) err = open_cap_file(fname, is_tempfile, cf); if (err == 0) { - /* Disable menu items that make sense only if you have a capture - file you've finished reading. */ - set_menu_sensitivity("/File/Open...", FALSE); - - /* Disable menu items that make sense only if you're not currently - running a capture. */ - set_menu_sensitivity("/Capture/Start...", FALSE); + /* Disable menu items that make no sense if you're currently running + a capture. */ + set_menus_for_capture_in_progress(TRUE); /* Enable menu items that make sense if you have some captured packets (yes, I know, we don't have any *yet*). */ - set_menu_sensitivity("/Display/Options...", TRUE); - set_menu_sensitivity("/Display/Match Selected", TRUE); - set_menu_sensitivity("/Display/Colorize Display...", TRUE); - set_menu_sensitivity("/Display/Find Frame...", TRUE); - set_menu_sensitivity("/Display/Go To Frame...", TRUE); - set_menu_sensitivity("/Tools/Graph", TRUE); - set_menu_sensitivity("/Tools/Summary", TRUE); + set_menus_for_captured_packets(TRUE); for (i = 0; i < cf->cinfo.num_cols; i++) { if (get_column_resize_type(cf->cinfo.col_fmt[i]) == RESIZE_LIVE) @@ -478,20 +448,14 @@ finish_tail_cap_file(capture_file *cf) set_display_filename(cf); - /* Restore the "File/Open" menu item. */ - set_menu_sensitivity("/File/Open...", TRUE); + /* Enable menu items that make sense if you're not currently running + a capture. */ + set_menus_for_capture_in_progress(FALSE); /* Enable menu items that make sense if you have a capture file you've finished reading. */ - set_menu_sensitivity("/File/Save", !cf->user_saved); - set_menu_sensitivity("/File/Save As...", TRUE); - set_menu_sensitivity("/File/Close", TRUE); - set_menu_sensitivity("/File/Reload", TRUE); - set_menu_sensitivity("/File/Print...", TRUE); - - /* Enable menu items that make sense if you're not currently running - a capture. */ - set_menu_sensitivity("/Capture/Start...", TRUE); + set_menus_for_capture_file(TRUE); + set_menus_for_unsaved_capture_file(!cf->user_saved); return err; } @@ -1259,16 +1223,8 @@ select_packet(capture_file *cf, int row) packet_hex_print(GTK_TEXT(byte_view), cf->pd, cf->current_frame->cap_len, -1, -1, cf->current_frame->encoding); - /* A packet is selected, so "File/Print Packet" has something to print. */ - set_menu_sensitivity("/File/Print Packet", TRUE); - set_menu_sensitivity("/Display/Collapse All", TRUE); - set_menu_sensitivity("/Display/Expand All", TRUE); - - if (pi.ipproto == 6) { - set_menu_sensitivity("/Tools/Follow TCP Stream", TRUE); - } else { - set_menu_sensitivity("/Tools/Follow TCP Stream", FALSE); - } + /* A packet is selected. */ + set_menus_for_selected_packet(TRUE); } /* Unselect the selected packet, if any. */ @@ -1288,11 +1244,8 @@ unselect_packet(capture_file *cf) /* Clear out the display of that packet. */ clear_tree_and_hex_views(); - /* No packet is selected, so "File/Print Packet" has nothing to print. */ - set_menu_sensitivity("/File/Print Packet", FALSE); - set_menu_sensitivity("/Display/Collapse All", FALSE); - set_menu_sensitivity("/Display/Expand All", FALSE); - set_menu_sensitivity("/Tools/Follow TCP Stream", FALSE); + /* No packet is selected. */ + set_menus_for_selected_packet(FALSE); } static void @@ -1517,7 +1470,7 @@ done: if ((err = open_cap_file(fname, FALSE, cf)) == 0) { /* XXX - report errors if this fails? */ err = read_cap_file(cf); - set_menu_sensitivity("/File/Save", FALSE); + set_menus_for_unsaved_capture_file(FALSE); } } } diff --git a/gtk/menu.c b/gtk/menu.c index 84bbfaac7c..ee6b15f326 100644 --- a/gtk/menu.c +++ b/gtk/menu.c @@ -1,7 +1,7 @@ /* menu.c * Menu routines * - * $Id: menu.c,v 1.12 1999/12/10 07:04:30 guy Exp $ + * $Id: menu.c,v 1.13 2000/01/03 03:57:04 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -36,6 +36,8 @@ # include #endif +#include "../menu.h" + #include "main.h" #include "menu.h" #include "packet.h" @@ -148,25 +150,14 @@ menus_init(void) { factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "
", grp); gtk_item_factory_create_items_ac(factory, nmenu_items, menu_items, NULL,2); - set_menu_sensitivity("/File/Close", FALSE); - set_menu_sensitivity("/File/Save", FALSE); - set_menu_sensitivity("/File/Save As...", FALSE); - set_menu_sensitivity("/File/Reload", FALSE); - set_menu_sensitivity("/File/Print...", FALSE); - set_menu_sensitivity("/File/Print Packet", FALSE); + set_menus_for_unsaved_capture_file(FALSE); + set_menus_for_capture_file(FALSE); set_menu_sensitivity("/Edit/Cut", FALSE); set_menu_sensitivity("/Edit/Copy", FALSE); set_menu_sensitivity("/Edit/Paste", FALSE); set_menu_sensitivity("/Edit/Find", FALSE); - set_menu_sensitivity("/Display/Match Selected", FALSE); - set_menu_sensitivity("/Display/Colorize Display...", FALSE); - set_menu_sensitivity("/Display/Find Frame...", FALSE); - set_menu_sensitivity("/Display/Go To Frame...", FALSE); - set_menu_sensitivity("/Display/Collapse All", FALSE); - set_menu_sensitivity("/Display/Expand All", FALSE); - set_menu_sensitivity("/Tools/Follow TCP Stream", FALSE); - set_menu_sensitivity("/Tools/Graph", FALSE); - set_menu_sensitivity("/Tools/Summary", FALSE); + set_menus_for_captured_packets(FALSE); + set_menus_for_selected_packet(FALSE); } } @@ -186,4 +177,53 @@ set_menu_object_data (gchar *path, gchar *key, gpointer data) { gtk_object_set_data(GTK_OBJECT(menu), key, data); } +/* Enable or disable menu items based on whether you have a capture file + you've finished reading. */ +void +set_menus_for_capture_file(gboolean have_capture_file) +{ + set_menu_sensitivity("/File/Save As...", have_capture_file); + set_menu_sensitivity("/File/Close", have_capture_file); + set_menu_sensitivity("/File/Reload", have_capture_file); + set_menu_sensitivity("/File/Print...", have_capture_file); +} + +/* Enable or disable menu items based on whether you have an unsaved + capture file you've finished reading. */ +void +set_menus_for_unsaved_capture_file(gboolean have_unsaved_capture_file) +{ + set_menu_sensitivity("/File/Save", have_unsaved_capture_file); +} +/* Enable or disable menu items based on whether there's a capture in + progress. */ +void +set_menus_for_capture_in_progress(gboolean capture_in_progress) +{ + set_menu_sensitivity("/File/Open...", !capture_in_progress); + set_menu_sensitivity("/Capture/Start...", !capture_in_progress); +} + +/* Enable or disable menu items based on whether you have some captured + packets. */ +void +set_menus_for_captured_packets(gboolean have_captured_packets) +{ + set_menu_sensitivity("/Display/Match Selected", have_captured_packets); + set_menu_sensitivity("/Display/Colorize Display...", have_captured_packets); + set_menu_sensitivity("/Display/Find Frame...", have_captured_packets); + set_menu_sensitivity("/Display/Go To Frame...", have_captured_packets); + set_menu_sensitivity("/Tools/Summary", have_captured_packets); +} + +/* Enable or disable menu items based on whether a packet is selected. */ +void +set_menus_for_selected_packet(gboolean have_selected_packet) +{ + set_menu_sensitivity("/File/Print Packet", have_selected_packet); + set_menu_sensitivity("/Display/Collapse All", have_selected_packet); + set_menu_sensitivity("/Display/Expand All", have_selected_packet); + set_menu_sensitivity("/Tools/Follow TCP Stream", + have_selected_packet ? (pi.ipproto == 6) : FALSE); +} diff --git a/gtk/menu.h b/gtk/menu.h index f3559fa723..289581225a 100644 --- a/gtk/menu.h +++ b/gtk/menu.h @@ -1,7 +1,7 @@ /* menu.h * Menu definitions * - * $Id: menu.h,v 1.1 1999/09/01 03:04:23 gram Exp $ + * $Id: menu.h,v 1.2 2000/01/03 03:57:04 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -23,8 +23,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __MENU_H__ -#define __MENU_H__ +#ifndef __GTKGUIMENU_H__ +#define __GTKGUIMENU_H__ #ifdef __cplusplus extern "C" { @@ -44,4 +44,4 @@ void menus_create (GtkMenuEntry *, int); } #endif /* __cplusplus */ -#endif /* __MENU_H__ */ +#endif /* __GTKGUIMENU_H__ */ diff --git a/menu.h b/menu.h new file mode 100644 index 0000000000..f442803569 --- /dev/null +++ b/menu.h @@ -0,0 +1,60 @@ +/* menu.h + * Definitions for menu routines with toolkit-independent APIs but + * toolkit-dependent implementations. + * + * $Id: menu.h,v 1.7 2000/01/03 03:56:55 guy Exp $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __MENU_H__ +#define __MENU_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Routines to enable or disable sets of menu items. */ + +/* Enable or disable menu items based on whether you have a capture file + you've finished reading. */ +void set_menus_for_capture_file(gboolean); + +/* Enable or disable menu items based on whether you have an unsaved + capture file you've finished reading. */ +void set_menus_for_unsaved_capture_file(gboolean); + +/* Enable or disable menu items based on whether there's a capture in + progress. */ +void set_menus_for_capture_in_progress(gboolean); + +/* Enable or disable menu items based on whether you have some captured + packets. */ +void set_menus_for_captured_packets(gboolean); + +/* Enable or disable menu items based on whether a packet is selected. */ +void set_menus_for_selected_packet(gboolean); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __MENU_H__ */ + -- cgit v1.2.3