4 * $Id: menu.c,v 1.1 1999/09/01 03:04:23 gram Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #ifdef HAVE_SYS_TYPES_H
36 # include <sys/types.h>
52 /* This is the GtkItemFactoryEntry structure used to generate new menus.
53 Item 1: The menu path. The letter after the underscore indicates an
54 accelerator key once the menu is open.
55 Item 2: The accelerator key for the entry
56 Item 3: The callback function.
57 Item 4: The callback action. This changes the parameters with
58 which the function is called. The default is 0.
59 Item 5: The item type, used to define what kind of an item it is.
60 Here are the possible values:
64 "<Title>" -> create a title item
65 "<Item>" -> create a simple item
66 "<CheckItem>" -> create a check item
67 "<ToggleItem>" -> create a toggle item
68 "<RadioItem>" -> create a radio item
69 <path> -> path of a radio item to link against
70 "<Separator>" -> create a separator
71 "<Branch>" -> create an item to hold sub items (optional)
72 "<LastBranch>" -> create a right justified branch
75 static GtkItemFactoryEntry menu_items[] =
77 {"/_File", NULL, NULL, 0, "<Branch>" },
78 {"/File/_Open...", "<control>O", GTK_MENU_FUNC(file_open_cmd_cb), 0, NULL},
79 {"/File/_Close", "<control>W", GTK_MENU_FUNC(file_close_cmd_cb), 0, NULL},
80 {"/File/_Save", "<control>S", GTK_MENU_FUNC(file_save_cmd_cb), 0, NULL},
81 {"/File/Save _As...", NULL, GTK_MENU_FUNC(file_save_as_cmd_cb), 0, NULL},
82 {"/File/_Reload", "<control>R", GTK_MENU_FUNC(file_reload_cmd_cb), 0, NULL},
83 {"/File/<separator>", NULL, NULL, 0, "<Separator>"},
84 {"/File/Print...", NULL, GTK_MENU_FUNC(file_print_cmd_cb), 0, NULL},
85 {"/File/Print Pac_ket", "<control>P", GTK_MENU_FUNC(file_print_packet_cmd_cb), 0, NULL},
86 {"/File/<separator>", NULL, NULL, 0, "<Separator>"},
87 {"/File/_Quit", "<control>Q", GTK_MENU_FUNC(file_quit_cmd_cb), 0, NULL},
88 {"/_Edit", NULL, NULL, 0, "<Branch>" },
89 {"/Edit/Cut", "<control>X", NULL, 0, NULL},
90 {"/Edit/Copy", "<control>C", NULL, 0, NULL},
91 {"/Edit/Paste", "<control>V", NULL, 0, NULL},
92 {"/Edit/<separator>", NULL, NULL, 0, "<Separator>"},
93 {"/Edit/Find", "<control>F", NULL, 0, NULL},
94 {"/Edit/<separator>", NULL, NULL, 0, "<Separator>"},
95 {"/Edit/_Preferences...", NULL, GTK_MENU_FUNC(prefs_cb), E_PR_PG_NONE, NULL},
97 {"/_Capture", NULL, NULL, 0, "<Branch>" },
98 {"/Capture/_Start...", "<control>K", GTK_MENU_FUNC(capture_prep_cb), 0, NULL},
100 {"/_Display", NULL, NULL, 0, "<Branch>" },
101 {"/Display/_Options...", NULL, GTK_MENU_FUNC(display_opt_cb), 0, NULL},
102 {"/Display/_Match Selected", NULL, GTK_MENU_FUNC(match_selected_cb), 0, NULL},
103 {"/Display/_Colorize Display...", NULL, GTK_MENU_FUNC(color_display_cb), 0, NULL},
104 {"/_Tools", NULL, NULL, 0, "<Branch>" },
105 {"/Tools/_Follow TCP Stream", NULL, GTK_MENU_FUNC(follow_stream_cb), 0, NULL},
106 /* {"/Tools/Graph", NULL, NULL, 0, NULL}, future use */
107 {"/Tools/_Summary", NULL, GTK_MENU_FUNC(summary_prep_cb), 0, NULL},
108 {"/_Help", NULL, NULL, 0, "<LastBranch>" },
109 {"/Help/_About Ethereal...", NULL, GTK_MENU_FUNC(about_ethereal), 0, NULL}
112 /* calculate the number of menu_items */
113 static int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
115 static int initialize = TRUE;
116 static GtkItemFactory *factory = NULL;
119 get_main_menu(GtkWidget ** menubar, GtkAccelGroup ** table) {
121 grp = gtk_accel_group_new();
127 *menubar = factory->widget;
139 factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", grp);
140 gtk_item_factory_create_items_ac(factory, nmenu_items, menu_items, NULL,2);
141 set_menu_sensitivity("/File/Close", FALSE);
142 set_menu_sensitivity("/File/Save", FALSE);
143 set_menu_sensitivity("/File/Save As...", FALSE);
144 set_menu_sensitivity("/File/Reload", FALSE);
145 set_menu_sensitivity("/File/Print...", FALSE);
146 set_menu_sensitivity("/File/Print Packet", FALSE);
147 set_menu_sensitivity("/Edit/Cut", FALSE);
148 set_menu_sensitivity("/Edit/Copy", FALSE);
149 set_menu_sensitivity("/Edit/Paste", FALSE);
150 set_menu_sensitivity("/Edit/Find", FALSE);
151 set_menu_sensitivity("/Tools/Graph", FALSE);
152 set_menu_sensitivity("/Tools/Summary", FALSE);
157 set_menu_sensitivity (gchar *path, gint val) {
160 if ((menu = gtk_item_factory_get_widget(factory, path)) != NULL)
161 gtk_widget_set_sensitive(menu, val);
165 set_menu_object_data (gchar *path, gchar *key, gpointer data) {
168 if ((menu = gtk_item_factory_get_widget(factory, path)) != NULL)
169 gtk_object_set_data(GTK_OBJECT(menu), key, data);