Commit: 4fa69fbda8871753fcd2d1ae09d62d8dac880a47 Author: Julian Eisel Date: Thu Jan 19 11:50:45 2023 +0100 Branches: asset-shelf https://developer.blender.org/rB4fa69fbda8871753fcd2d1ae09d62d8dac880a47
Popup to select which catalogs are displayed in the asset shelf footer The selected catalogs are currently listed as simple labels in the footer, just for testing. =================================================================== M source/blender/editors/asset/CMakeLists.txt M source/blender/editors/asset/ED_asset_shelf.h M source/blender/editors/asset/intern/asset_shelf.cc M source/blender/editors/include/UI_interface.h M source/blender/editors/interface/interface_region_popup.cc M source/blender/editors/interface/views/tree_view.cc M source/blender/editors/space_view3d/space_view3d.cc M source/blender/makesdna/DNA_screen_types.h M source/blender/makesdna/DNA_view3d_types.h M source/blender/makesrna/intern/rna_ui.c M source/blender/windowmanager/WM_types.h =================================================================== diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt index 3e45a0bccdf..bc6b9a474b8 100644 --- a/source/blender/editors/asset/CMakeLists.txt +++ b/source/blender/editors/asset/CMakeLists.txt @@ -13,6 +13,8 @@ set(INC ../../windowmanager ../../../../intern/clog ../../../../intern/guardedalloc + # dna_type_offsets.h + ${CMAKE_CURRENT_BINARY_DIR}/../../makesdna/intern # RNA_prototypes.h ${CMAKE_BINARY_DIR}/source/blender/makesrna ) diff --git a/source/blender/editors/asset/ED_asset_shelf.h b/source/blender/editors/asset/ED_asset_shelf.h index 5d5a483ef0b..8298cf8f042 100644 --- a/source/blender/editors/asset/ED_asset_shelf.h +++ b/source/blender/editors/asset/ED_asset_shelf.h @@ -11,18 +11,54 @@ extern "C" { #endif struct ARegionType; +struct AssetShelfSettings; struct bContext; +struct bContextDataResult; +struct BlendDataReader; +struct BlendWriter; struct wmWindowManager; -void ED_region_asset_shelf_footer_init(struct wmWindowManager *wm, struct ARegion *region); -void ED_region_asset_shelf_footer(const struct bContext *C, struct ARegion *region); +/* -------------------------------------------------------------------- */ +/* Asset Shelf Regions */ -void ED_region_asset_shelf_listen(const struct wmRegionListenerParams *params); +/** Only needed for #RGN_TYPE_ASSET_SHELF (not #RGN_TYPE_ASSET_SHELF_FOOTER). */ +void ED_asset_shelf_region_listen(const struct wmRegionListenerParams *params); +void ED_asset_shelf_footer_region_init(struct wmWindowManager *wm, struct ARegion *region); +void ED_asset_shelf_footer_region(const struct bContext *C, struct ARegion *region); +void ED_asset_shelf_footer_region_listen(const struct wmRegionListenerParams *params); void ED_asset_shelf_footer_register(struct ARegionType *region_type, const char *idname, const int space_type); +/* -------------------------------------------------------------------- */ +/* Asset Shelf Settings */ + +/** + * Deep-copies \a shelf_settings into newly allocated memory. Must be freed using #MEM_freeN() or + * #MEM_delete(). + */ +AssetShelfSettings *ED_asset_shelf_settings_duplicate(const AssetShelfSettings *shelf_settings); +/** + * Frees the contained data, not \a shelf_settings itself. + */ +void ED_asset_shelf_settings_free(AssetShelfSettings *shelf_settings); + +void ED_asset_shelf_settings_blend_write(struct BlendWriter *writer, + const struct AssetShelfSettings *storage); +void ED_asset_shelf_settings_blend_read_data(struct BlendDataReader *reader, + struct AssetShelfSettings **storage); + +/* -------------------------------------------------------------------- */ + +/** + * Creates an `"asset_shelf_settings"` context member, pointing to \a shelf_settings. + */ +int ED_asset_shelf_context(const struct bContext *C, + const char *member, + struct bContextDataResult *result, + struct AssetShelfSettings *shelf_settings); + #ifdef __cplusplus } #endif diff --git a/source/blender/editors/asset/intern/asset_shelf.cc b/source/blender/editors/asset/intern/asset_shelf.cc index 42396d5d435..3ea457a9056 100644 --- a/source/blender/editors/asset/intern/asset_shelf.cc +++ b/source/blender/editors/asset/intern/asset_shelf.cc @@ -1,44 +1,411 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /** \file * \ingroup edasset */ +#include "AS_asset_catalog.hh" +#include "AS_asset_catalog_tree.hh" +#include "AS_asset_library.hh" + +#include "BKE_context.h" #include "BKE_screen.h" +#include "BLO_read_write.h" + +#include "BLT_translation.h" + #include "DNA_screen_types.h" #include "ED_asset_list.h" +#include "ED_asset_list.hh" #include "ED_screen.h" +#include "RNA_prototypes.h" + #include "UI_interface.h" +#include "UI_interface.hh" #include "UI_resources.h" +#include "UI_tree_view.hh" + +#include "WM_api.h" #include "ED_asset_shelf.h" -static void asset_shelf_draw(const bContext * /*C*/, Header *header) -{ - uiLayout *layout = header->layout; - uiItemL(layout, "Fooo\n", ICON_ASSET_MANAGER); -} +using namespace blender; -void ED_region_asset_shelf_listen(const wmRegionListenerParams *params) +/* -------------------------------------------------------------------- */ +/** \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_region_asset_shelf_footer_init(wmWindowManager * /*wm*/, ARegion *region) +void ED_asset_shelf_footer_region_listen(const wmRegionListenerParams *params) +{ + ARegion *region = params->region; + const wmNotifier *wmn = params->notifier; + + switch (wmn->category) { + case NC_SPACE: + if (wmn->data == ND_SPACE_ASSET_SHELF) { + ED_region_tag_redraw(region); + } + break; + } +} + +void ED_asset_shelf_footer_region_init(wmWindowManager * /*wm*/, ARegion *region) { ED_region_header_init(region); } -void ED_region_asset_shelf_footer(const bContext *C, ARegion *region) +void ED_asset_shelf_footer_region(const bContext *C, ARegion *region) { ED_region_header(C, region); } +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Asset Shelf Settings + * \{ */ + +AssetShelfSettings *ED_asset_shelf_settings_duplicate(const AssetShelfSettings *shelf_settings) +{ + if (!shelf_settings) { + return nullptr; + } + + static_assert( + std::is_trivial_v<AssetShelfSettings>, + "AssetShelfSettings needs to be trivial to allow freeing with MEM_freeN() (API promise)"); + AssetShelfSettings *new_settings = MEM_new<AssetShelfSettings>(__func__, *shelf_settings); + + LISTBASE_FOREACH (LinkData *, catalog_path_item, &shelf_settings->enabled_catalog_paths) { + LinkData *new_path_item = static_cast<LinkData *>(MEM_dupallocN(catalog_path_item)); + new_path_item->data = BLI_strdup((char *)catalog_path_item->data); + BLI_addtail(&new_settings->enabled_catalog_paths, new_path_item); + } + + return new_settings; +} + +static void asset_shelf_settings_clear_enabled_catalogs(AssetShelfSettings &shelf_settings) +{ + LISTBASE_FOREACH_MUTABLE (LinkData *, catalog_path_item, &shelf_settings.enabled_catalog_paths) { + MEM_freeN(catalog_path_item->data); + BLI_freelinkN(&shelf_settings.enabled_catalog_paths, catalog_path_item); + } + BLI_assert(BLI_listbase_is_empty(&shelf_settings.enabled_catalog_paths)); +} + +void ED_asset_shelf_settings_free(AssetShelfSettings *shelf_settings) +{ + asset_shelf_settings_clear_enabled_catalogs(*shelf_settings); +} + +void ED_asset_shelf_settings_blend_write(BlendWriter *writer, + const AssetShelfSettings *shelf_settings) +{ + if (!shelf_settings) { + return; + } + + BLO_write_struct(writer, AssetShelfSettings, shelf_settings); + + LISTBASE_FOREACH (LinkData *, catalog_path_item, &shelf_settings->enabled_catalog_paths) { + BLO_write_struct(writer, LinkData, catalog_path_item); + BLO_write_string(writer, (const char *)catalog_path_item->data); + } +} + +void ED_asset_shelf_settings_blend_read_data(BlendDataReader *reader, + AssetShelfSettings **shelf_settings) +{ + if (!*shelf_settings) { + return; + } + + BLO_read_data_address(reader, shelf_settings); + + BLO_read_list(reader, &(*shelf_settings)->enabled_catalog_paths); + LISTBASE_FOREACH (LinkData *, catalog_path_item, &(*shelf_settings)->enabled_catalog_paths) { + BLO_read_data_address(reader, &catalog_path_item->data); + } +} + +static bool asset_shelf_settings_is_catalog_path_enabled( + const AssetShelfSettings &shelf_settings, const asset_system::AssetCatalogPath &path) +{ + LISTBASE_FOREACH (LinkData *, catalog_path_item, &shelf_settings.enabled_catalog_paths) { + if (StringRef((const char *)catalog_path_item->data) == path.str()) { + return true; + } + } + return false; +} + +static void asset_shelf_settings_set_catalog_path_enabled( + AssetShelfSettings &shelf_settings, const asset_system::AssetCatalogPath &path) +{ + char *path_copy = BLI_strdupn(path.c_str(), path.length()); + BLI_addtail(&shelf_settings.enabled_catalog_paths, BLI_genericNodeN(path_copy)); +} + +static void asset_shelf_settings_foreach_enabled_catalog_path( + const AssetShelfSettings &shelf_settings, + FunctionRef<void(const asset_system::AssetCatalogPath &catalog_path)> fn) +{ + LISTBASE_FOREACH (LinkData *, catalog_path_item, &shelf_settings.enabled_catalog_paths) { + fn(asset_system::AssetCatalogPath((char *)catalog_path_item->data)); + } +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Asset Shelf Context + * \{ */ + +int ED_asset_shelf_context(const bContext *C, + const char *member, + bContextDataResult *result, + AssetShelfSettings *shelf_settings) +{ + static const char *context_dir[] = { + "asset_shelf_settings", + nullptr, + }; + + if (CTX_data_dir(member)) { + CTX_data_dir_set(result, context_dir); + return CTX_RESULT_OK; + } + + bScreen *screen = CTX_wm_screen(C); + + if (CTX_data_equals(member, "asset_shelf_settings")) { + CTX_data_pointer_set(result, &screen->id, &RNA_AssetShelfSettings, shelf_settings); + + return CTX_RESULT_OK; + } + + return CTX_RESULT_MEMBER_NOT_FOUND; +} + +static AssetShelfSettings *get_asset_shelf_settings_from_context(const bContext *C) +{ + PointerRNA shelf_settings_ptr = CTX_data_pointer_get_type( + C, "asset_shelf_settings", &RNA_AssetShelfSettings); + return static_cast<AssetShelfSettings *>(shelf_settings_ptr.data); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Asset Catalog Selector UI + * + * Popup containing a tree-view to select which catalogs to disp @@ Diff output truncated at 10240 characters. @@ _______________________________________________ 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