Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2021-09-30 16:05:47 +0300
committerJulian Eisel <julian@blender.org>2021-09-30 16:23:13 +0300
commit07c5d02a113180a6a088a397a25e03175ee5fcf5 (patch)
tree72ab68d91cd0027eecff7a09630c47f920f4d82c /source/blender/editors/space_file/filelist.c
parent3453b22b1e9cd11ca26960403cbc7b75bfcbe119 (diff)
Asset Browser: Support activating catalogs in the "Current File" library
If the "Current File" asset library is selected in the Asset Browser, now asssets are filtered based on the active asset catalog. Previously it would just show all assets. This was marked as a TODO in the code already. Maniphest Task: https://developer.blender.org/T91820
Diffstat (limited to 'source/blender/editors/space_file/filelist.c')
-rw-r--r--source/blender/editors/space_file/filelist.c61
1 files changed, 43 insertions, 18 deletions
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index 91178b85823..bdf61e792d3 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -810,22 +810,6 @@ static bool is_filtered_hidden(const char *filename,
return true;
}
- /* TODO Make catalog activation work properly with the "Current File" asset library. Currently
- * this will only work for external asset data. */
- if (file->imported_asset_data) {
- switch (filter->asset_catalog_visibility) {
- case FILE_SHOW_ASSETS_WITHOUT_CATALOG:
- return !BLI_uuid_is_nil(file->imported_asset_data->catalog_id);
- case FILE_SHOW_ASSETS_FROM_CATALOG:
- /* TODO show all assets that are in child catalogs of the selected catalog. */
- return BLI_uuid_is_nil(filter->asset_catalog_id) ||
- !BLI_uuid_equal(filter->asset_catalog_id, file->imported_asset_data->catalog_id);
- case FILE_SHOW_ASSETS_ALL_CATALOGS:
- /* All asset files should be visible. */
- break;
- }
- }
-
return false;
}
@@ -913,6 +897,39 @@ static bool is_filtered_id_file(const FileListInternEntry *file,
return is_filtered;
}
+/**
+ * Get the asset metadata of a file, if it represents an asset. This may either be of a local ID
+ * (ID in the current #Main) or read from an external asset library.
+ */
+static AssetMetaData *filelist_file_internal_get_asset_data(const FileListInternEntry *file)
+{
+ const ID *local_id = file->local_data.id;
+ return local_id ? local_id->asset_data : file->imported_asset_data;
+}
+
+static bool is_filtered_asset(FileListInternEntry *file, FileListFilter *filter)
+{
+ const AssetMetaData *asset_data = filelist_file_internal_get_asset_data(file);
+ bool is_visible = false;
+
+ switch (filter->asset_catalog_visibility) {
+ case FILE_SHOW_ASSETS_WITHOUT_CATALOG:
+ is_visible = BLI_uuid_is_nil(asset_data->catalog_id);
+ break;
+ case FILE_SHOW_ASSETS_FROM_CATALOG:
+ /* TODO show all assets that are in child catalogs of the selected catalog. */
+ is_visible = !BLI_uuid_is_nil(filter->asset_catalog_id) &&
+ BLI_uuid_equal(filter->asset_catalog_id, asset_data->catalog_id);
+ break;
+ case FILE_SHOW_ASSETS_ALL_CATALOGS:
+ /* All asset files should be visible. */
+ is_visible = true;
+ break;
+ }
+
+ return is_visible;
+}
+
static bool is_filtered_lib(FileListInternEntry *file, const char *root, FileListFilter *filter)
{
bool is_filtered;
@@ -930,6 +947,13 @@ static bool is_filtered_lib(FileListInternEntry *file, const char *root, FileLis
return is_filtered;
}
+static bool is_filtered_asset_library(FileListInternEntry *file,
+ const char *root,
+ FileListFilter *filter)
+{
+ return is_filtered_lib(file, root, filter) && is_filtered_asset(file, filter);
+}
+
static bool is_filtered_main(FileListInternEntry *file,
const char *UNUSED(dir),
FileListFilter *filter)
@@ -942,7 +966,8 @@ static bool is_filtered_main_assets(FileListInternEntry *file,
FileListFilter *filter)
{
/* "Filtered" means *not* being filtered out... So return true if the file should be visible. */
- return is_filtered_id_file(file, file->relpath, file->name, filter);
+ return is_filtered_id_file(file, file->relpath, file->name, filter) &&
+ is_filtered_asset(file, filter);
}
static void filelist_filter_clear(FileList *filelist)
@@ -1779,7 +1804,7 @@ void filelist_settype(FileList *filelist, short type)
case FILE_ASSET_LIBRARY:
filelist->check_dir_fn = filelist_checkdir_lib;
filelist->read_job_fn = filelist_readjob_asset_library;
- filelist->filter_fn = is_filtered_lib;
+ filelist->filter_fn = is_filtered_asset_library;
break;
case FILE_MAIN_ASSET:
filelist->check_dir_fn = filelist_checkdir_main_assets;