Brush Assets: Add catalog option to asset pushing operator #118382
|
@ -651,7 +651,7 @@ void AssetCatalogService::undo()
|
|||
|
||||
redo_snapshots_.append(std::move(catalog_collection_));
|
||||
catalog_collection_ = undo_snapshots_.pop_last();
|
||||
rebuild_tree();
|
||||
this->rebuild_tree();
|
||||
AssetLibraryService::get()->rebuild_all_library();
|
||||
}
|
||||
|
||||
|
@ -681,8 +681,8 @@ std::unique_ptr<AssetCatalogCollection> AssetCatalogCollection::deep_copy() cons
|
|||
auto copy = std::make_unique<AssetCatalogCollection>();
|
||||
|
||||
copy->has_unsaved_changes_ = this->has_unsaved_changes_;
|
||||
copy->catalogs_ = copy_catalog_map(this->catalogs_);
|
||||
copy->deleted_catalogs_ = copy_catalog_map(this->deleted_catalogs_);
|
||||
copy->catalogs_ = this->copy_catalog_map(this->catalogs_);
|
||||
copy->deleted_catalogs_ = this->copy_catalog_map(this->deleted_catalogs_);
|
||||
|
||||
if (catalog_definition_file_) {
|
||||
copy->catalog_definition_file_ = catalog_definition_file_->copy_and_remap(
|
||||
|
|
|
@ -129,7 +129,8 @@ AssetCatalogPath AssetCatalogPath::cleanup() const
|
|||
|
||||
std::string AssetCatalogPath::cleanup_component(StringRef component)
|
||||
{
|
||||
std::string cleaned = component.trim();
|
||||
// std::string cleaned = component.trim();
|
||||
std::string cleaned = component;
|
||||
/* Replace colons with something else, as those are used in the CDF file as delimiter. */
|
||||
std::replace(cleaned.begin(), cleaned.end(), ':', '-');
|
||||
return cleaned;
|
||||
|
|
|
@ -303,10 +303,12 @@ TEST(string_ref, TrimWhitespace)
|
|||
StringRef ref2(" test ");
|
||||
StringRef ref3(" \t Urož with spaces ");
|
||||
StringRef ref4(" \t \n\r \t ");
|
||||
StringRef ref5("my/asset/is/best");
|
||||
EXPECT_EQ(ref1.trim(), "test");
|
||||
EXPECT_EQ(ref2.trim(), "test");
|
||||
EXPECT_EQ(ref3.trim(), "Urož with spaces");
|
||||
EXPECT_EQ(ref4.trim(), "");
|
||||
EXPECT_EQ(ref5.trim(), "my/asset/is/best");
|
||||
}
|
||||
|
||||
TEST(string_ref, TrimCharacter)
|
||||
|
|
|
@ -1129,6 +1129,8 @@ static bool brush_asset_write_in_library(Main *bmain,
|
|||
Brush *brush,
|
||||
const char *name,
|
||||
const StringRefNull filepath,
|
||||
const std::optional<asset_system::CatalogID> catalog,
|
||||
const std::optional<StringRefNull> catalog_simple_name,
|
||||
std::string &final_full_file_path,
|
||||
ReportList *reports)
|
||||
{
|
||||
|
@ -1171,6 +1173,13 @@ static bool brush_asset_write_in_library(Main *bmain,
|
|||
}
|
||||
brush->id.override_library = nullptr;
|
||||
|
||||
if (catalog) {
|
||||
brush->id.asset_data->catalog_id = *catalog;
|
||||
}
|
||||
if (catalog_simple_name) {
|
||||
STRNCPY(brush->id.asset_data->catalog_simple_name, catalog_simple_name->c_str());
|
||||
}
|
||||
|
||||
BKE_blendfile_write_partial_tag_ID(&brush->id, true);
|
||||
|
||||
/* TODO: check overwriting existing file. */
|
||||
|
@ -1301,24 +1310,32 @@ static int brush_asset_save_as_exec(bContext *C, wmOperator *op)
|
|||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
char catalog_path[MAX_NAME];
|
||||
RNA_string_get(op->ptr, "catalog_path", catalog_path);
|
||||
const asset_system::AssetCatalog &catalog = asset_library_ensure_catalog(*library, catalog_path);
|
||||
library->catalog_service->write_to_disk(filepath);
|
||||
|
||||
/* Turn brush into asset if it isn't yet. */
|
||||
if (!BKE_paint_brush_is_valid_asset(brush)) {
|
||||
asset::mark_id(&brush->id);
|
||||
brush->id.asset_data->catalog_id = catalog.catalog_id;
|
||||
STRNCPY(brush->id.asset_data->catalog_simple_name, catalog.simple_name.c_str());
|
||||
asset::generate_preview(C, &brush->id);
|
||||
}
|
||||
BLI_assert(BKE_paint_brush_is_valid_asset(brush));
|
||||
|
||||
/* Add asset to catalog. */
|
||||
char catalog_path[MAX_NAME];
|
||||
RNA_string_get(op->ptr, "catalog_path", catalog_path);
|
||||
const asset_system::AssetCatalog &catalog = asset_library_ensure_catalog(*library, catalog_path);
|
||||
const asset_system::CatalogID catalog_id = catalog.catalog_id;
|
||||
const std::string catalog_simple_name = catalog.simple_name;
|
||||
|
||||
library->catalog_service->write_to_disk(filepath);
|
||||
|
||||
/* Save to asset library. */
|
||||
std::string final_full_asset_filepath;
|
||||
|
||||
const bool sucess = brush_asset_write_in_library(
|
||||
CTX_data_main(C), brush, name, filepath, final_full_asset_filepath, op->reports);
|
||||
const bool sucess = brush_asset_write_in_library(CTX_data_main(C),
|
||||
brush,
|
||||
name,
|
||||
filepath,
|
||||
catalog_id,
|
||||
catalog_simple_name,
|
||||
final_full_asset_filepath,
|
||||
op->reports);
|
||||
|
||||
if (!sucess) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Failed to write to asset library");
|
||||
|
@ -1388,6 +1405,9 @@ static void visit_asset_catalog_for_search_fn(
|
|||
if (!user_library) {
|
||||
return;
|
||||
}
|
||||
|
||||
// asset_system::AssetLibrary *library = asset::list::library_get_once_available(
|
||||
// user_library_to_library_ref(*user_library));
|
||||
asset_system::AssetLibrary *library = AS_asset_library_load(
|
||||
CTX_data_main(C), user_library_to_library_ref(*user_library));
|
||||
if (!library) {
|
||||
|
@ -1395,10 +1415,10 @@ static void visit_asset_catalog_for_search_fn(
|
|||
}
|
||||
|
||||
asset_system::AssetCatalogTree &full_tree = *library->catalog_service->get_catalog_tree();
|
||||
full_tree.foreach_root_item([&](const asset_system::AssetCatalogTreeItem &item) {
|
||||
StringPropertySearchVisitParams visit_params{};
|
||||
visit_params.text = item.catalog_path();
|
||||
visit_fn(visit_params);
|
||||
full_tree.foreach_item([&](const asset_system::AssetCatalogTreeItem &item) {
|
||||
// StringPropertySearchVisitParams visit_params{};
|
||||
// visit_params.text = item.catalog_path();
|
||||
visit_fn(StringPropertySearchVisitParams{item.catalog_path().str(), std::nullopt});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1531,6 +1551,8 @@ static int brush_asset_update_exec(bContext *C, wmOperator *op)
|
|||
brush,
|
||||
brush->id.name + 2,
|
||||
filepath,
|
||||
std::nullopt,
|
||||
std::nullopt,
|
||||
final_full_asset_filepath,
|
||||
op->reports);
|
||||
|
||||
|
|
|
@ -278,7 +278,7 @@ void AssetCatalogTreeViewItem::on_activate(bContext & /*C*/)
|
|||
void AssetCatalogTreeViewItem::build_row(uiLayout &row)
|
||||
{
|
||||
const std::string label_override = catalog_item_.has_unsaved_changes() ? (label_ + "*") : label_;
|
||||
add_label(row, label_override);
|
||||
this->add_label(row, label_override);
|
||||
|
||||
if (!is_hovered()) {
|
||||
return;
|
||||
|
@ -332,7 +332,7 @@ void AssetCatalogTreeViewItem::build_context_menu(bContext &C, uiLayout &column)
|
|||
bool AssetCatalogTreeViewItem::supports_renaming() const
|
||||
{
|
||||
const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>(
|
||||
get_tree_view());
|
||||
this->get_tree_view());
|
||||
return !asset::catalogs_read_only(*tree_view.asset_library_);
|
||||
}
|
||||
|
||||
|
@ -342,7 +342,7 @@ bool AssetCatalogTreeViewItem::rename(const bContext &C, StringRefNull new_name)
|
|||
BasicTreeViewItem::rename(C, new_name);
|
||||
|
||||
const AssetCatalogTreeView &tree_view = static_cast<const AssetCatalogTreeView &>(
|
||||
get_tree_view());
|
||||
this->get_tree_view());
|
||||
asset::catalog_rename(tree_view.asset_library_, catalog_item_.get_catalog_id(), new_name);
|
||||
return true;
|
||||
}
|
||||
|
@ -356,7 +356,7 @@ std::unique_ptr<ui::AbstractViewItemDragController> AssetCatalogTreeViewItem::
|
|||
create_drag_controller() const
|
||||
{
|
||||
return std::make_unique<AssetCatalogDragController>(
|
||||
static_cast<AssetCatalogTreeView &>(get_tree_view()), catalog_item_);
|
||||
static_cast<AssetCatalogTreeView &>(this->get_tree_view()), catalog_item_);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
@ -371,11 +371,11 @@ bool AssetCatalogDropTarget::can_drop(const wmDrag &drag, const char **r_disable
|
|||
{
|
||||
if (drag.type == WM_DRAG_ASSET_CATALOG) {
|
||||
const asset_system::AssetLibrary &library = get_asset_library();
|
||||
if (!can_modify_catalogs(library, r_disabled_hint)) {
|
||||
if (!this->can_modify_catalogs(library, r_disabled_hint)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const AssetCatalog *drag_catalog = get_drag_catalog(drag, library);
|
||||
const AssetCatalog *drag_catalog = this->get_drag_catalog(drag, library);
|
||||
/* NOTE: Technically it's not an issue to allow this (the catalog will just receive a new
|
||||
* path and the catalog system will generate missing parents from the path). But it does
|
||||
* appear broken to users, so disabling entirely. */
|
||||
|
@ -399,15 +399,15 @@ bool AssetCatalogDropTarget::can_drop(const wmDrag &drag, const char **r_disable
|
|||
std::string AssetCatalogDropTarget::drop_tooltip(const ui::DragInfo &drag_info) const
|
||||
{
|
||||
if (drag_info.drag_data.type == WM_DRAG_ASSET_CATALOG) {
|
||||
return drop_tooltip_asset_catalog(drag_info.drag_data);
|
||||
return this->drop_tooltip_asset_catalog(drag_info.drag_data);
|
||||
}
|
||||
return drop_tooltip_asset_list(drag_info.drag_data);
|
||||
return this->drop_tooltip_asset_list(drag_info.drag_data);
|
||||
}
|
||||
|
||||
std::string AssetCatalogDropTarget::drop_tooltip_asset_catalog(const wmDrag &drag) const
|
||||
{
|
||||
BLI_assert(drag.type == WM_DRAG_ASSET_CATALOG);
|
||||
const AssetCatalog *src_catalog = get_drag_catalog(drag, get_asset_library());
|
||||
const AssetCatalog *src_catalog = this->get_drag_catalog(drag, get_asset_library());
|
||||
|
||||
return fmt::format(
|
||||
TIP_("Move catalog {} into {}"), src_catalog->path.name(), catalog_item_.get_name());
|
||||
|
@ -439,14 +439,14 @@ std::string AssetCatalogDropTarget::drop_tooltip_asset_list(const wmDrag &drag)
|
|||
bool AssetCatalogDropTarget::on_drop(bContext *C, const ui::DragInfo &drag) const
|
||||
{
|
||||
if (drag.drag_data.type == WM_DRAG_ASSET_CATALOG) {
|
||||
return drop_asset_catalog_into_catalog(
|
||||
drag.drag_data, get_view<AssetCatalogTreeView>(), catalog_item_.get_catalog_id());
|
||||
return this->drop_asset_catalog_into_catalog(
|
||||
drag.drag_data, this->get_view<AssetCatalogTreeView>(), catalog_item_.get_catalog_id());
|
||||
}
|
||||
return drop_assets_into_catalog(C,
|
||||
get_view<AssetCatalogTreeView>(),
|
||||
drag.drag_data,
|
||||
catalog_item_.get_catalog_id(),
|
||||
catalog_item_.get_simple_name());
|
||||
return this->drop_assets_into_catalog(C,
|
||||
this->get_view<AssetCatalogTreeView>(),
|
||||
drag.drag_data,
|
||||
catalog_item_.get_catalog_id(),
|
||||
catalog_item_.get_simple_name());
|
||||
}
|
||||
|
||||
bool AssetCatalogDropTarget::drop_asset_catalog_into_catalog(
|
||||
|
@ -539,7 +539,7 @@ bool AssetCatalogDropTarget::can_modify_catalogs(const asset_system::AssetLibrar
|
|||
|
||||
asset_system::AssetLibrary &AssetCatalogDropTarget::get_asset_library() const
|
||||
{
|
||||
return *get_view<AssetCatalogTreeView>().asset_library_;
|
||||
return *this->get_view<AssetCatalogTreeView>().asset_library_;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
@ -565,7 +565,7 @@ void *AssetCatalogDragController::create_drag_data() const
|
|||
|
||||
void AssetCatalogDragController::on_drag_start()
|
||||
{
|
||||
AssetCatalogTreeView &tree_view_ = get_view<AssetCatalogTreeView>();
|
||||
AssetCatalogTreeView &tree_view_ = this->get_view<AssetCatalogTreeView>();
|
||||
tree_view_.activate_catalog_by_id(catalog_item_.get_catalog_id());
|
||||
}
|
||||
|
||||
|
@ -577,11 +577,13 @@ void AssetCatalogTreeViewAllItem::build_row(uiLayout &row)
|
|||
|
||||
PointerRNA *props;
|
||||
|
||||
UI_but_extra_operator_icon_add(
|
||||
(uiBut *)view_item_button(), "ASSET_OT_catalogs_save", WM_OP_INVOKE_DEFAULT, ICON_FILE_TICK);
|
||||
UI_but_extra_operator_icon_add((uiBut *)this->view_item_button(),
|
||||
"ASSET_OT_catalogs_save",
|
||||
WM_OP_INVOKE_DEFAULT,
|
||||
ICON_FILE_TICK);
|
||||
|
||||
props = UI_but_extra_operator_icon_add(
|
||||
(uiBut *)view_item_button(), "ASSET_OT_catalog_new", WM_OP_INVOKE_DEFAULT, ICON_ADD);
|
||||
(uiBut *)this->view_item_button(), "ASSET_OT_catalog_new", WM_OP_INVOKE_DEFAULT, ICON_ADD);
|
||||
/* No parent path to use the root level. */
|
||||
RNA_string_set(props, "parent_path", nullptr);
|
||||
}
|
||||
|
@ -602,7 +604,7 @@ bool AssetCatalogTreeViewAllItem::DropTarget::can_drop(const wmDrag &drag,
|
|||
if (drag.type != WM_DRAG_ASSET_CATALOG) {
|
||||
return false;
|
||||
}
|
||||
asset_system::AssetLibrary &library = *get_view<AssetCatalogTreeView>().asset_library_;
|
||||
asset_system::AssetLibrary &library = *this->get_view<AssetCatalogTreeView>().asset_library_;
|
||||
if (!AssetCatalogDropTarget::can_modify_catalogs(library, r_disabled_hint)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -621,7 +623,7 @@ std::string AssetCatalogTreeViewAllItem::DropTarget::drop_tooltip(
|
|||
{
|
||||
BLI_assert(drag_info.drag_data.type == WM_DRAG_ASSET_CATALOG);
|
||||
const AssetCatalog *drag_catalog = AssetCatalogDropTarget::get_drag_catalog(
|
||||
drag_info.drag_data, *get_view<AssetCatalogTreeView>().asset_library_);
|
||||
drag_info.drag_data, *this->get_view<AssetCatalogTreeView>().asset_library_);
|
||||
|
||||
return fmt::format(TIP_("Move catalog {} to the top level of the tree"),
|
||||
drag_catalog->path.name());
|
||||
|
@ -633,7 +635,7 @@ bool AssetCatalogTreeViewAllItem::DropTarget::on_drop(bContext * /*C*/,
|
|||
BLI_assert(drag.drag_data.type == WM_DRAG_ASSET_CATALOG);
|
||||
return AssetCatalogDropTarget::drop_asset_catalog_into_catalog(
|
||||
drag.drag_data,
|
||||
get_view<AssetCatalogTreeView>(),
|
||||
this->get_view<AssetCatalogTreeView>(),
|
||||
/* No value to drop into the root level. */
|
||||
std::nullopt);
|
||||
}
|
||||
|
@ -676,7 +678,7 @@ bool AssetCatalogTreeViewUnassignedItem::DropTarget::on_drop(bContext *C,
|
|||
{
|
||||
/* Assign to nil catalog ID. */
|
||||
return AssetCatalogDropTarget::drop_assets_into_catalog(
|
||||
C, get_view<AssetCatalogTreeView>(), drag.drag_data, CatalogID{});
|
||||
C, this->get_view<AssetCatalogTreeView>(), drag.drag_data, CatalogID{});
|
||||
}
|
||||
|
||||
} // namespace blender::ed::asset_browser
|
||||
|
|
Loading…
Reference in New Issue
Maybe add: