diff gtk3/dw.c @ 1295:d0c9d4d0ff3b

Implement default filename support for GTK.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 01 Nov 2011 10:48:19 +0000
parents b99b0b2c2826
children 9c8de9cccc07
line wrap: on
line diff
--- 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 )