Search
lxdream.org :: lxdream/src/gtkui/gtkcb.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtkcb.c
changeset 1036:af7b0c5905dd
prev1034:7044e01148f0
next1040:9e3e41eab2db
author nkeynes
date Wed Jun 24 06:06:40 2009 +0000 (14 years ago)
permissions -rw-r--r--
last change Support shell substitutions in config paths
Keep track of last folder in file dialogs
Fix out-of-dateness in GTK path dialog
file annotate diff log raw
1.1 --- a/src/gtkui/gtkcb.c Wed Jun 24 02:41:12 2009 +0000
1.2 +++ b/src/gtkui/gtkcb.c Wed Jun 24 06:06:40 2009 +0000
1.3 @@ -40,58 +40,74 @@
1.4 }
1.5
1.6 gchar *open_file_dialog( const char *title, const char *pattern, const char *patname,
1.7 - const gchar *initial_dir )
1.8 + int initial_dir_key )
1.9 {
1.10 GtkWidget *file;
1.11 gchar *filename = NULL;
1.12 - gchar *initial_path = get_absolute_path(initial_dir);
1.13 +
1.14 file = gtk_file_chooser_dialog_new( title, NULL,
1.15 GTK_FILE_CHOOSER_ACTION_OPEN,
1.16 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.17 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1.18 NULL );
1.19 add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
1.20 - gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
1.21 + if( initial_dir_key != -1 ) {
1.22 + gchar *initial_path = get_absolute_path(gui_get_configurable_path(initial_dir_key));
1.23 + gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
1.24 + g_free(initial_path);
1.25 + }
1.26 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
1.27 gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
1.28 int result = gtk_dialog_run( GTK_DIALOG(file) );
1.29 if( result == GTK_RESPONSE_ACCEPT ) {
1.30 filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
1.31 + if( initial_dir_key != -1 ) {
1.32 + gchar *end_path = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(file) );
1.33 + gui_set_configurable_path(initial_dir_key,end_path);
1.34 + g_free(end_path);
1.35 + }
1.36 }
1.37 gtk_widget_destroy(file);
1.38 - g_free(initial_path);
1.39
1.40 return filename;
1.41 }
1.42
1.43 gchar *save_file_dialog( const char *title, const char *pattern, const char *patname,
1.44 - const gchar *initial_dir )
1.45 + int initial_dir_key )
1.46 {
1.47 GtkWidget *file;
1.48 gchar *filename;
1.49 - gchar *initial_path = get_absolute_path(initial_dir);
1.50 +
1.51 file = gtk_file_chooser_dialog_new( title, NULL,
1.52 GTK_FILE_CHOOSER_ACTION_SAVE,
1.53 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.54 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1.55 NULL );
1.56 add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
1.57 - gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
1.58 + if( initial_dir_key != -1 ) {
1.59 + gchar *initial_path = get_absolute_path(gui_get_configurable_path(initial_dir_key));
1.60 + gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
1.61 + g_free(initial_path);
1.62 + }
1.63 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
1.64 gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
1.65 int result = gtk_dialog_run( GTK_DIALOG(file) );
1.66 if( result == GTK_RESPONSE_ACCEPT ) {
1.67 filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
1.68 + if( initial_dir_key != -1 ) {
1.69 + gchar *end_path = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(file) );
1.70 + gui_set_configurable_path(initial_dir_key,end_path);
1.71 + g_free(end_path);
1.72 + }
1.73 }
1.74 gtk_widget_destroy(file);
1.75 - g_free(initial_path);
1.76 return filename;
1.77 }
1.78
1.79 void open_file_dialog_cb( const char *title, file_callback_t action, const char *pattern, const char *patname,
1.80 - const gchar *initial_dir )
1.81 + int initial_dir_key )
1.82 {
1.83 - gchar *filename = open_file_dialog( title, pattern, patname, initial_dir );
1.84 + gchar *filename = open_file_dialog( title, pattern, patname, initial_dir_key );
1.85 if( filename != NULL ) {
1.86 action( filename );
1.87 g_free(filename);
1.88 @@ -99,9 +115,9 @@
1.89 }
1.90
1.91 void save_file_dialog_cb( const char *title, file_callback_t action, const char *pattern, const char *patname,
1.92 - const gchar *initial_dir )
1.93 + int initial_dir_key )
1.94 {
1.95 - gchar *filename = save_file_dialog( title, pattern, patname, initial_dir );
1.96 + gchar *filename = save_file_dialog( title, pattern, patname, initial_dir_key );
1.97 if( filename != NULL ) {
1.98 action(filename);
1.99 g_free(filename);
1.100 @@ -110,8 +126,7 @@
1.101
1.102 void mount_action_callback( GtkAction *action, gpointer user_data)
1.103 {
1.104 - const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
1.105 - open_file_dialog_cb( "Open...", gdrom_mount_image, NULL, NULL, dir );
1.106 + open_file_dialog_cb( "Open...", gdrom_mount_image, NULL, NULL, CONFIG_DEFAULT_PATH );
1.107 }
1.108 void reset_action_callback( GtkAction *action, gpointer user_data)
1.109 {
1.110 @@ -130,8 +145,7 @@
1.111
1.112 void load_binary_action_callback( GtkAction *action, gpointer user_data)
1.113 {
1.114 - const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
1.115 - open_file_dialog_cb( "Open Binary...", file_load_magic, NULL, NULL, dir );
1.116 + open_file_dialog_cb( "Open Binary...", file_load_magic, NULL, NULL, CONFIG_DEFAULT_PATH );
1.117 }
1.118
1.119 void load_state_preview_callback( GtkFileChooser *chooser, gpointer user_data )
1.120 @@ -157,7 +171,7 @@
1.121 {
1.122 GtkWidget *file, *preview, *frame, *align;
1.123 GtkRequisition size;
1.124 - const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
1.125 + const gchar *dir = gui_get_configurable_path(CONFIG_SAVE_PATH);
1.126 gchar *path = get_absolute_path(dir);
1.127 file = gtk_file_chooser_dialog_new( _("Load state..."), NULL,
1.128 GTK_FILE_CHOOSER_ACTION_OPEN,
1.129 @@ -186,6 +200,9 @@
1.130 int result = gtk_dialog_run( GTK_DIALOG(file) );
1.131 if( result == GTK_RESPONSE_ACCEPT ) {
1.132 gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
1.133 + gchar *end_path = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(file) );
1.134 + gui_set_configurable_path(CONFIG_SAVE_PATH,end_path);
1.135 + g_free(end_path);
1.136 dreamcast_load_state( filename );
1.137 }
1.138 gtk_widget_destroy(file);
1.139 @@ -194,8 +211,7 @@
1.140
1.141 void save_state_action_callback( GtkAction *action, gpointer user_data)
1.142 {
1.143 - const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
1.144 - save_file_dialog_cb( "Save state...", dreamcast_save_state, "*.dst", _("lxDream Save State (*.dst)"), dir );
1.145 + save_file_dialog_cb( "Save state...", dreamcast_save_state, "*.dst", _("lxDream Save State (*.dst)"), CONFIG_SAVE_PATH );
1.146 }
1.147 void about_action_callback( GtkAction *action, gpointer user_data)
1.148 {
1.149 @@ -269,8 +285,7 @@
1.150
1.151 void save_scene_action_callback( GtkAction *action, gpointer user_data)
1.152 {
1.153 - const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
1.154 - save_file_dialog_cb( _("Save next scene..."), pvr2_save_next_scene, "*.dsc", _("lxdream scene file (*.dsc)"), dir );
1.155 + save_file_dialog_cb( _("Save next scene..."), pvr2_save_next_scene, "*.dsc", _("lxdream scene file (*.dsc)"), CONFIG_SAVE_PATH );
1.156 }
1.157
1.158 int debug_window_get_selected_row( debug_window_t data );
.