# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1320184639 0 # Node ID 9c8de9cccc07fc410b73f1ece1d9e32bbd1c4768 # Parent 66d4e16349e02d7889502e7133daf5f81d1ea684 Fix for file and folder not being selected on GTK if file does not exist. diff -r 66d4e16349e0 -r 9c8de9cccc07 gtk/dw.c --- a/gtk/dw.c Tue Nov 01 20:29:58 2011 +0000 +++ b/gtk/dw.c Tue Nov 01 21:57:19 2011 +0000 @@ -11616,10 +11616,41 @@ } 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(strchr(mypath, '/')) + { + unsigned long x = strlen(mypath) - 1; + + /* Trim off the filename */ + while(x > 0 && mypath[x] != '/') + { + x--; + } + if(mypath[x] == '/') + { + char *file = NULL; + char temp[PATH_MAX+1]; + + /* Save the original path in temp */ + strcpy(temp, mypath); + mypath[x] = 0; + + /* Check to make sure the trimmed piece is a directory */ + if(realpath(mypath, temp) && stat(temp, &buf) == 0) + { + if(buf.st_mode & S_IFDIR) + { + /* We now have it split */ + file = &mypath[x+1]; + } + } + + /* Select folder... */ + gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(filew), temp ); + /* ... and file separately */ + if(file) + gtk_file_chooser_set_current_name( GTK_FILE_CHOOSER(filew), file ); + } + } } } diff -r 66d4e16349e0 -r 9c8de9cccc07 gtk3/dw.c --- a/gtk3/dw.c Tue Nov 01 20:29:58 2011 +0000 +++ b/gtk3/dw.c Tue Nov 01 21:57:19 2011 +0000 @@ -9897,10 +9897,41 @@ } 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(strchr(mypath, '/')) + { + unsigned long x = strlen(mypath) - 1; + + /* Trim off the filename */ + while(x > 0 && mypath[x] != '/') + { + x--; + } + if(mypath[x] == '/') + { + char *file = NULL; + char temp[PATH_MAX+1]; + + /* Save the original path in temp */ + strcpy(temp, mypath); + mypath[x] = 0; + + /* Check to make sure the trimmed piece is a directory */ + if(realpath(mypath, temp) && stat(temp, &buf) == 0) + { + if(buf.st_mode & S_IFDIR) + { + /* We now have it split */ + file = &mypath[x+1]; + } + } + + /* Select folder... */ + gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(filew), temp ); + /* ... and file separately */ + if(file) + gtk_file_chooser_set_current_name( GTK_FILE_CHOOSER(filew), file ); + } + } } }