From 9104b3079ae9654573f488774490d6bd27a347b8 Mon Sep 17 00:00:00 2001 From: JP Rosevear 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 * 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/ChangeLog | 10 +++++++++ e-util/e-dialog-utils.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ e-util/e-dialog-utils.h | 2 ++ 3 files changed, 70 insertions(+) (limited to 'e-util') diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 6ea7c05660..375de2f381 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,13 @@ +2002-03-29 JP Rosevear + + * 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 + 2002-03-22 Ettore Perazzoli * e-lang-utils.c: New. 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 #include +#include #include +#include +#include +#include +#include #include +#include #include #include @@ -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; +} + + diff --git a/e-util/e-dialog-utils.h b/e-util/e-dialog-utils.h index 1e1b8af22f..275f8ec264 100644 --- a/e-util/e-dialog-utils.h +++ b/e-util/e-dialog-utils.h @@ -42,5 +42,7 @@ GtkWidget *e_gnome_ok_cancel_dialog_parented (const char *message, GnomeReplyCallback callback, gpointer data, GtkWindow *parent); +char *e_file_dialog_save (const char *title); + #endif -- cgit v1.2.3