32#include "RNA_prototypes.hh"
107 const char *msg_single =
108 "Data-block does not support asset operations - must be "
110 const char *msg_multiple =
111 "No data-block selected that supports asset operations - select at least "
113 return is_single ? msg_single : msg_multiple;
128 int tot_already_asset = 0;
129 ID *last_id =
nullptr;
141 if (id->asset_data) {
142 stats.tot_already_asset++;
157 return stats.tot_created > 0;
164 if (stats.tot_already_asset > 0) {
167 "Selected data-blocks are already assets (or do not support use as assets)");
172 "No data-blocks to create assets for found (or do not support use as assets)");
176 else if (stats.tot_created == 1) {
188 mark_helper(*C, ids);
215 ot->
name =
"Mark as Asset";
217 "Enable easier reuse of selected data-blocks through the Asset Browser, with the help of "
218 "customizable metadata (like previews, descriptions and tags)";
236 ot->
name =
"Mark as Single Asset";
238 "Enable easier reuse of a data-block through the Asset Browser, with the help of "
239 "customizable metadata (like previews, descriptions and tags)";
240 ot->
idname =
"ASSET_OT_mark_single";
255 const bool set_fake_user_;
268 ID *last_id =
nullptr;
280 if (!id->asset_data) {
288 if (set_fake_user_) {
305 "No asset data-blocks from the current file selected (assets must be stored in "
306 "the current file to be able to edit or clear them)");
312 else if (stats.tot_cleared == 1) {
315 &reports,
RPT_INFO,
"Data-block '%s' is not an asset anymore", stats.last_id->
name + 2);
318 BKE_reportf(&reports,
RPT_INFO,
"%i data-blocks are not assets anymore", stats.tot_cleared);
324 return stats.tot_cleared > 0;
349 const char *msg_single =
N_(
"Data-block is not marked as asset");
350 const char *msg_multiple =
N_(
"No data-block selected that is marked as asset");
367 if (!set_fake_user) {
371 "Delete all asset metadata, turning the selected asset data-blocks back into normal "
372 "data-blocks, and set Fake User to ensure the data-blocks will still be saved");
382 "Delete all asset metadata and turn the selected asset data-blocks back into normal "
400 "Ensure the data-block is saved, even when it is no longer marked as asset");
405 ot->
name =
"Clear Single Asset";
407 "Delete all asset metadata and turn the asset data-block back into a normal data-block";
409 ot->
idname =
"ASSET_OT_clear_single";
424 "Ensure the data-block is saved, even when it is no longer marked as asset");
470 ot->
name =
"Refresh Asset Library";
471 ot->
description =
"Reread assets and asset catalogs from the asset library on disk";
472 ot->
idname =
"ASSET_OT_library_refresh";
488 if (!asset_library) {
505 asset_library,
DATA_(
"Catalog"), parent_path);
522 ot->
name =
"New Asset Catalog";
524 ot->
idname =
"ASSET_OT_catalog_new";
535 "Optional path defining the location to put the new catalog under");
561 ot->
name =
"Delete Asset Catalog";
563 "Remove an asset catalog from the asset library (contained assets will not be affected and "
564 "show up as unassigned)";
565 ot->
idname =
"ASSET_OT_catalog_delete";
571 RNA_def_string(
ot->
srna,
"catalog_id",
nullptr, 0,
"Catalog ID",
"ID of the catalog to delete");
592 if (!catalog_service) {
596 catalog_service->
undo();
610 ot->
name =
"Undo Catalog Edits";
611 ot->
description =
"Undo the last edit to the asset catalogs";
612 ot->
idname =
"ASSET_OT_catalog_undo";
622 if (!catalog_service) {
626 catalog_service->
redo();
640 ot->
name =
"Redo Catalog Edits";
641 ot->
description =
"Redo the last undone edit to the asset catalogs";
642 ot->
idname =
"ASSET_OT_catalog_redo";
652 if (!catalog_service) {
668 ot->
name =
"Store undo snapshot for asset catalog edits";
669 ot->
description =
"Store the current state of the asset catalogs in the undo buffer";
670 ot->
idname =
"ASSET_OT_catalog_undo_push";
718 ot->
name =
"Save Asset Catalogs";
720 "Make any edits to any catalogs permanent by writing the current set up to the asset "
722 ot->
idname =
"ASSET_OT_catalogs_save";
741 if (sfile ==
nullptr) {
790 const size_t len = strlen(filepath);
821 return operator_result;
828 R
"(Saved "%s" to asset library "%s")",
852 ot->
name =
"Copy to Asset Library";
854 "Copy the current .blend file into an Asset Library. Only works on standalone .blend files "
855 "(i.e. when no other files are referenced)";
856 ot->
idname =
"ASSET_OT_bundle_install";
881 return fnmatch(
"*_bundle.blend", bmain->
filepath, FNM_CASEFOLD) == 0;
886 const int enum_value =
RNA_enum_get(op->
ptr,
"asset_library_reference");
910 if (
lib ==
nullptr) {
916 if (blend_filename ==
nullptr || blend_filename[0] ==
'\0') {
935 const char *path_src)
977 "Unable to copy bundle due to external dependency: \"%s\"",
986 "Unable to copy bundle due to %zu external dependencies; more details on the console",
988 printf(
"Unable to copy bundle due to %zu external dependencies:\n",
991 printf(
" \"%s\"\n", path.c_str());
bool AS_asset_library_has_any_unsaved_catalogs()
Main runtime representation of an asset.
@ BKE_BPATH_TRAVERSE_SKIP_WEAK_REFERENCES
@ BKE_BPATH_FOREACH_PATH_SKIP_PACKED
@ BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE
void BKE_bpath_foreach_path_main(BPathForeachPathData *bpath_data)
SpaceFile * CTX_wm_space_file(const bContext *C)
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
wmWindow * CTX_wm_window(const bContext *C)
const AssetLibraryReference * CTX_wm_asset_library_ref(const bContext *C)
class blender::asset_system::AssetRepresentation * CTX_wm_asset(const bContext *C)
Main * CTX_data_main(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
bool CTX_data_selected_ids(const bContext *C, blender::Vector< PointerRNA > *list)
void id_fake_user_set(ID *id)
struct bUserAssetLibrary * BKE_preferences_asset_library_find_index(const struct UserDef *userdef, int index) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
struct bUserAssetLibrary * BKE_preferences_asset_library_containing_path(const struct UserDef *userdef, const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_report(ReportList *reports, eReportType type, const char *message)
#define BLI_assert_msg(a, msg)
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool BLI_path_contains(const char *container_path, const char *containee_path) ATTR_NONNULL(1
#define BLI_path_join(...)
bool BLI_uuid_parse_string(bUUID *uuid, const char *buffer) ATTR_NONNULL()
struct AssetRepresentationHandle AssetRepresentationHandle
#define ED_ASSET_TYPE_IDS_NON_EXPERIMENTAL_UI_STRING
void ED_fileselect_activate_asset_catalog(const SpaceFile *sfile, bUUID catalog_id)
bool ED_fileselect_is_file_browser(const SpaceFile *sfile)
bool ED_fileselect_is_local_asset_library(const SpaceFile *sfile)
blender::asset_system::AssetLibrary * ED_fileselect_active_asset_library_get(const SpaceFile *sfile)
void ED_fileselect_clear(wmWindowManager *wm, SpaceFile *sfile)
bool ED_operator_asset_browsing_active(bContext *C)
#define ND_SPACE_ASSET_PARAMS
#define ND_ASSET_CATALOGS
#define ND_SPACE_FILE_LIST
constexpr int64_t size() const
void append(const T &value)
bool is_undo_possbile() const
void prepare_to_merge_on_write()
bool is_redo_possbile() const
const CatalogID catalog_id
AssetCatalogService & catalog_service() const
void reportResults(const bContext *C, ReportList &reports) const
void operator()(Span< PointerRNA > ids)
AssetClearHelper(const bool set_fake_user)
bool wasSuccessful() const
bool wasSuccessful() const
void operator()(const bContext &C, Span< PointerRNA > ids)
void reportResults(ReportList &reports) const
void MEM_freeN(void *vmemh)
void clear(const AssetLibraryReference *library_reference, const bContext *C)
bool storage_has_list_for_library(const AssetLibraryReference *library_reference)
static bool asset_catalogs_save_poll(bContext *C)
static bool could_be_asset_bundle(const Main *bmain)
void catalog_remove(asset_system::AssetLibrary *library, const asset_system::CatalogID &catalog_id)
bool catalogs_read_only(const asset_system::AssetLibrary &library)
static bool asset_catalog_undo_push_poll(bContext *C)
static bool external_file_check_callback(BPathForeachPathData *bpath_data, char *, size_t, const char *path_src)
static int asset_catalogs_save_exec(bContext *C, wmOperator *)
static void ASSET_OT_clear(wmOperatorType *ot)
void catalogs_save_from_main_path(asset_system::AssetLibrary *library, const Main *bmain)
static void ASSET_OT_catalog_redo(wmOperatorType *ot)
static int asset_catalog_undo_push_exec(bContext *C, wmOperator *)
AssetLibraryReference library_reference_from_enum_value(int value)
static std::string asset_clear_get_description(bContext *, wmOperatorType *, PointerRNA *ptr)
static void ASSET_OT_catalog_new(wmOperatorType *ot)
static bool asset_catalog_redo_poll(bContext *C)
static void ASSET_OT_clear_single(wmOperatorType *ot)
static void ASSET_OT_catalog_delete(wmOperatorType *ot)
static IDVecStats asset_operation_get_id_vec_stats_from_ids(const Span< PointerRNA > id_pointers)
asset_system::AssetCatalog * catalog_add(asset_system::AssetLibrary *library, StringRefNull name, StringRef parent_path=nullptr)
static int asset_mark_exec(const bContext *C, const wmOperator *op, const Span< PointerRNA > ids)
static void ASSET_OT_mark_single(wmOperatorType *ot)
static bool is_contained_in_selected_asset_library(wmOperator *op, const char *filepath)
static Vector< PointerRNA > asset_operation_get_ids_from_context(const bContext *C)
static int asset_catalog_undo_exec(bContext *C, wmOperator *)
static Vector< PointerRNA > get_single_id_vec_from_context(const bContext *C)
static bool asset_clear_poll(bContext *C, const Span< PointerRNA > ids)
static bool asset_bundle_install_poll(bContext *C)
void operatortypes_asset()
static int asset_catalog_new_exec(bContext *C, wmOperator *op)
static void ASSET_OT_catalog_undo_push(wmOperatorType *ot)
const EnumPropertyItem * library_reference_to_rna_enum_itemf(bool include_generated)
static bool set_filepath_for_asset_lib(const Main *bmain, wmOperator *op)
static int asset_clear_exec(const bContext *C, const wmOperator *op, const Span< PointerRNA > ids)
void generate_preview(const bContext *C, ID *id)
static void ASSET_OT_bundle_install(wmOperatorType *ot)
static const char * asset_operation_unsupported_type_msg(const bool is_single)
static bool asset_catalog_undo_poll(bContext *C)
static bool asset_mark_poll(bContext *C, const Span< PointerRNA > ids)
static void ASSET_OT_mark(wmOperatorType *ot)
static int asset_library_refresh_exec(bContext *C, wmOperator *)
static int asset_catalog_delete_exec(bContext *C, wmOperator *op)
static void ASSET_OT_catalog_undo(wmOperatorType *ot)
static int asset_catalog_redo_exec(bContext *C, wmOperator *)
static int asset_bundle_install_exec(bContext *C, wmOperator *op)
static bool asset_library_refresh_poll(bContext *C)
static asset_system::AssetCatalogService * get_catalog_service(bContext *C)
static int asset_bundle_install_invoke(bContext *C, wmOperator *op, const wmEvent *)
static const bUserAssetLibrary * selected_asset_library(wmOperator *op)
static void ASSET_OT_library_refresh(wmOperatorType *ot)
bool id_type_is_supported(const ID *id)
static void ASSET_OT_catalogs_save(wmOperatorType *ot)
static bool has_external_files(Main *bmain, ReportList *reports)
static const EnumPropertyItem * rna_asset_library_reference_itemf(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
static bool asset_catalog_operator_poll(bContext *C)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
bool RNA_struct_is_ID(const StructRNA *type)
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
char * RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
Universally Unique Identifier according to RFC4122.
Set< std::string > external_files
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
std::string(* get_description)(bContext *C, wmOperatorType *ot, PointerRNA *ptr)
int(* invoke)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports
static DynamicLibrary lib
void WM_cursor_wait(bool val)
void WM_event_add_fileselect(bContext *C, wmOperator *op)
void WM_event_add_notifier_ex(wmWindowManager *wm, const wmWindow *win, uint type, void *reference)
void WM_main_add_notifier(uint type, void *reference)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
int WM_operator_name_call(bContext *C, const char *opstring, wmOperatorCallContext context, PointerRNA *properties, const wmEvent *event)
void WM_operator_properties_filesel(wmOperatorType *ot, const int filter, const short type, const eFileSel_Action action, const eFileSel_Flag flag, const short display, const short sort)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))