From cd2849c89b65131cc381a1bf9ab75527afd51a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 23 Nov 2021 12:29:44 +0100 Subject: Asset Browser: add operator for installing asset bundles Add an operator "Copy to Asset Library" for installing asset bundles into already-existing asset libraries. The operator is shown when: - the "Current File" library is selected, - the blend file name matches `*_bundle.blend`, and - the file is not already located in an asset library. The user can select a target asset library, then gets a "Save As" dialogue box to select where in that library the file should be saved. This allows for renaming, saving in a subdirectory, etc. The Asset Catalogs from the asset bundle are merged into the target asset library. The operator will refuse to run when external files are referenced. This is not done in its poll function, as it's quite an extensive operator (it loops over all ID datablocks). Reviewed by: Severin Differential Revision: https://developer.blender.org/D13312 --- source/blender/editors/space_file/file_panels.c | 16 +++++++++++++++- source/blender/editors/space_file/filesel.c | 9 +++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'source/blender/editors/space_file') diff --git a/source/blender/editors/space_file/file_panels.c b/source/blender/editors/space_file/file_panels.c index 0e468718a04..540d4729ed6 100644 --- a/source/blender/editors/space_file/file_panels.c +++ b/source/blender/editors/space_file/file_panels.c @@ -41,6 +41,7 @@ #include "ED_fileselect.h" #include "UI_interface.h" +#include "UI_interface_icons.h" #include "UI_resources.h" #include "WM_api.h" @@ -246,7 +247,20 @@ static void file_panel_asset_catalog_buttons_draw(const bContext *C, Panel *pane RNA_pointer_create(&screen->id, &RNA_FileAssetSelectParams, params, ¶ms_ptr); uiItemR(row, ¶ms_ptr, "asset_library_ref", 0, "", ICON_NONE); - if (params->asset_library_ref.type != ASSET_LIBRARY_LOCAL) { + if (params->asset_library_ref.type == ASSET_LIBRARY_LOCAL) { + bContext *mutable_ctx = CTX_copy(C); + if (WM_operator_name_poll(mutable_ctx, "asset.bundle_install")) { + uiItemS(col); + uiItemMenuEnumO(col, + mutable_ctx, + "asset.bundle_install", + "asset_library_ref", + "Copy Bundle to Asset Library...", + ICON_IMPORT); + } + CTX_free(mutable_ctx); + } + else { uiItemO(row, "", ICON_FILE_REFRESH, "FILE_OT_asset_library_refresh"); } diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 11757975a62..c59398e0016 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -411,6 +411,15 @@ FileAssetSelectParams *ED_fileselect_get_asset_params(const SpaceFile *sfile) return (sfile->browse_mode == FILE_BROWSE_MODE_ASSETS) ? sfile->asset_params : NULL; } +bool ED_fileselect_is_local_asset_library(const SpaceFile *sfile) +{ + const FileAssetSelectParams *asset_params = ED_fileselect_get_asset_params(sfile); + if (asset_params == NULL) { + return false; + } + return asset_params->asset_library_ref.type == ASSET_LIBRARY_LOCAL; +} + static void fileselect_refresh_asset_params(FileAssetSelectParams *asset_params) { AssetLibraryReference *library = &asset_params->asset_library_ref; -- cgit v1.2.3