diff options
author | Julian Eisel <julian@blender.org> | 2021-07-28 18:44:34 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-07-28 19:05:25 +0300 |
commit | 40ef71f465d19892838673cf8375dcc488de4abc (patch) | |
tree | 6df113e330455e7b494ab7c9e7c2d7aba250bf2f /source | |
parent | 0088b412fffb30b585ccd153086f3e85ee6764d2 (diff) |
Assets: Improve error message when "Clear Asset" fails
When using "Clear Asset" from the Asset Browser but with an asset
selected that is not stored in the current file, we can show a more
informative error message.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/asset/intern/asset_ops.cc | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/source/blender/editors/asset/intern/asset_ops.cc b/source/blender/editors/asset/intern/asset_ops.cc index 79edd1f8a6a..30f8bfe554a 100644 --- a/source/blender/editors/asset/intern/asset_ops.cc +++ b/source/blender/editors/asset/intern/asset_ops.cc @@ -169,7 +169,7 @@ class AssetClearHelper { public: void operator()(PointerRNAVec &ids); - void reportResults(ReportList &reports) const; + void reportResults(const bContext *C, ReportList &reports) const; bool wasSuccessful() const; private: @@ -198,10 +198,22 @@ void AssetClearHelper::operator()(PointerRNAVec &ids) } } -void AssetClearHelper::reportResults(ReportList &reports) const +void AssetClearHelper::reportResults(const bContext *C, ReportList &reports) const { if (!wasSuccessful()) { - BKE_report(&reports, RPT_ERROR, "No asset data-blocks selected/focused"); + bool is_valid; + /* Dedicated error message for when there is an active asset detected, but it's not an ID local + * to this file. Helps users better understanding what's going on. */ + if (AssetHandle active_asset = CTX_wm_asset_handle(C, &is_valid); + is_valid && !ED_asset_handle_get_local_id(&active_asset)) { + BKE_report(&reports, + RPT_ERROR, + "No asset data-blocks from the current file selected (assets must be stored in " + "the current file to be able to edit or clear them)"); + } + else { + BKE_report(&reports, RPT_ERROR, "No asset data-blocks selected/focused"); + } } else if (stats.tot_cleared == 1) { /* If only one data-block: Give more useful message by printing asset name. */ @@ -224,7 +236,7 @@ static int asset_clear_exec(bContext *C, wmOperator *op) AssetClearHelper clear_helper; clear_helper(ids); - clear_helper.reportResults(*op->reports); + clear_helper.reportResults(C, *op->reports); if (!clear_helper.wasSuccessful()) { return OPERATOR_CANCELLED; |