Search button now only displays when an enum has more than 10 items

To reduce visual clutter for enums with only a few values
Also tweak the online docs ui function
This commit is contained in:
Gorgious56
2022-10-28 08:33:56 +02:00
parent 5fb7f33fb0
commit 7164103a80
2 changed files with 13 additions and 8 deletions
+5 -4
View File
@@ -118,11 +118,12 @@ def export_attributes(props, callback=None):
def prop_with_search(layout, data, prop_name, **kwargs):
# kwargs are layout.prop arguments (text, icon, etc.)
row = layout.row(align=True)
# Magick courtesy of https://blender.stackexchange.com/a/203443/86891
row.context_pointer_set(name="data", data=data)
row.prop(data, prop_name, **kwargs)
op = row.operator("bim.enum_property_search", text="", icon="VIEWZOOM")
op.prop_name = prop_name
if len(get_enum_items(data, prop_name)) > 10:
# Magick courtesy of https://blender.stackexchange.com/a/203443/86891
row.context_pointer_set(name="data", data=data)
op = row.operator("bim.enum_property_search", text="", icon="VIEWZOOM")
op.prop_name = prop_name
def get_enum_items(data, prop_name, context=None):
+8 -4
View File
@@ -385,10 +385,12 @@ class BIM_PT_misc_object(Panel):
def draw_custom_context_menu(self, context):
layout = self.layout
layout.separator()
# https://blender.stackexchange.com/a/275555/86891
prop_value = getattr(context.button_pointer, context.button_prop.identifier)
prop = context.button_pointer
prop_name = context.button_prop.identifier
prop_value = getattr(prop, prop_name, None)
if prop_value is None:
return
try:
url = get_ifc_entity_doc_url(prop_value)
except KeyError:
@@ -396,5 +398,7 @@ def draw_custom_context_menu(self, context):
pass
else:
if url:
url_op = layout.operator("bim.open_webbrowser", icon="URL", text="Open IFC Documentation")
layout = self.layout
layout.separator()
url_op = layout.operator("bim.open_webbrowser", icon="URL", text="Online IFC Documentation")
url_op.url = url