Search
lxdream.org :: lxdream/src/gui/gui.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gui.c
changeset 18:9a1b5d75703f
prev9:2784c7660165
next23:1ec3acd0594d
author nkeynes
date Thu Dec 15 13:33:14 2005 +0000 (14 years ago)
permissions -rw-r--r--
last change Implement save states
file annotate diff log raw
1.1 --- a/src/gui/gui.c Thu Dec 08 13:38:00 2005 +0000
1.2 +++ b/src/gui/gui.c Thu Dec 15 13:33:14 2005 +0000
1.3 @@ -2,6 +2,7 @@
1.4 #include <stdarg.h>
1.5 #include <gnome.h>
1.6 #include <math.h>
1.7 +#include "dreamcast.h"
1.8 #include "gui.h"
1.9 #include "mem.h"
1.10 #include "sh4dasm.h"
1.11 @@ -12,9 +13,7 @@
1.12 GdkColor clrNormal, clrChanged, clrError, clrWarn, clrPC, clrDebug, clrTrace;
1.13 PangoFontDescription *fixed_list_font;
1.14
1.15 -void open_file_callback(GtkWidget *btn, gpointer user_data);
1.16 -void open_file_canceled(GtkWidget *btn, gpointer user_data);
1.17 -void open_file( char *filename );
1.18 +void open_file_callback(GtkWidget *btn, gint result, gpointer user_data);
1.19
1.20 void init_gui() {
1.21 GdkColormap *map;
1.22 @@ -51,29 +50,63 @@
1.23 dump_win_update_all();
1.24 }
1.25
1.26 -
1.27 -void open_file_callback(GtkWidget *btn, gpointer user_data) {
1.28 - GtkFileSelection *file = GTK_FILE_SELECTION(user_data);
1.29 - gchar *filename = strdup( gtk_file_selection_get_filename(
1.30 - GTK_FILE_SELECTION(file) ) );
1.31 - gtk_widget_destroy(GTK_WIDGET(file));
1.32 - open_file( filename );
1.33 - free(filename);
1.34 +void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
1.35 + GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
1.36 + if( result == GTK_RESPONSE_ACCEPT ) {
1.37 + gchar *filename =gtk_file_chooser_get_filename(
1.38 + GTK_FILE_CHOOSER(file) );
1.39 + file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
1.40 + gtk_widget_destroy(GTK_WIDGET(file));
1.41 + action( filename );
1.42 + g_free(filename);
1.43 + } else {
1.44 + gtk_widget_destroy(GTK_WIDGET(file));
1.45 + }
1.46 }
1.47
1.48 -void open_file_canceled(GtkWidget *btn, gpointer user_data) {
1.49 - gtk_widget_destroy(GTK_WIDGET(user_data));
1.50 +static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
1.51 +{
1.52 + if( pattern != NULL ) {
1.53 + GtkFileFilter *filter = gtk_file_filter_new();
1.54 + gtk_file_filter_add_pattern( filter, pattern );
1.55 + gtk_file_filter_set_name( filter, patname );
1.56 + gtk_file_chooser_add_filter( chooser, filter );
1.57 + filter = gtk_file_filter_new();
1.58 + gtk_file_filter_set_name( filter, "All files" );
1.59 + gtk_file_filter_add_pattern( filter, "*" );
1.60 + gtk_file_chooser_add_filter( chooser, filter );
1.61 + }
1.62 }
1.63
1.64 -void open_file_dialog( void )
1.65 +void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
1.66 {
1.67 GtkWidget *file;
1.68
1.69 - file = gtk_file_selection_new( "Open..." );
1.70 - gtk_signal_connect( GTK_OBJECT(GTK_FILE_SELECTION(file)->ok_button),
1.71 - "clicked", GTK_SIGNAL_FUNC(open_file_callback), file );
1.72 - gtk_signal_connect( GTK_OBJECT(GTK_FILE_SELECTION(file)->cancel_button),
1.73 - "clicked", GTK_SIGNAL_FUNC(open_file_canceled), file );
1.74 + file = gtk_file_chooser_dialog_new( title, NULL,
1.75 + GTK_FILE_CHOOSER_ACTION_OPEN,
1.76 + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.77 + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1.78 + NULL );
1.79 + add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
1.80 + g_signal_connect( GTK_OBJECT(file), "response",
1.81 + GTK_SIGNAL_FUNC(open_file_callback), file );
1.82 + gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
1.83 + gtk_widget_show( file );
1.84 +}
1.85 +
1.86 +void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
1.87 +{
1.88 + GtkWidget *file;
1.89 +
1.90 + file = gtk_file_chooser_dialog_new( title, NULL,
1.91 + GTK_FILE_CHOOSER_ACTION_SAVE,
1.92 + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.93 + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1.94 + NULL );
1.95 + add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
1.96 + g_signal_connect( GTK_OBJECT(file), "response",
1.97 + GTK_SIGNAL_FUNC(open_file_callback), file );
1.98 + gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
1.99 gtk_widget_show( file );
1.100 }
1.101
.