[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25430] trunk/blender/source/blender/ editors/space_file/fsmenu.c: OSX: populate file dialog system & bookmark defaults paths with the finder' s ones

Damien Plisson damien.plisson at yahoo.fr
Thu Dec 17 10:23:47 CET 2009


Revision: 25430
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25430
Author:   damien78
Date:     2009-12-17 10:23:47 +0100 (Thu, 17 Dec 2009)

Log Message:
-----------
OSX: populate file dialog system & bookmark defaults paths with the finder's ones

Former implementation was to populate the "system" paths with the mounted paths. The issue is that OSX mounts some paths that are of no use such as /home (The home dirs reside in /Users).

When compiled with 10.5 SDK, it retrieves the folders you have in the finder and OSX standard open/save dialog.
When compiled with older SDKs, it assumes these folders are the default ones (home, Desktop, Documents, Pictures, Music, Movies).

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_file/fsmenu.c

Modified: trunk/blender/source/blender/editors/space_file/fsmenu.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/fsmenu.c	2009-12-17 07:40:43 UTC (rev 25429)
+++ trunk/blender/source/blender/editors/space_file/fsmenu.c	2009-12-17 09:23:47 UTC (rev 25430)
@@ -284,8 +284,10 @@
 #else
 #ifdef __APPLE__
 	{
+#if (MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4)
 		OSErr err=noErr;
 		int i;
+		char *home;
 		
 		/* loop through all the OS X Volumes, and add them to the SYSTEM section */
 		for (i=1; err!=nsvErr; i++)
@@ -298,8 +300,109 @@
 				continue;
 			
 			FSRefMakePath(&dir, path, FILE_MAXDIR+FILE_MAXFILE);
-			fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, (char *)path, 1, 0);
+			if (strcmp((char*)path, "/home") && strcmp((char*)path, "/net"))
+			{ /* /net and /home are meaningless on OSX, home folders are stored in /Users */
+				fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, (char *)path, 1, 0);
+			}
 		}
+
+		/* As 10.4 doesn't provide proper API to retrieve the favorite places,
+		 assume they are the standard ones 
+		 TODO : replace hardcoded paths with proper BLI_get_folder calls */
+		home = BLI_gethome();
+		if(home) {
+			BLI_snprintf(line, 256, "%s/", home);
+			fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
+			BLI_snprintf(line, 256, "%s/Desktop/", home);
+			if (BLI_exists(line)) {
+				fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
+			}
+			BLI_snprintf(line, 256, "%s/Documents/", home);
+			if (BLI_exists(line)) {
+				fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
+			}
+			BLI_snprintf(line, 256, "%s/Pictures/", home);
+			if (BLI_exists(line)) {
+				fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
+			}
+			BLI_snprintf(line, 256, "%s/Music/", home);
+			if (BLI_exists(line)) {
+				fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
+			}
+			BLI_snprintf(line, 256, "%s/Movies/", home);
+			if (BLI_exists(line)) {
+				fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
+			}
+		}
+#else
+		/* 10.5 provides ability to retrieve Finder favorite places */
+		UInt32 seed;
+		OSErr err = noErr;
+		CFArrayRef pathesArray;
+		LSSharedFileListRef list;
+		LSSharedFileListItemRef itemRef;
+		CFIndex i, pathesCount;
+		CFURLRef cfURL = NULL;
+		CFStringRef pathString = NULL;
+		
+		/* First get mounted volumes */
+		list = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteVolumes, NULL);
+		pathesArray = LSSharedFileListCopySnapshot(list, &seed);
+		pathesCount = CFArrayGetCount(pathesArray);
+		
+		for (i=0; i<pathesCount; i++)
+		{
+			itemRef = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(pathesArray, i);
+			
+			err = LSSharedFileListItemResolve(itemRef, 
+											  kLSSharedFileListNoUserInteraction
+											  | kLSSharedFileListDoNotMountVolumes, 
+											  &cfURL, NULL);
+			if (err != noErr)
+				continue;
+			
+			pathString = CFURLCopyFileSystemPath(cfURL, kCFURLPOSIXPathStyle);
+			
+			if (!CFStringGetCString(pathString,line,256,kCFStringEncodingASCII))
+				continue;
+			fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, line, 1, 0);
+			
+			CFRelease(pathString);
+			CFRelease(cfURL);
+		}
+		
+		CFRelease(pathesArray);
+		CFRelease(list);
+		
+		/* Then get user favorite places */
+		list = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL);
+		pathesArray = LSSharedFileListCopySnapshot(list, &seed);
+		pathesCount = CFArrayGetCount(pathesArray);
+		
+		for (i=0; i<pathesCount; i++)
+		{
+			itemRef = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(pathesArray, i);
+			
+			err = LSSharedFileListItemResolve(itemRef, 
+											  kLSSharedFileListNoUserInteraction
+											  | kLSSharedFileListDoNotMountVolumes, 
+											  &cfURL, NULL);
+			if (err != noErr)
+				continue;
+			
+			pathString = CFURLCopyFileSystemPath(cfURL, kCFURLPOSIXPathStyle);
+			
+			if (!CFStringGetCString(pathString,line,256,kCFStringEncodingASCII))
+				continue;
+			fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
+			
+			CFRelease(pathString);
+			CFRelease(cfURL);
+		}
+		
+		CFRelease(pathesArray);
+		CFRelease(list);
+#endif /* OSX 10.5+ */
 	}
 #else
 	/* unix */





More information about the Bf-blender-cvs mailing list