diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-18 16:49:25 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-18 16:49:25 +0400 |
commit | adb567f6b3f21f820e6b40d8530b374ee5cc2d7a (patch) | |
tree | 01f2146e98f6a6a258f7e117e182006a4abcfc60 /source/blender/editors/space_file/fsmenu.c | |
parent | 3e83fd441d84617855dfdcfab50fd8f4fb041f00 (diff) |
File browser: list of system directories is now refreshed on pressing the refresh
button or opening the file browser, in case e.g. a USB stick was inserted.
Patch #31211 by Julien Duroure.
Diffstat (limited to 'source/blender/editors/space_file/fsmenu.c')
-rw-r--r-- | source/blender/editors/space_file/fsmenu.c | 73 |
1 files changed, 43 insertions, 30 deletions
diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c index 50261175852..a91b3669219 100644 --- a/source/blender/editors/space_file/fsmenu.c +++ b/source/blender/editors/space_file/fsmenu.c @@ -295,7 +295,7 @@ void fsmenu_read_bookmarks(struct FSMenu *fsmenu, const char *filename) fclose(fp); } -void fsmenu_read_system(struct FSMenu *fsmenu) +void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks) { char line[256]; #ifdef WIN32 @@ -319,10 +319,12 @@ void fsmenu_read_system(struct FSMenu *fsmenu) } /* Adding Desktop and My Documents */ - SHGetSpecialFolderPath(0, line, CSIDL_PERSONAL, 0); - fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0); - SHGetSpecialFolderPath(0, line, CSIDL_DESKTOPDIRECTORY, 0); - fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0); + if (read_bookmarks) { + SHGetSpecialFolderPath(0, line, CSIDL_PERSONAL, 0); + fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0); + SHGetSpecialFolderPath(0, line, CSIDL_DESKTOPDIRECTORY, 0); + fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0); + } } #else #ifdef __APPLE__ @@ -352,7 +354,7 @@ void fsmenu_read_system(struct FSMenu *fsmenu) * assume they are the standard ones * TODO : replace hardcoded paths with proper BLI_get_folder calls */ home = getenv("HOME"); - if (home) { + if (read_bookmarks && home) { BLI_snprintf(line, 256, "%s/", home); fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0); BLI_snprintf(line, 256, "%s/Desktop/", home); @@ -437,32 +439,34 @@ void fsmenu_read_system(struct FSMenu *fsmenu) } /* Finally 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(read_bookmarks) { + list = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL); + pathesArray = LSSharedFileListCopySnapshot(list, &seed); + pathesCount = CFArrayGetCount(pathesArray); - if (!CFStringGetCString(pathString, line, 256, kCFStringEncodingASCII)) - continue; - fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0); + 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(pathString); - CFRelease(cfURL); + CFRelease(pathesArray); + CFRelease(list); } - - CFRelease(pathesArray); - CFRelease(list); #endif /* OSX 10.5+ */ } #else @@ -470,7 +474,7 @@ void fsmenu_read_system(struct FSMenu *fsmenu) { const char *home = getenv("HOME"); - if (home) { + if (read_bookmarks && home) { BLI_snprintf(line, FILE_MAXDIR, "%s/", home); fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0); BLI_snprintf(line, FILE_MAXDIR, "%s/Desktop/", home); @@ -537,6 +541,15 @@ static void fsmenu_free_category(struct FSMenu *fsmenu, FSMenuCategory category) } } +void fsmenu_refresh_system_category(struct FSMenu *fsmenu) +{ + fsmenu_free_category(fsmenu, FS_CATEGORY_SYSTEM); + fsmenu_set_category(fsmenu, FS_CATEGORY_SYSTEM, NULL); + + /* Add all entries to system category */ + fsmenu_read_system(fsmenu, FALSE); +} + void fsmenu_free(struct FSMenu *fsmenu) { fsmenu_free_category(fsmenu, FS_CATEGORY_SYSTEM); |