aboutsummaryrefslogtreecommitdiffstats
path: root/gtk/print_dlg.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2002-09-09 20:39:01 +0000
committerGuy Harris <guy@alum.mit.edu>2002-09-09 20:39:01 +0000
commit5e8ecbaf4650a35ee0c3e9240bbcedb7def95e2c (patch)
tree7000f7732a62713bbfe2090a8de2e9282043c196 /gtk/print_dlg.c
parent49425de3968d29fc8af95f349aba0164a2989b77 (diff)
From Graeme Hewson:
Currently Ethereal sets and uses a default directory for reading and writing, but only in some places. This set of patches extends the setting of the default directory to the -w option as well as the -r option, and causes all file dialogs to use and set the default consistently. (I haven't changed the Preferences/Printing/File dialog, though, as that's a special case.) There's also a fix for a bug where Ethereal was issuing the message "Ring buffer requested, but capture isn't being saved to a permanent file" even though a file was specified with -w. There also appear to be some other cleanups in his patch. svn path=/trunk/; revision=6238
Diffstat (limited to 'gtk/print_dlg.c')
-rw-r--r--gtk/print_dlg.c46
1 files changed, 40 insertions, 6 deletions
diff --git a/gtk/print_dlg.c b/gtk/print_dlg.c
index 1b6ab11e77..ea9f6083b9 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.36 2002/09/05 18:47:47 jmayer Exp $
+ * $Id: print_dlg.c,v 1.37 2002/09/09 20:38:58 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -35,7 +35,9 @@
#include "simple_dialog.h"
#include "ui_util.h"
#include "dlg_utils.h"
+#include "main.h"
#include <epan/epan_dissect.h>
+#include <epan/filesystem.h>
#ifdef _WIN32
#include <io.h>
#include "print_mswin.h"
@@ -56,7 +58,7 @@ static void print_cmd_toggle_detail(GtkWidget *widget, gpointer data);
static void print_file_cb(GtkWidget *file_bt, gpointer file_te);
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, 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);
@@ -241,6 +243,8 @@ file_print_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
gtk_table_attach_defaults(GTK_TABLE(main_tb), file_te, 1, 2, 3, 4);
gtk_widget_set_sensitive(file_te, print_to_file);
gtk_widget_show(file_te);
+ if (print_to_file)
+ gtk_widget_grab_focus(file_te);
gtk_signal_connect(GTK_OBJECT(file_bt), "clicked",
GTK_SIGNAL_FUNC(print_file_cb), GTK_OBJECT(file_te));
@@ -442,6 +446,12 @@ print_file_cb(GtkWidget *file_bt, gpointer file_te)
}
fs = gtk_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);
+
gtk_object_set_data(GTK_OBJECT(fs), PRINT_FILE_TE_KEY, file_te);
/* Set the E_FS_CALLER_PTR_KEY for the new dialog to point to our caller. */
@@ -453,7 +463,7 @@ print_file_cb(GtkWidget *file_bt, gpointer file_te)
/* Call a handler when the file selection box is destroyed, so we can inform
our caller, if any, that it's been destroyed. */
gtk_signal_connect(GTK_OBJECT(fs), "destroy",
- GTK_SIGNAL_FUNC(print_fs_destroy_cb), NULL);
+ GTK_SIGNAL_FUNC(print_fs_destroy_cb), file_te);
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION(fs)->ok_button),
"clicked", (GtkSignalFunc) print_fs_ok_cb, fs);
@@ -473,11 +483,31 @@ print_file_cb(GtkWidget *file_bt, gpointer file_te)
static void
print_fs_ok_cb(GtkWidget *w _U_, gpointer data)
{
+ gchar *cf_name;
+ gchar *dirname;
+
+ cf_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(cf_name) == EISDIR) {
+ /* It's a directory - set the file selection box to display it. */
+ set_last_open_dir(cf_name);
+ g_free(cf_name);
+ gtk_file_selection_set_filename(GTK_FILE_SELECTION(data),
+ last_open_dir);
+ return;
+ }
gtk_entry_set_text(GTK_ENTRY(gtk_object_get_data(GTK_OBJECT(data),
- PRINT_FILE_TE_KEY)),
- gtk_file_selection_get_filename (GTK_FILE_SELECTION(data)));
+ PRINT_FILE_TE_KEY)), cf_name);
gtk_widget_destroy(GTK_WIDGET(data));
+
+ /* Save the directory name for future file dialogs. */
+ dirname = get_dirname(cf_name); /* Overwrites cf_name */
+ set_last_open_dir(dirname);
+ g_free(cf_name);
}
static void
@@ -487,7 +517,7 @@ print_fs_cancel_cb(GtkWidget *w _U_, gpointer data)
}
static void
-print_fs_destroy_cb(GtkWidget *win, gpointer data _U_)
+print_fs_destroy_cb(GtkWidget *win, GtkWidget* file_te)
{
GtkWidget *caller;
@@ -502,6 +532,10 @@ print_fs_destroy_cb(GtkWidget *win, gpointer data _U_)
/* 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