Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/asset/intern/asset_mark_clear.cc
| Show All 19 Lines | |||||
| * Functions for marking and clearing assets. | * Functions for marking and clearing assets. | ||||
| */ | */ | ||||
| #include <memory> | #include <memory> | ||||
| #include <string> | #include <string> | ||||
| #include "BKE_asset.h" | #include "BKE_asset.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_idtype.h" | |||||
| #include "BKE_lib_id.h" | #include "BKE_lib_id.h" | ||||
| #include "BKE_main.h" | |||||
| #include "BLO_readfile.h" | #include "BLO_readfile.h" | ||||
| #include "DNA_ID.h" | #include "DNA_ID.h" | ||||
| #include "DNA_asset_types.h" | #include "DNA_asset_types.h" | ||||
| #include "DNA_space_types.h" | #include "DNA_space_types.h" | ||||
| #include "UI_interface_icons.h" | #include "UI_interface_icons.h" | ||||
| Show All 9 Lines | if (id->asset_data) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (!BKE_id_can_be_asset(id)) { | if (!BKE_id_can_be_asset(id)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| id_fake_user_set(id); | id_fake_user_set(id); | ||||
| const IDTypeInfo *id_type_info = BKE_idtype_get_info_from_id(id); | |||||
| id->asset_data = BKE_asset_metadata_create(); | id->asset_data = BKE_asset_metadata_create(); | ||||
| id->asset_data->local_type_info = id_type_info->asset_type_info; | |||||
| UI_icon_render_id(C, nullptr, id, ICON_SIZE_PREVIEW, true); | UI_icon_render_id(C, nullptr, id, ICON_SIZE_PREVIEW, true); | ||||
| /* Important for asset storage to update properly! */ | /* Important for asset storage to update properly! */ | ||||
| ED_assetlist_storage_tag_main_data_dirty(); | ED_assetlist_storage_tag_main_data_dirty(); | ||||
| return true; | return true; | ||||
| } | } | ||||
| bool ED_asset_clear_id(ID *id) | bool ED_asset_clear_id(ID *id) | ||||
| { | { | ||||
| if (!id->asset_data) { | if (!id->asset_data) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| BKE_asset_metadata_free(&id->asset_data); | BKE_asset_metadata_free(&id->asset_data); | ||||
| id_fake_user_clear(id); | id_fake_user_clear(id); | ||||
| /* Important for asset storage to update properly! */ | /* Important for asset storage to update properly! */ | ||||
| ED_assetlist_storage_tag_main_data_dirty(); | ED_assetlist_storage_tag_main_data_dirty(); | ||||
| return true; | return true; | ||||
| } | } | ||||
| void ED_assets_pre_save(struct Main *bmain) | |||||
| { | |||||
| ID *id; | |||||
| FOREACH_MAIN_ID_BEGIN (bmain, id) { | |||||
| if (!id->asset_data || !id->asset_data->local_type_info) { | |||||
| continue; | |||||
| } | |||||
| if (id->asset_data->local_type_info->pre_save_fn) { | |||||
| id->asset_data->local_type_info->pre_save_fn(id, id->asset_data); | |||||
| } | |||||
| } | |||||
| FOREACH_MAIN_ID_END; | |||||
| } | |||||
| bool ED_asset_can_mark_single_from_context(const bContext *C) | bool ED_asset_can_mark_single_from_context(const bContext *C) | ||||
| { | { | ||||
| /* Context needs a "id" pointer to be set for #ASSET_OT_mark()/#ASSET_OT_clear() to use. */ | /* Context needs a "id" pointer to be set for #ASSET_OT_mark()/#ASSET_OT_clear() to use. */ | ||||
| return CTX_data_pointer_get_type_silent(C, "id", &RNA_ID).data != nullptr; | return CTX_data_pointer_get_type_silent(C, "id", &RNA_ID).data != nullptr; | ||||
| } | } | ||||