shithub: puzzles

Download patch

ref: d2b0d8cf3fe5dd6c379300e791a24493fac2bb76
parent: ff62f0aaff860b37a3dfc99956a67efac145a70d
author: Simon Tatham <[email protected]>
date: Mon Jan 26 14:11:34 EST 2009

Switch over to using the new-style GtkFileChooser in place of the
deprecated GtkFileSelection, at least when the latter is available.
Patch mostly due to Ori Avtalion.

[originally from svn r8431]

--- a/gtk.c
+++ b/gtk.c
@@ -32,6 +32,9 @@
 #  endif
 # endif
 #endif
+#if !GTK_CHECK_VERSION(2,4,0)
+# define OLD_FILESEL
+#endif
 
 #ifdef DEBUGGING
 static FILE *debug_fp = NULL;
@@ -128,7 +131,9 @@
     int paste_data_len;
     int pw, ph;                        /* pixmap size (w, h are area size) */
     int ox, oy;                        /* offset of pixmap in drawing area */
+#ifdef OLD_FILESEL
     char *filesel_name;
+#endif
     int npresets;
     GtkWidget **preset_bullets;
     GtkWidget *preset_custom_bullet;
@@ -1293,6 +1298,8 @@
     }
 }
 
+#ifdef OLD_FILESEL
+
 static void filesel_ok(GtkButton *button, gpointer data)
 {
     frontend *fe = (frontend *)data;
@@ -1333,6 +1340,34 @@
 
     return fe->filesel_name;
 }
+
+#else
+
+static char *file_selector(frontend *fe, char *title, int save)
+{
+    char *filesel_name = NULL;
+
+    GtkWidget *filesel =
+        gtk_file_chooser_dialog_new(title,
+				    GTK_WINDOW(fe->window),
+				    save ? GTK_FILE_CHOOSER_ACTION_SAVE :
+				    GTK_FILE_CHOOSER_ACTION_OPEN,
+				    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+				    save ? GTK_STOCK_SAVE : GTK_STOCK_OPEN,
+				    GTK_RESPONSE_ACCEPT,
+				    NULL);
+
+    if (gtk_dialog_run(GTK_DIALOG(filesel)) == GTK_RESPONSE_ACCEPT) {
+        const char *name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filesel));
+        filesel_name = dupstr(name);
+    }
+
+    gtk_widget_destroy(filesel);
+
+    return filesel_name;
+}
+
+#endif
 
 struct savefile_write_ctx {
     FILE *fp;