changeset 1296:40d62db77c90

Added some defpath support and extension support to the Mac dw_file_browse(). Also switched to using URLs instead of deprecated filenames method. Filename support does not currently work on the open dialog.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 01 Nov 2011 11:55:18 +0000
parents d0c9d4d0ff3b
children b8f6e7dd4544
files mac/dw.m
diffstat 1 files changed, 37 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Tue Nov 01 10:48:19 2011 +0000
+++ b/mac/dw.m	Tue Nov 01 11:55:18 2011 +0000
@@ -3130,6 +3130,13 @@
     {
         /* Create the File Open Dialog class. */
         NSOpenPanel* openDlg = [NSOpenPanel openPanel];
+        struct stat buf;
+        
+        if(defpath && stat(defpath, &buf) == 0)
+        {
+            if(buf.st_mode & S_IFDIR)
+                [openDlg setDirectoryURL:[NSURL URLWithString:[NSString stringWithUTF8String:defpath]]];
+        }
 
         /* Enable the selection of files in the dialog. */
         if(flags == DW_FILE_OPEN)
@@ -3142,6 +3149,13 @@
             [openDlg setCanChooseFiles:NO];
             [openDlg setCanChooseDirectories:YES];
         }
+        
+        /* Handle file types */
+        if(ext)
+        {
+            NSArray* fileTypes = [[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil];
+            [openDlg setAllowedFileTypes:fileTypes];
+        }
 
         /* Disable multiple selection */
         [openDlg setAllowsMultipleSelection:NO];
@@ -3154,19 +3168,36 @@
             /* Get an array containing the full filenames of all
              * files and directories selected.
              */
-            NSArray* files = [openDlg filenames];
-            NSString* fileName = [files objectAtIndex:0];
-            return strdup([ fileName UTF8String ]);
+            NSArray *files = [openDlg URLs];
+            NSString *fileName = [[files objectAtIndex:0] path];
+            if(fileName)
+                return strdup([ fileName UTF8String ]);
         }
     }
     else
     {
         /* Create the File Save Dialog class. */
         NSSavePanel* saveDlg = [NSSavePanel savePanel];
+        struct stat buf;
+        
+        if(defpath && stat(defpath, &buf) == 0)
+        {
+            if(buf.st_mode & S_IFDIR)
+                [saveDlg setDirectoryURL:[NSURL URLWithString:[NSString stringWithUTF8String:defpath]]];
+            else
+                [saveDlg setNameFieldStringValue:[NSString stringWithUTF8String:defpath]];
+        }
 
         /* Enable the creation of directories in the dialog. */
         [saveDlg setCanCreateDirectories:YES];
 
+        /* Handle file types */
+        if(ext)
+        {
+            NSArray* fileTypes = [[NSArray alloc] initWithObjects:[NSString stringWithUTF8String:ext], nil];
+            [saveDlg setAllowedFileTypes:fileTypes];
+        }
+        
         /* Display the dialog.  If the OK button was pressed,
          * process the files.
          */
@@ -3175,8 +3206,9 @@
             /* Get an array containing the full filenames of all
              * files and directories selected.
              */
-            NSString* fileName = [saveDlg filename];
-            return strdup([ fileName UTF8String ]);
+            NSString* fileName = [[saveDlg URL] path];
+            if(fileName)
+                return strdup([ fileName UTF8String ]);
         }
     }