aboutsummaryrefslogtreecommitdiffstats
path: root/gtk/gui_prefs.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2003-10-14 23:20:17 +0000
committerGuy Harris <guy@alum.mit.edu>2003-10-14 23:20:17 +0000
commitffa3ad8ef5e25ea4ea39e3f6cf8bee050ef0e87a (patch)
treeb24965e884a58b7294db3dbbe98413390d4ebbe2 /gtk/gui_prefs.c
parent2956d71a7b6cb56c49b04fffc58f6f335da1c21d (diff)
From Ian Schorr:
Add a preference to control whether the "File > Open" dialog box should start out in the last directory in which it looked - and save that in the preferences file across invocations - or should always start out in a user-specified directory, and add another preference to specify that directory. Write out section name comments into the preferences file. Clean up white space a bit. svn path=/trunk/; revision=8699
Diffstat (limited to 'gtk/gui_prefs.c')
-rw-r--r--gtk/gui_prefs.c74
1 files changed, 72 insertions, 2 deletions
diff --git a/gtk/gui_prefs.c b/gtk/gui_prefs.c
index 52a450f16f..57ccbcb1d1 100644
--- a/gtk/gui_prefs.c
+++ b/gtk/gui_prefs.c
@@ -1,7 +1,7 @@
/* gui_prefs.c
* Dialog box for GUI preferences
*
- * $Id: gui_prefs.c,v 1.40 2003/09/02 18:27:50 gerald Exp $
+ * $Id: gui_prefs.c,v 1.41 2003/10/14 23:20:17 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -28,6 +28,8 @@
#include <gtk/gtk.h>
+#include <string.h>
+
#include "color.h"
#include "color_utils.h"
#include "globals.h"
@@ -56,6 +58,8 @@ static void color_cancel_cb(GtkWidget *w, gpointer data);
static gboolean color_delete_cb(GtkWidget *prefs_w, gpointer dummy);
static void color_destroy_cb(GtkWidget *w, gpointer data);
static void fetch_colors(void);
+static gint fileopen_dir_changed_cb(GtkWidget *myentry _U_, GdkEvent *event, gpointer parent_w);
+static void fileopen_selected_cb(GtkWidget *mybutton_rb _U_, gpointer parent_w);
#define SCROLLBAR_PLACEMENT_KEY "scrollbar_placement"
#define PLIST_SEL_BROWSE_KEY "plist_sel_browse"
@@ -77,6 +81,9 @@ static void fetch_colors(void);
#define COLOR_SAMPLE_PTR_KEY "color_sample_ptr"
#define COLOR_SELECTION_PTR_KEY "color_selection_ptr"
+#define GUI_FILEOPEN_KEY "fileopen_behavior"
+#define GUI_FILEOPEN_DIR_KEY "fileopen_directory"
+
static const enum_val_t scrollbar_placement_vals[] = {
{ "Left", FALSE },
{ "Right", TRUE },
@@ -119,6 +126,12 @@ static const enum_val_t highlight_style_vals[] = {
{ NULL, 0 }
};
+static const enum_val_t gui_fileopen_vals[] = {
+ { "Remember last directory", FO_STYLE_LAST_OPENED },
+ { "Always start in directory:", FO_STYLE_SPECIFIED },
+ { NULL, 0 }
+};
+
/* Set to FALSE initially; set to TRUE if the user ever hits "OK" on
the "Colors..." dialog, so that we know that they (probably) changed
colors, and therefore that the "apply" function needs to recolor
@@ -135,13 +148,15 @@ static gboolean font_changed;
has been set to the name of the font the user selected. */
static gchar *new_font_name;
-#define GUI_TABLE_ROWS 8
+#define GUI_TABLE_ROWS 10
+
GtkWidget*
gui_prefs_show(void)
{
GtkWidget *main_tb, *main_vb, *hbox, *font_bt, *color_bt;
GtkWidget *scrollbar_om, *plist_browse_om;
GtkWidget *ptree_browse_om, *highlight_style_om;
+ GtkWidget *fileopen_rb, *fileopen_dir_te;
GtkWidget *save_position_cb, *save_size_cb;
#if GTK_MAJOR_VERSION < 2
GtkWidget *expander_style_om, *line_style_om;
@@ -241,6 +256,20 @@ gui_prefs_show(void)
#endif
SIGNAL_CONNECT(color_bt, "clicked", color_browse_cb, NULL);
gtk_table_attach_defaults( GTK_TABLE(main_tb), color_bt, 2, 3, 1, 2 );
+
+ /* Directory to default File Open dialog to */
+ fileopen_dir_te = create_preference_entry(main_tb, 9, "Directory:", NULL,
+ prefs.gui_fileopen_dir);
+ OBJECT_SET_DATA(main_vb, GUI_FILEOPEN_DIR_KEY, fileopen_dir_te);
+ SIGNAL_CONNECT(fileopen_dir_te, "focus-out-event", fileopen_dir_changed_cb, main_vb);
+
+ /* Allow user to select where they want the File Open dialog to open to by default */
+ fileopen_rb = create_preference_radio_buttons(main_tb, 8, "File Open dialog behavior:",
+ NULL, gui_fileopen_vals, prefs.gui_fileopen_style);
+ SIGNAL_CONNECT(fileopen_rb, "clicked", fileopen_selected_cb, main_vb);
+ OBJECT_SET_DATA(main_vb, GUI_FILEOPEN_KEY, fileopen_rb);
+
+ fileopen_selected_cb(NULL, main_vb);
/* Show 'em what we got */
gtk_widget_show_all(main_vb);
@@ -455,6 +484,13 @@ gui_prefs_fetch(GtkWidget *w)
GEOMETRY_POSITION_KEY));
prefs.gui_geometry_save_size =
gtk_toggle_button_get_active(OBJECT_GET_DATA(w, GEOMETRY_SIZE_KEY));
+ prefs.gui_fileopen_style = fetch_preference_radio_buttons_val(
+ OBJECT_GET_DATA(w, GUI_FILEOPEN_KEY), gui_fileopen_vals);
+
+ if (prefs.gui_fileopen_dir != NULL)
+ g_free(prefs.gui_fileopen_dir);
+ prefs.gui_fileopen_dir = g_strdup(gtk_entry_get_text(
+ GTK_ENTRY(OBJECT_GET_DATA(w, GUI_FILEOPEN_DIR_KEY))));
if (font_changed) {
if (prefs.gui_font_name != NULL)
@@ -590,6 +626,40 @@ static color_info_t color_info[MAX_HANDLED_COL] = {
static GdkColor *curcolor = NULL;
+static gint
+fileopen_dir_changed_cb(GtkWidget *fileopen_entry _U_, GdkEvent *event _U_, gpointer parent_w)
+{
+ GtkWidget *fileopen_dir_te;
+ char *lastchar;
+ gint fileopen_dir_te_length;
+
+ fileopen_dir_te = (GtkWidget *)OBJECT_GET_DATA(parent_w, GUI_FILEOPEN_DIR_KEY);
+ fileopen_dir_te_length = strlen(gtk_entry_get_text (GTK_ENTRY(fileopen_entry)));
+ lastchar = gtk_editable_get_chars(GTK_EDITABLE(fileopen_entry), fileopen_dir_te_length-1, -1);
+ if (strcmp(lastchar, G_DIR_SEPARATOR_S) != 0)
+ gtk_entry_append_text(GTK_ENTRY(fileopen_entry), G_DIR_SEPARATOR_S);
+ return(TRUE);
+}
+
+static void
+fileopen_selected_cb(GtkWidget *mybutton_rb _U_, gpointer parent_w)
+{
+ GtkWidget *fileopen_rb, *fileopen_dir_te;
+
+ fileopen_rb = (GtkWidget *)OBJECT_GET_DATA(parent_w, GUI_FILEOPEN_KEY);
+ fileopen_dir_te = (GtkWidget *)OBJECT_GET_DATA(parent_w, GUI_FILEOPEN_DIR_KEY);
+
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(fileopen_rb)))
+ {
+ gtk_widget_set_sensitive(GTK_WIDGET(fileopen_dir_te), TRUE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive(GTK_WIDGET(fileopen_dir_te), FALSE);
+ }
+ return;
+}
+
static void
color_browse_cb(GtkWidget *w, gpointer data _U_)
{