31#include "RNA_prototypes.hh"
42 std::optional<AssetWeakReference> active_asset_;
43 std::optional<asset_system::AssetCatalogFilter> catalog_filter_ = std::nullopt;
54 void set_catalog_filter(
const std::optional<asset_system::AssetCatalogFilter> &catalog_filter);
60 bool allow_asset_drag_ =
true;
89 : library_ref_(library_ref), shelf_(
shelf)
91 if (
shelf.type->get_active_asset) {
92 if (const AssetWeakReference *weak_ref = shelf.type->get_active_asset(shelf.type)) {
93 active_asset_ = *weak_ref;
96 active_asset_.reset();
109 if (shelf_.type->asset_poll && !shelf_.type->asset_poll(shelf_.type, &
asset)) {
114 if (catalog_filter_ && !catalog_filter_->contains(asset_data.
catalog_id)) {
123 asset, asset_index, identifier,
asset.get_name());
148 const std::optional<asset_system::AssetCatalogFilter> &catalog_filter)
150 if (catalog_filter) {
151 catalog_filter_.emplace(*catalog_filter);
154 catalog_filter_ = std::nullopt;
167 if (!active_catalog) {
186 allow_asset_drag_ =
false;
204 PointerRNA *op_props = MEM_new<PointerRNA>(__func__);
220 &RNA_FileSelectEntry,
237 MEM_delete(activate_op->opptr);
258 asset_.ensure_previewable();
260 const int preview_id = [&]() ->
int {
266 return ICON_PREVIEW_LOADING;
290 if (!asset_view.active_asset_) {
294 const bool matches = *asset_view.active_asset_ == weak_ref;
308 &
C, activate_op->optype, activate_op->opcontext, activate_op->opptr,
nullptr);
310 MEM_delete(activate_op->opptr);
317 return fnmatch(filter_string.
c_str(), asset_name.
c_str(), FNM_CASEFOLD) == 0;
322 if (!allow_asset_drag_) {
325 return std::make_unique<AssetDragController>(this->
get_view(), asset_);
336 return search_string;
356 std::unique_ptr asset_view = std::make_unique<AssetView>(library_ref,
shelf);
362 *block,
"asset shelf asset view", std::move(asset_view));
385 ID *local_id = asset_.local_id();
387 return static_cast<void *
>(local_id);
393 import_settings.
method = import_method;
Main runtime representation of an asset.
ScrArea * CTX_wm_area(const bContext *C)
@ ASSET_SHELF_TYPE_FLAG_NO_ASSET_DRAG
#define LISTBASE_FOREACH(type, var, list)
char char * BLI_strncpy_ensure_pad(char *__restrict dst, const char *__restrict src, char pad, size_t dst_maxncpy) ATTR_NONNULL(1
@ ASSET_IMPORT_APPEND_REUSE
blender::ui::AbstractGridView * UI_block_add_view(uiBlock &block, blender::StringRef idname, std::unique_ptr< blender::ui::AbstractGridView > grid_view)
bool UI_textbutton_activate_rna(const bContext *C, ARegion *region, const void *rna_poin_data, const char *rna_prop_id)
void UI_but_func_tooltip_custom_set(uiBut *but, uiButToolTipCustomFunc func, void *arg, uiFreeArgFunc free_arg)
void UI_but_operator_set(uiBut *but, wmOperatorType *optype, wmOperatorCallContext opcontext, const PointerRNA *opptr=nullptr)
void UI_but_context_ptr_set(uiBlock *block, uiBut *but, blender::StringRef name, const PointerRNA *ptr)
void UI_but_operator_set_never_call(uiBut *but)
void UI_but_view_item_draw_size_set(uiBut *but, const std::optional< int > draw_width=std::nullopt, const std::optional< int > draw_height=std::nullopt)
uiBlock * uiLayoutGetBlock(uiLayout *layout)
@ WM_OP_INVOKE_REGION_WIN
constexpr bool is_empty() const
constexpr const char * c_str() const
AssetCatalogFilter create_catalog_filter(CatalogID active_catalog_id) const
AssetCatalog * find_catalog_by_path(const AssetCatalogPath &path) const
const CatalogID catalog_id
AssetCatalogService & catalog_service() const
eWM_DragDataType get_drag_type() const override
AssetDragController(ui::AbstractGridView &view, asset_system::AssetRepresentation &asset)
void * create_drag_data() const override
AssetViewItem(asset_system::AssetRepresentation &asset_, int asset_index, StringRef identifier, StringRef label)
void build_grid_tile(const bContext &C, uiLayout &layout) const override
bool should_be_filtered_visible(StringRefNull filter_string) const override
void on_activate(bContext &C) override
void disable_asset_drag()
void build_context_menu(bContext &C, uiLayout &column) const override
std::unique_ptr< ui::AbstractViewItemDragController > create_drag_controller() const override
std::optional< bool > should_be_active() const override
friend class AssetDragController
bool begin_filtering(const bContext &C) const override
AssetView(const AssetLibraryReference &library_ref, const AssetShelf &shelf)
void set_catalog_filter(const std::optional< asset_system::AssetCatalogFilter > &catalog_filter)
void build_items() override
friend class AssetViewItem
AbstractGridView & get_view() const
bool matches(const AbstractViewItem &other) const override
ItemT & add_item(Args &&...args)
const GridViewStyle & get_style() const
AbstractViewItemDragController(AbstractView &view)
uiButViewItem * view_item_but_
uiButViewItem * view_item_button() const
void set_context_menu_title(const std::string &title)
void build_grid_view(const bContext &C, AbstractGridView &grid_view, uiLayout &layout, std::optional< StringRef > search_string={})
PreviewGridItem(StringRef identifier, StringRef label, int preview_icon_id)
void build_grid_tile_button(uiLayout &layout, BIFIconID override_preview_icon_id=ICON_NONE) const
void storage_fetch(const AssetLibraryReference *library_reference, const bContext *C)
asset_system::AssetLibrary * library_get_once_available(const AssetLibraryReference &library_reference)
bool is_loaded(const AssetLibraryReference *library_reference)
AssetHandle asset_handle_get_by_index(const AssetLibraryReference *library_reference, int asset_index)
void iterate(const AssetLibraryReference &library_reference, AssetListIndexIterFn fn)
static std::optional< wmOperatorCallParams > create_activate_operator_params(const StringRefNull op_name, const asset_system::AssetRepresentation &asset)
static std::optional< asset_system::AssetCatalogFilter > catalog_filter_from_shelf_settings(const AssetShelfSettings &shelf_settings, const asset_system::AssetLibrary &library)
int tile_height(const AssetShelfSettings &settings)
int tile_width(const AssetShelfSettings &settings)
static std::string filter_string_get(const AssetShelf &shelf)
void build_asset_view(uiLayout &layout, const AssetLibraryReference &library_ref, const AssetShelf &shelf, const bContext &C)
void asset_tooltip(const asset_system::AssetRepresentation &asset, uiTooltipData &tip, const bool include_name)
void operator_asset_reference_props_set(const asset_system::AssetRepresentation &asset, PointerRNA &ptr)
BIFIconID asset_preview_or_icon(const asset_system::AssetRepresentation &asset)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
const struct FileDirEntry * file_data
bool use_instance_collections
eAssetImportMethod method
const char * active_catalog_path
std::string activate_operator
void(* draw_context_menu)(const bContext *C, const AssetShelfType *shelf_type, const blender::asset_system::AssetRepresentation *asset, uiLayout *layout)
const AssetWeakReference *(* get_active_asset)(const AssetShelfType *shelf_type)
struct AssetShelfType * type
wmDragAsset * WM_drag_create_asset_data(const blender::asset_system::AssetRepresentation *asset, const AssetImportSettings &import_settings)
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wmOperatorCallContext context, PointerRNA *properties, const wmEvent *event)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot)
void WM_operator_properties_free(PointerRNA *ptr)