Gray out "Asset Shelf" region toggle in menu if none is available #110756
|
@ -27,6 +27,19 @@ class ASSETSHELF_PT_display(Panel):
|
|||
return context.asset_shelf is not None
|
||||
|
||||
|
||||
class Utils:
|
||||
|
||||
"""Class with public utilities."""
|
||||
@staticmethod
|
||||
def has_active_asset_shelf(context):
|
||||
for region in context.area.regions:
|
||||
if region.type != 'ASSET_SHELF':
|
||||
continue
|
||||
|
||||
with context.temp_override(region=region):
|
||||
return hasattr(context, "asset_shelf") and context.asset_shelf is not None
|
||||
return False
|
||||
|
||||
|
||||
classes = (
|
||||
ASSETSHELF_PT_display,
|
||||
)
|
||||
|
|
|
@ -1268,6 +1268,8 @@ class VIEW3D_MT_view(Menu):
|
|||
bl_label = "View"
|
||||
|
||||
def draw(self, context):
|
||||
import bl_ui.asset_shelf as asset_shelf
|
||||
|
||||
layout = self.layout
|
||||
view = context.space_data
|
||||
prefs = context.preferences
|
||||
|
@ -1276,7 +1278,9 @@ class VIEW3D_MT_view(Menu):
|
|||
layout.prop(view, "show_region_ui")
|
||||
layout.prop(view, "show_region_tool_header")
|
||||
if prefs.experimental.use_asset_shelf:
|
||||
layout.prop(view, "show_region_asset_shelf")
|
||||
sub = layout.row()
|
||||
sub.active = asset_shelf.Utils.has_active_asset_shelf(context)
|
||||
sub.prop(view, "show_region_asset_shelf")
|
||||
layout.prop(view, "show_region_hud")
|
||||
|
||||
layout.separator()
|
||||
|
|
|
@ -519,6 +519,10 @@ int ED_asset_shelf_context(const bContext *C, const char *member, bContextDataRe
|
|||
BLI_assert_unreachable();
|
||||
return CTX_RESULT_NO_DATA;
|
||||
}
|
||||
if (shelf_region->flag & RGN_FLAG_POLL_FAILED) {
|
||||
/* Don't return data when the region "doesn't exist" (poll failed). */
|
||||
return CTX_RESULT_NO_DATA;
|
||||
}
|
||||
|
||||
const RegionAssetShelf *shelf_regiondata = RegionAssetShelf::get_from_asset_shelf_region(
|
||||
*shelf_region);
|
||||
|
|
Loading…
Reference in New Issue
This is included in a way which makes it seem like it's intended to be a public function. If other UI code is expected to access this (outside of Blender's own scripts).
Would it be a more general solution to to able to access
region.poll()
or exposeRGN_FLAG_POLL_FAILED
to RNA?This way it's possible to check if regions would be shown without having custom per-region API's.