32 #include "RNA_prototypes.h"
76 bool has_asset =
false;
77 bool has_supported_type =
false;
78 bool is_single =
false;
109 const char *msg_single =
110 "Data-block does not support asset operations - must be "
112 const char *msg_multiple =
113 "No data-block selected that supports asset operations - select at least "
115 return is_single ? msg_single : msg_multiple;
124 void reportResults(
ReportList &reports)
const;
125 bool wasSuccessful()
const;
130 int tot_already_asset = 0;
131 ID *last_id =
nullptr;
144 stats.tot_already_asset++;
159 return stats.tot_created > 0;
165 if (!wasSuccessful()) {
166 if (stats.tot_already_asset > 0) {
169 "Selected data-blocks are already assets (or do not support use as assets)");
174 "No data-blocks to create assets for found (or do not support use as assets)");
178 else if (stats.tot_created == 1) {
180 BKE_reportf(&reports,
RPT_INFO,
"Data-block '%s' is now an asset", stats.last_id->name + 2);
192 mark_helper(*
C, ids);
219 ot->
name =
"Mark as Asset";
221 "Enable easier reuse of selected data-blocks through the Asset Browser, with the help of "
222 "customizable metadata (like previews, descriptions and tags)";
234 const bool set_fake_user_;
244 bool wasSuccessful()
const;
249 ID *last_id =
nullptr;
269 if (set_fake_user_) {
280 if (!wasSuccessful()) {
288 "No asset data-blocks from the current file selected (assets must be stored in "
289 "the current file to be able to edit or clear them)");
295 else if (stats.tot_cleared == 1) {
298 &reports,
RPT_INFO,
"Data-block '%s' is not an asset anymore", stats.last_id->name + 2);
301 BKE_reportf(&reports,
RPT_INFO,
"%i data-blocks are no assets anymore", stats.tot_cleared);
307 return stats.tot_cleared > 0;
334 const char *msg_single =
TIP_(
"Data-block is not marked as asset");
335 const char *msg_multiple =
TIP_(
"No data-block selected that is marked as asset");
352 if (!set_fake_user) {
357 TIP_(
"Delete all asset metadata, turning the selected asset data-blocks back into normal "
358 "data-blocks, and set Fake User to ensure the data-blocks will still be saved"));
365 "Delete all asset metadata and turn the selected asset data-blocks back into normal "
379 "Ensure the data-block is saved, even when it is no longer marked as asset");
425 ot->
name =
"Refresh Asset Library";
426 ot->
description =
"Reread assets and asset catalogs from the asset library on disk";
427 ot->
idname =
"ASSET_OT_library_refresh";
449 asset_library,
"Catalog", parent_path);
466 ot->
name =
"New Asset Catalog";
468 ot->
idname =
"ASSET_OT_catalog_new";
479 "Optional path defining the location to put the new catalog under");
505 ot->
name =
"Delete Asset Catalog";
507 "Remove an asset catalog from the asset library (contained assets will not be affected and "
508 "show up as unassigned)";
509 ot->
idname =
"ASSET_OT_catalog_delete";
515 RNA_def_string(
ot->
srna,
"catalog_id",
nullptr, 0,
"Catalog ID",
"ID of the catalog to delete");
532 if (!catalog_service) {
536 catalog_service->
undo();
550 ot->
name =
"Undo Catalog Edits";
551 ot->
description =
"Undo the last edit to the asset catalogs";
552 ot->
idname =
"ASSET_OT_catalog_undo";
562 if (!catalog_service) {
566 catalog_service->
redo();
580 ot->
name =
"Redo Catalog Edits";
581 ot->
description =
"Redo the last undone edit to the asset catalogs";
582 ot->
idname =
"ASSET_OT_catalog_redo";
592 if (!catalog_service) {
608 ot->
name =
"Store undo snapshot for asset catalog edits";
609 ot->
description =
"Store the current state of the asset catalogs in the undo buffer";
610 ot->
idname =
"ASSET_OT_catalog_undo_push";
658 ot->
name =
"Save Asset Catalogs";
660 "Make any edits to any catalogs permanent by writing the current set up to the asset "
662 ot->
idname =
"ASSET_OT_catalogs_save";
681 if (sfile ==
nullptr) {
732 const size_t len = strlen(filepath);
763 return operator_result;
770 R
"(Saved "%s" to asset library "%s")",
793 ot->
name =
"Copy to Asset Library";
795 "Copy the current .blend file into an Asset Library. Only works on standalone .blend files "
796 "(i.e. when no other files are referenced)";
797 ot->
idname =
"ASSET_OT_bundle_install";
822 return fnmatch(
"*_bundle.blend", bmain->
filepath, FNM_CASEFOLD) == 0;
851 if (
lib ==
nullptr) {
857 if (blend_filename ==
nullptr || blend_filename[0] ==
'\0') {
875 const char *path_src)
917 "Unable to copy bundle due to external dependency: \"%s\"",
926 "Unable to copy bundle due to %zu external dependencies; more details on the console",
928 printf(
"Unable to copy bundle due to %zu external dependencies:\n",
931 printf(
" \"%s\"\n", path.c_str());
bool BKE_asset_library_has_any_unsaved_catalogs(void)
struct AssetLibrary AssetLibrary
blender::bke::AssetCatalogService * BKE_asset_library_get_catalog_service(const ::AssetLibrary *library)
@ 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)
const struct AssetLibraryReference * CTX_wm_asset_library_ref(const bContext *C)
struct wmWindowManager * CTX_wm_manager(const bContext *C)
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
int CTX_data_selected_ids(const bContext *C, ListBase *list)
struct AssetHandle CTX_wm_asset_handle(const bContext *C, bool *r_is_valid)
void CTX_wm_operator_poll_msg_set(struct bContext *C, const char *msg)
struct Main * CTX_data_main(const bContext *C)
struct SpaceFile * CTX_wm_space_file(const bContext *C)
struct wmWindow * CTX_wm_window(const bContext *C)
void id_fake_user_set(struct ID *id)
struct bUserAssetLibrary * BKE_preferences_asset_library_find_from_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)
File and directory operations.
#define LISTBASE_FOREACH(type, var, list)
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
const char * BLI_path_basename(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
bool BLI_path_contains(const char *container_path, const char *containee_path) ATTR_WARN_UNUSED_RESULT
void BLI_join_dirfile(char *__restrict dst, size_t maxlen, const char *__restrict dir, const char *__restrict file) ATTR_NONNULL()
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
bool BLI_uuid_parse_string(bUUID *uuid, const char *buffer) ATTR_NONNULL()
external writefile.c function prototypes.
void ED_asset_catalogs_save_from_main_path(struct AssetLibrary *library, const struct Main *bmain)
void ED_asset_catalog_remove(AssetLibrary *library, const blender::bke::CatalogID &catalog_id)
blender::bke::AssetCatalog * ED_asset_catalog_add(AssetLibrary *library, blender::StringRefNull name, blender::StringRef parent_path=nullptr)
struct ID * ED_asset_handle_get_local_id(const struct AssetHandle *asset)
AssetLibraryReference ED_asset_library_reference_from_enum_value(int value)
const struct EnumPropertyItem * ED_asset_library_reference_to_rna_enum_itemf(bool include_local_library)
void ED_assetlist_clear(const struct AssetLibraryReference *library_reference, struct bContext *C)
bool ED_assetlist_storage_has_list_for_library(const AssetLibraryReference *library_reference)
bool ED_asset_clear_id(struct ID *id)
bool ED_asset_mark_id(struct ID *id)
void ED_asset_generate_preview(const struct bContext *C, struct ID *id)
bool ED_asset_type_is_supported(const ID *id)
#define ED_ASSET_TYPE_IDS_NON_EXPERIMENTAL_UI_STRING
void ED_fileselect_clear(struct wmWindowManager *wm, struct SpaceFile *sfile)
void ED_fileselect_activate_asset_catalog(const struct SpaceFile *sfile, bUUID catalog_id)
struct AssetLibrary * ED_fileselect_active_asset_library_get(const struct SpaceFile *sfile)
bool ED_fileselect_is_local_asset_library(const struct SpaceFile *sfile)
bool ED_operator_asset_browsing_active(struct bContext *C)
#define ND_SPACE_ASSET_PARAMS
#define ND_ASSET_CATALOGS
#define ND_SPACE_FILE_LIST
static int asset_catalog_undo_push_exec(bContext *C, wmOperator *)
static int asset_bundle_install_exec(bContext *C, wmOperator *op)
static bool external_file_check_callback(BPathForeachPathData *bpath_data, char *, const char *path_src)
static bool asset_catalog_undo_push_poll(bContext *C)
static int asset_catalog_delete_exec(bContext *C, wmOperator *op)
static bool asset_clear_poll(bContext *C)
void ED_operatortypes_asset()
static int asset_catalog_new_exec(bContext *C, wmOperator *op)
static void ASSET_OT_mark(wmOperatorType *ot)
static void ASSET_OT_catalog_undo_push(struct wmOperatorType *ot)
static int asset_catalog_undo_exec(bContext *C, wmOperator *)
static IDVecStats asset_operation_get_id_vec_stats_from_context(const bContext *C)
static bool asset_catalog_undo_poll(bContext *C)
static char * asset_clear_get_description(struct bContext *UNUSED(C), struct wmOperatorType *UNUSED(op), struct PointerRNA *values)
static void ASSET_OT_catalogs_save(struct wmOperatorType *ot)
static int asset_bundle_install_invoke(struct bContext *C, struct wmOperator *op, const struct wmEvent *)
static void ASSET_OT_catalog_redo(struct wmOperatorType *ot)
static const EnumPropertyItem * rna_asset_library_reference_itemf(bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
static bool asset_catalog_operator_poll(bContext *C)
static bool asset_library_refresh_poll(bContext *C)
static void ASSET_OT_catalog_delete(struct wmOperatorType *ot)
static void ASSET_OT_catalog_undo(struct wmOperatorType *ot)
static bool set_filepath_for_asset_lib(const Main *bmain, struct wmOperator *op)
static int asset_library_refresh_exec(bContext *C, wmOperator *UNUSED(unused))
static bool asset_catalog_redo_poll(bContext *C)
static const bUserAssetLibrary * selected_asset_library(struct wmOperator *op)
static int asset_catalogs_save_exec(bContext *C, wmOperator *)
static int asset_clear_exec(bContext *C, wmOperator *op)
static PointerRNAVec asset_operation_get_ids_from_context(const bContext *C)
static int asset_catalog_redo_exec(bContext *C, wmOperator *)
static bool asset_mark_poll(bContext *C)
static int asset_mark_exec(bContext *C, wmOperator *op)
static void ASSET_OT_clear(wmOperatorType *ot)
static void ASSET_OT_library_refresh(struct wmOperatorType *ot)
static const char * asset_operation_unsupported_type_msg(const bool is_single)
static bool has_external_files(Main *bmain, struct ReportList *reports)
static void ASSET_OT_catalog_new(struct wmOperatorType *ot)
static bke::AssetCatalogService * get_catalog_service(bContext *C)
static bool could_be_asset_bundle(const Main *bmain)
static void ASSET_OT_bundle_install(struct wmOperatorType *ot)
static bool asset_catalogs_save_poll(bContext *C)
static bool is_contained_in_selected_asset_library(struct wmOperator *op, const char *filepath)
static bool asset_bundle_install_poll(bContext *C)
bool wasSuccessful() const
void operator()(PointerRNAVec &ids)
AssetClearHelper(const bool set_fake_user)
void reportResults(const bContext *C, ReportList &reports) const
bool wasSuccessful() const
void operator()(const bContext &C, PointerRNAVec &ids)
void reportResults(ReportList &reports) const
void append(const T &value)
bool is_redo_possbile() const
bool is_undo_possbile() const
void prepare_to_merge_on_write()
void(* MEM_freeN)(void *vmemh)
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_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, 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)
Set< std::string > external_files
struct ReportList * reports
struct AssetMetaData * asset_data
Universally Unique Identifier according to RFC4122.
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
char *(* get_description)(struct bContext *C, struct wmOperatorType *, struct PointerRNA *)
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports
static FT_Library library
void WM_cursor_wait(bool val)
void WM_main_add_notifier(unsigned int type, void *reference)
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_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 *))