From ba6cdc967ca461d72a456378e8ef0420f134ee39 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 31 May 2024 12:48:16 +0500 Subject: [PATCH] materials ui - shift+click to expand/contract all categories #4771 --- .../bim/module/material/operator.py | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/material/operator.py b/src/blenderbim/blenderbim/bim/module/material/operator.py index 000aad780f..09bc1e0f87 100644 --- a/src/blenderbim/blenderbim/bim/module/material/operator.py +++ b/src/blenderbim/blenderbim/bim/module/material/operator.py @@ -700,17 +700,28 @@ class EditMaterialSetItem(bpy.types.Operator, tool.Ifc.Operator): class ExpandMaterialCategory(bpy.types.Operator): bl_idname = "bim.expand_material_category" bl_label = "Expand Material Category" + bl_description = "Expand material category.\n\nSHIFT+CLICK to expand all material categories" bl_options = {"REGISTER", "UNDO"} category: bpy.props.StringProperty() + expand_all: bpy.props.BoolProperty(name="Expand All", default=False, options={"SKIP_SAVE"}) + + def invoke(self, context, event): + # Expanding all categories on shift+click. + # Make sure to use SKIP_SAVE on property, otherwise it might get stuck. + if event.type == "LEFTMOUSE" and event.shift: + self.expand_all = True + return self.execute(context) def execute(self, context): props = context.scene.BIMMaterialProperties for index, category in [ - (i, c) for i, c in enumerate(props.materials) - if c.is_category and c.name == self.category + (i, c) + for i, c in enumerate(props.materials) + if c.is_category and (self.expand_all or c.name == self.category) ]: category.is_expanded = True - props.active_material_index = index + if category.name == self.category: + props.active_material_index = index core.load_materials(tool.Material, props.material_type) return {"FINISHED"} @@ -718,17 +729,28 @@ class ExpandMaterialCategory(bpy.types.Operator): class ContractMaterialCategory(bpy.types.Operator): bl_idname = "bim.contract_material_category" bl_label = "Contract Material Category" + bl_description = "Contract material category.\n\nSHIFT+CLICK to contract all material categories" bl_options = {"REGISTER", "UNDO"} category: bpy.props.StringProperty() + contract_all: bpy.props.BoolProperty(name="Contract All", default=False, options={"SKIP_SAVE"}) + + def invoke(self, context, event): + # Contracting all categories on shift+click. + # Make sure to use SKIP_SAVE on property, otherwise it might get stuck. + if event.type == "LEFTMOUSE" and event.shift: + self.contract_all = True + return self.execute(context) def execute(self, context): props = context.scene.BIMMaterialProperties for index, category in [ - (i, c) for i, c in enumerate(props.materials) - if c.is_category and c.name == self.category + (i, c) + for i, c in enumerate(props.materials) + if c.is_category and (self.contract_all or c.name == self.category) ]: category.is_expanded = False - props.active_material_index = index + if category.name == self.category: + props.active_material_index = index core.load_materials(tool.Material, props.material_type) return {"FINISHED"}