Re: [Evolution-hackers] gtk2.4 advanced file selection integration?



On Thu, 2004-03-11 at 09:21 -0800, Thomas Duffy wrote:

> Any chance of seeing gtk2.4 advanced file selection dialog integration
> in Evolution 2.0?  I notice it is not in 1.5.5.

This struck me as something I could try and do - patch attached that
makes e-dialog-utils.c use the new dialog if it is compiled against Gtk
>= 2.3.0.

Seems to work for me - the easiest place to test it is right-clicking on
a calender entry and choosing "Save as..". 

I've only converted over this one spot to use it, for now. If this patch
is OK, I'll volunteer to port over the other three or four spots that
would need touching to use the new dialog. I have CVS access, so let me
know if you want me to commit.

(Would you guys like me to get rid of the gtk_main() stuff in the code
for the old dialog? It's been established talking to NotZed on IRC that
it's not needed any more.)

Have fun
Grahame

Index: e-util/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/e-util/ChangeLog,v
retrieving revision 1.441
diff -u -r1.441 ChangeLog
--- e-util/ChangeLog	9 Mar 2004 21:10:41 -0000	1.441
+++ e-util/ChangeLog	12 Mar 2004 08:53:33 -0000
@@ -1,3 +1,9 @@
+2003-03-12  Grahame Bowland  <grahame angrygoats net>
+
+	* e-dialog-utils.c (e_file_dialog_save, response_ok):
+	Support the new GtkFileChooserDialog interface, with #define 
+	to support older Gtk versions.
+
 2004-03-04  William Jon McCann  <mccann jhu edu>
 
 	* e-dialog-utils.c (e_notice, e_notice_with_xid, save_ok): 
Index: e-util/e-dialog-utils.c
===================================================================
RCS file: /cvs/gnome/evolution/e-util/e-dialog-utils.c,v
retrieving revision 1.18
diff -u -r1.18 e-dialog-utils.c
--- e-util/e-dialog-utils.c	9 Mar 2004 21:10:42 -0000	1.18
+++ e-util/e-dialog-utils.c	12 Mar 2004 08:53:33 -0000
@@ -30,6 +30,13 @@
 #include <gtk/gtkmain.h>
 #include <gtk/gtkplug.h>
 
+#include <gtk/gtkversion.h>
+
+#if GTK_CHECK_VERSION(2,3,0)
+#include <gtk/gtkfilechooserdialog.h>
+#include <gtk/gtkstock.h>
+#endif
+
 #include <libgnome/gnome-i18n.h>
 #include <libgnome/gnome-util.h>
 
@@ -229,6 +236,68 @@
 
 
 
+
+#if GTK_CHECK_VERSION(2,3,0)
+
+static void
+response_ok (GtkWidget *fs, gint response, gpointer data)
+{
+	char **filename = data;
+	char *path;
+	int btn = GTK_RESPONSE_YES;
+
+	if (response == GTK_RESPONSE_ACCEPT) {
+		path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fs));
+
+		if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) {
+			GtkWidget *dlg;
+			
+			dlg = gtk_message_dialog_new (GTK_WINDOW (fs), 0,
+						      GTK_MESSAGE_QUESTION,
+						      GTK_BUTTONS_YES_NO,
+						      _("A file by that name already exists.\n"
+							"Overwrite it?"));
+			gtk_window_set_title (GTK_WINDOW (dlg), _("Overwrite file?"));
+			gtk_dialog_set_has_separator (GTK_DIALOG (dlg), FALSE);
+
+			btn = gtk_dialog_run (GTK_DIALOG (dlg));
+			gtk_widget_destroy (dlg);
+		}
+		
+		if (btn == GTK_RESPONSE_YES)
+			*filename = path;
+	}
+}
+
+char *
+e_file_dialog_save (const char *title)
+{
+	GtkWidget *fs;
+	char *path, *filename = NULL;
+
+	fs = gtk_file_chooser_dialog_new (title, 
+					      NULL, 
+					      GTK_FILE_CHOOSER_ACTION_SAVE,
+					      GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, 
+					      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 
+					      NULL);
+
+	path = g_strdup_printf ("%s/", g_get_home_dir ());
+	gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (fs), path);
+	g_free (path);
+	gtk_dialog_set_default_response (GTK_DIALOG (fs), GTK_RESPONSE_ACCEPT);
+
+	g_signal_connect (GTK_FILE_CHOOSER (fs), "response", G_CALLBACK (response_ok), &filename);
+
+	gtk_dialog_run (GTK_DIALOG (fs));
+
+	gtk_widget_destroy (GTK_WIDGET (fs));
+
+	return filename;
+}
+
+#else
+
 static void
 save_ok (GtkWidget *widget, gpointer data)
 {
@@ -284,4 +353,5 @@
 	return filename;
 }
 
+#endif
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]