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 void key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data);
40 gchar *filesel_select_file(const gchar *title, const gchar *file)
42 static gchar *filename = NULL;
43 static gchar *cwd = NULL;
45 filesel_create(title);
47 manage_window_set_transient(GTK_WINDOW(filesel));
55 cwd = g_strconcat(startup_dir, G_DIR_SEPARATOR_S, NULL);
57 gtk_file_selection_set_filename(GTK_FILE_SELECTION(filesel), cwd);
60 gtk_file_selection_set_filename(GTK_FILE_SELECTION(filesel),
63 gtk_widget_show(filesel);
70 str = gtk_file_selection_get_filename
71 (GTK_FILE_SELECTION(filesel));
72 if (str && str[0] != '\0') {
75 filename = g_strdup(str);
78 cwd = g_strconcat(dir, G_DIR_SEPARATOR_S, NULL);
83 manage_window_focus_out(filesel, NULL, NULL);
84 gtk_widget_destroy(filesel);
90 static void filesel_create(const gchar *title)
92 filesel = gtk_file_selection_new(title);
93 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(filesel)->ok_button),
94 "clicked", GTK_SIGNAL_FUNC(filesel_ok_cb),
97 (GTK_OBJECT(GTK_FILE_SELECTION(filesel)->cancel_button),
98 "clicked", GTK_SIGNAL_FUNC(filesel_cancel_cb),
100 gtk_signal_connect(GTK_OBJECT(filesel), "delete_event",
101 GTK_SIGNAL_FUNC(filesel_cancel_cb),
103 gtk_signal_connect(GTK_OBJECT(filesel), "key_press_event",
104 GTK_SIGNAL_FUNC(key_pressed), NULL);
105 gtk_signal_connect(GTK_OBJECT(filesel), "focus_in_event",
106 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
107 gtk_signal_connect(GTK_OBJECT(filesel), "focus_out_event",
108 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
110 gtk_window_set_modal(GTK_WINDOW(filesel), TRUE);
113 static void filesel_ok_cb(GtkWidget *widget, gpointer data)
119 static void filesel_cancel_cb(GtkWidget *widget, gpointer data)
125 static void key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
127 if (event && event->keyval == GDK_Escape)
128 filesel_cancel_cb(NULL, NULL);