Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/asset/intern/asset_mark_clear.cc
- This file was moved from source/blender/editors/asset/asset_edit.cc.
| Show All 10 Lines | |||||
| * | * | ||||
| * You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
| * along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| */ | */ | ||||
| /** \file | /** \file | ||||
| * \ingroup edasset | * \ingroup edasset | ||||
| * | |||||
| * Functions for marking and clearing assets. | |||||
| */ | */ | ||||
| #include <memory> | |||||
| #include <string> | |||||
| #include "BKE_asset.h" | #include "BKE_asset.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_lib_id.h" | #include "BKE_lib_id.h" | ||||
| #include "BLO_readfile.h" | |||||
| #include "DNA_ID.h" | #include "DNA_ID.h" | ||||
| #include "DNA_asset_types.h" | |||||
| #include "DNA_space_types.h" | |||||
| #include "UI_interface_icons.h" | #include "UI_interface_icons.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "ED_asset.h" | #include "ED_asset_list.h" | ||||
| #include "ED_asset_mark_clear.h" | |||||
| bool ED_asset_mark_id(const bContext *C, ID *id) | bool ED_asset_mark_id(const bContext *C, ID *id) | ||||
| { | { | ||||
| if (id->asset_data) { | 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); | ||||
| id->asset_data = BKE_asset_metadata_create(); | id->asset_data = BKE_asset_metadata_create(); | ||||
| 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! */ | |||||
| 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); | ||||
| /* Don't clear fake user here, there's no guarantee that it was actually set by | /* Don't clear fake user here, there's no guarantee that it was actually set by | ||||
| * #ED_asset_mark_id(), it might have been something/someone else. */ | * #ED_asset_mark_id(), it might have been something/someone else. */ | ||||
| /* Important for asset storage to update properly! */ | |||||
| ED_assetlist_storage_tag_main_data_dirty(); | |||||
| return true; | return true; | ||||
| } | } | ||||
| bool ED_asset_can_make_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; | ||||
| } | } | ||||