diff --git a/src/bonsai/bonsai/bim/module/bcf/prop.py b/src/bonsai/bonsai/bim/module/bcf/prop.py index 7a88d29521..9159c57621 100644 --- a/src/bonsai/bonsai/bim/module/bcf/prop.py +++ b/src/bonsai/bonsai/bim/module/bcf/prop.py @@ -30,6 +30,10 @@ from bpy.props import ( FloatVectorProperty, CollectionProperty, ) +from functools import partial +from typing import Literal +from typing_extensions import assert_never +from bcf.agnostic.extensions import get_extensions_attributes bcfviewpoints_enum = None @@ -85,7 +89,11 @@ class BcfReferenceLink(PropertyGroup): class BcfLabel(PropertyGroup): - name: StringProperty(name="Name", update=updateBcfLabel) + name: StringProperty( + name="Name", + update=updateBcfLabel, + search=lambda s, c, t: get_extensions_items(s, c, t, extensions_attr="topic_labels"), + ) def getBcfViewpoints(self, context, force_update=False): @@ -125,18 +133,48 @@ class BcfComment(PropertyGroup): is_editable: BoolProperty(name="Is Editable", default=False, update=updateBcfCommentIsEditable) +def get_extensions_items( + self: "BCFProperties", context: bpy.types.Context, edit_text: str, extensions_attr: str +) -> list[str]: + bcf_file = bcfstore.BcfStore.get_bcfxml() + assert bcf_file + extensions = bcf_file.extensions + if extensions is None: + return [] + + extension_data = getattr(extensions, extensions_attr) + if extension_data is None: + return [] + + attrs = get_extensions_attributes(extensions) + attribute_data = attrs[extensions_attr] + return getattr(extension_data, attribute_data.subattr_name) + + class BcfTopic(PropertyGroup): name: StringProperty(name="GUID") title: StringProperty(default="", name="Title", update=updateBcfTopicName) - type: StringProperty(default="", name="Type") - status: StringProperty(default="", name="Status") - priority: StringProperty(default="", name="Priority") - stage: StringProperty(default="", name="Stage") + type: StringProperty( + default="", name="Type", search=lambda s, c, t: get_extensions_items(s, c, t, extensions_attr="topic_types") + ) + status: StringProperty( + default="", + name="Status", + search=lambda s, c, t: get_extensions_items(s, c, t, extensions_attr="topic_statuses"), + ) + priority: StringProperty( + default="", name="Priority", search=lambda s, c, t: get_extensions_items(s, c, t, extensions_attr="priorities") + ) + stage: StringProperty( + default="", name="Stage", search=lambda s, c, t: get_extensions_items(s, c, t, extensions_attr="stages") + ) creation_date: StringProperty(default="", name="Date") creation_author: StringProperty(default="", name="Author") modified_date: StringProperty(default="", name="Modified Date") modified_author: StringProperty(default="", name="Modified By") - assigned_to: StringProperty(default="", name="Assigned To") + assigned_to: StringProperty( + default="", name="Assigned To", search=lambda s, c, t: get_extensions_items(s, c, t, extensions_attr="users") + ) due_date: StringProperty(default="", name="Due Date") description: StringProperty(default="", name="Topic Description") viewpoints: EnumProperty(items=lambda _, context: getBcfViewpoints(_, context), name="BCF Viewpoints") @@ -163,7 +201,9 @@ class BCFProperties(PropertyGroup): reference_link: StringProperty(default="", name="Reference Link") label: StringProperty(default="", name="Label") bim_snippet_reference: StringProperty(default="", name="Reference") - bim_snippet_type: StringProperty(default="", name="Type") + bim_snippet_type: StringProperty( + default="", name="Type", search=lambda s, c, t: get_extensions_items(s, c, t, extensions_attr="snippet_types") + ) bim_snippet_schema: StringProperty(default="", name="Schema") document_reference: StringProperty(default="", name="Referenced Document") document_reference_description: StringProperty(default="", name="Description") diff --git a/src/bonsai/bonsai/bim/module/bcf/ui.py b/src/bonsai/bonsai/bim/module/bcf/ui.py index d0a77a0ad5..8594944d99 100644 --- a/src/bonsai/bonsai/bim/module/bcf/ui.py +++ b/src/bonsai/bonsai/bim/module/bcf/ui.py @@ -78,18 +78,31 @@ class BIM_PT_bcf(Panel): row.operator("bim.remove_bcf_viewpoint", icon="X", text="") col = layout.column(align=True) - props = ("type", "status", "priority", "stage", "assigned_to", "due_date") - for prop in props: + topic_props = ("type", "status", "priority", "stage", "assigned_to", "due_date") + bl_rna_props = topic.bl_rna.properties + + def draw_prop(prop_name: str) -> None: + row = col.row(align=True) + row.label(text=f"{bl_rna_props[prop_name].name}") + row.label(text=getattr(topic, prop_name)) + + for prop in topic_props: if getattr(topic, prop) or is_editable: - col.prop(topic, prop, emboss=is_editable) + # Can't just use emboss because search= on props is changing + # how they look and adds "ui.button_string_clear" button + # which allows clearing out the string and we don't want to. + if is_editable: + col.prop(topic, prop, emboss=is_editable) + else: + draw_prop(prop) col = layout.column(align=True) if topic.modified_date: - col.prop(topic, "modified_date", emboss=False) - col.prop(topic, "modified_author", emboss=False) + draw_prop("modified_date") + draw_prop("modified_author") else: - col.prop(topic, "creation_date", emboss=False) - col.prop(topic, "creation_author", emboss=False) + draw_prop("creation_date") + draw_prop("creation_author") class BIM_PT_bcf_metadata(Panel):