From 5be54cce3692ae590433b786d8007767e3727469 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 29 Jul 2021 17:10:11 +0200 Subject: Cleanup: Pass asset handle to asset iterator, rather than wrapped file This iterator was introduced before `AssetHandle` existed, so it was dealing with the file data directly. Now we want as little code as possible to deal with the file data, all access should happen via the `AssetHandle`. --- source/blender/editors/asset/ED_asset_list.hh | 2 +- source/blender/editors/asset/intern/asset_list.cc | 8 +++++++- source/blender/editors/interface/interface_template_asset_view.cc | 5 +++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/source/blender/editors/asset/ED_asset_list.hh b/source/blender/editors/asset/ED_asset_list.hh index 7f41fba3457..fee34d929c2 100644 --- a/source/blender/editors/asset/ED_asset_list.hh +++ b/source/blender/editors/asset/ED_asset_list.hh @@ -34,5 +34,5 @@ std::string ED_assetlist_asset_filepath_get(const bContext *C, const AssetHandle &asset_handle); /* Can return false to stop iterating. */ -using AssetListIterFn = blender::FunctionRef; +using AssetListIterFn = blender::FunctionRef; void ED_assetlist_iterate(const AssetLibraryReference *library_reference, AssetListIterFn fn); diff --git a/source/blender/editors/asset/intern/asset_list.cc b/source/blender/editors/asset/intern/asset_list.cc index 445269d563e..d94a2bbf438 100644 --- a/source/blender/editors/asset/intern/asset_list.cc +++ b/source/blender/editors/asset/intern/asset_list.cc @@ -215,7 +215,13 @@ void AssetList::iterate(AssetListIterFn fn) const for (int i = 0; i < numfiles; i++) { FileDirEntry *file = filelist_file(files, i); - if (!fn(*file)) { + if ((file->typeflag & FILE_TYPE_ASSET) == 0) { + continue; + } + + AssetHandle asset_handle = {file}; + if (!fn(asset_handle)) { + /* If the callback returns false, we stop iterating. */ break; } } diff --git a/source/blender/editors/interface/interface_template_asset_view.cc b/source/blender/editors/interface/interface_template_asset_view.cc index a691fff4963..fe2c660f2d0 100644 --- a/source/blender/editors/interface/interface_template_asset_view.cc +++ b/source/blender/editors/interface/interface_template_asset_view.cc @@ -170,11 +170,12 @@ static void asset_view_template_refresh_asset_collection( RNA_property_collection_clear(&assets_dataptr, assets_prop); - ED_assetlist_iterate(&asset_library, [&](FileDirEntry &file) { + ED_assetlist_iterate(&asset_library, [&](AssetHandle asset) { PointerRNA itemptr, fileptr; RNA_property_collection_add(&assets_dataptr, assets_prop, &itemptr); - RNA_pointer_create(nullptr, &RNA_FileSelectEntry, &file, &fileptr); + RNA_pointer_create( + nullptr, &RNA_FileSelectEntry, const_cast(asset.file_data), &fileptr); RNA_pointer_set(&itemptr, "file_data", fileptr); /* Copy name from file to asset-handle name ID-property. */ -- cgit v1.2.3