Report/confirm overwrite of 'asset library' blendfiles. #117346

Merged
Bastien Montagne merged 5 commits from mont29/blender:bap-open-warning into brush-assets-project 2024-01-25 17:10:39 +01:00
6 changed files with 48 additions and 24 deletions
Showing only changes of commit 97504185eb - Show all commits

View File

@ -19,6 +19,11 @@ struct ReportList;
struct UserDef;
struct WorkspaceConfigFileData;
/**
* The suffix used for blendfiles managed by the asset system.
*/
#define BLENDER_ASSET_FILE_SUFFIX ".asset.blend"
/**
* Check whether given path ends with a blend file compatible extension
* (`.blend`, `.ble` or `.blend.gz`).

View File

@ -143,14 +143,12 @@ struct Main {
bool has_forward_compatibility_issues;
/**
* The currently opened .blend file was 'partial-written' (it does not contain some typical data
* required for a complete normal blendfile, like a current screen and current scene...).
* The currently opened .blend file was created as an asset library storage.
*
* This is used to warn the user when they try to save it from Blender UI, since they are likely
* overwriting a file generated (and potentially managed) by some tool, e.g. some asset library
* file.
* This is used to warn the user when they try to save it from Blender UI, since this will likely
* break the automatic management from the asset library system.
*/
bool is_data_only;
bool is_asset_repository;
/** Commit timestamp from `buildinfo`. */
uint64_t build_commit_timestamp;

View File

@ -853,7 +853,9 @@ static void setup_app_data(bContext *C,
* nullptr curscreen)... */
else if (ELEM(nullptr, bfd->curscreen, bfd->curscene)) {
BKE_report(reports->reports, RPT_WARNING, "Library file, loading empty scene");
bfd->main->is_data_only = true;
if (blender::StringRefNull(bfd->main->filepath).endswith(BLENDER_ASSET_FILE_SUFFIX)) {
bfd->main->is_asset_repository = true;
}
mode = LOAD_UI_OFF;
}
else if (G.fileflags & G_FILE_NO_UI) {

View File

@ -446,12 +446,12 @@ bool BKE_main_is_empty(Main *bmain)
bool BKE_main_has_issues(const Main *bmain)
{
return bmain->has_forward_compatibility_issues || bmain->is_data_only;
return bmain->has_forward_compatibility_issues || bmain->is_asset_repository;
}
bool BKE_main_needs_overwrite_confirm(const Main *bmain)
{
return bmain->has_forward_compatibility_issues || bmain->is_data_only;
return bmain->has_forward_compatibility_issues || bmain->is_asset_repository;
}
void BKE_main_lock(Main *bmain)

View File

@ -6579,12 +6579,12 @@ static void ui_template_status_info_warnings_messages(Main *bmain,
tooltip_message += fmt::format(RPT_("File saved by newer Blender\n({}), expect loss of data"),
writer_ver_str);
}
if (bmain->is_data_only) {
if (bmain->is_asset_repository) {
if (!tooltip_message.empty()) {
tooltip_message += "\n\n";
}
tooltip_message += RPT_(
"Not a regular Blender file, overwriting it\nmay break its handling by tools like the "
"This is an Asset Library Blender file, overwriting it\nmay break its handling by the "
mont29 marked this conversation as resolved Outdated

I would use the same text as the confirmation popup, just replace "overwriting" by "editing". The message to convey is the same.

This file is managed by the Blender asset system
By editing it as a regular blend file, it will no longer
be possible to update its assets through the asset browser
I would use the same text as the confirmation popup, just replace "overwriting" by "editing". The message to convey is the same. ``` This file is managed by the Blender asset system By editing it as a regular blend file, it will no longer be possible to update its assets through the asset browser ```
"Assets system");
}

View File

@ -3939,15 +3939,15 @@ static void file_overwrite_detailed_info_show(uiLayout *parent_layout, Main *bma
uiItemL(layout, message_line2, ICON_NONE);
}
if (bmain->is_data_only) {
if (bmain->is_asset_repository) {
if (bmain->has_forward_compatibility_issues) {
uiItemS_ex(layout, 1.4f);
}
uiItemL(layout, RPT_("This file was detected as a Library file"), ICON_NONE);
uiItemL(layout, RPT_("This file is managed by the Blender asset system"), ICON_NONE);
uiItemL(
layout, RPT_("It was likely generated by the asset system, or similar tool"), ICON_NONE);
uiItemL(layout, RPT_("Overwriting it may prevent its management by that tool"), ICON_NONE);
layout, RPT_("By overwriting it as a regular blend file, it will no longer "), ICON_NONE);
uiItemL(layout, RPT_("be possible to update its assets through the asset browser"), ICON_NONE);
}
}
@ -4025,10 +4025,27 @@ static void save_file_overwrite_confirm_button(uiBlock *block, wmGenericCallback
static void save_file_overwrite_saveas(bContext *C, void *arg_block, void * /*arg_data*/)
{
Main *bmain = CTX_data_main(C);
wmWindow *win = CTX_wm_window(C);
UI_popup_block_close(C, win, static_cast<uiBlock *>(arg_block));
WM_operator_name_call(C, "WM_OT_save_as_mainfile", WM_OP_INVOKE_DEFAULT, nullptr, nullptr);
PointerRNA props_ptr;
wmOperatorType *ot = WM_operatortype_find("WM_OT_save_as_mainfile", false);
WM_operator_properties_create_ptr(&props_ptr, ot);
if (bmain->is_asset_repository) {
/* If needed, substitute the 'proposed' Save As filepath by replacing the `.asset.blend` part
* of it by just `.blend`. */
std::string filepath = BKE_main_blendfile_path(bmain);
if (blender::StringRef(filepath).endswith(BLENDER_ASSET_FILE_SUFFIX)) {
filepath.replace(
filepath.rfind(BLENDER_ASSET_FILE_SUFFIX), strlen(BLENDER_ASSET_FILE_SUFFIX), ".blend");
RNA_string_set(&props_ptr, "filepath", filepath.c_str());
}
}
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr, nullptr);
WM_operator_properties_free(&props_ptr);
}
static void save_file_overwrite_saveas_button(uiBlock *block, wmGenericCallback *post_action)
@ -4067,20 +4084,22 @@ static uiBlock *block_create_save_file_overwrite_dialog(bContext *C, ARegion *re
/* Title. */
if (bmain->has_forward_compatibility_issues) {
if (bmain->is_data_only) {
uiItemL_ex(layout,
RPT_("Overwrite library file with an older Blender version?"),
ICON_NONE,
true,
false);
if (bmain->is_asset_repository) {
uiItemL_ex(
layout,
RPT_("Convert asset blend file to regular blend file with an older Blender version?"),
ICON_NONE,
true,
false);
}
else {
uiItemL_ex(
layout, RPT_("Overwrite file with an older Blender version?"), ICON_NONE, true, false);
}
}
else if (bmain->is_data_only) {
uiItemL_ex(layout, RPT_("Overwrite library file?"), ICON_NONE, true, false);
else if (bmain->is_asset_repository) {
uiItemL_ex(
layout, RPT_("Convert asset blend file to regular blend file?"), ICON_NONE, true, false);
}
else {
BLI_assert_unreachable();