From: Hugo Villeneuve Date: Sun, 8 Sep 2013 13:35:23 +0000 (-0400) Subject: Replace gtk_file_selection dialog with gtk_file_chooser X-Git-Tag: v2.0.0~175 X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=e57f14d42e7caff4850d0613611cfe764a9b39aa;p=emu8051.git Replace gtk_file_selection dialog with gtk_file_chooser Increase minimum gtk version to 2.4.0. --- diff --git a/configure.ac b/configure.ac index 30ae0c4..2418121 100644 --- a/configure.ac +++ b/configure.ac @@ -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) diff --git a/src/filemenu.c b/src/filemenu.c index ded4a5c..c3f13e0 100644 --- a/src/filemenu.c +++ b/src/filemenu.c @@ -34,64 +34,38 @@ #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