comparison gtk3/dw.c @ 1300:9c8de9cccc07

Fix for file and folder not being selected on GTK if file does not exist.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 01 Nov 2011 21:57:19 +0000
parents d0c9d4d0ff3b
children dbd507f42947
comparison
equal deleted inserted replaced
1299:66d4e16349e0 1300:9c8de9cccc07
9895 else if(flags == DW_FILE_OPEN) 9895 else if(flags == DW_FILE_OPEN)
9896 gtk_file_chooser_select_filename( GTK_FILE_CHOOSER( filew), mypath ); 9896 gtk_file_chooser_select_filename( GTK_FILE_CHOOSER( filew), mypath );
9897 } 9897 }
9898 else if(flags == DW_FILE_SAVE) 9898 else if(flags == DW_FILE_SAVE)
9899 { 9899 {
9900 /* If it doesn't exist... Try it as a file for now... 9900 if(strchr(mypath, '/'))
9901 * May need to separate it into folder and file. 9901 {
9902 */ 9902 unsigned long x = strlen(mypath) - 1;
9903 gtk_file_chooser_set_filename( GTK_FILE_CHOOSER( filew ), mypath ); 9903
9904 /* Trim off the filename */
9905 while(x > 0 && mypath[x] != '/')
9906 {
9907 x--;
9908 }
9909 if(mypath[x] == '/')
9910 {
9911 char *file = NULL;
9912 char temp[PATH_MAX+1];
9913
9914 /* Save the original path in temp */
9915 strcpy(temp, mypath);
9916 mypath[x] = 0;
9917
9918 /* Check to make sure the trimmed piece is a directory */
9919 if(realpath(mypath, temp) && stat(temp, &buf) == 0)
9920 {
9921 if(buf.st_mode & S_IFDIR)
9922 {
9923 /* We now have it split */
9924 file = &mypath[x+1];
9925 }
9926 }
9927
9928 /* Select folder... */
9929 gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(filew), temp );
9930 /* ... and file separately */
9931 if(file)
9932 gtk_file_chooser_set_current_name( GTK_FILE_CHOOSER(filew), file );
9933 }
9934 }
9904 } 9935 }
9905 } 9936 }
9906 9937
9907 if ( gtk_dialog_run( GTK_DIALOG( filew ) ) == GTK_RESPONSE_ACCEPT ) 9938 if ( gtk_dialog_run( GTK_DIALOG( filew ) ) == GTK_RESPONSE_ACCEPT )
9908 { 9939 {