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-04 17:05:14 +0300
committerJulian Eisel <julian@blender.org>2021-10-04 17:17:09 +0300
commit4a3464050c4e83d446d47c946e17b9540f5a3862 (patch)
tree16b9d5574f75f119caf1b04d6757ee12c88844f1
parentb536605e78eec10ad03c0eccd6cfd6b36b9216cf (diff)
Assets: Support dragging assets on "Unassigned" catalog
Dragging assets onto the "Unassigned" catalog tree item will effectively move the assets out of any catalog. Technically this means unsetting the Catalog-ID stored in the asset metadata, or more precisely setting the UUID to be all zeros.
-rw-r--r--source/blender/editors/space_file/asset_catalog_tree_view.cc66
1 files changed, 58 insertions, 8 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 629e06e5e71..883bc6d7890 100644
--- a/source/blender/editors/space_file/asset_catalog_tree_view.cc
+++ b/source/blender/editors/space_file/asset_catalog_tree_view.cc
@@ -85,6 +85,10 @@ class AssetCatalogTreeViewItem : public ui::BasicTreeViewItem {
AssetCatalogTreeViewItem(AssetCatalogTreeItem *catalog_item);
static bool has_droppable_item(const wmDrag &drag);
+ static bool drop_into_catalog(const AssetCatalogTreeView &tree_view,
+ const wmDrag &drag,
+ CatalogID catalog_id,
+ StringRefNull simple_name = "");
void on_activate() override;
@@ -105,6 +109,16 @@ class AssetCatalogTreeViewAllItem : public ui::BasicTreeViewItem {
void build_row(uiLayout &row) override;
};
+class AssetCatalogTreeViewUnassignedItem : public ui::BasicTreeViewItem {
+ using BasicTreeViewItem::BasicTreeViewItem;
+
+ bool can_drop(const wmDrag &drag) const override;
+ std::string drop_tooltip(const bContext &C,
+ const wmDrag &drag,
+ const wmEvent &event) const override;
+ bool on_drop(const wmDrag &drag) override;
+};
+
/* ---------------------------------------------------------------------- */
AssetCatalogTreeView::AssetCatalogTreeView(::AssetLibrary *library,
@@ -165,7 +179,7 @@ void AssetCatalogTreeView::add_unassigned_item()
{
FileAssetSelectParams *params = params_;
- ui::AbstractTreeViewItem &item = add_tree_item<ui::BasicTreeViewItem>(
+ AssetCatalogTreeViewUnassignedItem &item = add_tree_item<AssetCatalogTreeViewUnassignedItem>(
IFACE_("Unassigned"), ICON_FILE_HIDDEN, [params](ui::BasicTreeViewItem & /*item*/) {
params->asset_catalog_visibility = FILE_SHOW_ASSETS_WITHOUT_CATALOG;
WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr);
@@ -262,24 +276,23 @@ std::string AssetCatalogTreeViewItem::drop_tooltip(const bContext & /*C*/,
")";
}
-bool AssetCatalogTreeViewItem::on_drop(const wmDrag &drag)
+bool AssetCatalogTreeViewItem::drop_into_catalog(const AssetCatalogTreeView &tree_view,
+ const wmDrag &drag,
+ CatalogID catalog_id,
+ StringRefNull simple_name)
{
const ListBase *asset_drags = WM_drag_asset_list_get(&drag);
if (!asset_drags) {
return false;
}
- const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>(
- get_tree_view());
-
LISTBASE_FOREACH (wmDragAssetListItem *, asset_item, asset_drags) {
if (asset_item->is_external) {
/* Only internal assets can be modified! */
continue;
}
- BKE_asset_metadata_catalog_id_set(asset_item->asset_data.local_id->asset_data,
- catalog_item_.get_catalog_id(),
- catalog_item_.get_simple_name().c_str());
+ BKE_asset_metadata_catalog_id_set(
+ asset_item->asset_data.local_id->asset_data, catalog_id, simple_name.c_str());
/* Trigger re-run of filtering to update visible assets. */
filelist_tag_needs_filtering(tree_view.space_file_.files);
@@ -289,6 +302,14 @@ bool AssetCatalogTreeViewItem::on_drop(const wmDrag &drag)
return true;
}
+bool AssetCatalogTreeViewItem::on_drop(const wmDrag &drag)
+{
+ const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>(
+ get_tree_view());
+ return drop_into_catalog(
+ tree_view, drag, catalog_item_.get_catalog_id(), catalog_item_.get_simple_name());
+}
+
/* ---------------------------------------------------------------------- */
void AssetCatalogTreeViewAllItem::build_row(uiLayout &row)
@@ -306,6 +327,35 @@ void AssetCatalogTreeViewAllItem::build_row(uiLayout &row)
RNA_string_set(props, "parent_path", nullptr);
}
+/* ---------------------------------------------------------------------- */
+
+bool AssetCatalogTreeViewUnassignedItem::can_drop(const wmDrag &drag) const
+{
+ if (drag.type != WM_DRAG_ASSET_LIST) {
+ return false;
+ }
+ return AssetCatalogTreeViewItem::has_droppable_item(drag);
+}
+
+std::string AssetCatalogTreeViewUnassignedItem::drop_tooltip(const bContext & /*C*/,
+ const wmDrag &drag,
+ const wmEvent & /*event*/) const
+{
+ const ListBase *asset_drags = WM_drag_asset_list_get(&drag);
+ const bool is_multiple_assets = !BLI_listbase_is_single(asset_drags);
+
+ return is_multiple_assets ? TIP_("Move assets out of any catalog") :
+ TIP_("Move asset out of any catalog");
+}
+
+bool AssetCatalogTreeViewUnassignedItem::on_drop(const wmDrag &drag)
+{
+ const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>(
+ get_tree_view());
+ /* Assign to nil catalog ID. */
+ return AssetCatalogTreeViewItem::drop_into_catalog(tree_view, drag, CatalogID{});
+}
+
} // namespace blender::ed::asset_browser
/* ---------------------------------------------------------------------- */