Merge pull request #89 from RavuAlHemio/master

port directory choosing to GtkFileChooserDialog
This commit is contained in:
Timothee "TTimo" Besset 2012-07-18 05:05:54 -07:00
commit adb02c5f7e

View file

@ -1172,22 +1172,6 @@ int WINAPI gtk_MessageBox( void *parent, const char* lpText, const char* lpCapti
// fenris #3078 WHENHELLISFROZENOVER // fenris #3078 WHENHELLISFROZENOVER
static void file_sel_callback( GtkWidget *widget, gpointer data ){
GtkWidget *parent;
int *loop;
bool *success;
parent = gtk_widget_get_toplevel( widget );
loop = (int*)g_object_get_data( G_OBJECT( parent ), "loop" );
success = (bool*)g_object_get_data( G_OBJECT( parent ), "success" );
if ( GPOINTER_TO_INT( data ) == IDOK ) {
*success = true;
}
*loop = 0;
}
#ifdef _WIN32 #ifdef _WIN32
#include <commdlg.h> #include <commdlg.h>
static OPENFILENAME ofn; /* common dialog box structure */ static OPENFILENAME ofn; /* common dialog box structure */
@ -1638,40 +1622,27 @@ const char* file_dialog( void *parent, gboolean open, const char* title, const c
char* WINAPI dir_dialog( void *parent, const char* title, const char* path ){ char* WINAPI dir_dialog( void *parent, const char* title, const char* path ){
GtkWidget* file_sel; GtkWidget* file_sel;
char* filename = (char*)NULL; char* filename = (char*)NULL;
int loop = 1; int ret;
bool success = false;
file_sel = gtk_file_selection_new( title ); file_sel = gtk_file_chooser_dialog_new( title, GTK_WINDOW( parent ),
gtk_signal_connect( GTK_OBJECT( GTK_FILE_SELECTION( file_sel )->ok_button ), "clicked", GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
GTK_SIGNAL_FUNC( file_sel_callback ), GINT_TO_POINTER( IDOK ) ); GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
gtk_signal_connect( GTK_OBJECT( GTK_FILE_SELECTION( file_sel )->cancel_button ), "clicked", GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
GTK_SIGNAL_FUNC( file_sel_callback ), GINT_TO_POINTER( IDCANCEL ) ); NULL );
gtk_signal_connect( GTK_OBJECT( file_sel ), "delete_event",
GTK_SIGNAL_FUNC( dialog_delete_callback ), NULL );
gtk_file_selection_hide_fileop_buttons( GTK_FILE_SELECTION( file_sel ) );
if ( parent != NULL ) {
gtk_window_set_transient_for( GTK_WINDOW( file_sel ), GTK_WINDOW( parent ) );
}
gtk_widget_hide( GTK_FILE_SELECTION( file_sel )->file_list->parent );
g_object_set_data( G_OBJECT( file_sel ), "loop", &loop );
g_object_set_data( G_OBJECT( file_sel ), "success", &success );
if ( path != NULL ) { if ( path != NULL ) {
gtk_file_selection_set_filename( GTK_FILE_SELECTION( file_sel ), path ); gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( file_sel ), path );
} }
gtk_grab_add( file_sel ); ret = gtk_dialog_run( GTK_DIALOG( file_sel ) );
gtk_widget_show( file_sel );
while ( loop ) if ( ret == GTK_RESPONSE_ACCEPT ) {
gtk_main_iteration(); filename = g_strdup( gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( file_sel ) ) );
}
else {
filename = NULL;
}
filename = g_strdup( gtk_file_selection_get_filename( GTK_FILE_SELECTION( file_sel ) ) );
gtk_grab_remove( file_sel );
gtk_widget_destroy( file_sel ); gtk_widget_destroy( file_sel );
return filename; return filename;