[Bf-blender-cvs] [71c39a9e2ef] blender-v3.0-release: Asset Browser: Activate a catalog when dragging

Julian Eisel noreply at git.blender.org
Wed Nov 24 18:05:38 CET 2021


Commit: 71c39a9e2ef300a1ca451f1080cf59dda94ef4a4
Author: Julian Eisel
Date:   Wed Nov 24 18:02:56 2021 +0100
Branches: blender-v3.0-release
https://developer.blender.org/rB71c39a9e2ef300a1ca451f1080cf59dda94ef4a4

Asset Browser: Activate a catalog when dragging

Without this it's easy to loose track of which catalog you are dragging.
Things feel generally quite jumpy/disconnected, activating the catalog
makes things feel far less like that.
I consider this an important usability fix, therefore I'm adding it to
the release branch.

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

M	source/blender/editors/include/UI_tree_view.hh
M	source/blender/editors/interface/tree_view.cc
M	source/blender/editors/space_file/asset_catalog_tree_view.cc

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

diff --git a/source/blender/editors/include/UI_tree_view.hh b/source/blender/editors/include/UI_tree_view.hh
index 0d18eedeac9..5acee02a8cc 100644
--- a/source/blender/editors/include/UI_tree_view.hh
+++ b/source/blender/editors/include/UI_tree_view.hh
@@ -358,11 +358,18 @@ class AbstractTreeViewItem : public TreeViewItemContainer {
  * custom implementation of #AbstractTreeViewItem::create_drag_controller().
  */
 class AbstractTreeViewItemDragController {
+ protected:
+  AbstractTreeView &tree_view_;
+
  public:
+  AbstractTreeViewItemDragController(AbstractTreeView &tree_view);
   virtual ~AbstractTreeViewItemDragController() = default;
 
   virtual int get_drag_type() const = 0;
   virtual void *create_drag_data() const = 0;
+  virtual void on_drag_start();
+
+  template<class TreeViewType> inline TreeViewType &tree_view() const;
 };
 
 /**
@@ -453,6 +460,13 @@ inline ItemT &TreeViewItemContainer::add_tree_item(Args &&...args)
       add_tree_item(std::make_unique<ItemT>(std::forward<Args>(args)...)));
 }
 
+template<class TreeViewType> TreeViewType &AbstractTreeViewItemDragController::tree_view() const
+{
+  static_assert(std::is_base_of<AbstractTreeView, TreeViewType>::value,
+                "Type must derive from and implement the AbstractTreeView interface");
+  return static_cast<TreeViewType &>(tree_view_);
+}
+
 template<class TreeViewType> TreeViewType &AbstractTreeViewItemDropController::tree_view() const
 {
   static_assert(std::is_base_of<AbstractTreeView, TreeViewType>::value,
diff --git a/source/blender/editors/interface/tree_view.cc b/source/blender/editors/interface/tree_view.cc
index fcc878c440c..488b3bbb726 100644
--- a/source/blender/editors/interface/tree_view.cc
+++ b/source/blender/editors/interface/tree_view.cc
@@ -550,6 +550,19 @@ void AbstractTreeViewItem::change_state_delayed()
     activate();
   }
 }
+
+/* ---------------------------------------------------------------------- */
+
+AbstractTreeViewItemDragController::AbstractTreeViewItemDragController(AbstractTreeView &tree_view)
+    : tree_view_(tree_view)
+{
+}
+
+void AbstractTreeViewItemDragController::on_drag_start()
+{
+  /* Do nothing by default. */
+}
+
 /* ---------------------------------------------------------------------- */
 
 AbstractTreeViewItemDropController::AbstractTreeViewItemDropController(AbstractTreeView &tree_view)
@@ -714,6 +727,8 @@ bool UI_tree_view_item_drag_start(bContext *C, uiTreeViewItemHandle *item_)
                       drag_controller->create_drag_data(),
                       0,
                       WM_DRAG_FREE_DATA);
+  drag_controller->on_drag_start();
+
   return true;
 }
 
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 5c880c15a53..d2d95a10c2a 100644
--- a/source/blender/editors/space_file/asset_catalog_tree_view.cc
+++ b/source/blender/editors/space_file/asset_catalog_tree_view.cc
@@ -110,10 +110,12 @@ class AssetCatalogDragController : public ui::AbstractTreeViewItemDragController
   AssetCatalogTreeItem &catalog_item_;
 
  public:
-  explicit AssetCatalogDragController(AssetCatalogTreeItem &catalog_item);
+  explicit AssetCatalogDragController(AssetCatalogTreeView &tree_view,
+                                      AssetCatalogTreeItem &catalog_item);
 
   int get_drag_type() const override;
   void *create_drag_data() const override;
+  void on_drag_start() override;
 };
 
 class AssetCatalogDropController : public ui::AbstractTreeViewItemDropController {
@@ -355,7 +357,8 @@ std::unique_ptr<ui::AbstractTreeViewItemDropController> AssetCatalogTreeViewItem
 std::unique_ptr<ui::AbstractTreeViewItemDragController> AssetCatalogTreeViewItem::
     create_drag_controller() const
 {
-  return std::make_unique<AssetCatalogDragController>(catalog_item_);
+  return std::make_unique<AssetCatalogDragController>(
+      static_cast<AssetCatalogTreeView &>(get_tree_view()), catalog_item_);
 }
 
 /* ---------------------------------------------------------------------- */
@@ -513,8 +516,9 @@ bool AssetCatalogDropController::has_droppable_asset(const wmDrag &drag,
 
 /* ---------------------------------------------------------------------- */
 
-AssetCatalogDragController::AssetCatalogDragController(AssetCatalogTreeItem &catalog_item)
-    : catalog_item_(catalog_item)
+AssetCatalogDragController::AssetCatalogDragController(AssetCatalogTreeView &tree_view,
+                                                       AssetCatalogTreeItem &catalog_item)
+    : ui::AbstractTreeViewItemDragController(tree_view), catalog_item_(catalog_item)
 {
 }
 
@@ -531,6 +535,12 @@ void *AssetCatalogDragController::create_drag_data() const
   return drag_catalog;
 }
 
+void AssetCatalogDragController::on_drag_start()
+{
+  AssetCatalogTreeView &tree_view_ = tree_view<AssetCatalogTreeView>();
+  tree_view_.activate_catalog_by_id(catalog_item_.get_catalog_id());
+}
+
 /* ---------------------------------------------------------------------- */
 
 void AssetCatalogTreeViewAllItem::build_row(uiLayout &row)



More information about the Bf-blender-cvs mailing list