Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2021-10-27 15:50:48 +0300
committerJulian Eisel <julian@blender.org>2021-10-27 15:56:57 +0300
commitaae5f15238f73fcac762a1690e052b86fad23be1 (patch)
tree5549df5789c1b586404a2bae575f0043c56d51db /source/blender/editors/space_file/asset_catalog_tree_view.cc
parent1832e11f39a36681533c148de9300b290a8c309c (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/space_file/asset_catalog_tree_view.cc')
-rw-r--r--source/blender/editors/space_file/asset_catalog_tree_view.cc135
1 files changed, 113 insertions, 22 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 53981ca244d..e6b76e05e16 100644
--- a/source/blender/editors/space_file/asset_catalog_tree_view.cc
+++ b/source/blender/editors/space_file/asset_catalog_tree_view.cc
@@ -95,26 +95,44 @@ class AssetCatalogTreeViewItem : public ui::BasicTreeViewItem {
bool can_rename() const override;
bool rename(StringRefNull new_name) override;
+ /** Add drag support for catalog items. */
+ std::unique_ptr<ui::AbstractTreeViewItemDragController> create_drag_controller() const override;
/** Add dropping support for catalog items. */
std::unique_ptr<ui::AbstractTreeViewItemDropController> create_drop_controller() const override;
};
+class AssetCatalogDragController : public ui::AbstractTreeViewItemDragController {
+ AssetCatalogTreeItem &catalog_item_;
+
+ public:
+ explicit AssetCatalogDragController(AssetCatalogTreeItem &catalog_item);
+
+ int get_drag_type() const override;
+ void *create_drag_data() const override;
+};
+
class AssetCatalogDropController : public ui::AbstractTreeViewItemDropController {
AssetCatalogTreeItem &catalog_item_;
public:
- explicit AssetCatalogDropController(AssetCatalogTreeView &tree_view,
- AssetCatalogTreeItem &catalog_item);
+ AssetCatalogDropController(AssetCatalogTreeView &tree_view, AssetCatalogTreeItem &catalog_item);
bool can_drop(const wmDrag &drag, const char **r_disabled_hint) const override;
std::string drop_tooltip(const wmDrag &drag) const override;
bool on_drop(const wmDrag &drag) override;
- static bool has_droppable_item(const wmDrag &drag, const char **r_disabled_hint);
- static bool drop_into_catalog(const AssetCatalogTreeView &tree_view,
- const wmDrag &drag,
- CatalogID catalog_id,
- StringRefNull simple_name = "");
+ ::AssetLibrary &get_asset_library() const;
+
+ static bool has_droppable_asset(const wmDrag &drag, const char **r_disabled_hint);
+ static bool drop_assets_into_catalog(const AssetCatalogTreeView &tree_view,
+ const wmDrag &drag,
+ CatalogID catalog_id,
+ StringRefNull simple_name = "");
+
+ private:
+ bool drop_asset_catalog_into_catalog(const wmDrag &drag);
+ std::string drop_tooltip_asset_list(const wmDrag &drag) const;
+ std::string drop_tooltip_asset_catalog(const wmDrag &drag) const;
};
/** Only reason this isn't just `BasicTreeViewItem` is to add a '+' icon for adding a root level
@@ -308,6 +326,12 @@ std::unique_ptr<ui::AbstractTreeViewItemDropController> AssetCatalogTreeViewItem
static_cast<AssetCatalogTreeView &>(get_tree_view()), catalog_item_);
}
+std::unique_ptr<ui::AbstractTreeViewItemDragController> AssetCatalogTreeViewItem::
+ create_drag_controller() const
+{
+ return std::make_unique<AssetCatalogDragController>(catalog_item_);
+}
+
/* ---------------------------------------------------------------------- */
AssetCatalogDropController::AssetCatalogDropController(AssetCatalogTreeView &tree_view,
@@ -318,14 +342,41 @@ AssetCatalogDropController::AssetCatalogDropController(AssetCatalogTreeView &tre
bool AssetCatalogDropController::can_drop(const wmDrag &drag, const char **r_disabled_hint) const
{
- if (drag.type != WM_DRAG_ASSET_LIST) {
- return false;
+ if (drag.type == WM_DRAG_ASSET_CATALOG) {
+ /* Always supported. */
+ return true;
+ }
+ if (drag.type == WM_DRAG_ASSET_LIST) {
+ return has_droppable_asset(drag, r_disabled_hint);
}
- return has_droppable_item(drag, r_disabled_hint);
+ return false;
}
std::string AssetCatalogDropController::drop_tooltip(const wmDrag &drag) const
{
+ if (drag.type == WM_DRAG_ASSET_CATALOG) {
+ return drop_tooltip_asset_catalog(drag);
+ }
+ return drop_tooltip_asset_list(drag);
+}
+
+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);
+
+ return std::string(TIP_("Move Catalog")) + " '" + src_catalog->path.name() + "' " +
+ IFACE_("into") + " '" + catalog_item_.get_name() + "'";
+}
+
+std::string AssetCatalogDropController::drop_tooltip_asset_list(const wmDrag &drag) const
+{
+ BLI_assert(drag.type == WM_DRAG_ASSET_LIST);
+
const ListBase *asset_drags = WM_drag_asset_list_get(&drag);
const bool is_multiple_assets = !BLI_listbase_is_single(asset_drags);
@@ -340,17 +391,32 @@ std::string AssetCatalogDropController::drop_tooltip(const wmDrag &drag) const
bool AssetCatalogDropController::on_drop(const wmDrag &drag)
{
- return drop_into_catalog(tree_view<AssetCatalogTreeView>(),
- drag,
- catalog_item_.get_catalog_id(),
- catalog_item_.get_simple_name());
+ if (drag.type == WM_DRAG_ASSET_CATALOG) {
+ return drop_asset_catalog_into_catalog(drag);
+ }
+ return drop_assets_into_catalog(tree_view<AssetCatalogTreeView>(),
+ drag,
+ catalog_item_.get_catalog_id(),
+ catalog_item_.get_simple_name());
+}
+
+bool AssetCatalogDropController::drop_asset_catalog_into_catalog(const wmDrag &drag)
+{
+ BLI_assert(drag.type == WM_DRAG_ASSET_CATALOG);
+ wmDragAssetCatalog *catalog_drag = WM_drag_get_asset_catalog_data(&drag);
+ ED_asset_catalog_move(
+ &get_asset_library(), catalog_drag->drag_catalog_id, catalog_item_.get_catalog_id());
+
+ WM_main_add_notifier(NC_ASSET | ND_ASSET_CATALOGS, nullptr);
+ return true;
}
-bool AssetCatalogDropController::drop_into_catalog(const AssetCatalogTreeView &tree_view,
- const wmDrag &drag,
- CatalogID catalog_id,
- StringRefNull simple_name)
+bool AssetCatalogDropController::drop_assets_into_catalog(const AssetCatalogTreeView &tree_view,
+ const wmDrag &drag,
+ CatalogID catalog_id,
+ StringRefNull simple_name)
{
+ BLI_assert(drag.type == WM_DRAG_ASSET_LIST);
const ListBase *asset_drags = WM_drag_asset_list_get(&drag);
if (!asset_drags) {
return false;
@@ -373,8 +439,8 @@ bool AssetCatalogDropController::drop_into_catalog(const AssetCatalogTreeView &t
return true;
}
-bool AssetCatalogDropController::has_droppable_item(const wmDrag &drag,
- const char **r_disabled_hint)
+bool AssetCatalogDropController::has_droppable_asset(const wmDrag &drag,
+ const char **r_disabled_hint)
{
const ListBase *asset_drags = WM_drag_asset_list_get(&drag);
@@ -390,6 +456,31 @@ bool AssetCatalogDropController::has_droppable_item(const wmDrag &drag,
return false;
}
+::AssetLibrary &AssetCatalogDropController::get_asset_library() const
+{
+ return *tree_view<AssetCatalogTreeView>().asset_library_;
+}
+
+/* ---------------------------------------------------------------------- */
+
+AssetCatalogDragController::AssetCatalogDragController(AssetCatalogTreeItem &catalog_item)
+ : catalog_item_(catalog_item)
+{
+}
+
+int AssetCatalogDragController::get_drag_type() const
+{
+ return WM_DRAG_ASSET_CATALOG;
+}
+
+void *AssetCatalogDragController::create_drag_data() const
+{
+ wmDragAssetCatalog *drag_catalog = (wmDragAssetCatalog *)MEM_callocN(sizeof(*drag_catalog),
+ __func__);
+ drag_catalog->drag_catalog_id = catalog_item_.get_catalog_id();
+ return drag_catalog;
+}
+
/* ---------------------------------------------------------------------- */
void AssetCatalogTreeViewAllItem::build_row(uiLayout &row)
@@ -427,7 +518,7 @@ bool AssetCatalogTreeViewUnassignedItem::DropController::can_drop(
if (drag.type != WM_DRAG_ASSET_LIST) {
return false;
}
- return AssetCatalogDropController::has_droppable_item(drag, r_disabled_hint);
+ return AssetCatalogDropController::has_droppable_asset(drag, r_disabled_hint);
}
std::string AssetCatalogTreeViewUnassignedItem::DropController::drop_tooltip(
@@ -443,7 +534,7 @@ std::string AssetCatalogTreeViewUnassignedItem::DropController::drop_tooltip(
bool AssetCatalogTreeViewUnassignedItem::DropController::on_drop(const wmDrag &drag)
{
/* Assign to nil catalog ID. */
- return AssetCatalogDropController::drop_into_catalog(
+ return AssetCatalogDropController::drop_assets_into_catalog(
tree_view<AssetCatalogTreeView>(), drag, CatalogID{});
}