From 8783038a38ffefb1320359e78dea3061b520754d Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 14 Jun 2023 14:51:22 +0200 Subject: [PATCH] Refactor: Remove asset library reference in node add menu code The asset library reference isn't needed anymore for importing assets since ccc9eef1b9. So it doesn't need to be set in the add menu context, which simplifies code a bit. --- .../editors/space_node/add_menu_assets.cc | 29 +++++++------------ source/blender/editors/space_node/node_add.cc | 4 --- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/source/blender/editors/space_node/add_menu_assets.cc b/source/blender/editors/space_node/add_menu_assets.cc index 91c755d4566..ef779776a54 100644 --- a/source/blender/editors/space_node/add_menu_assets.cc +++ b/source/blender/editors/space_node/add_menu_assets.cc @@ -47,14 +47,10 @@ static void node_add_menu_assets_listen_fn(const wmRegionListenerParams *params) } } -struct LibraryAsset { - AssetLibraryReference library_ref; - asset_system::AssetRepresentation &asset; -}; - struct AssetItemTree { asset_system::AssetCatalogTree catalogs; - MultiValueMap assets_per_path; + MultiValueMap + assets_per_path; }; static AssetLibraryReference all_library_reference() @@ -106,7 +102,8 @@ static AssetItemTree build_catalog_tree(const bContext &C, const bNodeTree *node } /* Find all the matching node group assets for every catalog path. */ - MultiValueMap assets_per_path; + MultiValueMap + assets_per_path; AssetFilterSettings type_filter{}; type_filter.id_types = FILTER_ID_NT; @@ -139,7 +136,7 @@ static AssetItemTree build_catalog_tree(const bContext &C, const bNodeTree *node if (catalog == nullptr) { return true; } - assets_per_path.add(catalog->path, LibraryAsset{all_library_ref, asset}); + assets_per_path.add(catalog->path, &asset); return true; }); @@ -182,29 +179,25 @@ static void node_add_catalog_assets_draw(const bContext *C, Menu *menu) const asset_system::AssetCatalogPath &menu_path = *static_cast(menu_path_ptr.data); - const Span asset_items = tree.assets_per_path.lookup(menu_path); + const Span assets = tree.assets_per_path.lookup(menu_path); asset_system::AssetCatalogTreeItem *catalog_item = tree.catalogs.find_item(menu_path); BLI_assert(catalog_item != nullptr); - if (asset_items.is_empty() && !catalog_item->has_children()) { + if (assets.is_empty() && !catalog_item->has_children()) { return; } uiLayout *layout = menu->layout; uiItemS(layout); - for (const LibraryAsset &item : asset_items) { + for (const asset_system::AssetRepresentation *asset : assets) { uiLayout *col = uiLayoutColumn(layout, false); - PointerRNA asset_ptr{nullptr, &RNA_AssetRepresentation, &item.asset}; + PointerRNA asset_ptr{ + nullptr, &RNA_AssetRepresentation, const_cast(asset)}; uiLayoutSetContextPointer(col, "asset", &asset_ptr); - PointerRNA library_ptr{&screen.id, - &RNA_AssetLibraryReference, - const_cast(&item.library_ref)}; - uiLayoutSetContextPointer(col, "asset_library_ref", &library_ptr); - - uiItemO(col, IFACE_(item.asset.get_name().c_str()), ICON_NONE, "NODE_OT_add_group_asset"); + uiItemO(col, IFACE_(asset->get_name().c_str()), ICON_NONE, "NODE_OT_add_group_asset"); } asset_system::AssetLibrary *all_library = get_all_library_once_available(); diff --git a/source/blender/editors/space_node/node_add.cc b/source/blender/editors/space_node/node_add.cc index 586e7b27a75..269c0488aa7 100644 --- a/source/blender/editors/space_node/node_add.cc +++ b/source/blender/editors/space_node/node_add.cc @@ -427,10 +427,6 @@ static int node_add_group_asset_invoke(bContext *C, wmOperator *op, const wmEven ARegion ®ion = *CTX_wm_region(C); SpaceNode &snode = *CTX_wm_space_node(C); - const AssetLibraryReference *library_ref = CTX_wm_asset_library_ref(C); - if (!library_ref) { - return OPERATOR_CANCELLED; - } const AssetRepresentation *asset = CTX_wm_asset(C); if (!asset) { return OPERATOR_CANCELLED;