Commit: 56582fbf820a6eccba3b0ba1c641640540a9e7ef Author: Julian Eisel Date: Wed Feb 1 16:26:30 2023 +0100 Branches: asset-shelf https://developer.blender.org/rB56582fbf820a6eccba3b0ba1c641640540a9e7ef
Get filtering by asset catalog to work =================================================================== M source/blender/editors/asset/intern/asset_shelf.cc M source/blender/editors/interface/interface_template_asset_shelf.cc M source/blender/editors/space_view3d/space_view3d.cc =================================================================== diff --git a/source/blender/editors/asset/intern/asset_shelf.cc b/source/blender/editors/asset/intern/asset_shelf.cc index dedbc58f036..8e9f65c4270 100644 --- a/source/blender/editors/asset/intern/asset_shelf.cc +++ b/source/blender/editors/asset/intern/asset_shelf.cc @@ -34,18 +34,16 @@ using namespace blender; +static void asset_shelf_send_redraw_notifier(bContext &C) +{ + WM_event_add_notifier(&C, NC_SPACE | ND_SPACE_ASSET_SHELF, nullptr); +} + /* -------------------------------------------------------------------- */ /** \name Asset Shelf Regions * \{ */ -void ED_asset_shelf_region_listen(const wmRegionListenerParams *params) -{ - if (ED_assetlist_listen(params->notifier)) { - ED_region_tag_redraw_no_rebuild(params->region); - } -} - -void ED_asset_shelf_footer_region_listen(const wmRegionListenerParams *params) +static void asset_shelf_region_listen(const wmRegionListenerParams *params) { ARegion *region = params->region; const wmNotifier *wmn = params->notifier; @@ -59,6 +57,22 @@ void ED_asset_shelf_footer_region_listen(const wmRegionListenerParams *params) } } +void ED_asset_shelf_region_listen(const wmRegionListenerParams *params) +{ + if (ED_assetlist_listen(params->notifier)) { + ED_region_tag_redraw_no_rebuild(params->region); + } + /* If the asset list didn't catch the notifier, let the region itself listen. */ + else { + asset_shelf_region_listen(params); + } +} + +void ED_asset_shelf_footer_region_listen(const wmRegionListenerParams *params) +{ + asset_shelf_region_listen(params); +} + void ED_asset_shelf_footer_region_init(wmWindowManager * /*wm*/, ARegion *region) { ED_region_header_init(region); @@ -265,7 +279,7 @@ class AssetCatalogSelectorTree : public ui::AbstractTreeView { return view_item; } - void update_shelf_settings_from_enabled_catalogs(const bContext *C); + void update_shelf_settings_from_enabled_catalogs(); class Item : public ui::BasicTreeViewItem { asset_system::AssetCatalogTreeItem catalog_item_; @@ -294,6 +308,7 @@ class AssetCatalogSelectorTree : public ui::AbstractTreeView { void build_row(uiLayout &row) override { + AssetCatalogSelectorTree &tree = dynamic_cast<AssetCatalogSelectorTree &>(get_tree_view()); uiBlock *block = uiLayoutGetBlock(&row); uiLayoutSetEmboss(&row, UI_EMBOSS); @@ -316,29 +331,23 @@ class AssetCatalogSelectorTree : public ui::AbstractTreeView { 0, 0, TIP_("Toggle catalog visibility in the asset shelf")); - UI_but_func_set( - but, - [](bContext *C, void *selector_tree_ptr, void *) { - AssetCatalogSelectorTree &selector_tree = *static_cast<AssetCatalogSelectorTree *>( - selector_tree_ptr); - selector_tree.update_shelf_settings_from_enabled_catalogs(C); - }, - &dynamic_cast<AssetCatalogSelectorTree &>(get_tree_view()), - nullptr); + UI_but_func_set(but, [&tree](bContext &C) { + tree.update_shelf_settings_from_enabled_catalogs(); + asset_shelf_send_redraw_notifier(C); + }); UI_but_flag_disable(but, UI_BUT_UNDO); } }; }; -void AssetCatalogSelectorTree::update_shelf_settings_from_enabled_catalogs(const bContext *C) +void AssetCatalogSelectorTree::update_shelf_settings_from_enabled_catalogs() { asset_shelf_settings_clear_enabled_catalogs(shelf_settings_); - foreach_item([C, this](ui::AbstractTreeViewItem &view_item) { + foreach_item([this](ui::AbstractTreeViewItem &view_item) { const auto &selector_tree_item = dynamic_cast<AssetCatalogSelectorTree::Item &>(view_item); if (selector_tree_item.is_catalog_path_enabled()) { asset_shelf_settings_set_catalog_path_enabled(shelf_settings_, selector_tree_item.catalog_path()); - WM_event_add_notifier(C, NC_SPACE | ND_SPACE_ASSET_SHELF, nullptr); } }); } @@ -420,8 +429,9 @@ static void add_catalog_toggle_buttons(AssetShelfSettings &shelf_settings, uiLay "Enable catalog, making contained assets visible in the asset shelf"); UI_but_drawflag_enable(but, UI_BUT_ALIGN_TOP); - UI_but_func_set(but, [&shelf_settings, path](bContext &) { + UI_but_func_set(but, [&shelf_settings, path](bContext &C) { asset_shelf_settings_set_active_catalog(shelf_settings, path); + asset_shelf_send_redraw_notifier(C); }); UI_but_func_pushed_state_set(but, [&shelf_settings, path](const uiBut &) -> bool { return asset_shelf_settings_is_active_catalog(shelf_settings, path); diff --git a/source/blender/editors/interface/interface_template_asset_shelf.cc b/source/blender/editors/interface/interface_template_asset_shelf.cc index 26676a9d8e3..abab93c3612 100644 --- a/source/blender/editors/interface/interface_template_asset_shelf.cc +++ b/source/blender/editors/interface/interface_template_asset_shelf.cc @@ -4,8 +4,11 @@ * \ingroup edinterface */ +#include "AS_asset_library.hh" + #include "BKE_context.h" +#include "DNA_screen_types.h" #include "DNA_space_types.h" #include "ED_asset.h" @@ -14,6 +17,10 @@ #include "UI_resources.h" #include "interface_intern.hh" +#include "RNA_prototypes.h" + +using namespace blender; + /* TODO copy of #asset_view_item_but_drag_set(). */ static void asset_tile_but_drag_set(uiBut &but, AssetHandle &asset_handle) { @@ -69,14 +76,44 @@ static void asset_tile_draw(uiLayout &layout, asset_tile_but_drag_set(*but, asset_handle); } +static std::optional<asset_system::AssetCatalogFilter> catalog_filter_from_shelf_settings( + const AssetShelfSettings *shelf_settings, const asset_system::AssetLibrary *library) +{ + if (!shelf_settings || !shelf_settings->active_catalog_path) { + return {}; + } + + asset_system ::AssetCatalog *active_catalog = library->catalog_service->find_catalog_by_path( + shelf_settings->active_catalog_path); + if (!active_catalog) { + return {}; + } + + return library->catalog_service->create_catalog_filter(active_catalog->catalog_id); +} + void uiTemplateAssetShelf(uiLayout *layout, const bContext *C, const AssetFilterSettings *filter_settings) { const AssetLibraryReference *library_ref = CTX_wm_asset_library_ref(C); + const PointerRNA shelf_settings_ptr = CTX_data_pointer_get_type( + C, "asset_shelf_settings", &RNA_AssetShelfSettings); + const AssetShelfSettings *shelf_settings = static_cast<AssetShelfSettings *>( + shelf_settings_ptr.data); ED_assetlist_storage_fetch(library_ref, C); ED_assetlist_ensure_previews_job(library_ref, C); + + const asset_system::AssetLibrary *library = ED_assetlist_library_get_once_available( + *library_ref); + if (!library) { + return; + } + + std::optional<asset_system::AssetCatalogFilter> catalog_filter = + catalog_filter_from_shelf_settings(shelf_settings, library); + uiLayoutSetScaleX(layout, 1.0f); uiLayoutSetScaleY(layout, 1.0f); @@ -94,6 +131,11 @@ void uiTemplateAssetShelf(uiLayout *layout, /* Don't do anything else, but return true to continue iterating. */ return true; } + /* Filter by active catalog. */ + const AssetMetaData *asset_data = ED_asset_handle_get_metadata(&asset); + if (catalog_filter && !catalog_filter->contains(asset_data->catalog_id)) { + return true; + } asset_tile_draw(*row, asset, width, height, show_names); return true; diff --git a/source/blender/editors/space_view3d/space_view3d.cc b/source/blender/editors/space_view3d/space_view3d.cc index 560a83b0d1f..694792b8a04 100644 --- a/source/blender/editors/space_view3d/space_view3d.cc +++ b/source/blender/editors/space_view3d/space_view3d.cc @@ -2186,6 +2186,7 @@ void ED_spacetype_view3d() art->prefsizey = HEADERY * 3.5f; art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER; art->listener = ED_asset_shelf_region_listen; + art->context = view3d_asset_shelf_context; art->init = view3d_header_region_init; art->draw = ED_region_header; BLI_addhead(&st->regiontypes, art); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs