Replace gtk_file_selection dialog with gtk_file_chooser
authorHugo Villeneuve <hugo@hugovil.com>
Sun, 8 Sep 2013 13:35:23 +0000 (09:35 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Mon, 9 Sep 2013 00:54:10 +0000 (20:54 -0400)
Increase minimum gtk version to 2.4.0.

configure.ac
src/filemenu.c

index 30ae0c4..2418121 100644 (file)
@@ -36,7 +36,7 @@ AC_ARG_ENABLE(gui,
 AC_MSG_CHECKING([whether to build GUI])
 if test x$ac_cv_enable_gui = xyes; then
        AC_MSG_RESULT(yes)
-        PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.0.5, :, ac_cv_enable_gui=no)
+        PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.4.0, :, ac_cv_enable_gui=no)
        if test x$ac_cv_enable_gui = xyes; then
            AC_DEFINE([HAVE_GTK],1,[Set to 1 to enable GTK+ support for building GUI.])
             AC_SUBST(GTK_CFLAGS)
index ded4a5c..c3f13e0 100644 (file)
 
 #define FILENAME_DESCRIPTION "Open Intel Hex file"
 
-static void
-FileOpenDialog_OK(GtkWidget *widget, gpointer file_dialog)
+void
+FileOpenEvent(GtkObject *object, gpointer data)
 {
-       char *selected_file;
+       GtkWidget *file_dialog;
 
 #if defined(DEBUG)
-       g_print("FileOpenDialog_OK()\n");
+       g_print("FileOpenEvent()\n");
 #endif
 
-       /*
-        * The cast to (char *) is to remove a warning in GTK2, because the
-        * return value of the gtk_file_selection_get_filename() function is
-        * 'G_CONST_RETURN gchar *'.
-        */
-       selected_file = (char *) gtk_file_selection_get_filename(
-               GTK_FILE_SELECTION(file_dialog));
-
-       g_print("emugtk_File = %s\n", selected_file);
-
-       emugtk_new_file(selected_file);
+       /* Create a new file selection widget. */
+       file_dialog = gtk_file_chooser_dialog_new(
+               FILENAME_DESCRIPTION, NULL, GTK_FILE_CHOOSER_ACTION_OPEN,
+               GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+               GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
 
-       gtk_widget_destroy(GTK_WIDGET(file_dialog));
-}
+       if (gtk_dialog_run(GTK_DIALOG(file_dialog)) == GTK_RESPONSE_ACCEPT) {
+               char *selected_file;
 
-void
-FileOpenEvent(GtkObject *object, gpointer data)
-{
-       GtkWidget *file_dialog;
+               selected_file = gtk_file_chooser_get_filename(
+                       GTK_FILE_CHOOSER(file_dialog));
 
+               if (selected_file != NULL) {
 #if defined(DEBUG)
-       g_print("FileOpenEvent()\n");
+                       g_print("emugtk_File = %s\n", selected_file);
 #endif
 
-       /* Create a new file selection widget. */
-       file_dialog = gtk_file_selection_new(FILENAME_DESCRIPTION);
-
-       /* Connect the file dialog's OK button up to a handler. */
-       gtk_signal_connect(
-               GTK_OBJECT(GTK_FILE_SELECTION(file_dialog)->ok_button),
-               "clicked", GTK_SIGNAL_FUNC(FileOpenDialog_OK), file_dialog);
-
-       /*
-        * Ensure that the file selection dialog box is destroyed when the user
-        * clicks CANCEL.
-        */
-       gtk_signal_connect_object(
-               GTK_OBJECT(GTK_FILE_SELECTION(file_dialog)->cancel_button),
-               "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy),
-               (gpointer) file_dialog);
-
-       /* Show the dialog. */
-       gtk_widget_show(GTK_WIDGET(file_dialog));
-
-       /*
-        * To have the main window of our application being unusable while
-        * using the dialog.
-        */
-       gtk_window_set_modal(GTK_WINDOW(file_dialog), TRUE);
+                       emugtk_new_file(selected_file);
+                       g_free(selected_file);
+               }
+       }
+
+       gtk_widget_destroy(file_dialog);
 }
 
 static void