diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-10-19 19:07:22 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-10-19 19:07:22 +0300 |
commit | 823996b0342b7352fc5b2e24eceb6204612438cd (patch) | |
tree | 08dca1ce5386c2b06ab01fad1f2f1ac5c236047a /source/blender/editors/asset/intern/asset_ops.cc | |
parent | b6c3b41d413813d8059476f2c0357b7a4e51ad22 (diff) |
Asset Browser: Improved workflow for asset catalog saving
No longer save asset catalogs on blendfile save. Instead:
- extend the confirmation prompt for unsaved changes to show unsaved
catalogs.
- In the confirmation prompt, make catalog saving explicit & optional,
just like we do it for external images. {F10881736}
- In the Asset Browser catalog tree, show an operator icon to save the
catalogs to disk. It's grayed out if there are no changes to save, or
if the .blend wasn't saved yet (required to know where to save the
catalog definitions to). {F10881743}
Much of the work was done by @Severin and reviewed by me, then we
swapped roles.
Reviewed By: Severin
Differential Revision: https://developer.blender.org/D12796
Diffstat (limited to 'source/blender/editors/asset/intern/asset_ops.cc')
-rw-r--r-- | source/blender/editors/asset/intern/asset_ops.cc | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/source/blender/editors/asset/intern/asset_ops.cc b/source/blender/editors/asset/intern/asset_ops.cc index 33a22775280..834874abc19 100644 --- a/source/blender/editors/asset/intern/asset_ops.cc +++ b/source/blender/editors/asset/intern/asset_ops.cc @@ -22,6 +22,7 @@ #include "BKE_asset_library.hh" #include "BKE_context.h" #include "BKE_lib_id.h" +#include "BKE_main.h" #include "BKE_report.h" #include "BLI_string_ref.hh" @@ -398,7 +399,8 @@ static int asset_catalog_new_exec(bContext *C, wmOperator *op) MEM_freeN(parent_path); - WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr); + WM_event_add_notifier_ex( + CTX_wm_manager(C), CTX_wm_window(C), NC_ASSET | ND_ASSET_CATALOGS, nullptr); return OPERATOR_FINISHED; } @@ -436,7 +438,8 @@ static int asset_catalog_delete_exec(bContext *C, wmOperator *op) MEM_freeN(catalog_id_str); - WM_main_add_notifier(NC_SPACE | ND_SPACE_ASSET_PARAMS, nullptr); + WM_event_add_notifier_ex( + CTX_wm_manager(C), CTX_wm_window(C), NC_ASSET | ND_ASSET_CATALOGS, nullptr); return OPERATOR_FINISHED; } @@ -561,6 +564,55 @@ static void ASSET_OT_catalog_undo_push(struct wmOperatorType *ot) /* -------------------------------------------------------------------- */ +static bool asset_catalogs_save_poll(bContext *C) +{ + if (!asset_catalog_operator_poll(C)) { + return false; + } + + const Main *bmain = CTX_data_main(C); + if (!bmain->name[0]) { + CTX_wm_operator_poll_msg_set(C, "Cannot save asset catalogs before the Blender file is saved"); + return false; + } + + if (!BKE_asset_library_has_any_unsaved_catalogs()) { + CTX_wm_operator_poll_msg_set(C, "No changes to be saved"); + return false; + } + + return true; +} + +static int asset_catalogs_save_exec(bContext *C, wmOperator * /*op*/) +{ + const SpaceFile *sfile = CTX_wm_space_file(C); + ::AssetLibrary *asset_library = ED_fileselect_active_asset_library_get(sfile); + + ED_asset_catalogs_save_from_main_path(asset_library, CTX_data_main(C)); + + WM_event_add_notifier_ex( + CTX_wm_manager(C), CTX_wm_window(C), NC_ASSET | ND_ASSET_CATALOGS, nullptr); + + return OPERATOR_FINISHED; +} + +static void ASSET_OT_catalogs_save(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Save Asset Catalogs"; + ot->description = + "Make any edits to any catalogs permanent by writing the current set up to the asset " + "library"; + ot->idname = "ASSET_OT_catalogs_save"; + + /* api callbacks */ + ot->exec = asset_catalogs_save_exec; + ot->poll = asset_catalogs_save_poll; +} + +/* -------------------------------------------------------------------- */ + void ED_operatortypes_asset(void) { WM_operatortype_append(ASSET_OT_mark); @@ -568,6 +620,7 @@ void ED_operatortypes_asset(void) WM_operatortype_append(ASSET_OT_catalog_new); WM_operatortype_append(ASSET_OT_catalog_delete); + WM_operatortype_append(ASSET_OT_catalogs_save); WM_operatortype_append(ASSET_OT_catalog_undo); WM_operatortype_append(ASSET_OT_catalog_redo); WM_operatortype_append(ASSET_OT_catalog_undo_push); |