The Clear Asset operator (`ASSET_OT_clear`) now clears the Fake User. This makes it symmetrical with the Mark Asset (`ASSET_OT_mark`) operator, which sets Fake User to ensure assets are always saved to disk. Clear Asset now also has a `set_fake_user` boolean option, which allows users to Clear Asset and set Fake User in one go. The asset browser now shows these options in the context menu: - Clear Asset: also clears Fake User. This makes it possible to actually remove assets from the blend file without leaving the Asset Browser. - Clear Asset (Set Fake User): keeps the Fake User bit set. This makes it possible to "hide" the asset from the asset browser, without loosing the actual data. Internally, the `ED_asset_clear_id(id)` function now always clears the Fake User bit. If it was intended that this bit was kept set, it's up to the caller to explicitly call `id_fake_user_set(id)` afterwards. Manifest Task: T90844 Reviewed By: Severin Differential Revision: https://developer.blender.org/D12663
83 lines
2.0 KiB
C++
83 lines
2.0 KiB
C++
/*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*/
|
|
|
|
/** \file
|
|
* \ingroup edasset
|
|
*
|
|
* Functions for marking and clearing assets.
|
|
*/
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "BKE_asset.h"
|
|
#include "BKE_context.h"
|
|
#include "BKE_lib_id.h"
|
|
|
|
#include "BLO_readfile.h"
|
|
|
|
#include "DNA_ID.h"
|
|
#include "DNA_asset_types.h"
|
|
#include "DNA_space_types.h"
|
|
|
|
#include "UI_interface_icons.h"
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "ED_asset_list.h"
|
|
#include "ED_asset_mark_clear.h"
|
|
|
|
bool ED_asset_mark_id(const bContext *C, ID *id)
|
|
{
|
|
if (id->asset_data) {
|
|
return false;
|
|
}
|
|
if (!BKE_id_can_be_asset(id)) {
|
|
return false;
|
|
}
|
|
|
|
id_fake_user_set(id);
|
|
|
|
id->asset_data = BKE_asset_metadata_create();
|
|
|
|
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;
|
|
}
|
|
|
|
bool ED_asset_clear_id(ID *id)
|
|
{
|
|
if (!id->asset_data) {
|
|
return false;
|
|
}
|
|
BKE_asset_metadata_free(&id->asset_data);
|
|
id_fake_user_clear(id);
|
|
|
|
/* Important for asset storage to update properly! */
|
|
ED_assetlist_storage_tag_main_data_dirty();
|
|
|
|
return true;
|
|
}
|
|
|
|
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. */
|
|
return CTX_data_pointer_get_type_silent(C, "id", &RNA_ID).data != nullptr;
|
|
}
|