2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999,2000 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <gdk/gdkkeysyms.h>
22 #include <gtk/gtkwidget.h>
23 #include <gtk/gtkfilesel.h>
24 #include <gtk/gtkmain.h>
25 #include <gtk/gtksignal.h>
29 #include "manage_window.h"
32 static GtkWidget *filesel;
33 static gboolean filesel_ack;
35 static void filesel_create(const gchar *title);
36 static void filesel_ok_cb(GtkWidget *widget, gpointer data);
37 static void filesel_cancel_cb(GtkWidget *widget, gpointer data);
38 static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data);
39 static void key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data);
41 gchar *filesel_select_file(const gchar *title, const gchar *file)
43 static gchar *filename = NULL;
44 static gchar *cwd = NULL;
46 filesel_create(title);
48 manage_window_set_transient(GTK_WINDOW(filesel));
56 cwd = g_strconcat(startup_dir, G_DIR_SEPARATOR_S, NULL);
58 gtk_file_selection_set_filename(GTK_FILE_SELECTION(filesel), cwd);
61 gtk_file_selection_set_filename(GTK_FILE_SELECTION(filesel),
64 gtk_widget_show(filesel);
71 str = gtk_file_selection_get_filename
72 (GTK_FILE_SELECTION(filesel));
73 if (str && str[0] != '\0') {
76 filename = g_strdup(str);
79 cwd = g_strconcat(dir, G_DIR_SEPARATOR_S, NULL);
84 manage_window_focus_out(filesel, NULL, NULL);
85 gtk_widget_destroy(filesel);
91 static void filesel_create(const gchar *title)
93 filesel = gtk_file_selection_new(title);
94 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(filesel)->ok_button),
95 "clicked", GTK_SIGNAL_FUNC(filesel_ok_cb),
98 (GTK_OBJECT(GTK_FILE_SELECTION(filesel)->cancel_button),
99 "clicked", GTK_SIGNAL_FUNC(filesel_cancel_cb),
101 gtk_signal_connect(GTK_OBJECT(filesel), "delete_event",
102 GTK_SIGNAL_FUNC(delete_event),
104 gtk_signal_connect(GTK_OBJECT(filesel), "key_press_event",
105 GTK_SIGNAL_FUNC(key_pressed), NULL);
106 gtk_signal_connect(GTK_OBJECT(filesel), "focus_in_event",
107 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
108 gtk_signal_connect(GTK_OBJECT(filesel), "focus_out_event",
109 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
111 gtk_window_set_modal(GTK_WINDOW(filesel), TRUE);
114 static void filesel_ok_cb(GtkWidget *widget, gpointer data)
120 static void filesel_cancel_cb(GtkWidget *widget, gpointer data)
126 static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data)
128 filesel_cancel_cb(NULL, NULL);
132 static void key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
134 if (event && event->keyval == GDK_Escape)
135 filesel_cancel_cb(NULL, NULL);