# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1320144499 0 # Node ID d0c9d4d0ff3b9ccb03f5f61f734092aa34f0bb40 # Parent 4bc8b6ffbe1eab3a94809f1cb2ecd870b4ebeddd Implement default filename support for GTK. diff -r 4bc8b6ffbe1e -r d0c9d4d0ff3b gtk/dw.c --- a/gtk/dw.c Tue Nov 01 10:21:48 2011 +0000 +++ b/gtk/dw.c Tue Nov 01 10:48:19 2011 +0000 @@ -11596,11 +11596,31 @@ if ( defpath ) { + struct stat buf; + if ( g_path_is_absolute( defpath ) || !realpath(defpath, mypath)) { strcpy( mypath, defpath ); } - gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( filew ), mypath ); + + /* See if the path exists */ + if(stat(mypath, &buf) == 0) + { + /* If the path is a directory... set the current folder */ + if(buf.st_mode & S_IFDIR) + gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( filew ), mypath ); + else if(flags == DW_FILE_SAVE) /* Otherwise set the filename */ + gtk_file_chooser_set_filename( GTK_FILE_CHOOSER( filew ), mypath ); + else if(flags == DW_FILE_OPEN) + gtk_file_chooser_select_filename( GTK_FILE_CHOOSER( filew), mypath ); + } + else if(flags == DW_FILE_SAVE) + { + /* If it doesn't exist... Try it as a file for now... + * May need to separate it into folder and file. + */ + gtk_file_chooser_set_filename( GTK_FILE_CHOOSER( filew ), mypath ); + } } if ( gtk_dialog_run( GTK_DIALOG( filew ) ) == GTK_RESPONSE_ACCEPT ) diff -r 4bc8b6ffbe1e -r d0c9d4d0ff3b gtk3/dw.c --- a/gtk3/dw.c Tue Nov 01 10:21:48 2011 +0000 +++ b/gtk3/dw.c Tue Nov 01 10:48:19 2011 +0000 @@ -9877,11 +9877,31 @@ if ( defpath ) { + struct stat buf; + if ( g_path_is_absolute( defpath ) || !realpath(defpath, mypath)) { strcpy( mypath, defpath ); } - gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( filew ), mypath ); + + /* See if the path exists */ + if(stat(mypath, &buf) == 0) + { + /* If the path is a directory... set the current folder */ + if(buf.st_mode & S_IFDIR) + gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( filew ), mypath ); + else if(flags == DW_FILE_SAVE) /* Otherwise set the filename */ + gtk_file_chooser_set_filename( GTK_FILE_CHOOSER( filew ), mypath ); + else if(flags == DW_FILE_OPEN) + gtk_file_chooser_select_filename( GTK_FILE_CHOOSER( filew), mypath ); + } + else if(flags == DW_FILE_SAVE) + { + /* If it doesn't exist... Try it as a file for now... + * May need to separate it into folder and file. + */ + gtk_file_chooser_set_filename( GTK_FILE_CHOOSER( filew ), mypath ); + } } if ( gtk_dialog_run( GTK_DIALOG( filew ) ) == GTK_RESPONSE_ACCEPT )