changeset 67787:8c306a35f0b0

[TARGET_API_MAC_CARBON] (Fx_file_dialog): Use coercion of Apple event data for translation from/to file names.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Sat, 24 Dec 2005 02:50:34 +0000
parents 55dd97aa46da
children 114d965dfb60
files src/macfns.c
diffstat 1 files changed, 30 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/src/macfns.c	Sat Dec 24 02:50:11 2005 +0000
+++ b/src/macfns.c	Sat Dec 24 02:50:34 2005 +0000
@@ -4226,21 +4226,13 @@
     /* Set the default location and continue*/
     if (status == noErr)
       {
+	Lisp_Object encoded_dir = ENCODE_FILE (dir);
 	AEDesc defLocAed;
-#ifdef MAC_OSX
-	FSRef defLoc;
-	status = FSPathMakeRef(SDATA(ENCODE_FILE(dir)), &defLoc, NULL);
-#else
-	FSSpec defLoc;
-	status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (dir)), &defLoc);
-#endif
+
+	status = AECreateDesc (TYPE_FILE_NAME, SDATA (encoded_dir),
+			       SBYTES (encoded_dir), &defLocAed);
 	if (status == noErr)
 	  {
-#ifdef MAC_OSX
-	    AECreateDesc(typeFSRef, &defLoc, sizeof(FSRef), &defLocAed);
-#else
-	    AECreateDesc(typeFSS, &defLoc, sizeof(FSSpec), &defLocAed);
-#endif
 	    NavCustomControl(dialogRef, kNavCtlSetLocation, (void*) &defLocAed);
 	    AEDisposeDesc(&defLocAed);
 	  }
@@ -4262,41 +4254,36 @@
 	case kNavUserActionSaveAs:
 	  {
 	    NavReplyRecord reply;
-	    AEDesc aed;
-#ifdef MAC_OSX
-	    FSRef fsRef;
-#else
-	    FSSpec fs;
-#endif
+	    Size len;
+
 	    status = NavDialogGetReply(dialogRef, &reply);
-
-#ifdef MAC_OSX
-	    AECoerceDesc(&reply.selection, typeFSRef, &aed);
-	    AEGetDescData(&aed, (void *) &fsRef, sizeof (FSRef));
-	    FSRefMakePath(&fsRef, (UInt8 *) filename, sizeof (filename));
+	    if (status != noErr)
+	      break;
+	    status = AEGetNthPtr (&reply.selection, 1, TYPE_FILE_NAME,
+				  NULL, NULL, filename,
+				  sizeof (filename) - 1, &len);
+	    if (status == noErr)
+	      {
+		len = min (len, sizeof (filename) - 1);
+		filename[len] = '\0';
+		if (reply.saveFileName)
+		  {
+		    /* If it was a saved file, we need to add the file name */
+		    if (len && len < sizeof (filename) - 1
+			&& filename[len-1] != '/')
+		      filename[len++] = '/';
+		    CFStringGetCString(reply.saveFileName, filename+len,
+				       sizeof (filename) - len,
+#if MAC_OSX
+				       kCFStringEncodingUTF8
 #else
-	    AECoerceDesc (&reply.selection, typeFSS, &aed);
-	    AEGetDescData (&aed, (void *) &fs, sizeof (FSSpec));
-	    fsspec_to_posix_pathname (&fs, filename, sizeof (filename) - 1);
+				       CFStringGetSystemEncoding ()
 #endif
-	    AEDisposeDesc(&aed);
-	    if (reply.saveFileName)
-	      {
-		/* If it was a saved file, we need to add the file name */
-		int len = strlen(filename);
-		if (len && filename[len-1] != '/')
-		  filename[len++] = '/';
-		CFStringGetCString(reply.saveFileName, filename+len,
-				   sizeof (filename) - len,
-#if MAC_OSX
-				   kCFStringEncodingUTF8
-#else
-				   CFStringGetSystemEncoding ()
-#endif
-				   );
+				       );
+		  }
+		file = DECODE_FILE (make_unibyte_string (filename,
+							 strlen (filename)));
 	      }
-	    file = DECODE_FILE (make_unibyte_string (filename,
-						     strlen (filename)));
 	    NavDisposeReply(&reply);
 	  }
 	  break;