diff options
author | Damien Plisson <damien.plisson@yahoo.fr> | 2009-12-17 12:23:47 +0300 |
---|---|---|
committer | Damien Plisson <damien.plisson@yahoo.fr> | 2009-12-17 12:23:47 +0300 |
commit | 42c2cbdc671bef652e9c743590167bc04358063f (patch) | |
tree | 16d0bfe5250ded7e4409e8b92c568e0263e408fa /source/blender/editors/space_file | |
parent | 0cc34bebf42c04911bc0bf3de6035ae33a98c16a (diff) |
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).
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r-- | source/blender/editors/space_file/fsmenu.c | 105 |
1 files changed, 104 insertions, 1 deletions
diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c index b45b57c6be9..bd39a10f661 100644 --- a/source/blender/editors/space_file/fsmenu.c +++ b/source/blender/editors/space_file/fsmenu.c @@ -284,8 +284,10 @@ void fsmenu_read_file(struct FSMenu* fsmenu, const char *filename) #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 @@ void fsmenu_read_file(struct FSMenu* fsmenu, const char *filename) 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 */ |