[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46770] trunk/blender/source/blender/ editors/space_file: File browser: list of system directories is now refreshed on pressing the refresh

Brecht Van Lommel brechtvanlommel at pandora.be
Fri May 18 14:49:25 CEST 2012


Revision: 46770
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46770
Author:   blendix
Date:     2012-05-18 12:49:25 +0000 (Fri, 18 May 2012)
Log Message:
-----------
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.

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

Modified: trunk/blender/source/blender/editors/space_file/file_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/file_ops.c	2012-05-18 12:49:22 UTC (rev 46769)
+++ trunk/blender/source/blender/editors/space_file/file_ops.c	2012-05-18 12:49:25 UTC (rev 46770)
@@ -820,9 +820,13 @@
 static int file_refresh_exec(bContext *C, wmOperator *UNUSED(unused))
 {
 	SpaceFile *sfile= CTX_wm_space_file(C);
+	struct FSMenu* fsmenu = fsmenu_get(); 
 
 	ED_fileselect_clear(C, sfile);
 
+	/* refresh system directory menu */
+	fsmenu_refresh_system_category(fsmenu);
+
 	WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
 
 	return OPERATOR_FINISHED;

Modified: trunk/blender/source/blender/editors/space_file/fsmenu.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/fsmenu.c	2012-05-18 12:49:22 UTC (rev 46769)
+++ trunk/blender/source/blender/editors/space_file/fsmenu.c	2012-05-18 12:49:25 UTC (rev 46770)
@@ -295,7 +295,7 @@
 	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 @@
 		}
 
 		/* 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 @@
 		 * 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 @@
 		}
 		
 		/* 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);
+		if(read_bookmarks) {
+			list = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL);
+			pathesArray = LSSharedFileListCopySnapshot(list, &seed);
+			pathesCount = CFArrayGetCount(pathesArray);
 			
-			err = LSSharedFileListItemResolve(itemRef, 
-			                                  kLSSharedFileListNoUserInteraction |
-			                                  kLSSharedFileListDoNotMountVolumes,
-			                                  &cfURL, NULL);
-			if (err != noErr)
-				continue;
+			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);
+			}
 			
-			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);
 		}
-		
-		CFRelease(pathesArray);
-		CFRelease(list);
 #endif /* OSX 10.5+ */
 	}
 #else
@@ -470,7 +474,7 @@
 	{
 		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 @@
 	}
 }
 
+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);

Modified: trunk/blender/source/blender/editors/space_file/fsmenu.h
===================================================================
--- trunk/blender/source/blender/editors/space_file/fsmenu.h	2012-05-18 12:49:22 UTC (rev 46769)
+++ trunk/blender/source/blender/editors/space_file/fsmenu.h	2012-05-18 12:49:25 UTC (rev 46770)
@@ -74,10 +74,13 @@
 void	fsmenu_read_bookmarks	(struct FSMenu* fsmenu, const char *filename);
 
 	/** adds system specific directories */
-void	fsmenu_read_system	(struct FSMenu* fsmenu);
+void	fsmenu_read_system	(struct FSMenu* fsmenu, int read_bookmarks);
 
 	/** Free's all the memory associated with the fsmenu */
 void	fsmenu_free				(struct FSMenu* fsmenu);
 
+	/** Refresh system directory menu */
+void	fsmenu_refresh_system_category		(struct FSMenu* fsmenu);
+
 #endif
 

Modified: trunk/blender/source/blender/editors/space_file/space_file.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/space_file.c	2012-05-18 12:49:22 UTC (rev 46769)
+++ trunk/blender/source/blender/editors/space_file/space_file.c	2012-05-18 12:49:25 UTC (rev 46770)
@@ -151,6 +151,9 @@
 	SpaceFile *sfile= (SpaceFile*)sa->spacedata.first;
 	//printf("file_init\n");
 
+	/* refresh system directory list */
+	fsmenu_refresh_system_category(fsmenu_get());
+
 	if (sfile->layout) sfile->layout->dirty= TRUE;
 }
 
@@ -613,7 +616,7 @@
 {
 	char *cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL);
 	
-	fsmenu_read_system(fsmenu_get());
+	fsmenu_read_system(fsmenu_get(), TRUE);
 
 	if (cfgdir) {
 		char name[FILE_MAX];




More information about the Bf-blender-cvs mailing list