[Bf-blender-cvs] [ccc9eef1b92] master: Assets: Get asset path via new identifier (not via file browser hacks)
Julian Eisel
noreply at git.blender.org
Wed Nov 30 19:44:53 CET 2022
Commit: ccc9eef1b9278ec2e8b57feddbf44cdfcda9d0a9
Author: Julian Eisel
Date: Wed Nov 30 19:24:24 2022 +0100
Branches: master
https://developer.blender.org/rBccc9eef1b9278ec2e8b57feddbf44cdfcda9d0a9
Assets: Get asset path via new identifier (not via file browser hacks)
With the asset identifier introduced in the previous commit, we can now
locate an asset just from its `AssetRepresentation`, without requiring
information from the asset library and the file browser storage. With
this we can remove some hacks and function parameters. A RNA/BPY
function is also affected, but I didn't remove the paramter to keep
compatibility. It's simply ignored and not required anymore, noted this
in the parameter description (noted for T102877).
===================================================================
M release/scripts/startup/bl_operators/assets.py
M release/scripts/startup/bl_ui/space_filebrowser.py
M source/blender/editors/armature/pose_lib_2.c
M source/blender/editors/asset/ED_asset_handle.h
M source/blender/editors/asset/ED_asset_list.h
M source/blender/editors/asset/ED_asset_list.hh
M source/blender/editors/asset/ED_asset_temp_id_consumer.h
M source/blender/editors/asset/intern/asset_handle.cc
M source/blender/editors/asset/intern/asset_list.cc
M source/blender/editors/asset/intern/asset_temp_id_consumer.cc
M source/blender/editors/interface/interface_template_asset_view.cc
M source/blender/editors/space_node/add_node_search.cc
M source/blender/editors/space_node/link_drag_search.cc
M source/blender/editors/space_node/node_add.cc
M source/blender/makesrna/intern/rna_asset.c
M source/blender/windowmanager/WM_api.h
M source/blender/windowmanager/intern/wm_dragdrop.cc
===================================================================
diff --git a/release/scripts/startup/bl_operators/assets.py b/release/scripts/startup/bl_operators/assets.py
index 1911a98f930..b794ede10a2 100644
--- a/release/scripts/startup/bl_operators/assets.py
+++ b/release/scripts/startup/bl_operators/assets.py
@@ -97,13 +97,12 @@ class ASSET_OT_open_containing_blend_file(Operator):
def execute(self, context):
asset_file_handle = context.asset_file_handle
- asset_library_ref = context.asset_library_ref
if asset_file_handle.local_id:
self.report({'WARNING'}, "This asset is stored in the current blend file")
return {'CANCELLED'}
- asset_lib_path = bpy.types.AssetHandle.get_full_library_path(asset_file_handle, asset_library_ref)
+ asset_lib_path = bpy.types.AssetHandle.get_full_library_path(asset_file_handle)
self.open_in_new_blender(asset_lib_path)
wm = context.window_manager
diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index 1e7faf68b3f..614f350533b 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -862,8 +862,7 @@ def asset_path_str_get(_self):
if asset_file_handle.local_id:
return "Current File"
- asset_library_ref = bpy.context.asset_library_ref
- return bpy.types.AssetHandle.get_full_library_path(asset_file_handle, asset_library_ref)
+ return bpy.types.AssetHandle.get_full_library_path(asset_file_handle)
def register_props():
diff --git a/source/blender/editors/armature/pose_lib_2.c b/source/blender/editors/armature/pose_lib_2.c
index e3189eacdd5..1e69d9d0fc2 100644
--- a/source/blender/editors/armature/pose_lib_2.c
+++ b/source/blender/editors/armature/pose_lib_2.c
@@ -249,16 +249,15 @@ static void poselib_tempload_exit(PoseBlendData *pbd)
static bAction *poselib_blend_init_get_action(bContext *C, wmOperator *op)
{
bool asset_handle_valid;
- const AssetLibraryReference *asset_library_ref = CTX_wm_asset_library_ref(C);
const AssetHandle asset_handle = CTX_wm_asset_handle(C, &asset_handle_valid);
/* Poll callback should check. */
- BLI_assert((asset_library_ref != NULL) && asset_handle_valid);
+ BLI_assert(asset_handle_valid);
PoseBlendData *pbd = op->customdata;
pbd->temp_id_consumer = ED_asset_temp_id_consumer_create(&asset_handle);
return (bAction *)ED_asset_temp_id_consumer_ensure_local_id(
- pbd->temp_id_consumer, C, asset_library_ref, ID_AC, CTX_data_main(C), op->reports);
+ pbd->temp_id_consumer, ID_AC, CTX_data_main(C), op->reports);
}
static bAction *flip_pose(bContext *C, Object *ob, bAction *action)
@@ -508,11 +507,9 @@ static bool poselib_asset_in_context(bContext *C)
{
bool asset_handle_valid;
/* Check whether the context provides the asset data needed to add a pose. */
- const AssetLibraryReference *asset_library_ref = CTX_wm_asset_library_ref(C);
- AssetHandle asset_handle = CTX_wm_asset_handle(C, &asset_handle_valid);
+ const AssetHandle asset_handle = CTX_wm_asset_handle(C, &asset_handle_valid);
- return (asset_library_ref != NULL) && asset_handle_valid &&
- (ED_asset_handle_get_id_type(&asset_handle) == ID_AC);
+ return asset_handle_valid && (ED_asset_handle_get_id_type(&asset_handle) == ID_AC);
}
/* Poll callback for operators that require existing PoseLib data (with poses) to work. */
diff --git a/source/blender/editors/asset/ED_asset_handle.h b/source/blender/editors/asset/ED_asset_handle.h
index 4a81840c40d..c11f94a3259 100644
--- a/source/blender/editors/asset/ED_asset_handle.h
+++ b/source/blender/editors/asset/ED_asset_handle.h
@@ -27,9 +27,7 @@ struct AssetMetaData *ED_asset_handle_get_metadata(const struct AssetHandle *ass
struct ID *ED_asset_handle_get_local_id(const struct AssetHandle *asset);
ID_Type ED_asset_handle_get_id_type(const struct AssetHandle *asset);
int ED_asset_handle_get_preview_icon_id(const struct AssetHandle *asset);
-void ED_asset_handle_get_full_library_path(const struct bContext *C,
- const struct AssetLibraryReference *asset_library_ref,
- const struct AssetHandle *asset,
+void ED_asset_handle_get_full_library_path(const struct AssetHandle *asset,
char r_full_lib_path[]);
#ifdef __cplusplus
@@ -41,9 +39,7 @@ void ED_asset_handle_get_full_library_path(const struct bContext *C,
namespace blender::ed::asset {
/** If the ID already exists in the database, return it, otherwise add it. */
-ID *get_local_id_from_asset_or_append_and_reuse(Main &bmain,
- const AssetLibraryReference &library_ref,
- AssetHandle asset);
+ID *get_local_id_from_asset_or_append_and_reuse(Main &bmain, AssetHandle asset);
} // namespace blender::ed::asset
diff --git a/source/blender/editors/asset/ED_asset_list.h b/source/blender/editors/asset/ED_asset_list.h
index bcd5dbca8d4..635dc3bff32 100644
--- a/source/blender/editors/asset/ED_asset_list.h
+++ b/source/blender/editors/asset/ED_asset_list.h
@@ -51,7 +51,6 @@ void ED_assetlist_storage_id_remap(struct ID *id_old, struct ID *id_new);
void ED_assetlist_storage_exit(void);
struct ImBuf *ED_assetlist_asset_image_get(const AssetHandle *asset_handle);
-const char *ED_assetlist_library_path(const struct AssetLibraryReference *library_reference);
/**
* \return True if the region needs a UI redraw.
diff --git a/source/blender/editors/asset/ED_asset_list.hh b/source/blender/editors/asset/ED_asset_list.hh
index 20faf5c495d..541fa315f77 100644
--- a/source/blender/editors/asset/ED_asset_list.hh
+++ b/source/blender/editors/asset/ED_asset_list.hh
@@ -15,10 +15,6 @@ struct AssetLibraryReference;
struct FileDirEntry;
struct bContext;
-std::string ED_assetlist_asset_filepath_get(const bContext *C,
- const AssetLibraryReference &library_reference,
- const AssetHandle &asset_handle);
-
/* Can return false to stop iterating. */
using AssetListIterFn = blender::FunctionRef<bool(AssetHandle)>;
void ED_assetlist_iterate(const AssetLibraryReference &library_reference, AssetListIterFn fn);
diff --git a/source/blender/editors/asset/ED_asset_temp_id_consumer.h b/source/blender/editors/asset/ED_asset_temp_id_consumer.h
index 43a466d51ad..d6ed2509a32 100644
--- a/source/blender/editors/asset/ED_asset_temp_id_consumer.h
+++ b/source/blender/editors/asset/ED_asset_temp_id_consumer.h
@@ -27,13 +27,10 @@ struct bContext;
AssetTempIDConsumer *ED_asset_temp_id_consumer_create(const struct AssetHandle *handle);
void ED_asset_temp_id_consumer_free(AssetTempIDConsumer **consumer);
-struct ID *ED_asset_temp_id_consumer_ensure_local_id(
- AssetTempIDConsumer *consumer,
- const struct bContext *C,
- const struct AssetLibraryReference *asset_library_ref,
- ID_Type id_type,
- struct Main *bmain,
- struct ReportList *reports);
+struct ID *ED_asset_temp_id_consumer_ensure_local_id(AssetTempIDConsumer *consumer,
+ ID_Type id_type,
+ struct Main *bmain,
+ struct ReportList *reports);
#ifdef __cplusplus
}
diff --git a/source/blender/editors/asset/intern/asset_handle.cc b/source/blender/editors/asset/intern/asset_handle.cc
index 73686e02098..3528a3824db 100644
--- a/source/blender/editors/asset/intern/asset_handle.cc
+++ b/source/blender/editors/asset/intern/asset_handle.cc
@@ -6,7 +6,9 @@
#include <string>
+#include "AS_asset_identifier.hh"
#include "AS_asset_representation.h"
+#include "AS_asset_representation.hh"
#include "DNA_space_types.h"
@@ -42,14 +44,12 @@ int ED_asset_handle_get_preview_icon_id(const AssetHandle *asset)
return asset->file_data->preview_icon_id;
}
-void ED_asset_handle_get_full_library_path(const bContext *C,
- const AssetLibraryReference *asset_library_ref,
- const AssetHandle *asset,
+void ED_asset_handle_get_full_library_path(const AssetHandle *asset_handle,
char r_full_lib_path[FILE_MAX_LIBEXTRA])
{
*r_full_lib_path = '\0';
- std::string asset_path = ED_assetlist_asset_filepath_get(C, *asset_library_ref, *asset);
+ std::string asset_path = AS_asset_representation_full_path_get(asset_handle->file_data->asset);
if (asset_path.empty()) {
return;
}
@@ -59,16 +59,14 @@ void ED_asset_handle_get_full_library_path(const bContext *C,
namespace blender::ed::asset {
-ID *get_local_id_from_asset_or_append_and_reuse(Main &bmain,
- const AssetLibraryReference &library_ref,
- const AssetHandle asset)
+ID *get_local_id_from_asset_or_append_and_reuse(Main &bmain, const AssetHandle asset)
{
if (ID *local_id = ED_asset_handle_get_local_id(&asset)) {
return local_id;
}
char blend_path[FILE_MAX_LIBEXTRA];
- ED_asset_handle_get_full_library_path(nullptr, &library_ref, &asset, blend_path);
+ ED_asset_handle_get_full_library_path(&asset, blend_path);
const char *id_name = ED_asset_handle_get_name(&asset);
return WM_file_append_datablock(&bmain,
diff --git a/source/blender/editors/asset/intern/asset_list.cc b/source/blender/editors/asset/intern/asset_list.cc
index bb72c5cc1bb..4a1f26abad0 100644
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@ -22,8 +22,6 @@
#include "BKE_preferences.h"
-#include "ED_fileselect.h"
-
#include "WM_api.h"
/* XXX uses private header of file-space. */
@@ -119,7 +117,6 @@ class AssetList : NonCopyable {
int size() const;
void tagMainDataDirty() const;
void remapID(ID *id_old, ID *id_new) const;
- StringRef filepath() const;
};
AssetList::AssetList(eFileSelectType filesel_type, const AssetLibraryReference &asset_library_ref)
@@ -296
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list