Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_file/asset_catalog_tree_view.cc
| Show All 27 Lines | |||||
| #include "BKE_asset_library.hh" | #include "BKE_asset_library.hh" | ||||
| #include "BLI_string_ref.hh" | #include "BLI_string_ref.hh" | ||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "ED_asset.h" | #include "ED_asset.h" | ||||
| #include "ED_fileselect.h" | #include "ED_fileselect.h" | ||||
| #include "ED_undo.h" | |||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_interface.hh" | #include "UI_interface.hh" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "UI_tree_view.hh" | #include "UI_tree_view.hh" | ||||
| ▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | |||||
| class AssetCatalogDropController : public ui::AbstractTreeViewItemDropController { | class AssetCatalogDropController : public ui::AbstractTreeViewItemDropController { | ||||
| AssetCatalogTreeItem &catalog_item_; | AssetCatalogTreeItem &catalog_item_; | ||||
| public: | public: | ||||
| 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; | bool can_drop(const wmDrag &drag, const char **r_disabled_hint) const override; | ||||
| std::string drop_tooltip(const wmDrag &drag) const override; | std::string drop_tooltip(const wmDrag &drag) const override; | ||||
| bool on_drop(const wmDrag &drag) override; | bool on_drop(struct bContext *C, const wmDrag &drag) override; | ||||
| ::AssetLibrary &get_asset_library() const; | ::AssetLibrary &get_asset_library() const; | ||||
| static AssetCatalog *get_drag_catalog(const wmDrag &drag, const ::AssetLibrary &asset_library); | static AssetCatalog *get_drag_catalog(const wmDrag &drag, const ::AssetLibrary &asset_library); | ||||
| static bool has_droppable_asset(const wmDrag &drag, const char **r_disabled_hint); | static bool has_droppable_asset(const wmDrag &drag, const char **r_disabled_hint); | ||||
| static bool drop_assets_into_catalog(const AssetCatalogTreeView &tree_view, | static bool drop_assets_into_catalog(struct bContext *C, | ||||
| const AssetCatalogTreeView &tree_view, | |||||
| const wmDrag &drag, | const wmDrag &drag, | ||||
| CatalogID catalog_id, | CatalogID catalog_id, | ||||
| StringRefNull simple_name = ""); | StringRefNull simple_name = ""); | ||||
| /** | /** | ||||
| * \param drop_catalog_id: Can be unset to drop into the root level of the tree. | * \param drop_catalog_id: Can be unset to drop into the root level of the tree. | ||||
| */ | */ | ||||
| static bool drop_asset_catalog_into_catalog( | static bool drop_asset_catalog_into_catalog( | ||||
| const wmDrag &drag, | const wmDrag &drag, | ||||
| Show All 12 Lines | class AssetCatalogTreeViewAllItem : public ui::BasicTreeViewItem { | ||||
| void build_row(uiLayout &row) override; | void build_row(uiLayout &row) override; | ||||
| struct DropController : public ui::AbstractTreeViewItemDropController { | struct DropController : public ui::AbstractTreeViewItemDropController { | ||||
| DropController(AssetCatalogTreeView &tree_view); | DropController(AssetCatalogTreeView &tree_view); | ||||
| bool can_drop(const wmDrag &drag, const char **r_disabled_hint) const override; | bool can_drop(const wmDrag &drag, const char **r_disabled_hint) const override; | ||||
| std::string drop_tooltip(const wmDrag &drag) const override; | std::string drop_tooltip(const wmDrag &drag) const override; | ||||
| bool on_drop(const wmDrag &drag) override; | bool on_drop(struct bContext *C, const wmDrag &drag) override; | ||||
| }; | }; | ||||
| std::unique_ptr<ui::AbstractTreeViewItemDropController> create_drop_controller() const override; | std::unique_ptr<ui::AbstractTreeViewItemDropController> create_drop_controller() const override; | ||||
| }; | }; | ||||
| class AssetCatalogTreeViewUnassignedItem : public ui::BasicTreeViewItem { | class AssetCatalogTreeViewUnassignedItem : public ui::BasicTreeViewItem { | ||||
| using BasicTreeViewItem::BasicTreeViewItem; | using BasicTreeViewItem::BasicTreeViewItem; | ||||
| struct DropController : public ui::AbstractTreeViewItemDropController { | struct DropController : public ui::AbstractTreeViewItemDropController { | ||||
| DropController(AssetCatalogTreeView &tree_view); | DropController(AssetCatalogTreeView &tree_view); | ||||
| bool can_drop(const wmDrag &drag, const char **r_disabled_hint) const override; | bool can_drop(const wmDrag &drag, const char **r_disabled_hint) const override; | ||||
| std::string drop_tooltip(const wmDrag &drag) const override; | std::string drop_tooltip(const wmDrag &drag) const override; | ||||
| bool on_drop(const wmDrag &drag) override; | bool on_drop(struct bContext *C, const wmDrag &drag) override; | ||||
| }; | }; | ||||
| std::unique_ptr<ui::AbstractTreeViewItemDropController> create_drop_controller() const override; | std::unique_ptr<ui::AbstractTreeViewItemDropController> create_drop_controller() const override; | ||||
| }; | }; | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| AssetCatalogTreeView::AssetCatalogTreeView(::AssetLibrary *library, | AssetCatalogTreeView::AssetCatalogTreeView(::AssetLibrary *library, | ||||
| ▲ Show 20 Lines • Show All 233 Lines • ▼ Show 20 Lines | std::string AssetCatalogDropController::drop_tooltip_asset_list(const wmDrag &drag) const | ||||
| * harder, so use full literals. */ | * harder, so use full literals. */ | ||||
| std::string basic_tip = is_multiple_assets ? TIP_("Move assets to catalog") : | std::string basic_tip = is_multiple_assets ? TIP_("Move assets to catalog") : | ||||
| TIP_("Move asset to catalog"); | TIP_("Move asset to catalog"); | ||||
| return basic_tip + ": " + catalog_item_.get_name() + " (" + catalog_item_.catalog_path().str() + | return basic_tip + ": " + catalog_item_.get_name() + " (" + catalog_item_.catalog_path().str() + | ||||
| ")"; | ")"; | ||||
| } | } | ||||
| bool AssetCatalogDropController::on_drop(const wmDrag &drag) | bool AssetCatalogDropController::on_drop(struct bContext *C, const wmDrag &drag) | ||||
| { | { | ||||
| if (drag.type == WM_DRAG_ASSET_CATALOG) { | if (drag.type == WM_DRAG_ASSET_CATALOG) { | ||||
| return drop_asset_catalog_into_catalog( | return drop_asset_catalog_into_catalog( | ||||
| drag, tree_view<AssetCatalogTreeView>(), catalog_item_.get_catalog_id()); | drag, tree_view<AssetCatalogTreeView>(), catalog_item_.get_catalog_id()); | ||||
| } | } | ||||
| return drop_assets_into_catalog(tree_view<AssetCatalogTreeView>(), | return drop_assets_into_catalog(C, | ||||
| tree_view<AssetCatalogTreeView>(), | |||||
| drag, | drag, | ||||
| catalog_item_.get_catalog_id(), | catalog_item_.get_catalog_id(), | ||||
| catalog_item_.get_simple_name()); | catalog_item_.get_simple_name()); | ||||
| } | } | ||||
| bool AssetCatalogDropController::drop_asset_catalog_into_catalog( | bool AssetCatalogDropController::drop_asset_catalog_into_catalog( | ||||
| const wmDrag &drag, | const wmDrag &drag, | ||||
| AssetCatalogTreeView &tree_view, | AssetCatalogTreeView &tree_view, | ||||
| const std::optional<CatalogID> drop_catalog_id) | const std::optional<CatalogID> drop_catalog_id) | ||||
| { | { | ||||
| BLI_assert(drag.type == WM_DRAG_ASSET_CATALOG); | BLI_assert(drag.type == WM_DRAG_ASSET_CATALOG); | ||||
| wmDragAssetCatalog *catalog_drag = WM_drag_get_asset_catalog_data(&drag); | wmDragAssetCatalog *catalog_drag = WM_drag_get_asset_catalog_data(&drag); | ||||
| ED_asset_catalog_move(tree_view.asset_library_, catalog_drag->drag_catalog_id, drop_catalog_id); | ED_asset_catalog_move(tree_view.asset_library_, catalog_drag->drag_catalog_id, drop_catalog_id); | ||||
| tree_view.activate_catalog_by_id(catalog_drag->drag_catalog_id); | tree_view.activate_catalog_by_id(catalog_drag->drag_catalog_id); | ||||
| WM_main_add_notifier(NC_ASSET | ND_ASSET_CATALOGS, nullptr); | WM_main_add_notifier(NC_ASSET | ND_ASSET_CATALOGS, nullptr); | ||||
| return true; | return true; | ||||
| } | } | ||||
| bool AssetCatalogDropController::drop_assets_into_catalog(const AssetCatalogTreeView &tree_view, | bool AssetCatalogDropController::drop_assets_into_catalog(struct bContext *C, | ||||
| const AssetCatalogTreeView &tree_view, | |||||
| const wmDrag &drag, | const wmDrag &drag, | ||||
| CatalogID catalog_id, | CatalogID catalog_id, | ||||
| StringRefNull simple_name) | StringRefNull simple_name) | ||||
| { | { | ||||
| BLI_assert(drag.type == WM_DRAG_ASSET_LIST); | BLI_assert(drag.type == WM_DRAG_ASSET_LIST); | ||||
| const ListBase *asset_drags = WM_drag_asset_list_get(&drag); | const ListBase *asset_drags = WM_drag_asset_list_get(&drag); | ||||
| if (!asset_drags) { | if (!asset_drags) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| bool did_update = false; | |||||
| LISTBASE_FOREACH (wmDragAssetListItem *, asset_item, asset_drags) { | LISTBASE_FOREACH (wmDragAssetListItem *, asset_item, asset_drags) { | ||||
| if (asset_item->is_external) { | if (asset_item->is_external) { | ||||
| /* Only internal assets can be modified! */ | /* Only internal assets can be modified! */ | ||||
| continue; | continue; | ||||
| } | } | ||||
| did_update = true; | |||||
| BKE_asset_metadata_catalog_id_set( | BKE_asset_metadata_catalog_id_set( | ||||
| asset_item->asset_data.local_id->asset_data, catalog_id, simple_name.c_str()); | asset_item->asset_data.local_id->asset_data, catalog_id, simple_name.c_str()); | ||||
| /* Trigger re-run of filtering to update visible assets. */ | /* Trigger re-run of filtering to update visible assets. */ | ||||
| filelist_tag_needs_filtering(tree_view.space_file_.files); | filelist_tag_needs_filtering(tree_view.space_file_.files); | ||||
| file_select_deselect_all(&tree_view.space_file_, FILE_SEL_SELECTED | FILE_SEL_HIGHLIGHTED); | file_select_deselect_all(&tree_view.space_file_, FILE_SEL_SELECTED | FILE_SEL_HIGHLIGHTED); | ||||
| WM_main_add_notifier(NC_SPACE | ND_SPACE_FILE_LIST, nullptr); | WM_main_add_notifier(NC_SPACE | ND_SPACE_FILE_LIST, nullptr); | ||||
| } | } | ||||
| if (did_update) { | |||||
| ED_undo_push(C, "Assign Asset Catalog"); | |||||
| } | |||||
| return true; | return true; | ||||
| } | } | ||||
| AssetCatalog *AssetCatalogDropController::get_drag_catalog(const wmDrag &drag, | AssetCatalog *AssetCatalogDropController::get_drag_catalog(const wmDrag &drag, | ||||
| const ::AssetLibrary &asset_library) | const ::AssetLibrary &asset_library) | ||||
| { | { | ||||
| if (drag.type != WM_DRAG_ASSET_CATALOG) { | if (drag.type != WM_DRAG_ASSET_CATALOG) { | ||||
| return nullptr; | return nullptr; | ||||
| ▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | std::string AssetCatalogTreeViewAllItem::DropController::drop_tooltip(const wmDrag &drag) const | ||||
| BLI_assert(drag.type == WM_DRAG_ASSET_CATALOG); | BLI_assert(drag.type == WM_DRAG_ASSET_CATALOG); | ||||
| const AssetCatalog *drag_catalog = AssetCatalogDropController::get_drag_catalog( | const AssetCatalog *drag_catalog = AssetCatalogDropController::get_drag_catalog( | ||||
| drag, *tree_view<AssetCatalogTreeView>().asset_library_); | drag, *tree_view<AssetCatalogTreeView>().asset_library_); | ||||
| return std::string(TIP_("Move Catalog")) + " '" + drag_catalog->path.name() + "' " + | return std::string(TIP_("Move Catalog")) + " '" + drag_catalog->path.name() + "' " + | ||||
| TIP_("to the top level of the tree"); | TIP_("to the top level of the tree"); | ||||
| } | } | ||||
| bool AssetCatalogTreeViewAllItem::DropController::on_drop(const wmDrag &drag) | bool AssetCatalogTreeViewAllItem::DropController::on_drop(struct bContext *, const wmDrag &drag) | ||||
| { | { | ||||
| BLI_assert(drag.type == WM_DRAG_ASSET_CATALOG); | BLI_assert(drag.type == WM_DRAG_ASSET_CATALOG); | ||||
| return AssetCatalogDropController::drop_asset_catalog_into_catalog( | return AssetCatalogDropController::drop_asset_catalog_into_catalog( | ||||
| drag, | drag, | ||||
| tree_view<AssetCatalogTreeView>(), | tree_view<AssetCatalogTreeView>(), | ||||
| /* No value to drop into the root level. */ | /* No value to drop into the root level. */ | ||||
| std::nullopt); | std::nullopt); | ||||
| } | } | ||||
| Show All 26 Lines | |||||
| { | { | ||||
| const ListBase *asset_drags = WM_drag_asset_list_get(&drag); | const ListBase *asset_drags = WM_drag_asset_list_get(&drag); | ||||
| const bool is_multiple_assets = !BLI_listbase_is_single(asset_drags); | const bool is_multiple_assets = !BLI_listbase_is_single(asset_drags); | ||||
| return is_multiple_assets ? TIP_("Move assets out of any catalog") : | return is_multiple_assets ? TIP_("Move assets out of any catalog") : | ||||
| TIP_("Move asset out of any catalog"); | TIP_("Move asset out of any catalog"); | ||||
| } | } | ||||
| bool AssetCatalogTreeViewUnassignedItem::DropController::on_drop(const wmDrag &drag) | bool AssetCatalogTreeViewUnassignedItem::DropController::on_drop(struct bContext *C, | ||||
| const wmDrag &drag) | |||||
| { | { | ||||
| /* Assign to nil catalog ID. */ | /* Assign to nil catalog ID. */ | ||||
| return AssetCatalogDropController::drop_assets_into_catalog( | return AssetCatalogDropController::drop_assets_into_catalog( | ||||
| tree_view<AssetCatalogTreeView>(), drag, CatalogID{}); | C, tree_view<AssetCatalogTreeView>(), drag, CatalogID{}); | ||||
| } | } | ||||
| } // namespace blender::ed::asset_browser | } // namespace blender::ed::asset_browser | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| namespace blender::ed::asset_browser { | namespace blender::ed::asset_browser { | ||||
| ▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines | |||||