diff options
-rw-r--r-- | gtk/color_dlg.c | 3 | ||||
-rw-r--r-- | gtk/file_dlg.c | 118 | ||||
-rw-r--r-- | gtk/file_dlg.h | 5 | ||||
-rw-r--r-- | gtk/menu.c | 4 | ||||
-rw-r--r-- | gtk/print_dlg.c | 119 | ||||
-rw-r--r-- | gtk/proto_draw.c | 7 | ||||
-rw-r--r-- | gtk/toolbar.c | 4 |
7 files changed, 134 insertions, 126 deletions
diff --git a/gtk/color_dlg.c b/gtk/color_dlg.c index 9d7cea734e..c9ea39d392 100644 --- a/gtk/color_dlg.c +++ b/gtk/color_dlg.c @@ -1,7 +1,7 @@ /* color_dlg.c * Definitions for dialog boxes for color filters * - * $Id: color_dlg.c,v 1.27 2003/10/07 10:07:47 sahlberg Exp $ + * $Id: color_dlg.c,v 1.28 2003/11/30 04:21:54 sharpe Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -44,6 +44,7 @@ #include "ui_util.h" #include "dfilter_expr_dlg.h" #include "compat_macros.h" +#include "filter_prefs.h" #include "file_dlg.h" static GtkWidget* colorize_dialog_new(char *filter); diff --git a/gtk/file_dlg.c b/gtk/file_dlg.c index 21e1be231f..5d74db3ccd 100644 --- a/gtk/file_dlg.c +++ b/gtk/file_dlg.c @@ -1,7 +1,7 @@ /* file_dlg.c * Dialog boxes for handling files * - * $Id: file_dlg.c,v 1.64 2003/10/16 00:45:12 guy Exp $ + * $Id: file_dlg.c,v 1.65 2003/11/30 04:21:54 sharpe Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -56,6 +56,9 @@ static void file_color_import_ok_cb(GtkWidget *w, GtkFileSelection *fs); static void file_color_import_destroy_cb(GtkWidget *win, gpointer user_data); static void file_color_export_ok_cb(GtkWidget *w, GtkFileSelection *fs); static void file_color_export_destroy_cb(GtkWidget *win, gpointer user_data); +static void file_select_ok_cb(GtkWidget *w, gpointer data); +static void file_select_cancel_cb(GtkWidget *w, gpointer data); +static void file_select_destroy_cb(GtkWidget *win, GtkWidget* file_te); #define E_FILE_M_RESOLVE_KEY "file_dlg_mac_resolve_key" #define E_FILE_N_RESOLVE_KEY "file_dlg_network_resolve_key" @@ -64,6 +67,119 @@ static void file_color_export_destroy_cb(GtkWidget *win, gpointer user_data); #define ARGUMENT_CL "argument_cl" /* + * A generic select_file_cb routine that is intended to be connected to + * a Browse button on other dialog boxes. This allows the user to browse + * for a file and select it. We fill in the text_entry that is asssociated + * with the button that invoked us. + * + * We display the window label specified in our args. + */ +void +select_file_cb(GtkWidget *file_bt, construct_args_t *args _U_) +{ + GtkWidget *caller = gtk_widget_get_toplevel(file_bt); + GtkWidget *fs, *file_te; + + /* Has a file selection dialog box already been opened for that top-level + widget? */ + fs = OBJECT_GET_DATA(caller, E_FILE_SEL_DIALOG_PTR_KEY); + file_te = OBJECT_GET_DATA(file_bt, E_FILE_TE_PTR_KEY); + if (fs != NULL) { + /* Yes. Just re-activate that dialog box. */ + reactivate_window(fs); + return; + } + + fs = file_selection_new ("Ethereal: Print to File"); + + /* If we've opened a file, start out by showing the files in the directory + in which that file resided. */ + if (last_open_dir) + gtk_file_selection_set_filename(GTK_FILE_SELECTION(fs), last_open_dir); + + OBJECT_SET_DATA(fs, PRINT_FILE_TE_KEY, file_te); + + /* Set the E_FS_CALLER_PTR_KEY for the new dialog to point to our caller. */ + OBJECT_SET_DATA(fs, E_FS_CALLER_PTR_KEY, caller); + + /* Set the E_FILE_SEL_DIALOG_PTR_KEY for the caller to point to us */ + OBJECT_SET_DATA(caller, E_FILE_SEL_DIALOG_PTR_KEY, fs); + + /* Call a handler when the file selection box is destroyed, so we can inform + our caller, if any, that it's been destroyed. */ + SIGNAL_CONNECT(fs, "destroy", GTK_SIGNAL_FUNC(file_select_destroy_cb), + file_te); + + SIGNAL_CONNECT(GTK_FILE_SELECTION(fs)->ok_button, "clicked", + file_select_ok_cb, fs); + + /* Connect the cancel_button to destroy the widget */ + SIGNAL_CONNECT(GTK_FILE_SELECTION(fs)->cancel_button, "clicked", + file_select_cancel_cb, fs); + + /* Catch the "key_press_event" signal in the window, so that we can catch + the ESC key being pressed and act as if the "Cancel" button had + been selected. */ + dlg_set_cancel(fs, GTK_FILE_SELECTION(fs)->cancel_button); + + gtk_widget_show(fs); +} + +static void +file_select_ok_cb(GtkWidget *w _U_, gpointer data) +{ + gchar *f_name; + + f_name = g_strdup(gtk_file_selection_get_filename( + GTK_FILE_SELECTION (data))); + + /* Perhaps the user specified a directory instead of a file. + Check whether they did. */ + if (test_for_directory(f_name) == EISDIR) { + /* It's a directory - set the file selection box to display it. */ + set_last_open_dir(f_name); + g_free(f_name); + gtk_file_selection_set_filename(GTK_FILE_SELECTION(data), + last_open_dir); + return; + } + + gtk_entry_set_text(GTK_ENTRY(OBJECT_GET_DATA(data, PRINT_FILE_TE_KEY)), + f_name); + gtk_widget_destroy(GTK_WIDGET(data)); + + g_free(f_name); +} + +static void +file_select_cancel_cb(GtkWidget *w _U_, gpointer data) +{ + gtk_widget_destroy(GTK_WIDGET(data)); +} + +static void +file_select_destroy_cb(GtkWidget *win, GtkWidget* file_te) +{ + GtkWidget *caller; + + /* Get the widget that requested that we be popped up. + (It should arrange to destroy us if it's destroyed, so + that we don't get a pointer to a non-existent window here.) */ + caller = OBJECT_GET_DATA(win, E_FS_CALLER_PTR_KEY); + + /* Tell it we no longer exist. */ + OBJECT_SET_DATA(caller, E_FILE_SEL_DIALOG_PTR_KEY, NULL); + + /* Now nuke this window. */ + gtk_grab_remove(GTK_WIDGET(win)); + gtk_widget_destroy(GTK_WIDGET(win)); + + /* Give the focus to the file text entry widget so the user can just press + Return to print to the file. */ + gtk_widget_grab_focus(file_te); +} + +/* * Keep a static pointer to the current "Open Capture File" window, if * any, so that if somebody tries to do "File:Open" while there's already * an "Open Capture File" window up, we just pop up the existing one, diff --git a/gtk/file_dlg.h b/gtk/file_dlg.h index f252c6380b..e7117fbf0f 100644 --- a/gtk/file_dlg.h +++ b/gtk/file_dlg.h @@ -1,7 +1,7 @@ /* file_dlg.h * Definitions for dialog boxes for handling files * - * $Id: file_dlg.h,v 1.5 2003/11/29 06:09:53 sharpe Exp $ + * $Id: file_dlg.h,v 1.6 2003/11/30 04:21:54 sharpe Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -30,12 +30,15 @@ void file_save_cmd_cb(GtkWidget *, gpointer); void file_save_as_cmd_cb(GtkWidget *, gpointer); void file_close_cmd_cb(GtkWidget *, gpointer); void file_reload_cmd_cb(GtkWidget *, gpointer); +void select_file_cb(GtkWidget *file_bt, construct_args_t *args); void file_color_import_cmd_cb(GtkWidget *w, gpointer data); void file_color_export_cmd_cb(GtkWidget *, gpointer); /* Keys ... */ #define E_FILE_TE_PTR_KEY "file_te_ptr" +#define E_FILE_SEL_DIALOG_PTR_KEY "file_sel_dialog_ptr" +#define E_FS_CALLER_PTR_KEY "fs_caller_ptr" /* * Set the "Save only marked packets" toggle button as appropriate for diff --git a/gtk/menu.c b/gtk/menu.c index d59ab0550b..660a5709df 100644 --- a/gtk/menu.c +++ b/gtk/menu.c @@ -1,7 +1,7 @@ /* menu.c * Menu routines * - * $Id: menu.c,v 1.114 2003/11/29 06:15:05 sharpe Exp $ + * $Id: menu.c,v 1.115 2003/11/30 04:21:55 sharpe Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -37,8 +37,8 @@ #include "prefs.h" #include "capture_dlg.h" #include "color_dlg.h" -#include "file_dlg.h" #include "filter_prefs.h" +#include "file_dlg.h" #include "find_dlg.h" #include "goto_dlg.h" #include "summary_dlg.h" diff --git a/gtk/print_dlg.c b/gtk/print_dlg.c index c3166c0239..b5e0dcfd22 100644 --- a/gtk/print_dlg.c +++ b/gtk/print_dlg.c @@ -1,7 +1,7 @@ /* print_dlg.c * Dialog boxes for printing * - * $Id: print_dlg.c,v 1.46 2003/11/29 06:09:54 sharpe Exp $ + * $Id: print_dlg.c,v 1.47 2003/11/30 04:21:55 sharpe Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -37,6 +37,9 @@ * Only need this for construct_args */ #include "filter_prefs.h" +/* + * file_dlg.h must come after filter_prefs.h + */ #include "file_dlg.h" #include "ui_util.h" #include "dlg_utils.h" @@ -59,12 +62,8 @@ for this (and also use various UNIX printing APIs, when present?). */ -void print_file_cb(GtkWidget *file_bt, construct_args_t *args); static void print_cmd_toggle_dest(GtkWidget *widget, gpointer data); static void print_cmd_toggle_detail(GtkWidget *widget, gpointer data); -static void print_fs_ok_cb(GtkWidget *w, gpointer data); -static void print_fs_cancel_cb(GtkWidget *w, gpointer data); -static void print_fs_destroy_cb(GtkWidget *win, GtkWidget* file_te); static void print_ok_cb(GtkWidget *ok_bt, gpointer parent_w); static void print_close_cb(GtkWidget *close_bt, gpointer parent_w); static void print_destroy_cb(GtkWidget *win, gpointer user_data); @@ -97,10 +96,6 @@ static gchar * print_cmd; #define PRINT_EXPAND_ALL_RB_KEY "printer_expand_all_radio_button" #define PRINT_PRINT_ONLY_MARKED_RB_KEY "printer_print_only_marked_radio_button" -#define E_FS_CALLER_PTR_KEY "fs_caller_ptr" -#define E_FILE_SEL_DIALOG_PTR_KEY "file_sel_dialog_ptr" - - /* * Keep a static pointer to the current "Print" window, if any, so that if * somebody tries to do "File:Print" while there's already a "Print" window @@ -297,7 +292,7 @@ file_print_cmd_cb(GtkWidget *widget _U_, gpointer data _U_) #endif SIGNAL_CONNECT(dest_cb, "toggled", print_cmd_toggle_dest, NULL); - SIGNAL_CONNECT(file_bt, "clicked", print_file_cb, &file_dlg_args); + SIGNAL_CONNECT(file_bt, "clicked", select_file_cb, &file_dlg_args); /*****************************************************/ @@ -602,110 +597,6 @@ print_cmd_toggle_detail(GtkWidget *widget, gpointer data _U_) gtk_widget_set_sensitive(hex_cb, print_detail); } -void -print_file_cb(GtkWidget *file_bt, construct_args_t *args _U_) -{ - GtkWidget *caller = gtk_widget_get_toplevel(file_bt); - GtkWidget *fs, *file_te; - - /* Has a file selection dialog box already been opened for that top-level - widget? */ - fs = OBJECT_GET_DATA(caller, E_FILE_SEL_DIALOG_PTR_KEY); - file_te = OBJECT_GET_DATA(file_bt, E_FILE_TE_PTR_KEY); - if (fs != NULL) { - /* Yes. Just re-activate that dialog box. */ - reactivate_window(fs); - return; - } - - fs = file_selection_new ("Ethereal: Print to File"); - - /* If we've opened a file, start out by showing the files in the directory - in which that file resided. */ - if (last_open_dir) - gtk_file_selection_set_filename(GTK_FILE_SELECTION(fs), last_open_dir); - - OBJECT_SET_DATA(fs, PRINT_FILE_TE_KEY, file_te); - - /* Set the E_FS_CALLER_PTR_KEY for the new dialog to point to our caller. */ - OBJECT_SET_DATA(fs, E_FS_CALLER_PTR_KEY, caller); - - /* Set the E_FILE_SEL_DIALOG_PTR_KEY for the caller to point to us */ - OBJECT_SET_DATA(caller, E_FILE_SEL_DIALOG_PTR_KEY, fs); - - /* Call a handler when the file selection box is destroyed, so we can inform - our caller, if any, that it's been destroyed. */ - SIGNAL_CONNECT(fs, "destroy", GTK_SIGNAL_FUNC(print_fs_destroy_cb), file_te); - - SIGNAL_CONNECT(GTK_FILE_SELECTION(fs)->ok_button, "clicked", print_fs_ok_cb, - fs); - - /* Connect the cancel_button to destroy the widget */ - SIGNAL_CONNECT(GTK_FILE_SELECTION(fs)->cancel_button, "clicked", - print_fs_cancel_cb, fs); - - /* Catch the "key_press_event" signal in the window, so that we can catch - the ESC key being pressed and act as if the "Cancel" button had - been selected. */ - dlg_set_cancel(fs, GTK_FILE_SELECTION(fs)->cancel_button); - - gtk_widget_show(fs); -} - -static void -print_fs_ok_cb(GtkWidget *w _U_, gpointer data) -{ - gchar *f_name; - - f_name = g_strdup(gtk_file_selection_get_filename( - GTK_FILE_SELECTION (data))); - - /* Perhaps the user specified a directory instead of a file. - Check whether they did. */ - if (test_for_directory(f_name) == EISDIR) { - /* It's a directory - set the file selection box to display it. */ - set_last_open_dir(f_name); - g_free(f_name); - gtk_file_selection_set_filename(GTK_FILE_SELECTION(data), - last_open_dir); - return; - } - - gtk_entry_set_text(GTK_ENTRY(OBJECT_GET_DATA(data, PRINT_FILE_TE_KEY)), - f_name); - gtk_widget_destroy(GTK_WIDGET(data)); - - g_free(f_name); -} - -static void -print_fs_cancel_cb(GtkWidget *w _U_, gpointer data) -{ - gtk_widget_destroy(GTK_WIDGET(data)); -} - -static void -print_fs_destroy_cb(GtkWidget *win, GtkWidget* file_te) -{ - GtkWidget *caller; - - /* Get the widget that requested that we be popped up. - (It should arrange to destroy us if it's destroyed, so - that we don't get a pointer to a non-existent window here.) */ - caller = OBJECT_GET_DATA(win, E_FS_CALLER_PTR_KEY); - - /* Tell it we no longer exist. */ - OBJECT_SET_DATA(caller, E_FILE_SEL_DIALOG_PTR_KEY, NULL); - - /* Now nuke this window. */ - gtk_grab_remove(GTK_WIDGET(win)); - gtk_widget_destroy(GTK_WIDGET(win)); - - /* Give the focus to the file text entry widget so the user can just press - Return to print to the file. */ - gtk_widget_grab_focus(file_te); -} - #ifdef _WIN32 void setup_mswin_print( print_args_t *print_args) { diff --git a/gtk/proto_draw.c b/gtk/proto_draw.c index 0acf96efa1..e6ffb31843 100644 --- a/gtk/proto_draw.c +++ b/gtk/proto_draw.c @@ -1,7 +1,7 @@ /* proto_draw.c * Routines for GTK+ packet display * - * $Id: proto_draw.c,v 1.66 2003/11/29 06:09:54 sharpe Exp $ + * $Id: proto_draw.c,v 1.67 2003/11/30 04:21:55 sharpe Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -749,9 +749,6 @@ savehex_dlg_cancel_cb(GtkWidget *cancel_bt _U_, gpointer parent_w) gtk_widget_destroy(GTK_WIDGET(parent_w)); } -/* Needed because we don't declare it yet anywhere */ -void print_file_cb(GtkWidget *file_bt, construct_args_t *args _U_); - /* Forward declaration */ static void savehex_save_clicked_cb(GtkWidget * w, gpointer data); @@ -803,7 +800,7 @@ void savehex_cb(GtkWidget * w _U_, gpointer data _U_) /* File Browse button */ file_bt = gtk_button_new_with_label("Browse:"); - SIGNAL_CONNECT(file_bt, "clicked", print_file_cb, &args); + SIGNAL_CONNECT(file_bt, "clicked", select_file_cb, &args); /* file entry for print dialog */ OBJECT_SET_DATA(file_bt, E_FILE_TE_PTR_KEY, file_entry); diff --git a/gtk/toolbar.c b/gtk/toolbar.c index d1770bc1be..3c333b438d 100644 --- a/gtk/toolbar.c +++ b/gtk/toolbar.c @@ -2,7 +2,7 @@ * The main toolbar * Copyright 2003, Ulf Lamping <ulf.lamping@web.de> * - * $Id: toolbar.c,v 1.16 2003/11/28 18:59:02 ulfl Exp $ + * $Id: toolbar.c,v 1.17 2003/11/30 04:21:55 sharpe Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -46,12 +46,12 @@ #ifdef HAVE_LIBPCAP #include "capture_dlg.h" #endif /* HAVE_LIBPCAP */ +#include "filter_prefs.h" #include "file_dlg.h" #include "find_dlg.h" #include "goto_dlg.h" #include "color.h" #include "color_dlg.h" -#include "filter_prefs.h" #include "prefs.h" #include "prefs_dlg.h" #include "main.h" |