[Bf-blender-cvs] [faa8aa3bb98] blender-v3.0-release: Asset Browser: Forbid dragging catalogs into themselves

Julian Eisel noreply at git.blender.org
Tue Nov 16 13:03:37 CET 2021


Commit: faa8aa3bb98431c6e71f1d5bd96df51b9ec30243
Author: Julian Eisel
Date:   Tue Nov 16 12:05:59 2021 +0100
Branches: blender-v3.0-release
https://developer.blender.org/rBfaa8aa3bb98431c6e71f1d5bd96df51b9ec30243

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.

===================================================================

M	source/blender/editors/space_file/asset_catalog_tree_view.cc

===================================================================

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<AssetCatalogTreeView>().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)
 {



More information about the Bf-blender-cvs mailing list