diff --git a/source/blender/editors/asset/intern/asset_shelf.cc b/source/blender/editors/asset/intern/asset_shelf.cc index f05e36856af..82e3478561d 100644 --- a/source/blender/editors/asset/intern/asset_shelf.cc +++ b/source/blender/editors/asset/intern/asset_shelf.cc @@ -688,7 +688,7 @@ int context(const bContext *C, const char *member, bContextDataResult *result) static const char *context_dir[] = { "asset_shelf", "asset_library_reference", - "active_file", /* XXX yuk... */ + "asset", nullptr, }; @@ -722,8 +722,7 @@ int context(const bContext *C, const char *member, bContextDataResult *result) return CTX_RESULT_OK; } - /* XXX hack. Get the asset from the active item, but needs to be the file... */ - if (CTX_data_equals(member, "active_file")) { + if (CTX_data_equals(member, "asset")) { const ARegion *region = CTX_wm_region(C); const uiBut *but = UI_region_views_find_active_item_but(region); if (!but) { @@ -735,13 +734,13 @@ int context(const bContext *C, const char *member, bContextDataResult *result) return CTX_RESULT_NO_DATA; } - const PointerRNA *file_ptr = CTX_store_ptr_lookup( - but_context, "active_file", &RNA_FileSelectEntry); - if (!file_ptr) { + const PointerRNA *asset_ptr = CTX_store_ptr_lookup( + but_context, "asset", &RNA_AssetRepresentation); + if (!asset_ptr) { return CTX_RESULT_NO_DATA; } - CTX_data_pointer_set_ptr(result, file_ptr); + CTX_data_pointer_set_ptr(result, asset_ptr); return CTX_RESULT_OK; } diff --git a/source/blender/editors/asset/intern/asset_shelf_asset_view.cc b/source/blender/editors/asset/intern/asset_shelf_asset_view.cc index 90fae1dfa40..3548d9b7edc 100644 --- a/source/blender/editors/asset/intern/asset_shelf_asset_view.cc +++ b/source/blender/editors/asset/intern/asset_shelf_asset_view.cc @@ -56,14 +56,10 @@ class AssetView : public ui::AbstractGridView { class AssetViewItem : public ui::PreviewGridItem { asset_system::AssetRepresentation &asset_; - int asset_index_; bool allow_asset_drag_ = true; public: - AssetViewItem(asset_system::AssetRepresentation &asset_, - int asset_index, - StringRef identifier, - StringRef label); + AssetViewItem(asset_system::AssetRepresentation &asset_, StringRef identifier, StringRef label); void disable_asset_drag(); void build_grid_tile(const bContext &C, uiLayout &layout) const override; @@ -105,7 +101,7 @@ void AssetView::build_items() return; } - list::iterate(library_ref_, [&](asset_system::AssetRepresentation &asset, int asset_index) { + list::iterate(library_ref_, [&](asset_system::AssetRepresentation &asset) { if (shelf_.type->asset_poll && !shelf_.type->asset_poll(shelf_.type, &asset)) { return true; } @@ -119,8 +115,7 @@ void AssetView::build_items() const bool show_names = (shelf_.settings.display_flag & ASSETSHELF_SHOW_NAMES); const StringRef identifier = asset.library_relative_identifier(); - AssetViewItem &item = this->add_item( - asset, asset_index, identifier, asset.get_name()); + AssetViewItem &item = this->add_item(asset, identifier, asset.get_name()); if (!show_names) { item.hide_label(); } @@ -174,10 +169,9 @@ static std::optional catalog_filter_from_shelf /* ---------------------------------------------------------------------- */ AssetViewItem::AssetViewItem(asset_system::AssetRepresentation &asset, - int asset_index, StringRef identifier, StringRef label) - : ui::PreviewGridItem(identifier, label, ICON_NONE), asset_(asset), asset_index_(asset_index) + : ui::PreviewGridItem(identifier, label, ICON_NONE), asset_(asset) { } @@ -212,18 +206,9 @@ void AssetViewItem::build_grid_tile(const bContext & /*C*/, uiLayout &layout) co const AssetView &asset_view = reinterpret_cast(this->get_view()); const AssetShelfType &shelf_type = *asset_view.shelf_.type; - AssetHandle asset_handle = list::asset_handle_get_by_index(&asset_view.library_ref_, - asset_index_); - - PointerRNA file_ptr = RNA_pointer_create_discrete( - nullptr, - &RNA_FileSelectEntry, - /* XXX passing file pointer here, should be asset handle or asset representation. */ - const_cast(asset_handle.file_data)); - UI_but_context_ptr_set(uiLayoutGetBlock(&layout), - reinterpret_cast(view_item_but_), - "active_file", - &file_ptr); + PointerRNA asset_ptr = RNA_pointer_create_discrete(nullptr, &RNA_AssetRepresentation, &asset_); + UI_but_context_ptr_set( + uiLayoutGetBlock(&layout), reinterpret_cast(view_item_but_), "asset", &asset_ptr); uiBut *item_but = reinterpret_cast(this->view_item_button()); if (std::optional activate_op = create_activate_operator_params(