Attempt to fix missing asset library refreshes

This commit is contained in:
Julian Eisel
2024-10-29 18:26:51 +01:00
parent 219e655119
commit c71a6a5304
5 changed files with 53 additions and 3 deletions

View File

@@ -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).

View File

@@ -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)

View File

@@ -4,6 +4,7 @@
set(INC
../include
../../asset_system
../../blenkernel
../../blenloader
../../blentranslation

View File

@@ -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;

View File

@@ -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)
@@ -582,11 +584,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);
@@ -7118,7 +7124,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", "");