44#include <fmt/format.h>
48using namespace blender::asset_system;
57 std::shared_ptr<const asset_system::AssetCatalogTree> catalog_tree_;
79 void add_unassigned_item();
80 bool is_active_catalog(
CatalogID catalog_id)
const;
114 std::optional<eWM_DragDataType>
get_drag_type()
const override;
125 bool can_drop(
const wmDrag &drag,
const char **r_disabled_hint)
const override;
135 const char **r_disabled_hint);
147 const std::optional<CatalogID> drop_catalog_id = std::nullopt);
150 std::string drop_tooltip_asset_list(
const wmDrag &drag)
const;
151 std::string drop_tooltip_asset_catalog(
const wmDrag &drag)
const;
159 using BasicTreeViewItem::BasicTreeViewItem;
166 bool can_drop(
const wmDrag &drag,
const char **r_disabled_hint)
const override;
167 std::string drop_tooltip(
const ui::DragInfo &drag_info)
const override;
171 std::unique_ptr<ui::TreeViewItemDropTarget> create_drop_target()
override;
175 using BasicTreeViewItem::BasicTreeViewItem;
180 bool can_drop(
const wmDrag &drag,
const char **r_disabled_hint)
const override;
181 std::string drop_tooltip(
const ui::DragInfo &drag_info)
const override;
185 std::unique_ptr<ui::TreeViewItemDropTarget> create_drop_target()
override;
193 : asset_library_(
library), params_(params), space_file_(space_file)
198 std::shared_ptr<asset_system::AssetCatalogService> catalog_service =
199 library->catalog_service_ptr();
200 catalog_tree_ = catalog_service ? catalog_service->catalog_tree() :
nullptr;
203 catalog_tree_ =
nullptr;
215 build_catalog_items_recursive(all_item, item);
222 const bool shows_unassigned_item = params_->asset_catalog_visibility ==
224 if (!is_essentials || shows_unassigned_item) {
225 add_unassigned_item();
235 [
this, &catalog]() {
return is_active_catalog(catalog.
get_catalog_id()); });
238 build_catalog_items_recursive(view_item, child);
243AssetCatalogTreeViewAllItem &AssetCatalogTreeView::add_all_item()
252 item.set_is_active_fn(
257void AssetCatalogTreeView::add_unassigned_item()
259 FileAssetSelectParams *params = params_;
262 IFACE_(
"Unassigned"), ICON_FILE_HIDDEN);
264 item.set_on_activate_fn([params](bContext & , ui::BasicTreeViewItem & ) {
268 item.set_is_active_fn(
275 params_->catalog_id = catalog_id;
279bool AssetCatalogTreeView::is_active_catalog(
CatalogID catalog_id)
const
301 const std::string label_override = catalog_item_.has_unsaved_changes() ? (
"* " +
label_) :
312 props = button_extra_operator_icon_add(
reinterpret_cast<ui::Button *
>(view_item_but),
313 "ASSET_OT_catalog_new",
316 RNA_string_set(props,
"parent_path", catalog_item_.catalog_path().c_str());
323 props = column.
op(
"ASSET_OT_catalog_new",
328 RNA_string_set(&props,
"parent_path", catalog_item_.catalog_path().c_str());
330 props = column.
op(
"ASSET_OT_catalog_delete",
335 RNA_string_set(&props,
"catalog_id", catalog_item_.get_catalog_id().str().c_str());
336 column.
op(
"UI_OT_view_item_rename",
IFACE_(
"Rename"), ICON_NONE);
358 BasicTreeViewItem::rename(
C, new_name);
375 return std::make_unique<AssetCatalogDropTarget>(*
this, catalog_item_);
381 return std::make_unique<AssetCatalogDragController>(
405 if (catalog_item_.catalog_path().is_contained_in(drag_catalog->
path)) {
406 *r_disabled_hint =
RPT_(
"Catalog cannot be dropped into itself");
409 if (catalog_item_.catalog_path() == drag_catalog->
path.
parent()) {
410 *r_disabled_hint =
RPT_(
"Catalog is already placed inside this catalog");
425 return this->drop_tooltip_asset_catalog(drag_info.
drag_data);
427 return this->drop_tooltip_asset_list(drag_info.
drag_data);
430std::string AssetCatalogDropTarget::drop_tooltip_asset_catalog(
const wmDrag &drag)
const
435 return fmt::format(fmt::runtime(
TIP_(
"Move catalog {} into {}")),
440std::string AssetCatalogDropTarget::drop_tooltip_asset_list(
const wmDrag &drag)
const
445 const bool is_multiple_assets = !asset_drags->is_single();
449 std::string basic_tip = is_multiple_assets ?
TIP_(
"Move assets to catalog") :
450 TIP_(
"Move asset to catalog");
452 basic_tip +=
": " + catalog_item_.
get_name();
457 basic_tip +=
" (" + catalog_item_.catalog_path().str() +
")";
468 catalog_item_.get_catalog_id());
473 catalog_item_.get_catalog_id(),
474 catalog_item_.get_simple_name());
480 const std::optional<CatalogID> drop_catalog_id)
507 bool is_local_id_modified =
false;
509 ID *asset_id =
nullptr;
511 if (asset_item.is_external) {
518 *bmain,
asset->get_id_type(), asset_reference);
519 if (asset_id ==
nullptr) {
543 if (asset_item.is_external) {
554 is_local_id_modified =
true;
564 if (is_local_id_modified) {
589 if (!asset_item.is_external) {
592 BLI_assert(asset_item.asset_data.external_info);
593 BLI_assert(asset_item.asset_data.external_info->asset);
594 if (asset_item.asset_data.external_info->asset->is_potentially_editable_asset_blend()) {
599 *r_disabled_hint =
RPT_(
600 "Only assets from the current file or asset system files (.asset.blend) can be moved "
606 const char **r_disabled_hint)
609 *r_disabled_hint =
RPT_(
"Catalogs cannot be edited in this asset library");
648void AssetCatalogTreeViewAllItem::build_row(
ui::Layout &row)
655 "ASSET_OT_catalogs_save",
660 "ASSET_OT_catalog_new",
669 return std::make_unique<AssetCatalogTreeViewAllItem::DropTarget>(*
this);
672AssetCatalogTreeViewAllItem::DropTarget::DropTarget(AssetCatalogTreeViewAllItem &item)
673 :
ui::TreeViewItemDropTarget(item)
677bool AssetCatalogTreeViewAllItem::DropTarget::can_drop(
const wmDrag &drag,
678 const char **r_disabled_hint)
const
690 *r_disabled_hint =
RPT_(
"Catalog is already placed at the highest level");
697std::string AssetCatalogTreeViewAllItem::DropTarget::drop_tooltip(
698 const ui::DragInfo &drag_info)
const
702 drag_info.
drag_data, *this->get_view<AssetCatalogTreeView>().asset_library_);
704 return fmt::format(fmt::runtime(
TIP_(
"Move catalog {} to the top level of the tree")),
708bool AssetCatalogTreeViewAllItem::DropTarget::on_drop(bContext * ,
709 const ui::DragInfo &drag_info)
const
714 this->get_view<AssetCatalogTreeView>(),
724 return std::make_unique<AssetCatalogTreeViewUnassignedItem::DropTarget>(*
this);
727AssetCatalogTreeViewUnassignedItem::DropTarget::DropTarget(
728 AssetCatalogTreeViewUnassignedItem &item)
729 : ui::TreeViewItemDropTarget(item)
733bool AssetCatalogTreeViewUnassignedItem::DropTarget::can_drop(
const wmDrag &drag,
734 const char **r_disabled_hint)
const
742std::string AssetCatalogTreeViewUnassignedItem::DropTarget::drop_tooltip(
743 const ui::DragInfo &drag_info)
const
746 const bool is_multiple_assets = !asset_drags->is_single();
748 return is_multiple_assets ?
TIP_(
"Move assets out of any catalog") :
749 TIP_(
"Move asset out of any catalog");
752bool AssetCatalogTreeViewUnassignedItem::DropTarget::on_drop(bContext *
C,
753 const ui::DragInfo &drag_info)
const
772 return MEM_new<AssetCatalogFilterSettings>(__func__);
777 MEM_delete(*filter_settings);
778 *filter_settings =
nullptr;
784 const bUUID &catalog_id)
786 bool needs_update =
false;
809 filter_settings->
catalog_filter = std::make_unique<AssetCatalogFilter>(
845 "asset catalog tree view",
846 std::make_unique<ed::asset_browser::AssetCatalogTreeView>(
847 asset_library, params, *space_file));
#define ID_IS_LINKED(_id)
#define ND_SPACE_ASSET_PARAMS
#define ND_ASSET_CATALOGS
#define ND_SPACE_FILE_LIST
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
constexpr const char * c_str() const
AssetCatalogPath parent() const
const std::string & str() const
StringRefNull name() const
AssetCatalogFilter create_catalog_filter(CatalogID active_catalog_id) const
AssetCatalog * find_catalog(CatalogID catalog_id) const
void foreach_child(ItemIterFn callback) const
AssetCatalogPath catalog_path() const
CatalogID get_catalog_id() const
StringRefNull get_name() const
AssetCatalogService & catalog_service() const
void * create_drag_data() const override
std::optional< eWM_DragDataType > get_drag_type() const override
void on_drag_start(bContext &C, ui::AbstractViewItem &item) override
AssetCatalogDragController(AssetCatalogTreeView &tree_view, const AssetCatalogTreeItem &catalog_item)
bool can_drop(const wmDrag &drag, const char **r_disabled_hint) const override
static bool drop_asset_catalog_into_catalog(const wmDrag &drag, AssetCatalogTreeView &tree_view, const std::optional< CatalogID > drop_catalog_id=std::nullopt)
static AssetCatalog * get_drag_catalog(const wmDrag &drag, const asset_system::AssetLibrary &asset_library)
static bool has_droppable_asset(const wmDrag &drag, const char **r_disabled_hint)
static bool drop_assets_into_catalog(bContext *C, const AssetCatalogTreeView &tree_view, const wmDrag &drag, CatalogID catalog_id, StringRefNull simple_name="")
std::string drop_tooltip(const ui::DragInfo &drag_info) const override
static bool can_modify_catalogs(const asset_system::AssetLibrary &asset_library, const char **r_disabled_hint)
bool on_drop(bContext *C, const ui::DragInfo &drag_info) const override
AssetCatalogDropTarget(AssetCatalogTreeViewItem &item, const AssetCatalogTreeItem &catalog_item)
asset_system::AssetLibrary & get_asset_library() const
eFileSel_Params_AssetCatalogVisibility asset_catalog_visibility
std::unique_ptr< AssetCatalogFilter > catalog_filter
void on_activate(bContext &C) override
void build_context_menu(bContext &C, ui::Layout &column) const override
AssetCatalogTreeViewItem(const AssetCatalogTreeItem &catalog_item)
bool supports_renaming() const override
void delete_item(bContext *C) override
void build_row(ui::Layout &row) override
bool rename(const bContext &C, StringRefNull new_name) override
std::unique_ptr< ui::AbstractViewItemDragController > create_drag_controller() const override
std::unique_ptr< ui::TreeViewItemDropTarget > create_drop_target() override
friend class AssetCatalogTreeViewAllItem
void build_tree() override
friend class AssetCatalogTreeViewItem
friend class AssetCatalogDropTarget
void activate_catalog_by_id(CatalogID catalog_id)
AssetCatalogTreeView(asset_system::AssetLibrary *library, FileAssetSelectParams *params, SpaceFile &space_file)
AbstractTreeView & get_tree_view() const
virtual std::unique_ptr< TreeViewItemDropTarget > create_drop_target()
void uncollapse_by_default()
ViewType & get_view() const
AbstractViewItemDragController(AbstractView &view)
AbstractView & get_view() const
ui::ButtonViewItem * view_item_button() const
void set_context_menu_title(const std::string &title)
void add_label(Layout &layout, StringRefNull label_override="")
BasicTreeViewItem(StringRef label, BIFIconID icon=ICON_NONE)
void set_is_active_fn(IsActiveFn is_active_fn)
void build_row(Layout &row) override
static void build_tree_view(const bContext &C, AbstractTreeView &tree_view, Layout &layout, bool add_box=true)
ItemT & add_tree_item(Args &&...args)
TreeViewItemDropTarget(AbstractTreeViewItem &view_item, DropBehavior behavior=DropBehavior::Insert)
ViewType & get_view() const
ID * asset_edit_id_from_weak_reference(Main &global_main, ID_Type id_type, const AssetWeakReference &weak_ref)
bool asset_edit_id_save(Main &global_main, ID &id, ReportList &reports)
bool asset_edit_id_is_writable(const ID &id)
bool asset_edit_id_is_editable(const ID &id)
void file_ensure_updated_catalog_filter_data(AssetCatalogFilterSettings *filter_settings, const asset_system::AssetLibrary *asset_library)
bool file_set_asset_catalog_filter_settings(AssetCatalogFilterSettings *filter_settings, eFileSel_Params_AssetCatalogVisibility catalog_visibility, const bUUID &catalog_id)
void file_create_asset_catalog_tree_view_in_layout(const bContext *C, asset_system::AssetLibrary *asset_library, ui::Layout &layout, SpaceFile *space_file, FileAssetSelectParams *params)
AssetCatalogFilterSettings * file_create_asset_catalog_filter_settings()
bool file_is_asset_visible_in_catalog_filter_settings(const AssetCatalogFilterSettings *filter_settings, const AssetMetaData *asset_data)
void file_delete_asset_catalog_filter_settings(AssetCatalogFilterSettings **filter_settings)
void catalog_remove(asset_system::AssetLibrary *library, const asset_system::CatalogID &catalog_id)
bool catalogs_read_only(const asset_system::AssetLibrary &library)
void catalog_move(asset_system::AssetLibrary *library, asset_system::CatalogID src_catalog_id, std::optional< asset_system::CatalogID > dst_parent_catalog_id=std::nullopt)
void catalog_rename(asset_system::AssetLibrary *library, asset_system::CatalogID catalog_id, StringRefNull new_name)
TreeViewItemContainer TreeViewOrItem
void menutype_draw(bContext *C, MenuType *mt, Layout *layout)
void block_layout_set_current(Block *block, Layout *layout)
void WM_main_add_notifier(uint type, void *reference)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
const ListBaseT< wmDragAssetListItem > * WM_drag_asset_list_get(const wmDrag *drag)
void filelist_tag_needs_filtering(FileList *filelist)
bool BLI_uuid_equal(bUUID uuid1, bUUID uuid2)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
MenuType * WM_menutype_find(const StringRef idname, bool quiet)
void BKE_asset_metadata_catalog_id_set(AssetMetaData *asset_data, bUUID catalog_id, const char *catalog_simple_name)
void file_select_deselect_all(SpaceFile *sfile, eDirEntry_SelectFlag flag)
@ ASSET_LIBRARY_ESSENTIALS
wmDragAssetCatalog * WM_drag_get_asset_catalog_data(const wmDrag *drag)
void ED_undo_push(bContext *C, const char *str, UndoEncodeHints hints=UndoEncodeHints(0))
eFileSel_Params_AssetCatalogVisibility
@ FILE_SHOW_ASSETS_FROM_CATALOG
@ FILE_SHOW_ASSETS_WITHOUT_CATALOG
@ FILE_SHOW_ASSETS_ALL_CATALOGS
Main * CTX_data_main(const bContext *C)
ReportList * CTX_wm_reports(const bContext *C)
eFileSel_Params_AssetCatalogVisibility asset_catalog_visibility
struct AssetMetaData * asset_data
Universally Unique Identifier according to RFC4122.
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)