diff options
author | Julian Eisel <julian@blender.org> | 2021-07-08 23:33:02 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-07-15 17:12:36 +0300 |
commit | 3feb3ce32d7d1fddf745bf30592cf68d906c295f (patch) | |
tree | beb00d1e8295611520055bcd78f8d2c6226981c1 /source/blender/editors/space_file | |
parent | 7898089de3f20b08a08516bd2fd2be7dd1c565fe (diff) |
Assets: Expose active asset library in context
For the Asset Browser, this returns the active asset library of the
Asset Browser, otherwise it returns the one active in the workspace.
This gives simple access to the active asset library from UI code and
Python scripts. For example the upcoming Pose Library add-on uses this,
as well as the upcoming asset view template.
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r-- | source/blender/editors/space_file/space_file.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 05d484d8e2e..e71c00e2312 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -868,7 +868,12 @@ static void file_space_subtype_item_extend(bContext *UNUSED(C), } } -static const char *file_context_dir[] = {"active_file", "id", NULL}; +static const char *file_context_dir[] = { + "active_file", + "asset_library", + "id", + NULL, +}; static int /*eContextResult*/ file_context(const bContext *C, const char *member, @@ -899,6 +904,23 @@ static int /*eContextResult*/ file_context(const bContext *C, CTX_data_pointer_set(result, &screen->id, &RNA_FileSelectEntry, file); return CTX_RESULT_OK; } + if (CTX_data_equals(member, "asset_library")) { + FileAssetSelectParams *asset_params = ED_fileselect_get_asset_params(sfile); + if (!asset_params) { + return CTX_RESULT_NO_DATA; + } + + BLI_STATIC_ASSERT(offsetof(FileSelectAssetLibraryUID, type) == + offsetof(AssetLibraryReference, type), + "Expected FileSelectAssetLibraryUID to match AssetLibraryReference"); + BLI_STATIC_ASSERT(offsetof(FileSelectAssetLibraryUID, custom_library_index) == + offsetof(AssetLibraryReference, custom_library_index), + "Expected FileSelectAssetLibraryUID to match AssetLibraryReference"); + + CTX_data_pointer_set( + result, &screen->id, &RNA_AssetLibraryReference, &asset_params->asset_library); + return CTX_RESULT_OK; + } if (CTX_data_equals(member, "id")) { const FileDirEntry *file = filelist_file(sfile->files, params->active_file); if (file == NULL) { |