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.
This commit is contained in:
parent
cae3b581b0
commit
71c39a9e2e
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue