[Bf-blender-cvs] [0dfdca6] master: Fix T43684: File Browser is unusable on Windows Machines (do not BLI_is_dir() in draw loop!)

Bastien Montagne noreply at git.blender.org
Mon Feb 16 16:01:10 CET 2015


Commit: 0dfdca6d132dd0b26307ab0c35be87f78da98022
Author: Bastien Montagne
Date:   Mon Feb 16 15:48:37 2015 +0100
Branches: master
https://developer.blender.org/rB0dfdca6d132dd0b26307ab0c35be87f78da98022

Fix T43684: File Browser is unusable on Windows Machines (do not BLI_is_dir() in draw loop!)

Did not had any issue on linux, but looks like on some windows can slow things as Hell.
Or maybe just the presence of some network FS?

Anyway, not a good idea, so now fsmenu entries' valid status is stored and only evaluated
on startup (reading of bookmarks & co) and when opening file browser (refresh, like
for system bookmarks).

===================================================================

M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/fsmenu.c
M	source/blender/editors/space_file/fsmenu.h
M	source/blender/editors/space_file/space_file.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_space.c

===================================================================

diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 6cc4446..2a7e090 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -600,6 +600,7 @@ static int bookmark_cleanup_exec(bContext *C, wmOperator *UNUSED(op))
 
 		BLI_make_file_string("/", name, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
 		fsmenu_write_file(fsmenu, name);
+		fsmenu_refresh_bookmarks_status(fsmenu);
 		ED_area_tag_refresh(sa);
 		ED_area_tag_redraw(sa);
 	}
diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c
index 8d4384a..f717573 100644
--- a/source/blender/editors/space_file/fsmenu.c
+++ b/source/blender/editors/space_file/fsmenu.c
@@ -216,6 +216,16 @@ void ED_fsmenu_entry_set_name(struct FSMenuEntry *fsentry, const char *name)
 	}
 }
 
+void fsmenu_entry_refresh_valid(struct FSMenuEntry *fsentry)
+{
+	if (fsentry->path && fsentry->path[0]) {
+		fsentry->valid = BLI_is_dir(fsentry->path);
+	}
+	else {
+		fsentry->valid = false;
+	}
+}
+
 short fsmenu_can_save(struct FSMenu *fsmenu, FSMenuCategory category, int idx)
 {
 	FSMenuEntry *fsm_iter;
@@ -272,6 +282,7 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu, FSMenuCategory category, const c
 	else {
 		fsm_iter->name[0] = '\0';
 	}
+	fsmenu_entry_refresh_valid(fsm_iter);
 
 	if (fsm_prev) {
 		if (flag & FS_INSERT_FIRST) {
@@ -640,6 +651,19 @@ void fsmenu_refresh_system_category(struct FSMenu *fsmenu)
 	fsmenu_read_system(fsmenu, true);
 }
 
+void fsmenu_refresh_bookmarks_status(struct FSMenu *fsmenu)
+{
+	int categories[] = {FS_CATEGORY_SYSTEM, FS_CATEGORY_SYSTEM_BOOKMARKS, FS_CATEGORY_BOOKMARKS, FS_CATEGORY_RECENT};
+	int i;
+
+	for (i = sizeof(categories) / sizeof(*categories); i--; ) {
+		FSMenuEntry *fsm_iter = ED_fsmenu_get_category(fsmenu, categories[i]);
+		for ( ; fsm_iter; fsm_iter = fsm_iter->next) {
+			fsmenu_entry_refresh_valid(fsm_iter);
+		}
+	}
+}
+
 void fsmenu_free(void)
 {
 	if (g_fsmenu) {
diff --git a/source/blender/editors/space_file/fsmenu.h b/source/blender/editors/space_file/fsmenu.h
index fa92531..8101487 100644
--- a/source/blender/editors/space_file/fsmenu.h
+++ b/source/blender/editors/space_file/fsmenu.h
@@ -49,6 +49,9 @@ struct FSMenuEntry;
  */
 void    fsmenu_insert_entry(struct FSMenu *fsmenu, enum FSMenuCategory category, const char *path, const char *name, const enum FSMenuInsert flag);
 
+/** Refresh 'valid' status of given menu entry */
+void fsmenu_entry_refresh_valid(struct FSMenuEntry *fsentry);
+
 /** Return whether the entry was created by the user and can be saved and deleted */
 short   fsmenu_can_save(struct FSMenu *fsmenu, enum FSMenuCategory category, int index);
 
@@ -70,6 +73,9 @@ void    fsmenu_free(void);
 /** Refresh system directory menu */
 void    fsmenu_refresh_system_category(struct FSMenu *fsmenu);
 
+/** Refresh 'valid' status of all menu entries */
+void    fsmenu_refresh_bookmarks_status(struct FSMenu *fsmenu);
+
 /** Get active index based on given directory. */
 int     fsmenu_get_active_indices(struct FSMenu *fsmenu, enum FSMenuCategory category, const char *dir);
 
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index fe861fa..4d41f24 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -157,6 +157,12 @@ static void file_init(wmWindowManager *UNUSED(wm), ScrArea *sa)
 	/* refresh system directory list */
 	fsmenu_refresh_system_category(ED_fsmenu_get());
 
+	/* Update bookmarks 'valid' state.
+	 * Done here, because it seems BLI_is_dir() can have huge impact on performances
+	 * in some cases, on win systems... See T43684.
+	 */
+	fsmenu_refresh_bookmarks_status(ED_fsmenu_get());
+
 	if (sfile->layout) sfile->layout->dirty = true;
 }
 
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 9a495fb..69affc7 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -647,7 +647,8 @@ typedef struct FSMenuEntry {
 	char *path;
 	char name[256];  /* FILE_MAXFILE */
 	short save;
-	short pad[3];
+	short valid;
+	short pad[2];
 } FSMenuEntry;
 
 /* FileSelectParams.display */
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index ef5a6c2..13ec2dd 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -1423,13 +1423,6 @@ static int rna_FileBrowser_FSMenuEntry_name_get_editable(PointerRNA *ptr)
 	return fsm->save;
 }
 
-static int rna_FileBrowser_FSMenuEntry_is_valid_get(PointerRNA *ptr)
-{
-	char *path = ED_fsmenu_entry_get_path(ptr->data);
-
-	return path ? BLI_is_dir(path) : false;  /* For now, no path = invalid. */
-}
-
 static void rna_FileBrowser_FSMenu_next(CollectionPropertyIterator *iter)
 {
 	ListBaseIterator *internal = &iter->internal.listbase;
@@ -3638,8 +3631,8 @@ static void rna_def_filemenu_entry(BlenderRNA *brna)
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 
 	prop = RNA_def_property(srna, "is_valid", PROP_BOOLEAN, PROP_NONE);
-	RNA_def_property_boolean_funcs(prop, "rna_FileBrowser_FSMenuEntry_is_valid_get", NULL);
-	RNA_def_property_ui_text(prop, "Save", "Whether this path is saved in bookmarks, or generated from OS");
+	RNA_def_property_boolean_sdna(prop, NULL, "valid", 1);
+	RNA_def_property_ui_text(prop, "Valid", "Whether this path is currently reachable");
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 }




More information about the Bf-blender-cvs mailing list