UI: Gray out or hide asset shelf toggle if not available
The "Asset Shelf" checkbox can be confusing for people, they enable it but it still can't get the shelf to show up. This is because the shelf is only available in certain contexts (e.g. pose mode and paint modes in the 3D view, more is planned see blender/blender#135061). Gray out the toggle with a disabled hint when not available. The region toggle pie menus will hide the item. Pull Request: https://projects.blender.org/blender/blender/pulls/113063
This commit is contained in:
committed by
Julian Eisel
parent
da781fd685
commit
3c3c01a67c
@@ -3553,6 +3553,10 @@ class WM_MT_region_toggle_pie(Menu):
|
||||
continue
|
||||
# In some cases channels exists but can't be toggled.
|
||||
assert hasattr(space_data, attr)
|
||||
|
||||
if space_data.is_property_readonly(attr):
|
||||
continue
|
||||
|
||||
# Technically possible these double-up, in practice this should never happen.
|
||||
if region_type in region_by_type:
|
||||
print("{:s}: Unexpected double-up of region types {!r}".format(cls.__name__, region_type))
|
||||
|
||||
@@ -695,10 +695,10 @@ static StructRNA *rna_Space_refine(PointerRNA *ptr)
|
||||
return &RNA_Space;
|
||||
}
|
||||
|
||||
static ScrArea *rna_area_from_space(PointerRNA *ptr)
|
||||
static ScrArea *rna_area_from_space(const PointerRNA *ptr)
|
||||
{
|
||||
bScreen *screen = (bScreen *)ptr->owner_id;
|
||||
SpaceLink *link = (SpaceLink *)ptr->data;
|
||||
bScreen *screen = reinterpret_cast<bScreen *>(ptr->owner_id);
|
||||
SpaceLink *link = static_cast<SpaceLink *>(ptr->data);
|
||||
return BKE_screen_find_area_from_space(screen, link);
|
||||
}
|
||||
|
||||
@@ -931,6 +931,27 @@ static void rna_Space_show_region_asset_shelf_set(PointerRNA *ptr, bool value)
|
||||
{
|
||||
rna_Space_bool_from_region_flag_set_by_type(ptr, RGN_TYPE_ASSET_SHELF, RGN_FLAG_HIDDEN, !value);
|
||||
}
|
||||
static int rna_Space_show_region_asset_shelf_editable(const PointerRNA *ptr, const char **r_info)
|
||||
{
|
||||
ScrArea *area = rna_area_from_space(ptr);
|
||||
ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_ASSET_SHELF);
|
||||
|
||||
if (!region) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (region->flag & RGN_FLAG_POLL_FAILED) {
|
||||
if (r_info) {
|
||||
*r_info = N_(
|
||||
"The asset shelf is not available in the current context (try changing the active mode "
|
||||
"or tool)");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return PROP_EDITABLE;
|
||||
}
|
||||
|
||||
static void rna_Space_show_region_asset_shelf_update(bContext *C, PointerRNA *ptr)
|
||||
{
|
||||
rna_Space_bool_from_region_flag_update_by_type(C, ptr, RGN_TYPE_ASSET_SHELF, RGN_FLAG_HIDDEN);
|
||||
@@ -3820,7 +3841,18 @@ static void rna_def_space_generic_show_region_toggles(StructRNA *srna, int regio
|
||||
}
|
||||
if (region_type_mask & ((1 << RGN_TYPE_ASSET_SHELF) | (1 << RGN_TYPE_ASSET_SHELF_HEADER))) {
|
||||
region_type_mask &= ~((1 << RGN_TYPE_ASSET_SHELF) | (1 << RGN_TYPE_ASSET_SHELF_HEADER));
|
||||
DEF_SHOW_REGION_PROPERTY(show_region_asset_shelf, "Asset Shelf", "");
|
||||
|
||||
prop = RNA_def_property(srna, "show_region_asset_shelf", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
|
||||
RNA_def_property_boolean_funcs(
|
||||
prop, "rna_Space_show_region_asset_shelf_get", "rna_Space_show_region_asset_shelf_set");
|
||||
RNA_def_property_editable_func(prop, "rna_Space_show_region_asset_shelf_editable");
|
||||
RNA_def_property_ui_text(
|
||||
prop,
|
||||
"Asset Shelf",
|
||||
"Display a region with assets that may currently be relevant (such as "
|
||||
"brushes in paint modes, or poses in Pose Mode)");
|
||||
RNA_def_property_update(prop, 0, "rna_Space_show_region_asset_shelf_update");
|
||||
}
|
||||
BLI_assert(region_type_mask == 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user