Fix: All asset library not refreshed as available libraries change
Fixes #128751. As asset libraries were added or removed (through the UI or BPY), the "All" asset library wouldn't refresh to reflect the changes. In general this wasn't handled well. Even a manual refresh wouldn't give the right result. There were multiple issues really: - Only the first load of the "All" library would query the preferences for the available libraries. Further loads would only refresh the catalogs, ignoring any added/removed libraries. - Operators and BPY functions didn't clear the asset libraries to enforce a re-fetch. - When clearing an asset library, the "All" library wasn't cleared in some cases, it would show the old state still. - The API function to clear an asset library's asset list would not clear the storage of asset browsers so they wouldn't refresh. It makes no sense to only do one, so let the API handle both cases. The way we handle asset library updating could be improved generally, and be more internal to the asset system. For now this explicit clearing seems fine. We also need to handle removal of libraries better still, I think they remain in memory. Pull Request: https://projects.blender.org/blender/blender/pulls/129541
This commit is contained in:
committed by
Julian Eisel
parent
a641001207
commit
a859ed1130
@@ -207,12 +207,6 @@ void AssetLibraryService::reload_all_library_catalogs_if_dirty()
|
||||
|
||||
AssetLibrary *AssetLibraryService::get_asset_library_all(const Main *bmain)
|
||||
{
|
||||
if (all_library_) {
|
||||
CLOG_INFO(&LOG, 2, "get all lib (cached)");
|
||||
all_library_->refresh_catalogs();
|
||||
return all_library_.get();
|
||||
}
|
||||
|
||||
/* (Re-)load all other asset libraries. */
|
||||
for (AssetLibraryReference &library_ref : all_valid_asset_library_refs()) {
|
||||
/* Skip self :) */
|
||||
@@ -224,10 +218,15 @@ AssetLibrary *AssetLibraryService::get_asset_library_all(const Main *bmain)
|
||||
this->get_asset_library(bmain, library_ref);
|
||||
}
|
||||
|
||||
CLOG_INFO(&LOG, 2, "get all lib (loaded)");
|
||||
all_library_ = std::make_unique<AllAssetLibrary>();
|
||||
if (!all_library_) {
|
||||
CLOG_INFO(&LOG, 2, "get all lib (loaded)");
|
||||
all_library_ = std::make_unique<AllAssetLibrary>();
|
||||
}
|
||||
else {
|
||||
CLOG_INFO(&LOG, 2, "get all lib (cached)");
|
||||
}
|
||||
|
||||
/* Don't reload catalogs on this initial read, they've just been loaded above. */
|
||||
/* Don't reload catalogs, they've just been loaded above. */
|
||||
all_library_->rebuild_catalogs_from_nested(/*reload_nested_catalogs=*/false);
|
||||
|
||||
return all_library_.get();
|
||||
|
||||
@@ -60,7 +60,18 @@ void iterate(const AssetLibraryReference &library_reference, AssetListIterFn fn)
|
||||
void storage_fetch(const AssetLibraryReference *library_reference, const bContext *C);
|
||||
bool is_loaded(const AssetLibraryReference *library_reference);
|
||||
void ensure_previews_job(const AssetLibraryReference *library_reference, const bContext *C);
|
||||
/**
|
||||
* Clears this asset library and the "All" asset library for reload in both the static asset list
|
||||
* storage, as well as for all open asset browsers. Call this whenever the content of the given
|
||||
* asset library changed in a way that a reload is necessary.
|
||||
*/
|
||||
void clear(const AssetLibraryReference *library_reference, const bContext *C);
|
||||
/**
|
||||
* Clears the all asset library for reload in both the static asset list storage, as well as for
|
||||
* all open asset browsers. Call this whenever any asset library content changed in a way that a
|
||||
* reload is necessary.
|
||||
*/
|
||||
void clear_all_library(const bContext *C);
|
||||
bool storage_has_list_for_library(const AssetLibraryReference *library_reference);
|
||||
/**
|
||||
* Tag all asset lists in the storage that show main data as needing an update (re-fetch).
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
#include "ED_asset_indexer.hh"
|
||||
#include "ED_asset_list.hh"
|
||||
#include "ED_fileselect.hh"
|
||||
#include "ED_screen.hh"
|
||||
#include "asset_library_reference.hh"
|
||||
|
||||
@@ -458,6 +459,35 @@ void clear(const AssetLibraryReference *library_reference, const bContext *C)
|
||||
if (list) {
|
||||
list->clear(C);
|
||||
}
|
||||
|
||||
wmWindowManager *wm = CTX_wm_manager(C);
|
||||
LISTBASE_FOREACH (const wmWindow *, win, &wm->windows) {
|
||||
const bScreen *screen = WM_window_get_active_screen(win);
|
||||
LISTBASE_FOREACH (const ScrArea *, area, &screen->areabase) {
|
||||
/* Only needs to cover visible file/asset browsers, since others are already cleared through
|
||||
* area exiting. */
|
||||
if (area->spacetype == SPACE_FILE) {
|
||||
SpaceFile *sfile = reinterpret_cast<SpaceFile *>(area->spacedata.first);
|
||||
if (sfile->browse_mode == FILE_BROWSE_MODE_ASSETS) {
|
||||
if (sfile->asset_params && sfile->asset_params->asset_library_ref == *library_reference)
|
||||
{
|
||||
ED_fileselect_clear(wm, sfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Always clear the all library when clearing a nested one. */
|
||||
if (library_reference->type != ASSET_LIBRARY_ALL) {
|
||||
clear_all_library(C);
|
||||
}
|
||||
}
|
||||
|
||||
void clear_all_library(const bContext *C)
|
||||
{
|
||||
const AssetLibraryReference all_lib_ref = asset_system::all_library_reference();
|
||||
clear(&all_lib_ref, C);
|
||||
}
|
||||
|
||||
bool storage_has_list_for_library(const AssetLibraryReference *library_reference)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
set(INC
|
||||
../include
|
||||
../../asset_system
|
||||
../../blenkernel
|
||||
../../blenloader
|
||||
../../blentranslation
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "WM_api.hh"
|
||||
#include "WM_types.hh"
|
||||
|
||||
#include "ED_asset.hh"
|
||||
#include "ED_userpref.hh"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
@@ -136,7 +137,7 @@ static void PREFERENCES_OT_autoexec_path_remove(wmOperatorType *ot)
|
||||
/** \name Add Asset Library Operator
|
||||
* \{ */
|
||||
|
||||
static int preferences_asset_library_add_exec(bContext * /*C*/, wmOperator *op)
|
||||
static int preferences_asset_library_add_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
char *path = RNA_string_get_alloc(op->ptr, "directory", nullptr, 0, nullptr);
|
||||
char dirname[FILE_MAXFILE];
|
||||
@@ -152,6 +153,7 @@ static int preferences_asset_library_add_exec(bContext * /*C*/, wmOperator *op)
|
||||
|
||||
/* There's no dedicated notifier for the Preferences. */
|
||||
WM_main_add_notifier(NC_WINDOW, nullptr);
|
||||
blender::ed::asset::list::clear_all_library(C);
|
||||
|
||||
MEM_freeN(path);
|
||||
return OPERATOR_FINISHED;
|
||||
@@ -204,7 +206,7 @@ static bool preferences_asset_library_remove_poll(bContext *C)
|
||||
return true;
|
||||
}
|
||||
|
||||
static int preferences_asset_library_remove_exec(bContext * /*C*/, wmOperator *op)
|
||||
static int preferences_asset_library_remove_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
const int index = RNA_int_get(op->ptr, "index");
|
||||
bUserAssetLibrary *library = static_cast<bUserAssetLibrary *>(
|
||||
@@ -219,6 +221,7 @@ static int preferences_asset_library_remove_exec(bContext * /*C*/, wmOperator *o
|
||||
CLAMP(U.active_asset_library, 0, count_remaining - 1);
|
||||
U.runtime.is_dirty = true;
|
||||
|
||||
blender::ed::asset::list::clear_all_library(C);
|
||||
/* Trigger refresh for the Asset Browser. */
|
||||
WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
|
||||
|
||||
|
||||
@@ -227,6 +227,8 @@ static const EnumPropertyItem rna_enum_preferences_extension_repo_source_type_it
|
||||
# include "MEM_CacheLimiterC-Api.h"
|
||||
# include "MEM_guardedalloc.h"
|
||||
|
||||
# include "ED_asset_list.hh"
|
||||
|
||||
# include "UI_interface.hh"
|
||||
|
||||
static void rna_userdef_version_get(PointerRNA *ptr, int *value)
|
||||
@@ -369,6 +371,12 @@ static void rna_userdef_asset_library_path_set(PointerRNA *ptr, const char *valu
|
||||
BKE_preferences_asset_library_path_set(library, value);
|
||||
}
|
||||
|
||||
static void rna_userdef_asset_library_path_update(bContext *C, PointerRNA *ptr)
|
||||
{
|
||||
blender::ed::asset::list::clear_all_library(C);
|
||||
rna_userdef_update(CTX_data_main(C), CTX_data_scene(C), ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use sparingly as a sync may be time consuming.
|
||||
* Any change that may cause loading remote data to change behavior
|
||||
@@ -582,11 +590,15 @@ static void rna_userdef_script_directory_remove(ReportList *reports, PointerRNA
|
||||
USERDEF_TAG_DIRTY;
|
||||
}
|
||||
|
||||
static bUserAssetLibrary *rna_userdef_asset_library_new(const char *name, const char *directory)
|
||||
static bUserAssetLibrary *rna_userdef_asset_library_new(const bContext *C,
|
||||
const char *name,
|
||||
const char *directory)
|
||||
{
|
||||
bUserAssetLibrary *new_library = BKE_preferences_asset_library_add(
|
||||
&U, name ? name : "", directory ? directory : "");
|
||||
|
||||
blender::ed::asset::list::clear_all_library(C);
|
||||
|
||||
/* Trigger refresh for the Asset Browser. */
|
||||
WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
|
||||
|
||||
@@ -594,7 +606,7 @@ static bUserAssetLibrary *rna_userdef_asset_library_new(const char *name, const
|
||||
return new_library;
|
||||
}
|
||||
|
||||
static void rna_userdef_asset_library_remove(ReportList *reports, PointerRNA *ptr)
|
||||
static void rna_userdef_asset_library_remove(bContext *C, ReportList *reports, PointerRNA *ptr)
|
||||
{
|
||||
bUserAssetLibrary *library = static_cast<bUserAssetLibrary *>(ptr->data);
|
||||
|
||||
@@ -604,6 +616,7 @@ static void rna_userdef_asset_library_remove(ReportList *reports, PointerRNA *pt
|
||||
}
|
||||
|
||||
BKE_preferences_asset_library_remove(&U, library);
|
||||
blender::ed::asset::list::clear_all_library(C);
|
||||
|
||||
/* Update active library index to be in range. */
|
||||
const int count_remaining = BLI_listbase_count(&U.asset_libraries);
|
||||
@@ -6901,7 +6914,8 @@ static void rna_def_userdef_filepaths_asset_library(BlenderRNA *brna)
|
||||
prop, "Path", "Path to a directory with .blend files to use as an asset library");
|
||||
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_EDITOR_FILEBROWSER);
|
||||
RNA_def_property_string_funcs(prop, nullptr, nullptr, "rna_userdef_asset_library_path_set");
|
||||
RNA_def_property_update(prop, 0, "rna_userdef_update");
|
||||
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
|
||||
RNA_def_property_update(prop, 0, "rna_userdef_asset_library_path_update");
|
||||
|
||||
static const EnumPropertyItem import_method_items[] = {
|
||||
{ASSET_IMPORT_LINK, "LINK", 0, "Link", "Import the assets as linked data-block"},
|
||||
@@ -7118,7 +7132,7 @@ static void rna_def_userdef_asset_library_collection(BlenderRNA *brna, PropertyR
|
||||
RNA_def_struct_ui_text(srna, "User Asset Libraries", "Collection of user asset libraries");
|
||||
|
||||
func = RNA_def_function(srna, "new", "rna_userdef_asset_library_new");
|
||||
RNA_def_function_flag(func, FUNC_NO_SELF);
|
||||
RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT);
|
||||
RNA_def_function_ui_description(func, "Add a new Asset Library");
|
||||
RNA_def_string(func, "name", nullptr, sizeof(bUserAssetLibrary::name), "Name", "");
|
||||
RNA_def_string(func, "directory", nullptr, sizeof(bUserAssetLibrary::dirpath), "Directory", "");
|
||||
@@ -7127,7 +7141,7 @@ static void rna_def_userdef_asset_library_collection(BlenderRNA *brna, PropertyR
|
||||
RNA_def_function_return(func, parm);
|
||||
|
||||
func = RNA_def_function(srna, "remove", "rna_userdef_asset_library_remove");
|
||||
RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_REPORTS);
|
||||
RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
|
||||
RNA_def_function_ui_description(func, "Remove an Asset Library");
|
||||
parm = RNA_def_pointer(func, "library", "UserAssetLibrary", "", "");
|
||||
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
|
||||
|
||||
Reference in New Issue
Block a user