From 052c22199da8ccbccd36be2edfb043f78dcc0d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 16 Nov 2021 12:35:39 +0100 Subject: Asset Browser: use one more refresh operator Refreshing the assets requires `file_OT_asset_library_refresh` in the asset browser, and `asset_OT_list_refresh` for the asset view. Both are now done from `ASSET_OT_open_containing_blend_file`. --- release/scripts/startup/bl_operators/assets.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/release/scripts/startup/bl_operators/assets.py b/release/scripts/startup/bl_operators/assets.py index a8ee44037d6..58f02201905 100644 --- a/release/scripts/startup/bl_operators/assets.py +++ b/release/scripts/startup/bl_operators/assets.py @@ -148,6 +148,8 @@ class ASSET_OT_open_containing_blend_file(Operator): bpy.ops.file.refresh() if bpy.ops.asset.list_refresh.poll(): bpy.ops.asset.list_refresh() + if bpy.ops.file.asset_library_refresh.poll(): + bpy.ops.file.asset_library_refresh() self.cancel(context) return {'FINISHED'} -- cgit v1.2.3 From faa8aa3bb98431c6e71f1d5bd96df51b9ec30243 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Tue, 16 Nov 2021 12:05:59 +0100 Subject: Asset Browser: Forbid dragging catalogs into themselves While there is nothing technically that would cause issues when moving a catalog into itself (it just changes the path of the catalog, and the missing parent catalogs will be created), it seems broken to the user. So disable this in the drag & drop code for asset catalogs. --- .../editors/space_file/asset_catalog_tree_view.cc | 28 +++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/source/blender/editors/space_file/asset_catalog_tree_view.cc b/source/blender/editors/space_file/asset_catalog_tree_view.cc index b3b81c5e07f..41559278910 100644 --- a/source/blender/editors/space_file/asset_catalog_tree_view.cc +++ b/source/blender/editors/space_file/asset_catalog_tree_view.cc @@ -122,6 +122,7 @@ class AssetCatalogDropController : public ui::AbstractTreeViewItemDropController bool on_drop(const wmDrag &drag) override; ::AssetLibrary &get_asset_library() const; + AssetCatalog *get_drag_catalog(const wmDrag &drag) const; static bool has_droppable_asset(const wmDrag &drag, const char **r_disabled_hint); static bool drop_assets_into_catalog(const AssetCatalogTreeView &tree_view, @@ -343,7 +344,14 @@ AssetCatalogDropController::AssetCatalogDropController(AssetCatalogTreeView &tre bool AssetCatalogDropController::can_drop(const wmDrag &drag, const char **r_disabled_hint) const { if (drag.type == WM_DRAG_ASSET_CATALOG) { - /* Always supported. */ + const AssetCatalog *drag_catalog = get_drag_catalog(drag); + /* Note: Technically it's not an issue to allow this (the catalog will just receive a new + * path and the catalog system will generate missing parents from the path). But it does + * appear broken to users, so disabling entirely. */ + if (catalog_item_.catalog_path().is_contained_in(drag_catalog->path)) { + *r_disabled_hint = "Catalog cannot be dropped into itself"; + return false; + } return true; } if (drag.type == WM_DRAG_ASSET_LIST) { @@ -363,11 +371,7 @@ std::string AssetCatalogDropController::drop_tooltip(const wmDrag &drag) const std::string AssetCatalogDropController::drop_tooltip_asset_catalog(const wmDrag &drag) const { BLI_assert(drag.type == WM_DRAG_ASSET_CATALOG); - - const ::AssetLibrary *asset_library = tree_view().asset_library_; - bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(asset_library); - wmDragAssetCatalog *catalog_drag = WM_drag_get_asset_catalog_data(&drag); - AssetCatalog *src_catalog = catalog_service->find_catalog(catalog_drag->drag_catalog_id); + const AssetCatalog *src_catalog = get_drag_catalog(drag); return std::string(TIP_("Move Catalog")) + " '" + src_catalog->path.name() + "' " + TIP_("into") + " '" + catalog_item_.get_name() + "'"; @@ -439,6 +443,18 @@ bool AssetCatalogDropController::drop_assets_into_catalog(const AssetCatalogTree return true; } +AssetCatalog *AssetCatalogDropController::get_drag_catalog(const wmDrag &drag) const +{ + if (drag.type != WM_DRAG_ASSET_CATALOG) { + return nullptr; + } + const bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service( + &get_asset_library()); + const wmDragAssetCatalog *catalog_drag = WM_drag_get_asset_catalog_data(&drag); + + return catalog_service->find_catalog(catalog_drag->drag_catalog_id); +} + bool AssetCatalogDropController::has_droppable_asset(const wmDrag &drag, const char **r_disabled_hint) { -- cgit v1.2.3 From c7a1e115b5071ae55db4aa66085d19c183ea325d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 16 Nov 2021 12:47:14 +0100 Subject: Tests: fix memory leak of GHOST system paths Dispose of GHOST system paths when tearing down `BlendfileLoadingBaseTest` and some other test cases. This prevents a memory leak. A better solution would be to rework Blender's initialisation & teardown structure, but that's outside the scope of this fix. No functional changes to Blender. --- source/blender/blenkernel/intern/layer_test.cc | 4 ++++ source/blender/blenloader/CMakeLists.txt | 1 + source/blender/blenloader/tests/blendfile_loading_base_test.cc | 3 +++ 3 files changed, 8 insertions(+) diff --git a/source/blender/blenkernel/intern/layer_test.cc b/source/blender/blenkernel/intern/layer_test.cc index b5f800dd181..c8e5de75bfa 100644 --- a/source/blender/blenkernel/intern/layer_test.cc +++ b/source/blender/blenkernel/intern/layer_test.cc @@ -33,6 +33,8 @@ #include "RNA_access.h" +#include "GHOST_Path-api.h" + namespace blender::bke::tests { TEST(view_layer, aov_unique_names) @@ -94,6 +96,7 @@ TEST(view_layer, aov_unique_names) IMB_exit(); BKE_appdir_exit(); CLG_exit(); + GHOST_DisposeSystemPaths(); } static void test_render_pass_conflict(Scene *scene, @@ -173,6 +176,7 @@ TEST(view_layer, aov_conflict) IMB_exit(); BKE_appdir_exit(); CLG_exit(); + GHOST_DisposeSystemPaths(); } } // namespace blender::bke::tests diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt index 89631588ed0..b3df5c8aa67 100644 --- a/source/blender/blenloader/CMakeLists.txt +++ b/source/blender/blenloader/CMakeLists.txt @@ -34,6 +34,7 @@ set(INC ../sequencer ../windowmanager ../../../intern/clog + ../../../intern/ghost ../../../intern/guardedalloc # for writefile.c: dna_type_offsets.h diff --git a/source/blender/blenloader/tests/blendfile_loading_base_test.cc b/source/blender/blenloader/tests/blendfile_loading_base_test.cc index 8afa631ffc5..21156868655 100644 --- a/source/blender/blenloader/tests/blendfile_loading_base_test.cc +++ b/source/blender/blenloader/tests/blendfile_loading_base_test.cc @@ -48,6 +48,8 @@ #include "WM_api.h" #include "wm.h" +#include "GHOST_Path-api.h" + #include "CLG_log.h" void BlendfileLoadingBaseTest::SetUpTestCase() @@ -93,6 +95,7 @@ void BlendfileLoadingBaseTest::TearDownTestCase() RNA_exit(); DEG_free_node_types(); + GHOST_DisposeSystemPaths(); DNA_sdna_current_free(); BLI_threadapi_exit(); -- cgit v1.2.3