From 9104b3079ae9654573f488774490d6bd27a347b8 Mon Sep 17 00:00:00 2001
From: JP Rosevear <jpr@ximian.com>
Date: Fri, 29 Mar 2002 21:30:46 +0000
Subject: open a file selection dialog with the given title and return the
 selected

2002-03-29  JP Rosevear  <jpr@ximian.com>

	* e-dialog-utils.c (e_file_dialog_save): open a file selection
	dialog with the given title and return the selected file name
	(save_ok): if the ok button is clicked, make sure the file doesn't
	already exist and if it does, see if the user wants to over write
	it

	* e-dialog-utils.h: new proto

svn path=/trunk/; revision=16284
---
 e-util/e-dialog-utils.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

(limited to 'e-util/e-dialog-utils.c')

diff --git a/e-util/e-dialog-utils.c b/e-util/e-dialog-utils.c
index f155b83145..0102c45167 100644
--- a/e-util/e-dialog-utils.c
+++ b/e-util/e-dialog-utils.c
@@ -30,9 +30,15 @@
 #include <gdk/gdkprivate.h>
 #include <gdk/gdk.h>
 
+#include <gtk/gtkmain.h>
 #include <gtk/gtksignal.h>
+#include <gtk/gtkfilesel.h>
 
+#include <libgnome/gnome-defs.h>
+#include <libgnome/gnome-i18n.h>
+#include <libgnome/gnome-util.h>
 #include <libgnomeui/gnome-dialog-util.h>
+#include <libgnomeui/gnome-uidefs.h>
 
 #include <bonobo/bonobo-control.h>
 #include <bonobo/bonobo-property-bag.h>
@@ -204,3 +210,55 @@ e_gnome_ok_cancel_dialog_parented (const char *message, GnomeReplyCallback callb
 	
 	return dialog;
 }
+
+static void
+save_ok (GtkWidget *widget, gpointer data)
+{
+	GtkWidget *fs;
+	char **filename = data;
+	char *path;
+	int btn = GNOME_YES;
+
+	fs = gtk_widget_get_toplevel (widget);
+	path = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
+
+	if (g_file_test (path, G_FILE_TEST_ISFILE)) {
+		GtkWidget *dlg;
+
+		dlg = gnome_question_dialog_modal (_("A file by that name already exists.\n"
+						     "Overwrite it?"), NULL, NULL);
+		btn = gnome_dialog_run_and_close (GNOME_DIALOG (dlg));
+	}
+
+	if (btn == GNOME_YES)
+		*filename = g_strdup (path);
+
+	gtk_main_quit ();
+}
+
+char *
+e_file_dialog_save (const char *title)
+{
+	GtkFileSelection *fs;
+	char *path, *filename = NULL;
+
+	fs = GTK_FILE_SELECTION (gtk_file_selection_new (title));
+	path = g_strdup_printf ("%s/", g_get_home_dir ());
+	gtk_file_selection_set_filename (fs, path);
+	g_free (path);
+	
+	gtk_signal_connect (GTK_OBJECT (fs->ok_button), "clicked",
+			    GTK_SIGNAL_FUNC (save_ok), &filename);
+	gtk_signal_connect (GTK_OBJECT (fs->cancel_button), "clicked",
+			    GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
+	
+	gtk_widget_show (GTK_WIDGET (fs));
+	gtk_grab_add (GTK_WIDGET (fs));
+	gtk_main ();
+	
+	gtk_widget_destroy (GTK_WIDGET (fs));
+
+	return filename;
+}
+
+
-- 
cgit