Support renaming materials by double clicking them in materials ui

Example - https://imgur.com/a/NXr6Ku2

Which is especially important for non-IfcMaterials as they currently don't have their own editing UI (besides when they are applied to some element).
This commit is contained in:
Andrej730
2024-07-08 14:24:11 +05:00
parent c9989c5f8f
commit c33c19c483
2 changed files with 18 additions and 2 deletions
@@ -119,8 +119,18 @@ def get_contexts(self, context):
return MaterialsData.data["contexts"]
def update_material_name(self: "Material", context: bpy.types.Context) -> None:
ifc_file = tool.Ifc.get()
name = self.name
material = ifc_file.by_id(self.ifc_definition_id)
if material.is_a("IfcMaterialLayerSet"):
material.LayerSetName = name
else:
material.Name = name
class Material(PropertyGroup):
name: StringProperty(name="Name")
name: StringProperty(name="Name", update=update_material_name)
ifc_definition_id: IntProperty(name="IFC Definition ID")
is_category: BoolProperty(name="Is Category", default=False)
is_expanded: BoolProperty(name="Is Expanded", default=False)
@@ -348,6 +348,9 @@ class BIM_PT_object_material(Panel):
class BIM_UL_materials(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
mprops = context.scene.BIMMaterialProperties
material_type = mprops.material_type
if item:
row = layout.row(align=True)
@@ -363,7 +366,10 @@ class BIM_UL_materials(UIList):
row.label(text=item.name)
else:
row.label(text="", icon="BLANK1")
row.label(text=item.name, icon="MATERIAL")
if material_type == "IfcMaterialList":
row.label(text=item.name, icon="MATERIAL")
else:
row.prop(item, "name", text="", icon="MATERIAL", emboss=False)
row2 = row.row()
row2.alignment = "RIGHT"