diff options
author | Julian Eisel <julian@blender.org> | 2021-10-27 15:50:48 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-10-27 15:56:57 +0300 |
commit | aae5f15238f73fcac762a1690e052b86fad23be1 (patch) | |
tree | 5549df5789c1b586404a2bae575f0043c56d51db /source/blender/editors/asset | |
parent | 1832e11f39a36681533c148de9300b290a8c309c (diff) |
Asset Browser: Support dragging catalogs to move them in the hierarchy
Uses the additions to the UI tree-view API from the previous commit to
enable drag & drop of asset catalogs. The catalogs will be moved in the
tree including children.
A remaining issue is that a catalog with children will always be
collapsed when dropping. I need to find a way to fix that in the
tree-view API.
There are a few improvements I can think of for the tree-item drag &
drop support, but time for these is too short. These can be done as
normal cleanups at some point.
Diffstat (limited to 'source/blender/editors/asset')
-rw-r--r-- | source/blender/editors/asset/ED_asset_catalog.hh | 3 | ||||
-rw-r--r-- | source/blender/editors/asset/intern/asset_catalog.cc | 27 |
2 files changed, 30 insertions, 0 deletions
diff --git a/source/blender/editors/asset/ED_asset_catalog.hh b/source/blender/editors/asset/ED_asset_catalog.hh index 8b8fc4d3574..8da8fc0d6c9 100644 --- a/source/blender/editors/asset/ED_asset_catalog.hh +++ b/source/blender/editors/asset/ED_asset_catalog.hh @@ -37,3 +37,6 @@ void ED_asset_catalog_remove(AssetLibrary *library, const blender::bke::CatalogI void ED_asset_catalog_rename(AssetLibrary *library, blender::bke::CatalogID catalog_id, blender::StringRefNull new_name); +void ED_asset_catalog_move(AssetLibrary *library, + blender::bke::CatalogID src_catalog_id, + blender::bke::CatalogID dst_parent_catalog_id); diff --git a/source/blender/editors/asset/intern/asset_catalog.cc b/source/blender/editors/asset/intern/asset_catalog.cc index f3ba12a6324..8e1e5be2e47 100644 --- a/source/blender/editors/asset/intern/asset_catalog.cc +++ b/source/blender/editors/asset/intern/asset_catalog.cc @@ -121,6 +121,33 @@ void ED_asset_catalog_rename(::AssetLibrary *library, WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr); } +void ED_asset_catalog_move(::AssetLibrary *library, + const CatalogID src_catalog_id, + const CatalogID dst_parent_catalog_id) +{ + bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(library); + if (!catalog_service) { + BLI_assert_unreachable(); + return; + } + + AssetCatalog *src_catalog = catalog_service->find_catalog(src_catalog_id); + AssetCatalog *dst_catalog = catalog_service->find_catalog(dst_parent_catalog_id); + + const AssetCatalogPath new_path = dst_catalog->path / StringRef(src_catalog->path.name()); + const AssetCatalogPath clean_new_path = new_path.cleanup(); + + if (new_path == src_catalog->path || clean_new_path == src_catalog->path) { + /* Nothing changed, so don't bother renaming for nothing. */ + return; + } + + catalog_service->undo_push(); + catalog_service->tag_has_unsaved_changes(src_catalog); + catalog_service->update_catalog_path(src_catalog_id, clean_new_path); + WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr); +} + void ED_asset_catalogs_save_from_main_path(::AssetLibrary *library, const Main *bmain) { bke::AssetCatalogService *catalog_service = BKE_asset_library_get_catalog_service(library); |