diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 6cc4446274a..2a7e090b0d2 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 8d4384acba6..f717573d965 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 fa925310c2b..81014874fb5 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 fe861fa1dca..4d41f24a3e3 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 9a495fbb43f..69affc74ed7 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 ef5a6c2a51c..13ec2ddf523 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); }