diff --git a/source/blender/editors/include/ED_render.hh b/source/blender/editors/include/ED_render.hh index 3a97fad1da5..553d0091046 100644 --- a/source/blender/editors/include/ED_render.hh +++ b/source/blender/editors/include/ED_render.hh @@ -75,7 +75,7 @@ void ED_preview_free_dbase(); /** * Check if \a id is supported by the automatic preview render. */ -bool ED_preview_id_is_supported(const ID *id); +bool ED_preview_id_is_supported(const ID *id, const char **r_disabled_hint = nullptr); void ED_preview_set_visibility(Main *pr_main, Scene *scene, diff --git a/source/blender/editors/render/render_preview.cc b/source/blender/editors/render/render_preview.cc index 920e8bbc1b1..4b65bed6bb1 100644 --- a/source/blender/editors/render/render_preview.cc +++ b/source/blender/editors/render/render_preview.cc @@ -27,6 +27,8 @@ #include "BLI_time.h" #include "BLI_utildefines.h" +#include "BLT_translation.hh" + #include "BLO_readfile.hh" #include "DNA_brush_types.h" @@ -1892,22 +1894,37 @@ static void icon_preview_free(void *customdata) MEM_freeN(ip); } -bool ED_preview_id_is_supported(const ID *id) +bool ED_preview_id_is_supported(const ID *id, const char **r_disabled_hint) { if (id == nullptr) { return false; } - if (GS(id->name) == ID_NT) { - /* Node groups don't support standard preview generation. */ - return false; + + /* Get both the result and the "potential" disabled hint. After that we can decide if the + * disabled hint needs to be returned to the caller. */ + const auto [result, disabled_hint] = [id]() -> std::pair { + switch (GS(id->name)) { + case ID_NT: + return {false, RPT_("Node groups do not support automatic previews")}; + case ID_OB: + return {object_preview_is_type_supported((const Object *)id), + RPT_("Object type does not support automatic previews")}; + case ID_GR: + return { + collection_preview_contains_geometry_recursive((const Collection *)id), + RPT_("Collection does not contain object types that can be rendered for the automatic " + "preview")}; + default: + return {BKE_previewimg_id_get_p(id) != nullptr, + RPT_("Data-block type does not support automatic previews")}; + } + }(); + + if (result == false && disabled_hint && r_disabled_hint) { + *r_disabled_hint = disabled_hint; } - if (GS(id->name) == ID_OB) { - return object_preview_is_type_supported((const Object *)id); - } - if (GS(id->name) == ID_GR) { - return collection_preview_contains_geometry_recursive((const Collection *)id); - } - return BKE_previewimg_id_get_p(id) != nullptr; + + return result; } void ED_preview_icon_render( diff --git a/source/blender/editors/util/ed_util_ops.cc b/source/blender/editors/util/ed_util_ops.cc index fd4aa5a4e5f..1228049df1b 100644 --- a/source/blender/editors/util/ed_util_ops.cc +++ b/source/blender/editors/util/ed_util_ops.cc @@ -60,10 +60,6 @@ static bool lib_id_preview_editing_poll(bContext *C) CTX_wm_operator_poll_msg_set(C, "Data-block does not support previews"); return false; } - if (!ED_preview_id_is_supported(id)) { - CTX_wm_operator_poll_msg_set(C, "Object type does not support previews"); - return false; - } return true; } @@ -147,8 +143,9 @@ static bool lib_id_generate_preview_poll(bContext *C) const PointerRNA idptr = CTX_data_pointer_get(C, "id"); const ID *id = (ID *)idptr.data; - if (GS(id->name) == ID_NT) { - CTX_wm_operator_poll_msg_set(C, "Can't generate automatic preview for node group"); + const char *disabled_hint = nullptr; + if (!ED_preview_id_is_supported(id, &disabled_hint)) { + CTX_wm_operator_poll_msg_set(C, disabled_hint); return false; } @@ -192,7 +189,7 @@ static void ED_OT_lib_id_generate_preview(wmOperatorType *ot) static bool lib_id_generate_preview_from_object_poll(bContext *C) { - if (!lib_id_preview_editing_poll(C)) { + if (!lib_id_generate_preview_poll(C)) { return false; } if (CTX_data_active_object(C) == nullptr) {